updated Api Defaults
This commit is contained in:
@@ -15,9 +15,10 @@ export function FormDisplay<T>({
|
||||
lang,
|
||||
translations,
|
||||
formProps = {},
|
||||
apiUrl,
|
||||
}: FormDisplayProps<T>) {
|
||||
const [enhancedFormProps, setEnhancedFormProps] = useState(formProps);
|
||||
|
||||
|
||||
// Dynamically import schema definitions if provided in formProps
|
||||
useEffect(() => {
|
||||
const loadSchemaDefinitions = async () => {
|
||||
@@ -26,7 +27,7 @@ export function FormDisplay<T>({
|
||||
if (formProps.schemaPath) {
|
||||
// Dynamic import of the schema module
|
||||
const schemaModule = await import(formProps.schemaPath);
|
||||
|
||||
|
||||
// Get the appropriate field definitions based on mode
|
||||
let fieldDefs;
|
||||
if (schemaModule.fieldDefinitions?.getDefinitionsByMode) {
|
||||
@@ -38,7 +39,7 @@ export function FormDisplay<T>({
|
||||
} else if (mode === "view" && schemaModule.viewFieldDefinitions) {
|
||||
fieldDefs = schemaModule.viewFieldDefinitions;
|
||||
}
|
||||
|
||||
|
||||
// Get the appropriate validation schema based on mode
|
||||
let validationSchema;
|
||||
if (mode === "create" && schemaModule.CreateApplicationSchema) {
|
||||
@@ -50,10 +51,10 @@ export function FormDisplay<T>({
|
||||
} else if (schemaModule.ApplicationSchema) {
|
||||
validationSchema = schemaModule.ApplicationSchema;
|
||||
}
|
||||
|
||||
|
||||
// Get the grouped field definitions structure if available
|
||||
const groupedFieldDefs = schemaModule.baseFieldDefinitions || {};
|
||||
|
||||
|
||||
// Update form props with schema information
|
||||
setEnhancedFormProps({
|
||||
...formProps,
|
||||
@@ -67,10 +68,10 @@ export function FormDisplay<T>({
|
||||
console.error("Error loading schema definitions:", error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
loadSchemaDefinitions();
|
||||
}, [formProps, mode, lang]); // Added lang as a dependency to ensure re-fetch when language changes
|
||||
|
||||
|
||||
// Render the appropriate component based on the mode
|
||||
switch (mode) {
|
||||
case "create":
|
||||
@@ -84,6 +85,7 @@ export function FormDisplay<T>({
|
||||
lang={lang}
|
||||
translations={translations}
|
||||
formProps={enhancedFormProps}
|
||||
apiUrl={apiUrl}
|
||||
/>
|
||||
);
|
||||
case "update":
|
||||
@@ -98,6 +100,7 @@ export function FormDisplay<T>({
|
||||
lang={lang}
|
||||
translations={translations}
|
||||
formProps={enhancedFormProps}
|
||||
apiUrl={apiUrl}
|
||||
/>
|
||||
) : null;
|
||||
case "view":
|
||||
|
||||
Reference in New Issue
Block a user