updated components common header layouts

This commit is contained in:
2025-05-03 13:51:02 +03:00
parent 1ce28ec5f0
commit 71c808a5c3
33 changed files with 769 additions and 809 deletions

View File

@@ -19,9 +19,9 @@ export function FormDisplay<T>({
}: FormDisplayProps<T>) {
const [enhancedFormProps, setEnhancedFormProps] = useState(formProps);
// Dynamically import schema definitions if provided in formProps
// Update form props when language or mode changes
useEffect(() => {
const loadSchemaDefinitions = async () => {
const updateFormProps = async () => {
try {
// Check if schemaPath is provided in formProps
if (formProps.schemaPath) {
@@ -40,12 +40,14 @@ export function FormDisplay<T>({
fieldDefs = schemaModule.viewFieldDefinitions;
}
// Get the appropriate validation schema based on mode
// Get the appropriate validation schema based on mode and language
let validationSchema;
if (mode === "create" && schemaModule.CreateApplicationSchema) {
validationSchema = schemaModule.CreateApplicationSchema;
} else if (mode === "update" && schemaModule.UpdateApplicationSchema) {
validationSchema = schemaModule.UpdateApplicationSchema;
if (mode === "create" && schemaModule.getCreateApplicationSchema) {
// Use language-aware schema factory function
validationSchema = schemaModule.getCreateApplicationSchema(lang as "en" | "tr");
} else if (mode === "update" && schemaModule.getUpdateApplicationSchema) {
// Use language-aware schema factory function
validationSchema = schemaModule.getUpdateApplicationSchema(lang as "en" | "tr");
} else if (mode === "view" && schemaModule.ViewApplicationSchema) {
validationSchema = schemaModule.ViewApplicationSchema;
} else if (schemaModule.ApplicationSchema) {
@@ -55,22 +57,40 @@ export function FormDisplay<T>({
// Get the grouped field definitions structure if available
const groupedFieldDefs = schemaModule.baseFieldDefinitions || {};
// Update form props with schema information
// Update form props with schema information and current language
setEnhancedFormProps({
...formProps,
fieldDefinitions: fieldDefs || {},
validationSchema,
fieldsByMode: schemaModule.fieldsByMode || {},
groupedFieldDefinitions: groupedFieldDefs,
// Add current language to force child components to recognize changes
currentLang: lang,
// Add schema path for dynamic imports in child components
schemaPath: formProps.schemaPath
});
} else {
// If no schema path, just update with current language
setEnhancedFormProps({
...formProps,
currentLang: lang
});
}
} catch (error) {
console.error("Error loading schema definitions:", error);
// Even on error, update the language
setEnhancedFormProps({
...formProps,
currentLang: lang
});
}
};
loadSchemaDefinitions();
}, [formProps, mode, lang]); // Added lang as a dependency to ensure re-fetch when language changes
updateFormProps();
}, [formProps, mode, lang]); // Lang dependency ensures re-fetch when language changes
// Debug the props received by FormDisplay
// FormDisplay component renders different form modes based on the mode prop
// Render the appropriate component based on the mode
switch (mode) {
@@ -89,9 +109,12 @@ export function FormDisplay<T>({
/>
);
case "update":
// Create a stable key for the component to ensure proper re-rendering
const updateKey = `update-${lang}-${(initialData as any)?.uu_id || 'new'}`;
return initialData ? (
<UpdateComponent<T>
key={`update-${lang}`} // Add key with lang to force re-render on language change
key={updateKey} // Add key with lang and item ID to force re-render
initialData={initialData}
refetch={refetch}
setMode={setMode}