From 6bcb538746b697550ecb4acc65eaa5a42092085a Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Wed, 4 Dec 2024 00:22:10 +0530 Subject: [PATCH] Issue feat: Fix translation issue on rjsf form and reload issue upon cohort creation at master data --- src/components/AddNewCenters.tsx | 4 +- src/components/CommonUserModal.tsx | 5 +- src/components/UserTable.tsx | 1191 ++++++++++++++-------------- src/pages/centers.tsx | 4 +- src/pages/district.tsx | 1 + 5 files changed, 606 insertions(+), 599 deletions(-) diff --git a/src/components/AddNewCenters.tsx b/src/components/AddNewCenters.tsx index 2b387809..914dd69e 100644 --- a/src/components/AddNewCenters.tsx +++ b/src/components/AddNewCenters.tsx @@ -11,7 +11,7 @@ import { Box, Button, Typography } from "@mui/material"; import { IChangeEvent } from "@rjsf/core"; import { RJSFSchema } from "@rjsf/utils"; import React, { useEffect, useState } from "react"; -import { useTranslation } from "next-i18next"; +import { i18n, useTranslation } from "next-i18next"; import { transformArray } from "../utils/Helper"; import AreaSelection from "./AreaSelection"; import { showToastMessage } from "./Toastify"; @@ -152,7 +152,7 @@ const AddNewCenters: React.FC = ({ } }; getAddLearnerFormData(); - }, [cohortFormData]); + }, [cohortFormData,i18n?.language]); const handleDependentFieldsChange = () => { setShowForm(true); diff --git a/src/components/CommonUserModal.tsx b/src/components/CommonUserModal.tsx index 1f852cb0..d294f031 100644 --- a/src/components/CommonUserModal.tsx +++ b/src/components/CommonUserModal.tsx @@ -136,6 +136,7 @@ const CommonUserModal: React.FC = ({ queryFn: () => getFormRead(FormContext.USERS, FormContextType.TEAM_LEADER), staleTime: apiCatchingDuration.GETREADFORM, }); + const { i18n } = useTranslation(); const { data: contentCreatorFormData, @@ -258,7 +259,7 @@ console.log("userType",userType, FormContextType.CONTENT_CREATOR) } }; getAddUserFormData(); - }, [userType, teacherFormData, studentFormData, teamLeaderFormData, contentCreatorFormData]); + }, [userType, teacherFormData, studentFormData, teamLeaderFormData, contentCreatorFormData, i18n.language]); const { getNotification } = useNotification(); const handleSubmit = async ( data: IChangeEvent, @@ -786,6 +787,8 @@ console.log("userType",userType, FormContextType.CONTENT_CREATOR) showErrorList={true} customFields={customFields} formData={formValue} + key={`${i18n.language}`} + > {/* */} diff --git a/src/components/UserTable.tsx b/src/components/UserTable.tsx index c0383537..d483bed3 100644 --- a/src/components/UserTable.tsx +++ b/src/components/UserTable.tsx @@ -1,7 +1,12 @@ import DeleteUserModal from "@/components/DeleteUserModal"; import HeaderComponent from "@/components/HeaderComponent"; import PageSizeSelector from "@/components/PageSelector"; -import { FormContextType, SORT, Status, TelemetryEventType } from "@/utils/app.constant"; +import { + FormContextType, + SORT, + Status, + TelemetryEventType, +} from "@/utils/app.constant"; import DeleteIcon from "@mui/icons-material/Delete"; import EditIcon from "@mui/icons-material/Edit"; import Box from "@mui/material/Box"; @@ -11,25 +16,39 @@ import Typography from "@mui/material/Typography"; import { DataType, SortDirection } from "ka-table/enums"; import { useTranslation } from "next-i18next"; import Image from "next/image"; -import React, { useEffect, useState } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import glass from "../../public/images/empty_hourglass.svg"; import KaTableComponent from "../components/KaTableComponent"; import Loader from "../components/Loader"; import { deleteUser } from "../services/DeleteUser"; import { getCohortList } from "../services/GetCohortList"; -import { userList, getUserDetailsInfo, cohortMemberList } from "../services/UserList"; +import { + userList, + getUserDetailsInfo, + cohortMemberList, +} from "../services/UserList"; import PersonSearchIcon from "@mui/icons-material/PersonSearch"; import { Role, apiCatchingDuration } from "@/utils/app.constant"; import { getFormRead } from "@/services/CreateUserService"; import { showToastMessage } from "./Toastify"; -import { capitalizeFirstLetterOfEachWordInArray , firstLetterInUpperCase} from "../utils/Helper"; -import { getUserTableColumns, getTLTableColumns, getContentCreatorTableColumns } from "@/data/tableColumns"; +import { + capitalizeFirstLetterOfEachWordInArray, + firstLetterInUpperCase, +} from "../utils/Helper"; +import { + getUserTableColumns, + getTLTableColumns, + getContentCreatorTableColumns, +} from "@/data/tableColumns"; import { TablePagination, useMediaQuery } from "@mui/material"; import { Theme } from "@mui/system"; import CommonUserModal from "./CommonUserModal"; import { useQuery } from "@tanstack/react-query"; import ReassignCenterModal from "./ReassignCenterModal"; -import { getCenterList, getStateBlockDistrictList } from "@/services/MasterDataService"; +import { + getCenterList, + getStateBlockDistrictList, +} from "@/services/MasterDataService"; import { updateCohortMemberStatus } from "@/services/CohortService/cohortService"; import useSubmittedButtonStore from "@/utils/useSharedState"; import { useRouter } from "next/router"; @@ -47,13 +66,13 @@ type UserDetails = { state?: any; district?: any; blocks?: any; - stateCode?:any; - districtCode?:any; - blockCode?:any; - centerMembershipIdList?:any; - blockMembershipIdList?:any; - cohortIds?:any; - districtValue?:any + stateCode?: any; + districtCode?: any; + blockCode?: any; + centerMembershipIdList?: any; + blockMembershipIdList?: any; + cohortIds?: any; + districtValue?: any; }; type FilterDetails = { role: any; @@ -62,7 +81,7 @@ type FilterDetails = { states?: any; blocks?: any; name?: any; - cohortId?: any + cohortId?: any; }; interface CenterProp { cohortId: string; @@ -74,8 +93,8 @@ interface Cohort { parentId: string | null; type: string; customField: any[]; - cohortMemberStatus?:string - cohortMembershipId?:string + cohortMemberStatus?: string; + cohortMembershipId?: string; } interface UserTableProps { role: string; @@ -97,8 +116,12 @@ const UserTable: React.FC = ({ }) => { console.log(userType); const [selectedState, setSelectedState] = React.useState([]); - const [blockMembershipIdList, setBlockMembershipIdList] = React.useState([]); - const [centerMembershipIdList, setCenterMembershipIdList] = React.useState([]); + const [blockMembershipIdList, setBlockMembershipIdList] = React.useState< + string[] + >([]); + const [centerMembershipIdList, setCenterMembershipIdList] = React.useState< + string[] + >([]); const router = useRouter(); const store = useStore(); const isActiveYear = store.isActiveYearSelected; @@ -121,14 +144,11 @@ const UserTable: React.FC = ({ const setSelectedCenterStore = useSubmittedButtonStore( (state: any) => state.setSelectedCenterStore ); - const isArchived = useSubmittedButtonStore( - (state: any) => state.isArchived - ); + const isArchived = useSubmittedButtonStore((state: any) => state.isArchived); const setIsArchived = useSubmittedButtonStore( (state: any) => state.setIsArchived ); - const [selectedStateCode, setSelectedStateCode] = useState(""); const [selectedDistrict, setSelectedDistrict] = React.useState([]); const [selectedDistrictCode, setSelectedDistrictCode] = useState(""); @@ -143,15 +163,19 @@ const UserTable: React.FC = ({ const { t } = useTranslation(); const [pageSize, setPageSize] = React.useState("10"); const [sortBy, setSortBy] = useState(["createdAt", "asc"]); - const [sortByForCohortMemberList, setsortByForCohortMemberList] = useState(["name", SORT.ASCENDING]); + const [sortByForCohortMemberList, setsortByForCohortMemberList] = useState([ + "name", + SORT.ASCENDING, + ]); const [statusValue, setStatusValue] = useState(Status.ACTIVE); const [pageCount, setPageCount] = useState(1); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); - const [isReassignCohortModalOpen, setIsReassignCohortModalOpen] = useState(false); + const [isReassignCohortModalOpen, setIsReassignCohortModalOpen] = + useState(false); const [centers, setCenters] = useState([]); const [userName, setUserName] = useState(""); const [blocks, setBlocks] = useState([]); - const [userCohort, setUserCohorts] = useState (""); + const [userCohort, setUserCohorts] = useState(""); const [assignedCenters, setAssignedCenters] = useState(); const [initialized, setInitialized] = useState(false); @@ -165,7 +189,6 @@ const UserTable: React.FC = ({ const [blockCode, setBlockCode] = useState(""); const [districtCode, setDistrictCode] = useState(""); - const [selectedReason, setSelectedReason] = useState(""); const [otherReason, setOtherReason] = useState(""); const [deleteUserState, setDeleteUserState] = useState(false); @@ -174,7 +197,6 @@ const UserTable: React.FC = ({ const [enableCenterFilter, setEnableCenterFilter] = useState(false); - const isMobile: boolean = useMediaQuery((theme: Theme) => theme.breakpoints.down("sm") ); @@ -189,33 +211,49 @@ const UserTable: React.FC = ({ const [userId, setUserId] = useState(); const [submitValue, setSubmitValue] = useState(false); - console.log(selectedBlockCode) + console.log(selectedBlockCode); const reassignButtonStatus = useSubmittedButtonStore( (state: any) => state.reassignButtonStatus ); - const { data:teacherFormData ,isLoading: teacherFormDataLoading, error :teacherFormDataErrror } = useQuery({ - queryKey: ["teacherFormData"], - queryFn: () => Promise.resolve([]), + const { + data: teacherFormData, + isLoading: teacherFormDataLoading, + error: teacherFormDataErrror, + } = useQuery({ + queryKey: ["teacherFormData"], + queryFn: () => Promise.resolve([]), staleTime: apiCatchingDuration.GETREADFORM, - enabled: false, + enabled: false, }); - const {data:studentFormData ,isLoading: studentFormDataLoading, error :studentFormDataErrror} = useQuery({ - queryKey: ["studentFormData"], - queryFn: () => Promise.resolve([]), + const { + data: studentFormData, + isLoading: studentFormDataLoading, + error: studentFormDataErrror, + } = useQuery({ + queryKey: ["studentFormData"], + queryFn: () => Promise.resolve([]), staleTime: apiCatchingDuration.GETREADFORM, - enabled: false, + enabled: false, }); - const { data:teamLeaderFormData ,isLoading: teamLeaderFormDataLoading, error :teamLeaderFormDataErrror } = useQuery({ - queryKey: ["teamLeaderFormData"], - queryFn: () => Promise.resolve([]), + const { + data: teamLeaderFormData, + isLoading: teamLeaderFormDataLoading, + error: teamLeaderFormDataErrror, + } = useQuery({ + queryKey: ["teamLeaderFormData"], + queryFn: () => Promise.resolve([]), staleTime: apiCatchingDuration.GETREADFORM, - enabled: false, + enabled: false, }); - const { data:contentCreatorFormData ,isLoading: contentCreatorFormDataFormDataLoading, error :contentCreatorFormDataErrror } = useQuery({ - queryKey: ["contentCreatorFormData"], - queryFn: () => Promise.resolve([]), + const { + data: contentCreatorFormData, + isLoading: contentCreatorFormDataFormDataLoading, + error: contentCreatorFormDataErrror, + } = useQuery({ + queryKey: ["contentCreatorFormData"], + queryFn: () => Promise.resolve([]), staleTime: apiCatchingDuration.GETREADFORM, - enabled: false, + enabled: false, }); const handleOpenAddLearnerModal = () => { setOpenAddLearnerModal(true); @@ -253,7 +291,6 @@ const UserTable: React.FC = ({ const [filters, setFilters] = useState({ role: role, status: [statusValue], - }); const handleChange = (event: SelectChangeEvent) => { @@ -267,29 +304,27 @@ const UserTable: React.FC = ({ ) => { setPageOffset(value - 1); const windowUrl = window.location.pathname; - const cleanedUrl = windowUrl.replace(/^\//, ''); + const cleanedUrl = windowUrl.replace(/^\//, ""); const env = cleanedUrl.split("/")[0]; - const telemetryInteract = { context: { env: env, cdata: [], }, edata: { - id: 'change-page-number:'+value, + id: "change-page-number:" + value, type: TelemetryEventType.CLICK, - subtype: '', + subtype: "", pageid: cleanedUrl, }, }; telemetryFactory.interact(telemetryInteract); - }; const PagesSelector = () => ( <> - + = ({ /> ); const handleStateChange = async (selected: string[], code: string[]) => { - const newQuery = { ...router.query }; - - if (newQuery.center) { - delete newQuery.center; - } - if (newQuery.district) { + const newQuery = { ...router.query }; + + if (newQuery.center) { + delete newQuery.center; + } + if (newQuery.district) { delete newQuery.district; } - if (newQuery.block) { - delete newQuery.block; - } - router.replace({ - pathname: router.pathname, - query: { - ...newQuery, - state: code?.join(","), - } - }); - setSelectedCenterCode([]) - - setEnableCenterFilter(false) + if (newQuery.block) { + delete newQuery.block; + } + router.replace({ + pathname: router.pathname, + query: { + ...newQuery, + state: code?.join(","), + }, + }); + setSelectedCenterCode([]); + + setEnableCenterFilter(false); setSelectedDistrict([]); setSelectedCenter([]); @@ -340,9 +375,8 @@ const UserTable: React.FC = ({ setSelectedBlockCode(""); setSelectedDistrictCode(""); setSelectedState(selected); - - console.log(selected[0]) + console.log(selected[0]); if (selected[0] === "" || selected[0] === t("COMMON.ALL_STATES")) { if (filters.status) setFilters({ status: [filters.status], role: role }); else setFilters({ role: role }); @@ -354,15 +388,17 @@ const UserTable: React.FC = ({ states: stateCodes, role: role, status: filters.status, - }); else setFilters({ states: stateCodes, role: role }); } console.log("Selected categories:", typeof code[0]); }; - const handleFilterChange = async (event: React.SyntheticEvent, newValue: any) => { - setStatusValue(newValue) + const handleFilterChange = async ( + event: React.SyntheticEvent, + newValue: any + ) => { + setStatusValue(newValue); console.log(newValue); setSelectedFilter(newValue); if (newValue === Status.ACTIVE) { @@ -372,14 +408,12 @@ const UserTable: React.FC = ({ status: [Status.ACTIVE], })); setIsArchived(false); - } else if (newValue === Status.ARCHIVED) { setFilters((prevFilters) => ({ ...prevFilters, status: [Status.ARCHIVED], })); setIsArchived(true); - } else { setIsArchived(false); @@ -388,26 +422,23 @@ const UserTable: React.FC = ({ return { ...restFilters, }; - }); } console.log(filters); - const windowUrl = window.location.pathname; - const cleanedUrl = windowUrl.replace(/^\//, ''); + const cleanedUrl = windowUrl.replace(/^\//, ""); const env = cleanedUrl.split("/")[0]; - const telemetryInteract = { context: { env: env, cdata: [], }, edata: { - id: 'changed-tab-to:'+newValue, + id: "changed-tab-to:" + newValue, type: TelemetryEventType.CLICK, - subtype: '', + subtype: "", pageid: cleanedUrl, }, }; @@ -415,34 +446,32 @@ const UserTable: React.FC = ({ }; const handleDistrictChange = (selected: string[], code: string[]) => { - const newQuery = { ...router.query }; -console.log(selected) + const newQuery = { ...router.query }; + console.log(selected); if (newQuery.center) { - delete newQuery.center; + delete newQuery.center; } if (newQuery.block) { delete newQuery.block; } - - setSelectedCenterCode([]) - setEnableCenterFilter(false) + setSelectedCenterCode([]); + + setEnableCenterFilter(false); setSelectedCenter([]); setSelectedBlock([]); setSelectedDistrict(selected); -setSelectedBlockCode(""); -localStorage.setItem('selectedDistrict', selected[0]) + setSelectedBlockCode(""); + localStorage.setItem("selectedDistrict", selected[0]); -setSelectedDistrictStore(selected[0]) + setSelectedDistrictStore(selected[0]); if (selected[0] === "" || selected[0] === t("COMMON.ALL_DISTRICTS")) { - if (filters.status) { setFilters({ states: selectedStateCode, role: role, status: filters.status, - }); } else { setFilters({ @@ -451,23 +480,23 @@ setSelectedDistrictStore(selected[0]) }); } if (newQuery.district) { - delete newQuery.district; + delete newQuery.district; } router.replace({ pathname: router.pathname, - query: { - ...newQuery, - state: selectedStateCode, - } + query: { + ...newQuery, + state: selectedStateCode, + }, }); } else { router.replace({ pathname: router.pathname, - query: { - ...newQuery, - state: selectedStateCode, - district: code?.join(",") - } + query: { + ...newQuery, + state: selectedStateCode, + district: code?.join(","), + }, }); const districts = code?.join(","); setSelectedDistrictCode(districts); @@ -477,7 +506,6 @@ setSelectedDistrictStore(selected[0]) districts: districts, role: role, status: filters.status, - }); } else { setFilters({ @@ -490,35 +518,33 @@ setSelectedDistrictStore(selected[0]) console.log("Selected categories:", selected); }; const handleBlockChange = (selected: string[], code: string[]) => { - setSelectedCenterCode([]) + setSelectedCenterCode([]); - setEnableCenterFilter(false) - setSelectedCenter([]); - const newQuery = { ...router.query }; + setEnableCenterFilter(false); + setSelectedCenter([]); + const newQuery = { ...router.query }; if (newQuery.center) { - delete newQuery.center; + delete newQuery.center; } if (newQuery.block) { delete newQuery.block; } - console.log(code?.join(",")) - - - + console.log(code?.join(",")); + setSelectedBlock(selected); - localStorage.setItem('selectedBlock', selected[0]) - setSelectedBlockStore(selected[0]) + localStorage.setItem("selectedBlock", selected[0]); + setSelectedBlockStore(selected[0]); if (selected[0] === "" || selected[0] === t("COMMON.ALL_BLOCKS")) { if (newQuery.block) { delete newQuery.block; } router.replace({ pathname: router.pathname, - query: { - ...newQuery, - state: selectedStateCode, - district: selectedDistrictCode, - } + query: { + ...newQuery, + state: selectedStateCode, + district: selectedDistrictCode, + }, }); if (filters.status) { setFilters({ @@ -526,7 +552,6 @@ setSelectedDistrictStore(selected[0]) districts: selectedDistrictCode, role: role, status: filters.status, - }); } else { setFilters({ @@ -538,12 +563,12 @@ setSelectedDistrictStore(selected[0]) } else { router.replace({ pathname: router.pathname, - query: { - ...newQuery, - state: selectedStateCode, - district: selectedDistrictCode, - block: code?.join(",") - } + query: { + ...newQuery, + state: selectedStateCode, + district: selectedDistrictCode, + block: code?.join(","), + }, }); const blocks = code?.join(","); setSelectedBlockCode(blocks); @@ -554,7 +579,6 @@ setSelectedDistrictStore(selected[0]) blocks: blocks, role: role, status: filters.status, - }); } else { setFilters({ @@ -567,60 +591,47 @@ setSelectedDistrictStore(selected[0]) } console.log("Selected categories:", selected); }; - const handleCenterChange = async(selected: string[], code: string[]) => { - if(code[0]) - { -console.log(code[0]) + const handleCenterChange = async (selected: string[], code: string[]) => { + if (code[0]) { + console.log(code[0]); router.replace({ pathname: router.pathname, - query: { - ...router.query, - state: selectedStateCode, - district: selectedDistrictCode, - block: selectedBlockCode, - center: code[0] - } + query: { + ...router.query, + state: selectedStateCode, + district: selectedDistrictCode, + block: selectedBlockCode, + center: code[0], + }, }); + } else { + const newQuery = { ...router.query }; + if (newQuery.center) { + delete newQuery.center; + router.replace({ + ...newQuery, + }); + } } - else - { - const newQuery = { ...router.query }; - if (newQuery.center) { - delete newQuery.center; - router.replace({ - ...newQuery, - - }); - } - - } - - + setSelectedCenterCode([code[0]]); - - - setSelectedCenterCode([code[0]]) - - setSelectedCenter(selected) - localStorage.setItem('selectedCenter',selected[0] ) - setSelectedCenterStore(selected[0]) - console.log(selected[0]) + setSelectedCenter(selected); + localStorage.setItem("selectedCenter", selected[0]); + setSelectedCenterStore(selected[0]); + console.log(selected[0]); if (selected[0] === "" || selected[0] === t("COMMON.ALL_CENTERS")) { - setEnableCenterFilter(false) - setSelectedCenterCode([]) + setEnableCenterFilter(false); + setSelectedCenterCode([]); if (filters.status) { - setFilters({ states: selectedStateCode, districts: selectedDistrictCode, blocks: selectedBlockCode, role: role, status: filters.status, - }); } else { - setFilters({ states: selectedStateCode, districts: selectedDistrictCode, @@ -628,61 +639,55 @@ console.log(code[0]) role: role, }); } - } - else - { - setEnableCenterFilter(true) + } else { + setEnableCenterFilter(true); setFilters({ // states: selectedStateCode, // districts: selectedDistrictCode, // blocks: blocks, - cohortId:code[0], + cohortId: code[0], role: role, - status:[statusValue] + status: [statusValue], }); - } - - - }; const handleSortChange = async (event: SelectChangeEvent) => { // let sort; - console.log(enableCenterFilter) + console.log(enableCenterFilter); if (event.target?.value === "Z-A") { - enableCenterFilter? - setsortByForCohortMemberList(["name", SORT.DESCENDING]): setSortBy(["name", SORT.DESCENDING]); + enableCenterFilter + ? setsortByForCohortMemberList(["name", SORT.DESCENDING]) + : setSortBy(["name", SORT.DESCENDING]); } else if (event.target?.value === "A-Z") { - enableCenterFilter? - setsortByForCohortMemberList(["name", SORT.ASCENDING]): setSortBy(["name", SORT.ASCENDING]); - + enableCenterFilter + ? setsortByForCohortMemberList(["name", SORT.ASCENDING]) + : setSortBy(["name", SORT.ASCENDING]); } else { - enableCenterFilter? setsortByForCohortMemberList(["name", SORT.ASCENDING]): setSortBy(["createdAt", SORT.ASCENDING]); - + enableCenterFilter + ? setsortByForCohortMemberList(["name", SORT.ASCENDING]) + : setSortBy(["createdAt", SORT.ASCENDING]); } setSelectedSort(event.target?.value as string); const windowUrl = window.location.pathname; - const cleanedUrl = windowUrl.replace(/^\//, ''); + const cleanedUrl = windowUrl.replace(/^\//, ""); const env = cleanedUrl.split("/")[0]; - const telemetryInteract = { context: { env: env, cdata: [], }, edata: { - id: 'sort-by:'+event.target?.value, + id: "sort-by:" + event.target?.value, type: TelemetryEventType.CLICK, - subtype: '', + subtype: "", pageid: cleanedUrl, }, }; telemetryFactory.interact(telemetryInteract); - }; const mapFields = (formFields: any, response: any) => { let initialFormData: any = {}; @@ -754,9 +759,8 @@ console.log(code[0]) return initialFormData; }; const handleEdit = async (rowData: any) => { - submitValue ? setSubmitValue(false) : setSubmitValue(true); - setUserName(rowData?.name) + setUserName(rowData?.name); console.log("Edit row:", rowData); @@ -769,11 +773,11 @@ console.log(code[0]) let formFields; if (Role.STUDENT === role) { - // formFields = await getFormRead("USERS", "STUDENT"); + // formFields = await getFormRead("USERS", "STUDENT"); setFormData(mapFields(studentFormData, response)); console.log("mapped formdata", formdata); } else if (Role.TEACHER === role) { - // formFields = await getFormRead("USERS", "TEACHER"); + // formFields = await getFormRead("USERS", "TEACHER"); setFormData(mapFields(teacherFormData, response)); // handleOpenAddFacilitatorModal(); @@ -781,9 +785,7 @@ console.log(code[0]) formFields = await getFormRead("USERS", "TEAM LEADER"); setFormData(mapFields(teamLeaderFormData, response)); // handleOpenAddTeamLeaderModal(); - } - else if(Role.CONTENT_CREATOR === role) - { + } else if (Role.CONTENT_CREATOR === role) { formFields = await getFormRead("USERS", Role.CONTENT_CREATOR); setFormData(mapFields(contentCreatorFormData, response)); } @@ -798,100 +800,88 @@ console.log(code[0]) const handleDelete = (rowData: any) => { setIsDeleteModalOpen(true); - console.log(rowData) - setUserName(rowData?.name) - console.log(userName) + console.log(rowData); + setUserName(rowData?.name); + console.log(userName); - setBlockMembershipIdList(rowData.blockMembershipIdList) - setCenterMembershipIdList(rowData.centerMembershipIdList) + setBlockMembershipIdList(rowData.blockMembershipIdList); + setCenterMembershipIdList(rowData.centerMembershipIdList); setSelectedUserId(rowData.userId); - if(userType===Role.TEAM_LEADERS) - { - setUserCohorts(rowData.blocks) - console.log(userCohort) - - } - else{ - setUserCohorts(rowData.centers) + if (userType === Role.TEAM_LEADERS) { + setUserCohorts(rowData.blocks); + console.log(userCohort); + } else { + setUserCohorts(rowData.centers); } //const userData=""; console.log("Delete row:", rowData.userId); }; - - const handleReassignCohort = async(rowData: any) => { - // setIsDeleteModalOpen(true); - console.log(rowData) - setSelectedUserId(rowData?.userId ); - setUserName(rowData?.name) - - setCohortId(rowData?.cohortIds); - setBlock(rowData?.blocks) - console.log(rowData?.districtValue) - - setDistrict(rowData?.districtValue) - setDistrictCode(rowData?.districtCode) - setBlockCode(rowData?.blockCode) - setAssignedCenters(rowData?.centers) - const reassignUserInfo = { - blocks: rowData?.blocks || [], - districtValue: rowData?.districtValue || '', - districtCode: rowData?.districtCode || '', - blockCode: rowData?.blockCode || '' - }; - localStorage.setItem('reassignuserInfo', JSON.stringify(reassignUserInfo)); - setIsReassignCohortModalOpen(true) + const handleReassignCohort = async (rowData: any) => { + // setIsDeleteModalOpen(true); + console.log(rowData); + setSelectedUserId(rowData?.userId); + setUserName(rowData?.name); - //const userData=""; - try{ - console.log(userType , Role.TEAM_LEADER) - if(userType!=="Team Leaders") - { - - - const getCentersObject = { - limit: 0, - offset: 0, - filters: { - // "type":"COHORT", - status: ["active"], - states: rowData.stateCode, - districts: rowData.districtCode, - blocks: rowData.blockCode - // "name": selected[0] - }, + setCohortId(rowData?.cohortIds); + setBlock(rowData?.blocks); + console.log(rowData?.districtValue); + + setDistrict(rowData?.districtValue); + setDistrictCode(rowData?.districtCode); + setBlockCode(rowData?.blockCode); + setAssignedCenters(rowData?.centers); + const reassignUserInfo = { + blocks: rowData?.blocks || [], + districtValue: rowData?.districtValue || "", + districtCode: rowData?.districtCode || "", + blockCode: rowData?.blockCode || "", }; - const response = await getCenterList(getCentersObject); - const dataArray = response?.result?.results?.cohortDetails; - - const cohortInfo = dataArray - ?.filter((cohort: any) => cohort.type !== "BLOCK") - .map((item: any) => ({ - cohortId: item?.cohortId, - name: item?.name, - })); - setCenters(cohortInfo) - } - else{ + localStorage.setItem("reassignuserInfo", JSON.stringify(reassignUserInfo)); + setIsReassignCohortModalOpen(true); + //const userData=""; + try { + console.log(userType, Role.TEAM_LEADER); + if (userType !== "Team Leaders") { + const getCentersObject = { + limit: 0, + offset: 0, + filters: { + // "type":"COHORT", + status: ["active"], + states: rowData.stateCode, + districts: rowData.districtCode, + blocks: rowData.blockCode, + // "name": selected[0] + }, + }; + const response = await getCenterList(getCentersObject); + const dataArray = response?.result?.results?.cohortDetails; + + const cohortInfo = dataArray + ?.filter((cohort: any) => cohort.type !== "BLOCK") + .map((item: any) => ({ + cohortId: item?.cohortId, + name: item?.name, + })); + setCenters(cohortInfo); + } else { const object = { controllingfieldfk: rowData.districtCode, fieldName: "blocks", }; const response = await getStateBlockDistrictList(object); - //console.log(blockFieldId) + //console.log(blockFieldId) const result = response?.result?.values; - console.log(result) + console.log(result); setBlocks(result); } - - } - catch(error: any) - { - console.log(error) - } + } catch (error: any) { + console.log(error); + } }; const handleSearch = (keyword: string) => { // console.log(filters) @@ -909,32 +899,34 @@ console.log(code[0]) let limit = pageLimit; let offset = pageOffset * limit; // const filters = { role: role , status:"active"}; - const sort = enableCenterFilter? sortByForCohortMemberList: sortBy; + const sort = enableCenterFilter ? sortByForCohortMemberList : sortBy; console.log("filters", filters); if (filters.name) { offset = 0; } let resp; - if(enableCenterFilter) - { - resp=await cohortMemberList({ limit, filters,sort, offset, fields }) - } - else{ + if (enableCenterFilter) { + resp = await cohortMemberList({ + limit, + filters, + sort, + offset, + fields, + }); + } else { resp = await userList({ limit, filters, sort, offset, fields }); - } - if (!resp?.userDetails &&enableCenterFilter) { + if (!resp?.userDetails && enableCenterFilter) { setData([]); //showToastMessage("No data found", "info"); - } - else if(!resp?.getUserDetails) - { + } else if (!resp?.getUserDetails) { setData([]); - - } - const result = enableCenterFilter?resp?.userDetails:resp?.getUserDetails; - console.log(result) - console.log(resp?.totalCount) + } + const result = enableCenterFilter + ? resp?.userDetails + : resp?.getUserDetails; + console.log(result); + console.log(resp?.totalCount); if (resp?.totalCount >= 15) { setPagination(true); @@ -957,8 +949,7 @@ console.log(code[0]) setPageCount(Math.ceil(resp?.totalCount / pageLimit)); console.log(result); let finalResult; - if(enableCenterFilter) - { + if (enableCenterFilter) { finalResult = result?.map((user: any) => { const ageField = user?.customField?.find( (field: any) => field?.label === "AGE" @@ -975,93 +966,101 @@ console.log(code[0]) const stateField = user?.customField?.find( (field: any) => field?.label === "STATES" ); - return { - userId: user?.userId, - username: user?.username, - status: user?.status, - name: - user?.name?.charAt(0).toUpperCase() + - user?.name?.slice(1).toLowerCase(), - role: user.role, - // gender: user.gender, - mobile: user.mobile === "NaN" ? "-" : user.mobile, - age: ageField ? ageField?.value : "-", - district: districtField ? districtField?.value+" , "+firstLetterInUpperCase(blockField?.value) : "-", - state: stateField ? stateField?.value : "-", - blocks: blockField ? firstLetterInUpperCase(blockField?.value) : "-", - gender: genderField - ? genderField?.value?.charAt(0)?.toUpperCase() + - genderField?.value?.slice(1).toLowerCase() - : "-", + return { + userId: user?.userId, + username: user?.username, + status: user?.status, + name: + user?.name?.charAt(0).toUpperCase() + + user?.name?.slice(1).toLowerCase(), + role: user.role, + // gender: user.gender, + mobile: user.mobile === "NaN" ? "-" : user.mobile, + age: ageField ? ageField?.value : "-", + district: districtField + ? districtField?.value + + " , " + + firstLetterInUpperCase(blockField?.value) + : "-", + state: stateField ? stateField?.value : "-", + blocks: blockField + ? firstLetterInUpperCase(blockField?.value) + : "-", + gender: genderField + ? genderField?.value?.charAt(0)?.toUpperCase() + + genderField?.value?.slice(1).toLowerCase() + : "-", // createdAt: user?.createdAt, // updatedAt: user?.updatedAt, - createdBy: user?.createdBy, - updatedBy: user?.updatedBy, - stateCode:stateField?.code, - - districtCode:districtField?.code, - blockCode:blockField?.code, - districtValue:districtField? districtField?.value: "-" - - // // centers: null, - // Programs: null, - }; - - + createdBy: user?.createdBy, + updatedBy: user?.updatedBy, + stateCode: stateField?.code, + + districtCode: districtField?.code, + blockCode: blockField?.code, + districtValue: districtField ? districtField?.value : "-", + + // // centers: null, + // Programs: null, + }; + }); + } else { + finalResult = result?.map((user: any) => { + const ageField = user?.customFields?.find( + (field: any) => field?.label === "AGE" + ); + const genderField = user?.customFields?.find( + (field: any) => field?.label === "GENDER" + ); + const blockField = user?.customFields?.find( + (field: any) => field?.label === "BLOCKS" + ); + const districtField = user?.customFields?.find( + (field: any) => field?.label === "DISTRICTS" + ); + const stateField = user?.customFields?.find( + (field: any) => field?.label === "STATES" + ); + + return { + userId: user.userId, + username: user.username, + status: user.status, + name: + user.name.charAt(0).toUpperCase() + + user.name.slice(1).toLowerCase(), + role: user.role, + // gender: user.gender, + mobile: user.mobile === "NaN" ? "-" : user?.mobile, + age: ageField ? ageField?.value : "-", + district: districtField + ? districtField?.value + + " , " + + firstLetterInUpperCase(blockField?.value) + : "-", + state: stateField ? stateField?.value : "-", + blocks: blockField + ? firstLetterInUpperCase(blockField?.value) + : "-", + gender: genderField + ? genderField.value?.charAt(0)?.toUpperCase() + + genderField.value.slice(1).toLowerCase() + : "-", + createdAt: user.createdAt, + updatedAt: user.updatedAt, + createdBy: user.createdBy, + updatedBy: user.updatedBy, + stateCode: stateField?.code, + districtCode: districtField?.code, + blockCode: blockField?.code, + districtValue: districtField ? districtField?.value : "-", + + // centers: null, + // Programs: null, + }; }); } - else{ - finalResult = result?.map((user: any) => { - const ageField = user?.customFields?.find( - (field: any) => field?.label === "AGE" - ); - const genderField = user?.customFields?.find( - (field: any) => field?.label === "GENDER" - ); - const blockField = user?.customFields?.find( - (field: any) => field?.label === "BLOCKS" - ); - const districtField = user?.customFields?.find( - (field: any) => field?.label === "DISTRICTS" - ); - const stateField = user?.customFields?.find( - (field: any) => field?.label === "STATES" - ); - - - return { - userId: user.userId, - username: user.username, - status: user.status, - name: - user.name.charAt(0).toUpperCase() + - user.name.slice(1).toLowerCase(), - role: user.role, - // gender: user.gender, - mobile: user.mobile === "NaN" ? "-" : user?.mobile, - age: ageField ? ageField?.value : "-", - district: districtField ? districtField?.value+" , "+firstLetterInUpperCase(blockField?.value) : "-", - state: stateField ? stateField?.value : "-", - blocks: blockField ? firstLetterInUpperCase(blockField?.value) : "-", - gender: genderField - ? genderField.value?.charAt(0)?.toUpperCase() + - genderField.value.slice(1).toLowerCase() - : "-", - createdAt: user.createdAt, - updatedAt: user.updatedAt, - createdBy: user.createdBy, - updatedBy: user.updatedBy, - stateCode:stateField?.code, - districtCode:districtField?.code, - blockCode:blockField?.code, - districtValue:districtField? districtField?.value: "-" - - // centers: null, - // Programs: null, - }; - }); - } - console.log(finalResult) + console.log(finalResult); if (filters?.name && resp?.getUserDetails) { const prioritizedResult = finalResult.sort((a: any, b: any) => { @@ -1074,13 +1073,10 @@ console.log(code[0]) }); setData(prioritizedResult); - } else if (resp?.userDetails || resp?.getUserDetails){ + } else if (resp?.userDetails || resp?.getUserDetails) { setData(finalResult); - } - else - { + } else { setData([]); - } setLoading(false); @@ -1096,12 +1092,15 @@ console.log(code[0]) console.log(error); } }; - console.log(data ) - if ((selectedBlockCode !== "") || (selectedDistrictCode !== "" && selectedBlockCode === "") || (userType===Role.TEAM_LEADERS && selectedDistrictCode!=="") ){ + console.log(data); + if ( + selectedBlockCode !== "" || + (selectedDistrictCode !== "" && selectedBlockCode === "") || + (userType === Role.TEAM_LEADERS && selectedDistrictCode !== "") + ) { fetchUserList(); } - // fetchUserList(); - + // fetchUserList(); }, [ pageOffset, submitValue, @@ -1113,9 +1112,9 @@ console.log(code[0]) sortByForCohortMemberList, reassignButtonStatus, enableCenterFilter, - userType + userType, ]); -console.log(selectedBlockStore) + console.log(selectedBlockStore); useEffect(() => { const fetchData = async () => { try { @@ -1129,34 +1128,49 @@ console.log(selectedBlockStore) // (cohort: Cohort) => cohort.name, // ); const cohortNames = response?.result?.cohortData - ?.filter((cohort: Cohort) => cohort.type !== "BLOCK" && cohort?.cohortMemberStatus!=="archived") + ?.filter( + (cohort: Cohort) => + cohort.type !== "BLOCK" && + cohort?.cohortMemberStatus !== "archived" + ) .map((cohort: Cohort) => cohort.name); - const cohortIds = response?.result?.cohortData - ?.filter((cohort: Cohort) => cohort.type !== "BLOCK" && cohort?.cohortMemberStatus!=="archived") - .map((cohort: Cohort) => cohort.cohortId); - - const centerMembershipIdList = response?.result?.cohortData - ?.filter((cohort: Cohort) => cohort.type !== "BLOCK" && cohort?.cohortMemberStatus!=="archived") + const cohortIds = response?.result?.cohortData + ?.filter( + (cohort: Cohort) => + cohort.type !== "BLOCK" && + cohort?.cohortMemberStatus !== "archived" + ) + .map((cohort: Cohort) => cohort.cohortId); + + const centerMembershipIdList = response?.result?.cohortData + ?.filter( + (cohort: Cohort) => + cohort.type !== "BLOCK" && + cohort?.cohortMemberStatus !== "archived" + ) .map((cohort: Cohort) => cohort.cohortMembershipId); - const blockMembershipIdList = response?.result?.cohortData - ?.filter((cohort: Cohort) => cohort.type === "BLOCK" && cohort?.cohortMemberStatus!=="archived") + const blockMembershipIdList = response?.result?.cohortData + ?.filter( + (cohort: Cohort) => + cohort.type === "BLOCK" && + cohort?.cohortMemberStatus !== "archived" + ) .map((cohort: Cohort) => cohort.cohortMembershipId); // const cohortMembershipId=response?.result?.cohortData?.cohortMembershipId; - console.log(blockMembershipIdList) - console.log(cohortIds) - + console.log(blockMembershipIdList); + console.log(cohortIds); let finalArray; if (cohortNames?.length >= 1) { finalArray = capitalizeFirstLetterOfEachWordInArray(cohortNames); } // const finalArray=capitalizeFirstLetterOfEachWordInArray(cohortNames) - console.log(finalArray) + console.log(finalArray); return { ...user, centerMembershipIdList: centerMembershipIdList, blockMembershipIdList: blockMembershipIdList, - cohortIds:cohortIds, + cohortIds: cohortIds, centers: finalArray ? finalArray?.join(" , ") : "-", }; }) @@ -1171,27 +1185,27 @@ console.log(selectedBlockStore) fetchData(); }, [data, cohortsFetched]); -console.log(userType) + console.log(userType); useEffect(() => { - const fetchData = () => { + const fetchData = () => { try { const object = { // "limit": 20, // "offset": 0, fieldName: "states", }; - // const response = await getStateBlockDistrictList(object); - // const result = response?.result?.values; + // const response = await getStateBlockDistrictList(object); + // const result = response?.result?.values; if (typeof window !== "undefined" && window.localStorage) { const admin = localStorage.getItem("adminInfo"); - if(admin) - { - const stateField = JSON.parse(admin).customFields.find((field: any) => field.label === "STATES"); - console.log(stateField.value, stateField.code) - if (!stateField.value.includes(',')) { + if (admin) { + const stateField = JSON.parse(admin).customFields.find( + (field: any) => field.label === "STATES" + ); + console.log(stateField.value, stateField.code); + if (!stateField.value.includes(",")) { setSelectedState([stateField.value]); - setSelectedStateCode(stateField.code) - + setSelectedStateCode(stateField.code); // setFilters({ // states: stateField.code, @@ -1200,14 +1214,14 @@ console.log(userType) // role: role, // status:[statusValue], // } - + // ) // console.log(selectedDistrict) // console.log(selectedBlock) // if( selectedDistrict.length===0 ||selectedDistrict[0]==="All Districts") // { - // const newQuery = { ...router.query }; - + // const newQuery = { ...router.query }; + // if (newQuery.district) { // delete newQuery.district; // } @@ -1221,21 +1235,21 @@ console.log(userType) // console.log(newQuery) // router.replace({ // pathname: router.pathname, - // query: { - // ...newQuery, + // query: { + // ...newQuery, // } // }); - + // } // console.log(selectedBlock) // if( selectedBlock.length===0 ||selectedBlock[0]==="All Blocks") // { - // const newQuery = { ...router.query }; - + // const newQuery = { ...router.query }; + // // if (newQuery.district) { // // delete newQuery.district; // // } - + // if (newQuery.block) { // delete newQuery.block; // } @@ -1245,112 +1259,111 @@ console.log(userType) // } // router.replace({ // pathname: router.pathname, - // query: { - // ...newQuery, + // query: { + // ...newQuery, // } // }); // } - if(userType===Role.CONTENT_CREATOR) - { + if (userType === Role.CONTENT_CREATOR) { setFilters({ states: stateField.code, role: role, - status:[statusValue], - }) - - } - else{ - - if(selectedDistrictCode && selectedDistrict.length!==0 &&selectedDistrict[0]!==t("COMMON.ALL_DISTRICTS") &&userType!==Role.CONTENT_CREATOR) - { - setFilters({ - states: stateField.code, - districts:selectedDistrictCode, - // blocks:selectedBlockCode, - role: role, - status:[statusValue], - }) - } - if(selectedBlockCode && selectedBlock.length!==0 && selectedBlock[0]!==t("COMMON.ALL_BLOCKS") && userType!==Role.CONTENT_CREATOR) - { - setFilters({ - states: stateField.code, - districts:selectedDistrictCode, - blocks:selectedBlockCode, - role: role, - status:[statusValue], - }) - } - - + status: [statusValue], + }); + } else { + if ( + selectedDistrictCode && + selectedDistrict.length !== 0 && + selectedDistrict[0] !== t("COMMON.ALL_DISTRICTS") && + userType !== Role.CONTENT_CREATOR + ) { + setFilters({ + states: stateField.code, + districts: selectedDistrictCode, + // blocks:selectedBlockCode, + role: role, + status: [statusValue], + }); + } + if ( + selectedBlockCode && + selectedBlock.length !== 0 && + selectedBlock[0] !== t("COMMON.ALL_BLOCKS") && + userType !== Role.CONTENT_CREATOR + ) { + setFilters({ + states: stateField.code, + districts: selectedDistrictCode, + blocks: selectedBlockCode, + role: role, + status: [statusValue], + }); + } } } - - + // setStates(object); - } } - // setStates(result); + // setStates(result); } catch (error) { console.log(error); } }; - + fetchData(); }, [selectedBlockCode, selectedDistrictCode, userType]); useEffect(() => { - const fetchData = () => { - // console.log(selectedCenter.length) - if(userType===Role.TEAM_LEADERS || userType===Role.CONTENT_CREATOR) - { + const fetchData = () => { + // console.log(selectedCenter.length) + if (userType === Role.TEAM_LEADERS || userType === Role.CONTENT_CREATOR) { setEnableCenterFilter(false); + } else { + if (selectedCenter.length !== 0) { + if ( + selectedCenter[0] === "" || + selectedCenter[0] === t("COMMON.ALL_CENTERS") + ) { + setEnableCenterFilter(false); + } else { + console.log(selectedCenterCode); - } - else{ - if(selectedCenter.length!==0) - { - if (selectedCenter[0] === "" || selectedCenter[0] === t("COMMON.ALL_CENTERS")) { - - setEnableCenterFilter(false); - - } - else - { - console.log(selectedCenterCode) - - setEnableCenterFilter(true); - - } + setEnableCenterFilter(true); + } //setEnableCenterFilter(true); - if(selectedCenterCode.length!==0) - { - setFilters({ - // states: selectedStateCode, - // districts: selectedDistrictCode, - // blocks: blocks, - cohortId:selectedCenterCode[0], - role: role, - status:[statusValue] - });} - - - } - else{ - setEnableCenterFilter(false) - if(selectedCenterCode.length!==0) - setSelectedCenterCode([]) + if (selectedCenterCode.length !== 0) { + setFilters({ + // states: selectedStateCode, + // districts: selectedDistrictCode, + // blocks: blocks, + cohortId: selectedCenterCode[0], + role: role, + status: [statusValue], + }); + } + } else { + setEnableCenterFilter(false); + if (selectedCenterCode.length !== 0) setSelectedCenterCode([]); } } - - - }; - + fetchData(); }, [selectedCenter, selectedCenterCode]); - console.log(enableCenterFilter) + + + const columns = useMemo(() => { + if (role === Role.TEAM_LEADER) { + return [...getTLTableColumns(t, isMobile, isArchived)]; + } + if (role === Role.CONTENT_CREATOR) { + return getContentCreatorTableColumns(t, isMobile, isArchived); + } + return [...getUserTableColumns(t, isMobile, isArchived)]; + }, [role, t, isMobile, isArchived]); + + console.log(enableCenterFilter); // useEffect(() => { // const { state, district, block, center } = router.query; @@ -1376,11 +1389,11 @@ console.log(userType) // // Handle replacement when only state and district codes are available // if (selectedStateCode!=="" && selectedDistrictCode==="" && selectedBlockCode==="") { // console.log("true") - // const newQuery = { ...router.query }; + // const newQuery = { ...router.query }; // console.log(newQuery) - + // if (newQuery.center) { - // delete newQuery.center; + // delete newQuery.center; // } // if (newQuery.district) { // delete newQuery.district; @@ -1390,88 +1403,85 @@ console.log(userType) // } // router.replace({ // pathname: router.pathname, - // query: { - // ...newQuery, - // state: selectedStateCode, + // query: { + // ...newQuery, + // state: selectedStateCode, // } // }); // } // if (selectedStateCode!=="" && selectedDistrictCode!=="" && selectedBlockCode==="") { - // const newQuery = { ...router.query }; + // const newQuery = { ...router.query }; // console.log(newQuery) - + // if (newQuery.center) { - // delete newQuery.center; + // delete newQuery.center; // } // if (newQuery.block) { // delete newQuery.block; // } // router.replace({ // pathname: router.pathname, - // query: { - // ...newQuery, - // state: selectedStateCode, - // district: selectedDistrictCode + // query: { + // ...newQuery, + // state: selectedStateCode, + // district: selectedDistrictCode // } // }); // } - + // // Handle replacement when state, district, and block codes are available // if (selectedStateCode!=="" && selectedDistrictCode!=="" && selectedBlockCode!=="" && selectedCenter.length === 0) { - // const newQuery = { ...router.query }; - + // const newQuery = { ...router.query }; + // if (newQuery.center) { - // delete newQuery.center; + // delete newQuery.center; // } // if (newQuery.block) { // delete newQuery.block; // } // router.replace({ // pathname: router.pathname, - // query: { - // ...newQuery, - // state: selectedStateCode, - // district: selectedDistrictCode, - // block: selectedBlockCode + // query: { + // ...newQuery, + // state: selectedStateCode, + // district: selectedDistrictCode, + // block: selectedBlockCode // } // }); // } - + // // Handle replacement when state, district, block, and center are all selected // if (selectedStateCode !==""&& selectedDistrictCode!=="" && selectedBlockCode!=="" && selectedCenter.length !== 0) { // console.log("heyyy") - + // console.log(selectedCenter); // if (userType !== Role.TEAM_LEADERS) { // router.replace({ // pathname: router.pathname, - // query: { - // ...router.query, - // state: selectedStateCode, - // district: selectedDistrictCode, - // block: selectedBlockCode, + // query: { + // ...router.query, + // state: selectedStateCode, + // district: selectedDistrictCode, + // block: selectedBlockCode, // center: selectedCenter // } // }); // } // } // }, [selectedStateCode]); - - const handleCloseDeleteModal = () => { setSelectedReason(""); setOtherReason(""); setIsDeleteModalOpen(false); setConfirmButtonDisable(true); - }; const handleCloseReassignModal = () => { // setSelectedReason(""); // setOtherReason(""); setIsReassignCohortModalOpen(false); - setSelectedUserId("") - // setConfirmButtonDisable(true); + setSelectedUserId(""); + // setConfirmButtonDisable(true); }; const handleDeleteUser = async (category: string) => { @@ -1488,54 +1498,46 @@ console.log(userType) if (cohortDeletionResponse) { deleteUserState ? setDeleteUserState(false) : setDeleteUserState(true); } - console.log(blockMembershipIdList) - if(userType===Role.TEAM_LEADERS && blockMembershipIdList.length>0) - { - - blockMembershipIdList.forEach(async(item) => { - - const memberStatus = Status.ARCHIVED; - const statusReason = selectedReason; - const membershipId = item; - - const response = await updateCohortMemberStatus({ - memberStatus, - statusReason, - membershipId, + console.log(blockMembershipIdList); + if (userType === Role.TEAM_LEADERS && blockMembershipIdList.length > 0) { + blockMembershipIdList.forEach(async (item) => { + const memberStatus = Status.ARCHIVED; + const statusReason = selectedReason; + const membershipId = item; + + const response = await updateCohortMemberStatus({ + memberStatus, + statusReason, + membershipId, + }); }); - + } else { + centerMembershipIdList.forEach(async (item) => { + const memberStatus = Status.ARCHIVED; + const statusReason = selectedReason; + const membershipId = item; + + const response = await updateCohortMemberStatus({ + memberStatus, + statusReason, + membershipId, + }); }); } - else{ - centerMembershipIdList.forEach(async(item) => { - - const memberStatus = Status.ARCHIVED; - const statusReason = selectedReason; - const membershipId = item; - - const response = await updateCohortMemberStatus({ - memberStatus, - statusReason, - membershipId, - }); - - }); - } - - console.log(centerMembershipIdList) + console.log(centerMembershipIdList); // const response = await deleteUser(userId, userData); // const memberStatus = Status.ARCHIVED; // const statusReason = selectedReason; // const membershipId = ""; - + // const teacherResponse = await updateCohortMemberStatus({ // memberStatus, // statusReason, // membershipId, // }); - + handleCloseDeleteModal(); showToastMessage(t("COMMON.USER_DELETE_SUCCSSFULLY"), "success"); } catch (error) { @@ -1557,18 +1559,17 @@ console.log(userType) ); - const userProps = { userType: userType, searchPlaceHolder: searchPlaceholder, selectedState: selectedState, selectedDistrict: selectedDistrict, - setSelectedDistrict:setSelectedDistrict, + setSelectedDistrict: setSelectedDistrict, selectedBlock: selectedBlock, - setSelectedBlock:setSelectedBlock, + setSelectedBlock: setSelectedBlock, selectedSort: selectedSort, - statusValue:statusValue, - setStatusValue:setStatusValue, + statusValue: statusValue, + setStatusValue: setStatusValue, handleStateChange: handleStateChange, handleDistrictChange: handleDistrictChange, handleBlockChange: handleBlockChange, @@ -1578,19 +1579,20 @@ console.log(userType) handleSearch: handleSearch, handleAddUserClick: handleAddUserClick, selectedBlockCode: selectedBlockCode, - setSelectedBlockCode:setSelectedBlockCode, + setSelectedBlockCode: setSelectedBlockCode, selectedDistrictCode: selectedDistrictCode, - setSelectedDistrictCode:setSelectedDistrictCode, + setSelectedDistrictCode: setSelectedDistrictCode, selectedStateCode: selectedStateCode, - handleCenterChange:handleCenterChange, - selectedCenter: selectedCenter, - setSelectedCenter:setSelectedCenter, - selectedCenterCode:selectedCenterCode, - setSelectedCenterCode: setSelectedCenterCode, - setSelectedStateCode:setSelectedStateCode, - showAddNew: !!isActiveYear + handleCenterChange: handleCenterChange, + selectedCenter: selectedCenter, + setSelectedCenter: setSelectedCenter, + selectedCenterCode: selectedCenterCode, + setSelectedCenterCode: setSelectedCenterCode, + setSelectedStateCode: setSelectedStateCode, + showAddNew: !!isActiveYear, }; - + + return ( @@ -1606,11 +1608,7 @@ console.log(userType) ) : data?.length !== 0 && loading === false ? ( ) : ( loading === false && @@ -1673,15 +1677,14 @@ console.log(userType) centers={userCohort} userId={selectedUserId} userName={userName} - userType={userType} - + userType={userType} /> - diff --git a/src/pages/centers.tsx b/src/pages/centers.tsx index 421cce76..1ac375c7 100644 --- a/src/pages/centers.tsx +++ b/src/pages/centers.tsx @@ -80,7 +80,7 @@ const Center: React.FC = () => { const store = useStore(); const isActiveYear = store.isActiveYearSelected; - const { t } = useTranslation(); + const { t , i18n} = useTranslation(); const adminInformation = useSubmittedButtonStore( (state: any) => state.adminInformation ); @@ -226,7 +226,7 @@ const Center: React.FC = () => { getAddCenterFormData(); // getCohortMemberlistData(); getAdminInformation(); - }, [cohortFormData]); + }, [cohortFormData, i18n.language]); const fetchUserList = async () => { setLoading(true); diff --git a/src/pages/district.tsx b/src/pages/district.tsx index d8142233..bc28b637 100644 --- a/src/pages/district.tsx +++ b/src/pages/district.tsx @@ -472,6 +472,7 @@ const District: React.FC = () => { if (cohortCreateResponse) { filteredCohortOptionData(); showToastMessage(t("COMMON.DISTRICT_ADDED_SUCCESS"), "success"); + setFetchDistrict(!fetchDistrict); const windowUrl = window.location.pathname; const cleanedUrl = windowUrl.replace(/^\//, ''); const env = cleanedUrl.split("/")[0];