From 78312000ccd05664229ca4771a75a8a2ecb891b2 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Wed, 4 Dec 2024 16:17:55 +0530 Subject: [PATCH] Issue feat:Fix router retention tab issue, undefined rjsf form value, make first letter capital for faciliator center on dashboard --- src/components/CohortSelectionSection.tsx | 2 +- src/components/DynamicForm.tsx | 19 +++++++++++--- src/pages/centers/[cohortId]/index.tsx | 31 ++++++++++++++++++++--- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/components/CohortSelectionSection.tsx b/src/components/CohortSelectionSection.tsx index e1bc9d88..956a19a0 100644 --- a/src/components/CohortSelectionSection.tsx +++ b/src/components/CohortSelectionSection.tsx @@ -648,7 +648,7 @@ const CohortSelectionSection: React.FC = ({ ) : ( - {filteredCohortData[0]?.name} + {toPascalCase(filteredCohortData[0]?.name)} )} diff --git a/src/components/DynamicForm.tsx b/src/components/DynamicForm.tsx index 5032be09..e6b9b594 100644 --- a/src/components/DynamicForm.tsx +++ b/src/components/DynamicForm.tsx @@ -81,7 +81,19 @@ const DynamicForm: React.FC = ({ } onError(errors); }; + const sanitizeFormData = (data: any): any => { + if (Array.isArray(data)) { + return data.map(item => (typeof item === "undefined" ? '' : sanitizeFormData(item))); + } + if (data !== null && typeof data === 'object') { + return Object.fromEntries( + + Object.entries(data)?.map(([key, value]) => [key, value === "undefined" ? "" : sanitizeFormData(value)]) + ); + } + return data; + }; function transformErrors(errors: any) { console.log('errors', errors); console.log('schema', schema); @@ -242,8 +254,9 @@ const DynamicForm: React.FC = ({ } function handleChange(event: any) { - console.log('Form data changed:', event.formData); - onChange(event); + const sanitizedData = sanitizeFormData(event.formData); + console.log('Form data changed:', sanitizedData); + onChange({ ...event, formData: sanitizedData }); } return ( @@ -251,7 +264,7 @@ const DynamicForm: React.FC = ({ { const userStore = useStore(); const isActiveYear = userStore.isActiveYearSelected; + const router = useRouter(); + const [value, setValue] = React.useState(() => { - return isEliminatedFromBuild('Events', 'feature') || !isActiveYear ? 2 : 1; + return isEliminatedFromBuild('Events', 'feature') || !isActiveYear ? 2 : router.query.tab ? Number(router.query.tab) : 1; }); const [showDetails, setShowDetails] = React.useState(false); const [classId, setClassId] = React.useState(''); - const router = useRouter(); const { cohortId }: any = router.query; const { t, i18n } = useTranslation(); const { dir, isRTL } = useDirection(); @@ -400,7 +401,30 @@ const CohortPage = () => { } } }, [extraSessions]); + useEffect(() => { + if (router.isReady) { + const queryParamValue = router.query.tab ? Number(router.query.tab) : 1; + if ([1, 2, 3].includes(queryParamValue)) + setValue(queryParamValue); + else + setValue(1); + } + }, [router.isReady, router.query.tab]); + useEffect(() => { + if (router.isReady) { + const updatedQuery = { ...router.query, tab: value }; + + router.push( + { + pathname: router.pathname, + query: updatedQuery, + }, + undefined, + { shallow: true } + ); + } + }, [value]); const handleEventDeleted = () => { setEventDeleted(true); }; @@ -435,7 +459,8 @@ const CohortPage = () => { }; const handleBackEvent = () => { - window.history.back(); + router.push('/centers'); + // window.history.back(); }; const showDetailsHandle = (dayStr: string) => {