From 7023e72460f764369ddbf626128ecf4cac7d4cce Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Wed, 16 Oct 2024 16:40:59 +0530 Subject: [PATCH] Issue feat: Add main branch bug fixes --- public/locales/en/common.json | 5 +++- src/components/AddNewCenters.tsx | 8 ++++++- src/components/FrameworkCategories.tsx | 2 +- src/pages/block.tsx | 9 +++++++ src/pages/centers.tsx | 33 +++++++++++++++----------- src/pages/stateDetails.tsx | 4 ++-- src/utils/Helper.ts | 5 ++++ src/utils/app.constant.ts | 2 ++ src/utils/useSharedState.ts | 3 +++ 9 files changed, 52 insertions(+), 19 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index f7a29224..4b8405a4 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -358,7 +358,10 @@ "LANGUAGE": "Language", "SCIENCE": "Science", "SOCIAL_SCIENCE": "Social Science", - "LIFE_SKILLS": "Life Skills" + "LIFE_SKILLS": "Life Skills", + "BOARD":"Board", + "MEDIUM":"Medium", + "GRADE":"Grade" }, "FORM_ERROR_MESSAGES": { "INVALID_INPUT": "Invalid Input.", diff --git a/src/components/AddNewCenters.tsx b/src/components/AddNewCenters.tsx index cb116f8b..747a70b4 100644 --- a/src/components/AddNewCenters.tsx +++ b/src/components/AddNewCenters.tsx @@ -86,7 +86,12 @@ const AddNewCenters: React.FC = ({ ); const [stateDefaultValueForCenter, setStateDefaultValueForCenter] = useState(""); - + const createCenterStatus = useSubmittedButtonStore( + (state: any) => state.createCenterStatus + ); + const setCreateCenterStatus = useSubmittedButtonStore( + (state: any) => state.setCreateCenterStatus + ); function removeHiddenFields(formResponse: any) { return { ...formResponse, @@ -212,6 +217,7 @@ const AddNewCenters: React.FC = ({ const cohortData = await createCohort(cohortDetails); if (cohortData) { showToastMessage(t("CENTERS.CENTER_CREATED_SUCCESSFULLY"), "success"); + createCenterStatus? setCreateCenterStatus(false):setCreateCenterStatus(true) setOpenAddNewCohort(false); onClose(); localStorage.removeItem("BMGSData"); diff --git a/src/components/FrameworkCategories.tsx b/src/components/FrameworkCategories.tsx index 0aa1b603..e558060f 100644 --- a/src/components/FrameworkCategories.tsx +++ b/src/components/FrameworkCategories.tsx @@ -77,7 +77,7 @@ const FrameworkCategories: React.FC = ({ useEffect(() => { const handleBMGS = async () => { - const userStateName = localStorage.getItem('userStateName'); + const userStateName = localStorage.getItem('stateName'); try { const url = `${process.env.NEXT_PUBLIC_SUNBIRDSAAS_API_URL}/api/framework/v1/read/${frameworkId}`; const boardData = await fetch(url).then((res) => res.json()); diff --git a/src/pages/block.tsx b/src/pages/block.tsx index 79f3c191..34a035f9 100644 --- a/src/pages/block.tsx +++ b/src/pages/block.tsx @@ -276,6 +276,15 @@ const Block: React.FC = () => { } }, [isFirstVisit, searchKeyword, pageLimit, pageOffset, stateCode]); + + useEffect(() => { + if(districtData[0]?.value && isFirstVisit) + { + setSelectedDistrict(districtData[0]?.value); + setIsFirstVisit(false); + } + + }, [districtData]); const fetchBlocks = async () => { try { // const response = await queryClient.fetchQuery({ diff --git a/src/pages/centers.tsx b/src/pages/centers.tsx index 6c15151d..8c1c9861 100644 --- a/src/pages/centers.tsx +++ b/src/pages/centers.tsx @@ -15,6 +15,7 @@ import { CohortTypes, Numbers, QueryKeys, + Role, SORT, Status, Storage, @@ -34,7 +35,7 @@ import { showToastMessage } from "@/components/Toastify"; import AddNewCenters from "@/components/AddNewCenters"; import { getCenterTableData } from "@/data/tableColumns"; import { Theme } from "@mui/system"; -import { firstLetterInUpperCase, mapFields } from "@/utils/Helper"; +import { firstLetterInUpperCase, mapFields , transformLabel} from "@/utils/Helper"; import SimpleModal from "@/components/SimpleModal"; import { IChangeEvent } from "@rjsf/core"; import { RJSFSchema } from "@rjsf/utils"; @@ -42,7 +43,6 @@ import DynamicForm from "@/components/DynamicForm"; import useSubmittedButtonStore from "@/utils/useSharedState"; import { useQueryClient } from "@tanstack/react-query"; import { useRouter } from "next/router"; - type cohortFilterDetails = { type?: string; status?: any; @@ -142,7 +142,12 @@ const Center: React.FC = () => { const setAdminInformation = useSubmittedButtonStore( (state: any) => state.setAdminInformation ); - + const createCenterStatus = useSubmittedButtonStore( + (state: any) => state.createCenterStatus + ); + const setCreateCenterStatus = useSubmittedButtonStore( + (state: any) => state.setCreateCenterStatus + ); const [filters, setFilters] = useState({ type: CohortTypes.COHORT, states: selectedStateCode, @@ -259,8 +264,8 @@ finalResult?.forEach((item: any, index: number) => { createdAt: item?.createdAt, updatedAt: item?.updatedAt, cohortId: item?.cohortId, - customFieldValues: cohortType[0] ? cohortType : "-", - totalActiveMembers: counts?.totalActiveMembers, + customFieldValues: cohortType[0] ? transformLabel(cohortType) : "-", + totalActiveMembers: counts?.totalActiveMembers, totalArchivedMembers: counts?.totalArchivedMembers, }; resultData?.push(requiredData); @@ -333,13 +338,11 @@ const response= await fetchCohortMemberList(data); if (response?.result) { const userDetails = response.result.userDetails; const getActiveMembers = userDetails?.filter( - (member: any) => member?.status === Status.ACTIVE - ); + (member: any) => member?.status === Status.ACTIVE && member?.role === Role.STUDENT ); const totalActiveMembers = getActiveMembers?.length || 0; const getArchivedMembers = userDetails?.filter( - (member: any) => member?.status === Status.ARCHIVED - ); + (member: any) => member?.status === Status.ARCHIVED && member?.role === Role.STUDENT ); const totalArchivedMembers = getArchivedMembers?.length || 0; return { @@ -372,9 +375,11 @@ const response= await fetchCohortMemberList(data); }; useEffect(() => { - fetchUserList(); + if ((selectedBlockCode !== "") || (selectedDistrictCode !== "" && selectedBlockCode === "") ){ + fetchUserList(); + } getFormData(); - }, [pageOffset, pageLimit, sortBy, filters, filters.states, filters.status]); + }, [pageOffset, pageLimit, sortBy, filters, filters.states, filters.status, createCenterStatus]); // handle functions const handleChange = (event: SelectChangeEvent) => { @@ -990,9 +995,9 @@ const response= await fetchCohortMemberList(data); if (urlData) { - router.push( - `learners?state=${urlData.stateCode}&district=${urlData.districtCode}&block=${urlData.blockCode}&status=${urlData.type}` - ); + // router.push( + // `learners?state=${urlData.stateCode}&district=${urlData.districtCode}&block=${urlData.blockCode}&status=${urlData.type}` + // ); } console.log("urlData", urlData); diff --git a/src/pages/stateDetails.tsx b/src/pages/stateDetails.tsx index 26dbf323..f42bedab 100644 --- a/src/pages/stateDetails.tsx +++ b/src/pages/stateDetails.tsx @@ -112,8 +112,8 @@ const StateDetails = () => { - {card.state} - + {tStore.state} + diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index cd68f48d..99086288 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -178,6 +178,11 @@ export const mapFields = (formFields: any, Details: any) => { return field?.value?.toLowerCase(); } } else if (item?.type === InputTypes.RADIO) { + if(field?.value===FormValues?.REGULAR|| field?.value===FormValues?.REMOTE) + { + + return field?.code; + } return field?.value || null; } else if (item?.type === InputTypes.NUMERIC) { return parseInt(String(field?.value)); diff --git a/src/utils/app.constant.ts b/src/utils/app.constant.ts index 0c4b96a0..d9928e27 100644 --- a/src/utils/app.constant.ts +++ b/src/utils/app.constant.ts @@ -79,6 +79,8 @@ export enum CohortTypes { export enum FormValues { FEMALE = "FEMALE", MALE = "MALE", + REGULAR="REGULAR", + REMOTE="REMOTE" } export enum InputTypes { diff --git a/src/utils/useSharedState.ts b/src/utils/useSharedState.ts index dba16d34..194a6ee2 100644 --- a/src/utils/useSharedState.ts +++ b/src/utils/useSharedState.ts @@ -4,6 +4,9 @@ const useSubmittedButtonStore = create((set) => ({ submittedButtonStatus: false, setSubmittedButtonStatus: (status: boolean) => set({ submittedButtonStatus: status }), + createCenterStatus: false, + setCreateCenterStatus: (status: boolean) => + set({ createCenterStatus: status }), reassignButtonStatus: false, setReassignButtonStatus: (status: boolean) => set({ reassignButtonStatus: status }),