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,
record?: any,
resourceBasePath: string,
onSubmit: (data: any) => void,
onSubmit?: (data: any) => void,
defaultValue?: any,
children?: ReactNode
card?: boolean
}
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 [schemaLoading, setSchemaLoading] = useState(true);
useEffect(() => {
const fetchSchema = async () => {
try {
const resourceSchema = record === undefined ? await jsonschemaProvider.getCreateResourceSchema(schemaName)
: await jsonschemaProvider.getUpdateResourceSchema(schemaName);
let resourceSchema
if (record === undefined) {
resourceSchema = await jsonschemaProvider.getCreateResourceSchema(schemaName);
} else {
if (card) {
resourceSchema = await jsonschemaProvider.getCardResourceSchema(schemaName);
} else {
resourceSchema = await jsonschemaProvider.getUpdateResourceSchema(schemaName);
}
}
setSchema(resourceSchema);
setSchemaLoading(false);
} catch (error) {