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,
resourceBasePath?: string,
resource: string,
id?: string
onSuccess?: (data: any) => void
id?: string,
onSuccess?: (data: any) => void,
defaultValue?: any
}
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({
resource: resourceBasePath == "" ? resource : `${resourceBasePath}/${resource}`,
@@ -46,7 +47,7 @@ export const CrudForm: React.FC<CrudFormProps> = (props) => {
return <CircularProgress />
}
const record = query?.data?.data;
const record = query?.data?.data || defaultValue;
return (
<BaseForm
schema={schema}

View File

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