From c1d2549c3ac9ec983c724f63e0c559b51d320c62 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Tue, 24 Sep 2024 13:32:31 +0530 Subject: [PATCH 1/8] Issue feat PS-2043: Add confirmation modal while reassigning block having already assigned TL --- public/locales/en/common.json | 5 +- src/components/CustomModal.tsx | 6 +- src/components/DeleteUserModal.tsx | 1 + src/components/ReassignCenterModal.tsx | 267 ++++++++++++++++++++++++- src/services/UserList.ts | 4 +- 5 files changed, 268 insertions(+), 15 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index ec231b01..c13c5c33 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -126,7 +126,10 @@ "NO_BLOCK_AVAILABLE": "No blocks available", "PLEASE_SELECT_BLOCK_LIST": "Please select block from block list", "ALL_CENTERS": "All centers", - "NO_CENTERS": "No centers" + "NO_CENTERS": "No centers", + "MULTIPLE_TEAM_LEADERS_ASSIGNED": "Selected block {{selectedBlockForTL}} already has {{assignedTeamLeader}} Team Leaders assigned.", + "SINGLE_TEAM_LEADERS_ASSIGNED":"Selected block {{selectedBlockForTL}} already has {{assignedTeamLeader}} Team Leader assigned.", + "CONTINUE_ASSIGNED_TEAM_LEADER":"Still do you want to continue to assign team leader to {{selectedBlockForTL}}" }, "LOGIN_PAGE": { "USERNAME": "Username", diff --git a/src/components/CustomModal.tsx b/src/components/CustomModal.tsx index 18f00c94..2dd3d161 100644 --- a/src/components/CustomModal.tsx +++ b/src/components/CustomModal.tsx @@ -15,7 +15,7 @@ import CloseIcon from "@mui/icons-material/Close"; interface CustomModalProps { open: boolean; handleClose: () => void; - title: string; + title?: string; subtitle?: string; primaryBtnText: string; secondaryBtnText?: string; @@ -25,6 +25,7 @@ interface CustomModalProps { backdropClose?: boolean; primaryBtnDisabled?: boolean; children: React.ReactNode; + width?:string } const CustomModal: React.FC = ({ @@ -40,6 +41,7 @@ const CustomModal: React.FC = ({ backdropClose = true, primaryBtnDisabled = true, children, + width }) => { // const isSmallScreen = useMediaQuery((theme: Theme) => // theme.breakpoints.down("sm"), @@ -61,7 +63,7 @@ const CustomModal: React.FC = ({ top: "50%", left: "50%", transform: "translate(-50%, -50%)", - width: isSmallScreen ? "90%" : isLargeScreen ? "65%" : "85%", + width: isSmallScreen ? "90%" : isLargeScreen ? width : "85%", maxWidth: "90%", bgcolor: "background.paper", boxShadow: 24, diff --git a/src/components/DeleteUserModal.tsx b/src/components/DeleteUserModal.tsx index 2103d2f8..c873e360 100644 --- a/src/components/DeleteUserModal.tsx +++ b/src/components/DeleteUserModal.tsx @@ -86,6 +86,7 @@ const DeleteUserModal: React.FC = ({ return ( = ({ open, onClose, @@ -59,6 +68,7 @@ const ReassignCenterModal: React.FC = ({ centers }) => { + console.log(userId) const { t } = useTranslation(); const theme = useTheme(); const roleType = userType; @@ -110,8 +120,29 @@ const { (state: any) => state.reassignButtonStatus ); console.log(names); - + // const [filters, setFilters] = useState({ + // // cohortId:selectedBlockCohortId, + // role: Role.TEAM_LEADER, + // status:[Status.ACTIVE] + + // }); const [searchInput, setSearchInput] = useState(""); + const [reassignAlertModal, setReassignAlertModal] = useState(false); + const [assignedTeamLeader, setAssignedTeamLeader] = useState(""); + const [selectedBlockForTL, setSelectedBlockForTL] = useState(""); + const [assignedTeamLeaderNames, setAssignedTeamLeaderNames] = useState([]); + const [confirmButtonDisable, setConfirmButtonDisable] = useState(true); + const [checkedConfirmation, setCheckedConfirmation] = useState(false); + const [selectedBlockCohortIdForTL, setSelectedBlockCohortIdForTL] = useState(""); + const [selectedTLUserID, setSelectedTLUserID] = useState(userId); + + + // const [reassignOpen, setReassignOpen] = useState(false); + + + + + //const [selectedBlockId, setselectedBlockId] = useState(blockName); @@ -261,6 +292,8 @@ const { "success" ); } else { + + const reassignBlockObject = { limit: 200, offset: 0, @@ -275,15 +308,46 @@ const { const selectedBlockCohortId = cohortDetails?.find( (item: any) => item?.type === "BLOCK" )?.cohortId; - - if (!selectedBlockCohortId) { + setSelectedBlockCohortIdForTL(selectedBlockCohortId) + // setFilters({ + // cohortId:selectedBlockCohortId, + // role: Role.TEAM_LEADER, + // status:[Status.ACTIVE]} + // ) +const filters: FilterDetails= +{ + cohortId:selectedBlockCohortId, + role: Role.TEAM_LEADER, + status:[Status.ACTIVE]} +console.log(filters) + let limit=200; + let offset=0; + let sort= ["name", "asc"] + let resp; + try { + resp = await cohortMemberList({ limit, filters, sort, offset }); + } catch (apiError) { + console.log("API call failed, proceeding to else block"); + resp = null; + } + if (!selectedBlockCohortId) { showToastMessage( t("COMMON.COHORT_ID_NOT_FOUND", { block: checkedCenters[0] }), "info" ); return; } - + if(resp?.userDetails) + { + handleClose(); + setReassignAlertModal(true) + setAssignedTeamLeader(resp?.userDetails?.length) + setSelectedBlockForTL(checkedCenters[0]) + const userNames = resp?.userDetails?.map((user: any )=> user.name); + setSelectedTLUserID(userId) + setAssignedTeamLeaderNames(userNames) + } + else{ const previousBlockObject = { limit: 200, offset: 0, @@ -355,9 +419,10 @@ const { "success" ); reassignButtonStatus ? setReassignButtonStatus(false) : setReassignButtonStatus(true); - + } } } catch (error) { + console.log(error) showToastMessage( t( userType === Role.TEAM_LEADERS @@ -414,12 +479,123 @@ console.log(formattedBlocks) setCheckedCenters([centerName]); } }; - - console.log(filteredCohorts) + const handleChange = (event: React.ChangeEvent) => { + setCheckedConfirmation(event.target.checked); + + }; + + const wrappedHandleReassignAction = async () => { + try{ + console.log(selectedTLUserID) + // await handleDeleteAction(); + const previousBlockObject = { + limit: 200, + offset: 0, + filters: { + status: ["active"], + name: blockName, + }, + }; + const previousResponse = await getCenterList(previousBlockObject); + const previousCohortDetails = previousResponse?.result?.results?.cohortDetails; + const previousBlockId = previousCohortDetails?.find( + (item: any) => item?.type === "BLOCK" + )?.cohortId; + +let unSelectedBlockCohortIds: string[] = []; + +console.log(previousBlockId) +unSelectedBlockCohortIds.push(previousBlockId); +let cohortIds = blocks +.filter((item:any) => item.label !== selectedBlockForTL) +.map((item:any) => item.cohortId); +cohortIds.push(previousBlockId) + const payload = { + userId: [selectedTLUserID], + cohortId: [selectedBlockCohortIdForTL], + removeCohortId:cohortIds, + }; + + await bulkCreateCohortMembers(payload); + handleClose(); + + const userDetails = await getUserDetailsInfo(selectedTLUserID); + const blockField = userDetails?.userData?.customFields.find( + (field: any) => field.label === "BLOCKS" + ); + const selectedCenterCode = filteredCBlocks.find(location => location.label === selectedBlockForTL)?.value; + let customFields = [ + { + fieldId: blockField.fieldId, + value: selectedCenterCode, + }, + ]; + console.log(selectedBlockCode,selectedBlockForTL) + if(selectedDistrict[0]!==districtName) + { + customFields = [ + { + fieldId: blockField.fieldId, + value: selectedCenterCode, + }, + { + fieldId: districtFieldId, + value: selectedDistrictCode, + }, + ]; + } + const updateObject = { + userData: {}, + customFields: customFields, + }; + if (selectedTLUserID) { + + await updateUser(selectedTLUserID, updateObject); + } + + showToastMessage( + t("COMMON.BLOCKS_REASSIGN_SUCCESSFULLY"), + "success" + ); + reassignButtonStatus ? setReassignButtonStatus(false) : setReassignButtonStatus(true); + } + catch(error) + { + console.log(error) + showToastMessage( + t("COMMON.SOMETHING_WENT_WRONG"), + "error" + ); + } + +finally{ handleCloseConfirmation(); +} + }; + const handleCancelAction = async () => { + // await handleDeleteAction(); + handleCloseConfirmation(); + }; + const handleCloseConfirmation= () => { + // await handleDeleteAction(); + // handleCloseConfirmation(); + setReassignAlertModal(false) + setCheckedConfirmation(false); + setConfirmButtonDisable(true) + }; + + + useEffect(() => { + if (checkedConfirmation) { + setConfirmButtonDisable(false); + } else { + setConfirmButtonDisable(true); + } + }, [checkedConfirmation]); return ( <> + { ( + + + +{assignedTeamLeaderNames.length>1 ?( + <> + {t('COMMON.MULTIPLE_TEAM_LEADERS_ASSIGNED', { selectedBlockForTL: selectedBlockForTL,assignedTeamLeader: assignedTeamLeader})} + + + ):(<> + + {t('COMMON.SINGLE_TEAM_LEADERS_ASSIGNED', { selectedBlockForTL: selectedBlockForTL,assignedTeamLeader: assignedTeamLeader})} + + ) +} + + + + {assignedTeamLeaderNames.length>1 ?( + <>{assignedTeamLeaderNames[0]} and more.. + ):(<> + {assignedTeamLeaderNames[0]} + ) + + } + + + } + label={ t('COMMON.CONTINUE_ASSIGNED_TEAM_LEADER', {selectedBlockForTL: selectedBlockForTL})} + sx={{ marginTop: "12px", color: "#555" }} + /> + + + )} ); }; diff --git a/src/services/UserList.ts b/src/services/UserList.ts index 632e7c2d..0682b9e8 100644 --- a/src/services/UserList.ts +++ b/src/services/UserList.ts @@ -4,7 +4,7 @@ export interface userListParam { limit: number; // page: number; filters: { - role: string; + role?: string; status?: string; states?: string; districts?: string; @@ -12,7 +12,7 @@ export interface userListParam { }; fields?: any; sort?: object; - offset: number; + offset?: number; } export const userList = async ({ From 8cf554e3e6ccb00b2938115e40fe5dad71bd66d8 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Tue, 24 Sep 2024 15:57:38 +0530 Subject: [PATCH 2/8] update pr --- src/components/CommonUserModal.tsx | 35 +++++++++++++++++++++++--- src/components/ReassignCenterModal.tsx | 13 +++++++--- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/components/CommonUserModal.tsx b/src/components/CommonUserModal.tsx index ffaac1b5..be3fcc87 100644 --- a/src/components/CommonUserModal.tsx +++ b/src/components/CommonUserModal.tsx @@ -11,7 +11,7 @@ import { } from "@/services/CreateUserService"; import { generateUsernameAndPassword } from "@/utils/Helper"; import { FormData } from "@/utils/Interfaces"; -import { FormContext, FormContextType, RoleId ,Role, apiCatchingDuration} from "@/utils/app.constant"; +import { FormContext, FormContextType, RoleId ,Role, apiCatchingDuration, Status} from "@/utils/app.constant"; import { useLocationState } from "@/utils/useLocationState"; import useSubmittedButtonStore from "@/utils/useSharedState"; import { Box, Button, useTheme } from "@mui/material"; @@ -26,6 +26,7 @@ import { showToastMessage } from "./Toastify"; import SendCredentialModal from './SendCredentialModal'; import { sendCredentialService } from "@/services/NotificationService"; import { useQuery } from "@tanstack/react-query"; +import { cohortMemberList } from "@/services/UserList"; interface UserModalProps { open: boolean; @@ -36,7 +37,15 @@ interface UserModalProps { onSubmit: (submitValue: boolean) => void; userType: string; } - +type FilterDetails = { + role: any; + status?: any; + districts?: any; + states?: any; + blocks?: any; + name?: any; + cohortId?: any +}; const CommonUserModal: React.FC = ({ open, onClose, @@ -156,7 +165,7 @@ const CommonUserModal: React.FC = ({ } = useLocationState(open, onClose, roleType); - +console.log(selectedBlockCohortId) useEffect(() => { const getAddUserFormData = () => { try { @@ -345,7 +354,25 @@ const CommonUserModal: React.FC = ({ showToastMessage(t(messageKey), "success"); } else { - + if(userType===Role.TEAM_LEADER) + { + + const filters: FilterDetails= +{ + cohortId:selectedBlockCohortId, + role: Role.TEAM_LEADER, + status:[Status.ACTIVE]} + let limit=200; + let offset=0; + let sort= ["name", "asc"] + let resp; + try { + resp = await cohortMemberList({ limit, filters, sort, offset }); + } catch (apiError) { + console.log("API call failed, proceeding to else block"); + resp = null; + } + } const response = await createUser(apiBody); console.log(response); if (response) { diff --git a/src/components/ReassignCenterModal.tsx b/src/components/ReassignCenterModal.tsx index 8028209e..504297f3 100644 --- a/src/components/ReassignCenterModal.tsx +++ b/src/components/ReassignCenterModal.tsx @@ -320,12 +320,12 @@ const filters: FilterDetails= role: Role.TEAM_LEADER, status:[Status.ACTIVE]} console.log(filters) - let limit=200; - let offset=0; + // let limit=200; + // let offset=0; let sort= ["name", "asc"] let resp; try { - resp = await cohortMemberList({ limit, filters, sort, offset }); + resp = await cohortMemberList({ filters, sort }); } catch (apiError) { console.log("API call failed, proceeding to else block"); resp = null; @@ -770,7 +770,12 @@ finally{ handleCloseConfirmation(); }} > {assignedTeamLeaderNames.length>1 ?( - <>{assignedTeamLeaderNames[0]} and more.. + <> + {t('COMMON.ASSIGNED_TEAM_LEADERS', { assignedTeamLeaderNames:assignedTeamLeaderNames[0]})} + + + + ):(<> {assignedTeamLeaderNames[0]} ) From ff99b8a2bc5734a90f2dca239598d87b48da054c Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Tue, 24 Sep 2024 16:07:59 +0530 Subject: [PATCH 3/8] update pr --- src/services/UserList.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/UserList.ts b/src/services/UserList.ts index 0682b9e8..0ce35335 100644 --- a/src/services/UserList.ts +++ b/src/services/UserList.ts @@ -1,7 +1,7 @@ import { post, get } from "./RestClient"; export interface userListParam { - limit: number; + limit?: number; // page: number; filters: { role?: string; From ea112d0ad3d3d7eab62b8f3fbb7e9db8d114cd2c Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Tue, 24 Sep 2024 16:13:30 +0530 Subject: [PATCH 4/8] add translation --- public/locales/en/common.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index c13c5c33..69a05594 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -129,7 +129,8 @@ "NO_CENTERS": "No centers", "MULTIPLE_TEAM_LEADERS_ASSIGNED": "Selected block {{selectedBlockForTL}} already has {{assignedTeamLeader}} Team Leaders assigned.", "SINGLE_TEAM_LEADERS_ASSIGNED":"Selected block {{selectedBlockForTL}} already has {{assignedTeamLeader}} Team Leader assigned.", - "CONTINUE_ASSIGNED_TEAM_LEADER":"Still do you want to continue to assign team leader to {{selectedBlockForTL}}" + "CONTINUE_ASSIGNED_TEAM_LEADER":"Still do you want to continue to assign team leader to {{selectedBlockForTL}}", + "ASSIGNED_TEAM_LEADERS":"{{assignedTeamLeaderNames}} and more.." }, "LOGIN_PAGE": { "USERNAME": "Username", From 369315e117aa34c3b5694f787a24d3cb7017ac38 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Tue, 24 Sep 2024 16:39:50 +0530 Subject: [PATCH 5/8] update pr: add blockcode while updating user after reassigning block --- src/components/ReassignCenterModal.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/ReassignCenterModal.tsx b/src/components/ReassignCenterModal.tsx index 504297f3..0dde6a0f 100644 --- a/src/components/ReassignCenterModal.tsx +++ b/src/components/ReassignCenterModal.tsx @@ -367,8 +367,11 @@ console.log(filters) unSelectedBlockCohortIds.push(previousBlockId); + let cohortCode = formattedBlocks +.filter((item:any) => item.label === checkedCenters[0]) +.map((item:any) => item.value); let cohortIds = blocks - .filter((item:any) => item.label !== checkedCenters[0]) + .filter((item:any) => item.value !== cohortCode[0]) .map((item:any) => item.cohortId); cohortIds.push(previousBlockId) payload = { @@ -388,7 +391,7 @@ console.log(filters) let customFields = [ { fieldId: blockField.fieldId, - value: selectedCenterCode, + value: cohortCode, }, ]; console.log(selectedBlockCode,checkedCenters[0]) @@ -507,8 +510,11 @@ let unSelectedBlockCohortIds: string[] = []; console.log(previousBlockId) unSelectedBlockCohortIds.push(previousBlockId); +let cohortCode = formattedBlocks +.filter((item:any) => item.label === selectedBlockForTL) +.map((item:any) => item.value); let cohortIds = blocks -.filter((item:any) => item.label !== selectedBlockForTL) +.filter((item:any) => item.value !== cohortCode) .map((item:any) => item.cohortId); cohortIds.push(previousBlockId) const payload = { @@ -537,7 +543,7 @@ cohortIds.push(previousBlockId) customFields = [ { fieldId: blockField.fieldId, - value: selectedCenterCode, + value: cohortCode, }, { fieldId: districtFieldId, From 945225b080dcd6fbab9d8c40fc1cd5b704fa2a18 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Tue, 24 Sep 2024 20:05:13 +0530 Subject: [PATCH 6/8] Issue feat: PS-2045Add confirmation modal while creating block having already assigned TL --- public/locales/en/common.json | 3 +- src/components/CommonUserModal.tsx | 188 ++++++++++++++++++++++++++++- src/components/CustomModal.tsx | 2 +- src/utils/useLocationState.tsx | 72 +++++++++-- 4 files changed, 252 insertions(+), 13 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 69a05594..0e97950d 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -130,7 +130,8 @@ "MULTIPLE_TEAM_LEADERS_ASSIGNED": "Selected block {{selectedBlockForTL}} already has {{assignedTeamLeader}} Team Leaders assigned.", "SINGLE_TEAM_LEADERS_ASSIGNED":"Selected block {{selectedBlockForTL}} already has {{assignedTeamLeader}} Team Leader assigned.", "CONTINUE_ASSIGNED_TEAM_LEADER":"Still do you want to continue to assign team leader to {{selectedBlockForTL}}", - "ASSIGNED_TEAM_LEADERS":"{{assignedTeamLeaderNames}} and more.." + "ASSIGNED_TEAM_LEADERS":"{{assignedTeamLeaderNames}} and more..", + "CONTINUE":"Continue" }, "LOGIN_PAGE": { "USERNAME": "Username", diff --git a/src/components/CommonUserModal.tsx b/src/components/CommonUserModal.tsx index 6215c729..ff8375fb 100644 --- a/src/components/CommonUserModal.tsx +++ b/src/components/CommonUserModal.tsx @@ -20,11 +20,12 @@ import { FormContextType, Role, RoleId, + Status, apiCatchingDuration, } from "@/utils/app.constant"; import { useLocationState } from "@/utils/useLocationState"; import useSubmittedButtonStore from "@/utils/useSharedState"; -import { Box, Button, useTheme } from "@mui/material"; +import { Box, Button, Checkbox, FormControlLabel, Typography, useTheme } from "@mui/material"; import { IChangeEvent } from "@rjsf/core"; import { RJSFSchema } from "@rjsf/utils"; import { useQuery } from "@tanstack/react-query"; @@ -35,6 +36,9 @@ import { transformArray } from "../utils/Helper"; import AreaSelection from "./AreaSelection"; import SendCredentialModal from "./SendCredentialModal"; import { showToastMessage } from "./Toastify"; +import { cohortMemberList } from "@/services/UserList"; +import CustomModal from "./CustomModal"; +import { setConfig } from "next/config"; interface UserModalProps { open: boolean; @@ -46,6 +50,16 @@ interface UserModalProps { userType: string; } + +type FilterDetails = { + role: any; + status?: any; + districts?: any; + states?: any; + blocks?: any; + name?: any; + cohortId?: any +}; const CommonUserModal: React.FC = ({ open, onClose, @@ -60,6 +74,13 @@ const CommonUserModal: React.FC = ({ const [uiSchema, setUiSchema] = React.useState(); const [openModal, setOpenModal] = React.useState(false); const [adminInfo, setAdminInfo] = React.useState(); + const [createTLAlertModal, setcreateTLAlertModal] = useState(false); + const [selectedBlockForTL, setSelectedBlockForTL] = useState(""); + const [confirmButtonDisable, setConfirmButtonDisable] = useState(true); + const [checkedConfirmation, setCheckedConfirmation] = useState(false); + const [selectedBlockCohortIdForTL, setSelectedBlockCohortIdForTL] = useState(""); + const [selectedTLUserID, setSelectedTLUserID] = useState(userId); + const messageKeyMap: Record = { [FormContextType.STUDENT]: "LEARNERS.LEARNER_CREATED_SUCCESSFULLY", [FormContextType.TEACHER]: "FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY", @@ -167,7 +188,10 @@ const CommonUserModal: React.FC = ({ stateFieldId, dynamicFormForBlock, stateDefaultValue, + assignedTeamLeader, + assignedTeamLeaderNames } = useLocationState(open, onClose, roleType); + console.log(assignedTeamLeaderNames) useEffect(() => { const getAddUserFormData = () => { @@ -464,7 +488,6 @@ const CommonUserModal: React.FC = ({ const handleChange = (event: IChangeEvent) => { console.log("Form data changed:", event.formData); }; - const handleError = (errors: any) => { console.log("Form errors:", errors); }; @@ -472,7 +495,33 @@ const CommonUserModal: React.FC = ({ setCreateFacilitator(false); setOpenModal(false); }; + const handleBlockAction = async() => { + // const filters: FilterDetails= + // { + // cohortId:selectedBlockCohortId, + // role: Role.TEAM_LEADER, + // status:[Status.ACTIVE]} + + // let sort= ["name", "asc"] + // let resp; + // try { + // resp = await cohortMemberList({ filters, sort }); + // } catch (apiError) { + // console.log("API call failed, proceeding to else block"); + // resp = null; + // } + // if(resp?.userDetails) + // { + // // onClose(); + // setcreateTLAlertModal(true) + // // setAssignedTeamLeader(resp?.userDetails?.length) + // setSelectedBlockForTL(selectedBlock[0]) + // const userNames = resp?.userDetails?.map((user: any )=> user.name); + // //setSelectedTLUserID(userId) + // // setAssignedTeamLeaderNames(userNames) + // } + }; const handleAction = () => { setTimeout(() => { setCreateFacilitator(true); @@ -499,6 +548,45 @@ const CommonUserModal: React.FC = ({ setSubmitButtonEnable(true); } }, [dynamicForm, dynamicFormForBlock, open]); + + + const handleChangeCheckBox = (event: React.ChangeEvent) => { + setCheckedConfirmation(event.target.checked); + + }; + + const wrappedHandleContinueAction = () => { + handleCloseConfirmation(); + setOpenModal(true); + //onClose(); + + + +} + + const handleCancelAction = async () => { + // await handleDeleteAction(); + handleCloseConfirmation(); +//setAssignedTeamLeaderNames([]); + }; + const handleCloseConfirmation= () => { + // await handleDeleteAction(); + // handleCloseConfirmation(); + setcreateTLAlertModal(false); + setCheckedConfirmation(false); + setConfirmButtonDisable(true); + // setAssignedTeamLeaderNames([]); + + }; + + + useEffect(() => { + if (checkedConfirmation) { + setConfirmButtonDisable(false); + } else { + setConfirmButtonDisable(true); + } + }, [checkedConfirmation]); useEffect(() => { if (typeof window !== "undefined" && window.localStorage) { const admin = localStorage.getItem("adminInfo"); @@ -554,7 +642,18 @@ const CommonUserModal: React.FC = ({ !isEditModal && noError ) { - setOpenModal(true); + // setOpenModal(true); + console.log(assignedTeamLeaderNames.length) + if(assignedTeamLeaderNames.length!==0 && userType===FormContextType.TEAM_LEADER) + { + setcreateTLAlertModal(true); + // setOpenModal(true) + + } + else{ + //onClose(); + setOpenModal(true) + } } console.log("Submit button was clicked"); }} @@ -664,6 +763,89 @@ const CommonUserModal: React.FC = ({ : Role.TEACHER } /> + + + + + + + + + + + + +{assignedTeamLeaderNames.length>1 ?( + <> + {t('COMMON.MULTIPLE_TEAM_LEADERS_ASSIGNED', { selectedBlockForTL: selectedBlock[0],assignedTeamLeader: assignedTeamLeader})} + + + ):(<> + + {t('COMMON.SINGLE_TEAM_LEADERS_ASSIGNED', { selectedBlockForTL: selectedBlock[0],assignedTeamLeader: assignedTeamLeader})} + + ) +} + + + + {assignedTeamLeaderNames.length>1 ?( + <> + {t('COMMON.ASSIGNED_TEAM_LEADERS', { assignedTeamLeaderNames:assignedTeamLeaderNames[0]})} + + + + + ):(<> + {assignedTeamLeaderNames[0]} + ) + + } + + + } + label={ t('COMMON.CONTINUE_ASSIGNED_TEAM_LEADER', {selectedBlockForTL: selectedBlock[0]})} + sx={{ marginTop: "12px", color: "#555" }} + /> + + ); }; diff --git a/src/components/CustomModal.tsx b/src/components/CustomModal.tsx index 2dd3d161..3a32cdd9 100644 --- a/src/components/CustomModal.tsx +++ b/src/components/CustomModal.tsx @@ -63,7 +63,7 @@ const CustomModal: React.FC = ({ top: "50%", left: "50%", transform: "translate(-50%, -50%)", - width: isSmallScreen ? "90%" : isLargeScreen ? width : "85%", + width: isSmallScreen ? "90%" : isLargeScreen ? width : width, maxWidth: "90%", bgcolor: "background.paper", boxShadow: 24, diff --git a/src/utils/useLocationState.tsx b/src/utils/useLocationState.tsx index 07a51343..76ec2c07 100644 --- a/src/utils/useLocationState.tsx +++ b/src/utils/useLocationState.tsx @@ -5,11 +5,20 @@ import { getCenterList, } from "../services/MasterDataService"; // Update the import path as needed import { getCohortList } from "@/services/CohortService/cohortService"; -import { FormContextType, QueryKeys } from "./app.constant"; +import { FormContextType, QueryKeys, Status, Role } from "./app.constant"; import { useTranslation } from "react-i18next"; import { useQueryClient } from "@tanstack/react-query"; import { formatedBlocks, formatedDistricts } from "@/services/formatedCohorts"; - +import { cohortMemberList } from "@/services/UserList"; +type FilterDetails = { + role: any; + status?: any; + districts?: any; + states?: any; + blocks?: any; + name?: any; + cohortId?: any +}; interface FieldProp { value: string; label: string; @@ -50,6 +59,8 @@ export const useLocationState = ( const [stateDefaultValue, setStateDefaultValue] = useState(""); const { t } = useTranslation(); const queryClient = useQueryClient(); + const [assignedTeamLeader, setAssignedTeamLeader] = useState(""); + const [assignedTeamLeaderNames, setAssignedTeamLeaderNames] = useState([]); const handleStateChangeWrapper = useCallback( async (selectedNames: string[], selectedCodes: string[]) => { @@ -154,17 +165,53 @@ export const useLocationState = ( }; const response = await getCenterList(object); const getCohortDetails = response?.result?.results?.cohortDetails; + console.log(getCohortDetails) const blockId = getCohortDetails?.map((item: any) => { if (item?.type === "BLOCK") { return item?.cohortId; } - }); + }) + const blockCohortId = getCohortDetails?.find( + (item: any) => item?.type === "BLOCK" + )?.cohortId; if (blockId) { console.log("blockId", blockId[0]); setSelectedBlockCohortId(blockId[0]); } else { console.log("No Block Id found"); } + + + const filters: FilterDetails= + { + cohortId:blockCohortId, + role: Role.TEAM_LEADER, + status:[Status.ACTIVE]} + + let sort= ["name", "asc"] + let resp; + try { + resp = await cohortMemberList({ filters, sort }); + } catch (apiError) { + console.log("API call failed, proceeding to else block"); + resp = null; + } + if(resp?.userDetails) + { + + // onClose(); + // setcreateTLAlertModal(true) + setAssignedTeamLeader(resp?.userDetails?.length) + // setSelectedBlockForTL(selectedBlock[0]) + const userNames = resp?.userDetails?.map((user: any )=> user.name); + //setSelectedTLUserID(userId) + setAssignedTeamLeaderNames(userNames) + } + else{ + setAssignedTeamLeader(""); + setAssignedTeamLeaderNames([]) + } + } else { const getCentersObject = { limit: 0, @@ -180,9 +227,14 @@ export const useLocationState = ( }; const response = await getCenterList(getCentersObject); console.log(response?.result?.results?.cohortDetails[0].cohortId); - setSelectedBlockCohortId( - response?.result?.results?.cohortDetails[0].cohortId - ); + // setSelectedBlockCohortId( + // response?.result?.results?.cohortDetails[0].cohortId + // ); + const blockCohortId = response?.result?.results?.cohortDetails?.find( + (item: any) => item?.type === "BLOCK" + )?.cohortId; + console.log(blockCohortId) + setSelectedBlockCohortId(blockCohortId) // const result = response?.result?.cohortDetails; const dataArray = response?.result?.results?.cohortDetails; @@ -195,7 +247,9 @@ export const useLocationState = ( console.log(dataArray); setAllCenters(cohortInfo); } - console.log(selected); + + + console.log(selected); } catch (error) { setAllCenters([]); @@ -462,7 +516,9 @@ export const useLocationState = ( setSelectedBlock, setSelectedDistrict, setSelectedDistrictCode, - setSelectedBlockCode + setSelectedBlockCode, + assignedTeamLeaderNames, + assignedTeamLeader }; }; From 9f433413bae4042d3f6d6d24d5a7101cfc2c09b7 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Tue, 24 Sep 2024 20:11:37 +0530 Subject: [PATCH 7/8] update pr --- src/components/CommonUserModal.tsx | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/components/CommonUserModal.tsx b/src/components/CommonUserModal.tsx index ff8375fb..8e4d7e6b 100644 --- a/src/components/CommonUserModal.tsx +++ b/src/components/CommonUserModal.tsx @@ -495,33 +495,7 @@ const CommonUserModal: React.FC = ({ setCreateFacilitator(false); setOpenModal(false); }; - const handleBlockAction = async() => { - // const filters: FilterDetails= - // { - // cohortId:selectedBlockCohortId, - // role: Role.TEAM_LEADER, - // status:[Status.ACTIVE]} - - // let sort= ["name", "asc"] - // let resp; - // try { - // resp = await cohortMemberList({ filters, sort }); - // } catch (apiError) { - // console.log("API call failed, proceeding to else block"); - // resp = null; - // } - // if(resp?.userDetails) - // { - - // // onClose(); - // setcreateTLAlertModal(true) - // // setAssignedTeamLeader(resp?.userDetails?.length) - // setSelectedBlockForTL(selectedBlock[0]) - // const userNames = resp?.userDetails?.map((user: any )=> user.name); - // //setSelectedTLUserID(userId) - // // setAssignedTeamLeaderNames(userNames) - // } - }; + const handleAction = () => { setTimeout(() => { setCreateFacilitator(true); From 8f7c329d2f35a0474c6939eec02392c803fecd0d Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Wed, 25 Sep 2024 08:39:21 +0530 Subject: [PATCH 8/8] update pr: remove unwanted code --- src/components/CommonUserModal.tsx | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/components/CommonUserModal.tsx b/src/components/CommonUserModal.tsx index 8e4d7e6b..cfdc7f91 100644 --- a/src/components/CommonUserModal.tsx +++ b/src/components/CommonUserModal.tsx @@ -51,15 +51,7 @@ interface UserModalProps { } -type FilterDetails = { - role: any; - status?: any; - districts?: any; - states?: any; - blocks?: any; - name?: any; - cohortId?: any -}; + const CommonUserModal: React.FC = ({ open, onClose, @@ -75,12 +67,9 @@ const CommonUserModal: React.FC = ({ const [openModal, setOpenModal] = React.useState(false); const [adminInfo, setAdminInfo] = React.useState(); const [createTLAlertModal, setcreateTLAlertModal] = useState(false); - const [selectedBlockForTL, setSelectedBlockForTL] = useState(""); const [confirmButtonDisable, setConfirmButtonDisable] = useState(true); const [checkedConfirmation, setCheckedConfirmation] = useState(false); - const [selectedBlockCohortIdForTL, setSelectedBlockCohortIdForTL] = useState(""); - const [selectedTLUserID, setSelectedTLUserID] = useState(userId); - + const messageKeyMap: Record = { [FormContextType.STUDENT]: "LEARNERS.LEARNER_CREATED_SUCCESSFULLY", [FormContextType.TEACHER]: "FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY",