BaseCrudPage allows you to quickly create a window with a standard implementation of the CRUD functionality.
import React from 'react';
import Entity from '@entities/Entity'
import BaseCrudPage from '@views/BaseCrudPage';
const MyComponent: React.FC = () = {
return (
<>
<BaseCrudPage
methods={Entity.methods}
fields={Entity.fields}
queryFilter={Entity.queryFilter}
filters={Entity.filters}
table={Entity.table}
forms={Entity.forms}
style={style}
/>
</>
);
};
export default MyComponent;
interface IMethods<T> {
getData: ((...args: any[]) => Promise<AxiosResponse<T[] | IErrorResponse>>) | ((...args: any[]) => void);
getById?: (id: number) => Promise<AxiosResponse<T | IErrorResponse>>;
create?: (body: any) => Promise<AxiosResponse<boolean | IErrorResponse>>;
update?: (id: number, body: any) => Promise<AxiosResponse<boolean | IErrorResponse>>;
delete?: (id: number) => Promise<AxiosResponse<boolean | IErrorResponse>>;
}
interface IEntityField {
[key: string]: {
name: string;
keyName: string;
fieldType?: FieldTypeEnum;
entityName?: EntityNameEnum;
label?: string;
filterableRowName?: string;
rowName?: string;
localFiltering?: boolean;
constName?: string;
};
}
enum FieldType {
DATEPICKER,
SELECT,
CHECKBOX,
RADIO,
INPUT,
COMPONENT,
}
interface IQueryFilter {
parameters: {
name: string;
type: PaginationParams;
defaultValue?: string | number;
required?: boolean;
}[];
}
enum PaginationParams {
OFFSET = 'offset',
LIMIT = 'limit',
SORT_BY = 'sortBy',
SORT_ORDER = 'sortOrder',
}
interface IEntityFilter {
filterFields: IFilterField[];
onSave: (...args: any) => void;
}
interface IEntityTable {
type: TableType;
tableFields: ITableField[];
actions?: IAction[];
footFields?: ITableFooterField[];
limit?: number;
rowClick?: (itemId?: number | string) => void;
style?: React.CSSProperties;
nodeStyle?: React.CSSProperties;
}
interface IEntityForm {
[key: string]: {
formFields: IFormField[];
};
}