Skip to content

Commit

Permalink
Merge pull request #498 from AkshataKatwal16/reassign-cohorts
Browse files Browse the repository at this point in the history
Issue feat:Fix router retention  tab issue, undefined rjsf form value, make first letter capital for faciliator center on dashboard
  • Loading branch information
itsvick authored Dec 4, 2024
2 parents 093cb4e + 7831200 commit 63895ca
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/CohortSelectionSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ const CohortSelectionSection: React.FC<CohortSelectionSectionProps> = ({
</FormControl>
) : (
<Typography color={theme.palette.warning['300']}>
{filteredCohortData[0]?.name}
{toPascalCase(filteredCohortData[0]?.name)}
</Typography>
)}
</>
Expand Down
19 changes: 16 additions & 3 deletions src/components/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
}
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);
Expand Down Expand Up @@ -242,16 +254,17 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
}

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 (
<div className="form-parent">
<FormWithMaterialUI
schema={schema}
uiSchema={uiSchema}
formData={formData}
formData={sanitizeFormData(formData)}
onChange={handleChange}
onSubmit={onSubmit}
validator={validator}
Expand Down
31 changes: 28 additions & 3 deletions src/pages/centers/[cohortId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ if (!isEliminatedFromBuild('Schedule', 'component')) {
const CohortPage = () => {
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();
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -435,7 +459,8 @@ const CohortPage = () => {
};

const handleBackEvent = () => {
window.history.back();
router.push('/centers');
// window.history.back();
};

const showDetailsHandle = (dayStr: string) => {
Expand Down

0 comments on commit 63895ca

Please sign in to comment.