Adding the injection of a default value in the form

This commit is contained in:
2025-04-23 00:06:23 +02:00
parent 9d835d49d9
commit e01430f60e
2 changed files with 9 additions and 6 deletions

View File

@@ -10,12 +10,13 @@ type CrudFormProps = {
uiSchema?: UiSchema, uiSchema?: UiSchema,
resourceBasePath?: string, resourceBasePath?: string,
resource: string, resource: string,
id?: string id?: string,
onSuccess?: (data: any) => void onSuccess?: (data: any) => void,
defaultValue?: any
} }
export const CrudForm: React.FC<CrudFormProps> = (props) => { export const CrudForm: React.FC<CrudFormProps> = (props) => {
const { schemaName, uiSchema, resourceBasePath="" ,resource, id, onSuccess } = props; const { schemaName, uiSchema, resourceBasePath="" ,resource, id, onSuccess, defaultValue } = props;
const { onFinish, query, formLoading } = useForm({ const { onFinish, query, formLoading } = useForm({
resource: resourceBasePath == "" ? resource : `${resourceBasePath}/${resource}`, resource: resourceBasePath == "" ? resource : `${resourceBasePath}/${resource}`,
@@ -46,7 +47,7 @@ export const CrudForm: React.FC<CrudFormProps> = (props) => {
return <CircularProgress /> return <CircularProgress />
} }
const record = query?.data?.data; const record = query?.data?.data || defaultValue;
return ( return (
<BaseForm <BaseForm
schema={schema} schema={schema}

View File

@@ -7,10 +7,11 @@ type NewProps = {
resource: string, resource: string,
schemaName: string, schemaName: string,
uiSchema?: UiSchema, uiSchema?: UiSchema,
defaultValue?: any
} }
const New = <T,>(props: NewProps) => { const New = <T,>(props: NewProps) => {
const { schemaName, resource, uiSchema } = props; const { schemaName, resource, uiSchema, defaultValue } = props;
const { currentFirm } = useContext(FirmContext); const { currentFirm } = useContext(FirmContext);
const resourceBasePath = `firm/${currentFirm.instance}/${currentFirm.firm}` const resourceBasePath = `firm/${currentFirm.instance}/${currentFirm.firm}`
@@ -20,7 +21,8 @@ const New = <T,>(props: NewProps) => {
uiSchema={uiSchema} uiSchema={uiSchema}
resourceBasePath={resourceBasePath} resourceBasePath={resourceBasePath}
resource={resource} resource={resource}
/> defaultValue={defaultValue}
/>
) )
} }