diff --git a/src/components/LearnersListItem.tsx b/src/components/LearnersListItem.tsx index 7b80cea8..23547689 100644 --- a/src/components/LearnersListItem.tsx +++ b/src/components/LearnersListItem.tsx @@ -119,7 +119,7 @@ const LearnersListItem: React.FC = ({ setCenters(centers); setCentersName(centersName); - }, [reloadState, setReloadState]); + }, [reloadState, setReloadState, userStore.cohorts]); const toggleDrawer = (anchor: Anchor, open: boolean) => @@ -366,7 +366,7 @@ const LearnersListItem: React.FC = ({ t('MANAGE_USERS.CENTERS_REASSIGNED_SUCCESSFULLY'), 'success' ); - setReloadState(true); + setReloadState(!reloadState); } catch (error) { console.error('Error creating cohort members', error); showToastMessage(t('MANAGE_USERS.CENTERS_REQUEST_FAILED'), 'error'); diff --git a/src/components/ManageCentersModal.tsx b/src/components/ManageCentersModal.tsx index f3c49835..d8b22458 100644 --- a/src/components/ManageCentersModal.tsx +++ b/src/components/ManageCentersModal.tsx @@ -88,7 +88,7 @@ const ManageCentersModal: React.FC = ({ }; const handleRadioChange = (name: string, cohortId: string) => { - setSelectedValue(name); + setSelectedValue(name.toLowerCase()); setCohortId(cohortId); }; @@ -192,7 +192,7 @@ const ManageCentersModal: React.FC = ({ {isForLearner ? ( handleRadioChange(center?.name, center?.cohortId) } diff --git a/src/components/ReassignModal.tsx b/src/components/ReassignModal.tsx index 2440bc29..326d7c45 100644 --- a/src/components/ReassignModal.tsx +++ b/src/components/ReassignModal.tsx @@ -48,6 +48,7 @@ const ReassignModal: React.FC = ({ reloadState, setReloadState, }) => { + console.log("ReassignModal") const theme = useTheme(); const { t } = useTranslation(); const store = useStore(); diff --git a/src/components/center/CreateCenterModal.tsx b/src/components/center/CreateCenterModal.tsx index e7a91c97..b13f8ac1 100644 --- a/src/components/center/CreateCenterModal.tsx +++ b/src/components/center/CreateCenterModal.tsx @@ -17,6 +17,8 @@ import { showToastMessage } from '../Toastify'; import FrameworkCategories from './FrameworkCategories'; import { telemetryFactory } from '@/utils/telemetry'; import { useQueryClient } from '@tanstack/react-query'; +import { getCohortList } from '@/services/CohortServices'; +import useStore from '@/store/store'; interface CreateBlockModalProps { open: boolean; handleClose: () => void; @@ -32,6 +34,21 @@ interface CohortDetails { parentId: string | null; customFields: CustomField[]; } +interface ChildData { + cohortId: string; + name: string; + parentId: string; + type: string; + customField: any[]; + childData: ChildData[]; + status?: string; +} +interface NameTypePair { + cohortId: string; + name: string; + cohortType: string; + status?: string; +} const CreateCenterModal: React.FC = ({ open, handleClose, @@ -45,6 +62,7 @@ const CreateCenterModal: React.FC = ({ const [showForm, setShowForm] = useState(false); const [isHiddenFieldPresent, setIsHiddenFieldPresent] = useState(false); const queryClient = useQueryClient(); + const setCohorts = useStore((state) => state.setCohorts); const { data: formResponse, isPending } = useFormRead( FormContext.COHORTS, @@ -89,6 +107,33 @@ const CreateCenterModal: React.FC = ({ setFormData(data.formData); }); }; + const extractNamesAndCohortTypes = ( + data: ChildData[] + ): NameTypePair[] => { + const nameTypePairs: NameTypePair[] = []; + const recursiveExtract = (items: ChildData[]) => { + items.forEach((item) => { + const cohortType = + item?.customField?.find( + (field) => field?.label === 'TYPE_OF_COHORT' + )?.value || 'Unknown'; + if (item?.cohortId && item?.name) { + nameTypePairs.push({ + cohortId: item?.cohortId, + name: item?.name, + status: item?.status, + cohortType, + }); + } + if (item?.childData && item?.childData?.length > 0) { + recursiveExtract(item?.childData); + } + }); + }; + recursiveExtract(data); + return nameTypePairs; + }; + useEffect(() => { if (formData) { handleButtonClick(); @@ -160,6 +205,14 @@ const CreateCenterModal: React.FC = ({ queryClient.invalidateQueries({ queryKey: [QueryKeys.MY_COHORTS, userId], }); + const myCohortList = await queryClient.fetchQuery({ + queryKey: [QueryKeys.MY_COHORTS, userId], + queryFn: () => getCohortList(userId as string, { customField: 'true' }), + }); + if (myCohortList?.length > 0) { + const nameTypePairs = extractNamesAndCohortTypes(myCohortList); + setCohorts(nameTypePairs); + } const telemetryInteract = { context: { env: 'teaching-center', diff --git a/src/components/center/centerList.tsx b/src/components/center/centerList.tsx index 804b8a75..9f82360c 100644 --- a/src/components/center/centerList.tsx +++ b/src/components/center/centerList.tsx @@ -64,7 +64,7 @@ const CenterList: React.FC = ({ onClick={() => { router.push(`/centers/${center?.cohortId}`); localStorage.setItem('classId', center?.cohortId); - localStorage.setItem('className', center?.cohortName); + localStorage.setItem('className', center?.cohortName?.toLowerCase()); }} sx={{ cursor: 'pointer',