Allowing crud forms with card format (showing read only fields)

This commit is contained in:
2025-05-03 18:27:16 +02:00
parent 78ffcb9b71
commit f03f8374c8

View File

@@ -10,21 +10,30 @@ type CrudFormProps = {
uiSchema?: UiSchema, uiSchema?: UiSchema,
record?: any, record?: any,
resourceBasePath: string, resourceBasePath: string,
onSubmit: (data: any) => void, onSubmit?: (data: any) => void,
defaultValue?: any, defaultValue?: any,
children?: ReactNode children?: ReactNode
card?: boolean
} }
export const CrudForm: React.FC<CrudFormProps> = (props) => { export const CrudForm: React.FC<CrudFormProps> = (props) => {
const { schemaName, uiSchema, record, resourceBasePath, defaultValue, children, onSubmit } = props; const { schemaName, uiSchema, record, resourceBasePath, defaultValue, children, onSubmit=(data: any) => {}, card=false } = props;
const [schema, setSchema] = useState({}); const [schema, setSchema] = useState({});
const [schemaLoading, setSchemaLoading] = useState(true); const [schemaLoading, setSchemaLoading] = useState(true);
useEffect(() => { useEffect(() => {
const fetchSchema = async () => { const fetchSchema = async () => {
try { try {
const resourceSchema = record === undefined ? await jsonschemaProvider.getCreateResourceSchema(schemaName) let resourceSchema
: await jsonschemaProvider.getUpdateResourceSchema(schemaName); if (record === undefined) {
resourceSchema = await jsonschemaProvider.getCreateResourceSchema(schemaName);
} else {
if (card) {
resourceSchema = await jsonschemaProvider.getCardResourceSchema(schemaName);
} else {
resourceSchema = await jsonschemaProvider.getUpdateResourceSchema(schemaName);
}
}
setSchema(resourceSchema); setSchema(resourceSchema);
setSchemaLoading(false); setSchemaLoading(false);
} catch (error) { } catch (error) {