From 81ac3dc6186316aa07c3c97a428e9ccbe6a3a596 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Sat, 24 Aug 2024 19:15:59 +0530 Subject: [PATCH 1/2] Issue feat: modify send email notification payload with key value paire of replacement --- src/components/CommonUserModal.tsx | 22 +++++++++++++++++----- src/utils/Interfaces.ts | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/CommonUserModal.tsx b/src/components/CommonUserModal.tsx index bce822c6..69c57a52 100644 --- a/src/components/CommonUserModal.tsx +++ b/src/components/CommonUserModal.tsx @@ -373,15 +373,27 @@ const CommonUserModal: React.FC = ({ if (typeof window !== 'undefined' && window.localStorage) { createrName = localStorage.getItem('name'); } - let replacements; + let replacements: { [key: string]: string }; + replacements={} + console.log(Object.keys(replacements).length === 0) if (createrName) { if(userType===FormContextType.STUDENT) { - replacements = [createrName, apiBody['name'], username, password]; - + replacements = + { + "{FirstName}": createrName, + "{UserName}": username, + "{LearnerName}" : apiBody['name'], + "{Password}": password + } } else{ - replacements = [apiBody['name'], username, password]; + replacements = + { + "{FirstName}": apiBody['name'], + "{UserName}": username, + "{Password}": password + } } @@ -391,7 +403,7 @@ const CommonUserModal: React.FC = ({ receipients: userType === FormContextType.STUDENT?[adminInfo?.email]: [formData?.email], }; - if (replacements && sendTo) { + if (Object.keys(replacements).length !== 0 && sendTo) { const response = await sendCredentialService({ isQueue, diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index 573531fe..a9ad123e 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -59,7 +59,7 @@ export interface SendCredentialsRequest { isQueue: boolean; context: string; key: string; - replacements: any[]; + replacements: object; email: { receipients: any[]; }; From b012b391774aaac20c51b9bc126a812d05819d29 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Sat, 24 Aug 2024 22:51:20 +0530 Subject: [PATCH 2/2] Issue PS-1793 feat: Modify delete user popup Integrate user from cohort API --- public/locales/en/common.json | 4 +- src/components/DeleteUserModal.tsx | 90 +++++++++++++++-- src/components/ReassignCenterModal.tsx | 2 +- src/components/UserTable.tsx | 102 ++++++++++++++++++-- src/services/CohortService/cohortService.ts | 28 +++++- 5 files changed, 209 insertions(+), 17 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index b198f122..f4e9c2bc 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -115,7 +115,9 @@ "CENTERS_REASSIGN_SUCCESSFULLY": "Center reassign successfully", "BLOCKS_REASSIGN_SUCCESSFULLY": "Block reassign successfully", "CENTERS_REASSIGN_FAILED":"Center Reassignment fails", - "BLOCKS_REASSIGN_FAILED":"Block Reassignment fails" + "BLOCKS_REASSIGN_FAILED":"Block Reassignment fails", + "USER_COHORTS": "{{name}} belongs to below cohorts", + "DELETE_COHORT_WARNING":"Do you want to delete user from cohort?" }, diff --git a/src/components/DeleteUserModal.tsx b/src/components/DeleteUserModal.tsx index b2950d3e..4000c724 100644 --- a/src/components/DeleteUserModal.tsx +++ b/src/components/DeleteUserModal.tsx @@ -14,6 +14,9 @@ import { useTranslation } from "next-i18next"; import CloseIcon from "@mui/icons-material/Close"; import { showToastMessage } from "./Toastify"; import CustomModal from "./CustomModal"; +import { Checkbox, FormControlLabel } from '@mui/material'; + + interface DeleteUserModalProps { open: boolean; onClose: () => void; @@ -24,6 +27,11 @@ interface DeleteUserModalProps { handleDeleteAction: any; confirmButtonDisable: boolean; setConfirmButtonDisable: any; + centers:any; + userId?:string; + userType?:string; + userName?:string + } const DeleteUserModal: React.FC = ({ @@ -36,39 +44,105 @@ const DeleteUserModal: React.FC = ({ handleDeleteAction, confirmButtonDisable = true, setConfirmButtonDisable, + centers, + userId, + userName }) => { + console.log(userName) const { t } = useTranslation(); const theme = useTheme(); const reasons = [ { value: "Incorrect Data Entry", label: t("COMMON.INCORRECT_DATA_ENTRY") }, { value: "Duplicated User", label: t("COMMON.DUPLICATED_USER") }, ]; + const [checkedCohortDeletion, setCheckedCohortDeletion] = useState(centers!=="-"? true: false); const handleRadioChange = (value: string) => { console.log(value); setSelectedValue(value); setConfirmButtonDisable(false); }; - + const handleChange = (event: React.ChangeEvent) => { + setCheckedCohortDeletion(event.target.checked); + }; const handleOtherReasonChange = (event: any) => { setOtherReason(event.target.value); }; - + + const handleClose = () => { + if(centers!=="") + { setCheckedCohortDeletion(true);} + else + { + setCheckedCohortDeletion(false); + } + onClose(); + }; + const wrappedHandleDeleteAction = async () => { + // setCheckedCohortDeletion(false); + await handleDeleteAction(); + handleClose(); + }; return ( <> <> - + { centers!=="-" && ( + + {t("COMMON.USER_COHORTS", {name: userName})} + + + + {centers} + + + + } + label= {t("COMMON.DELETE_COHORT_WARNING")} + sx={{ marginTop: '12px', color: '#555' }} + /> +) +} + + {checkedCohortDeletion && ( + + { t("COMMON.REASON_FOR_DELETION")} + {reasons?.map((option) => ( <> = ({ ))} + ) +} diff --git a/src/components/ReassignCenterModal.tsx b/src/components/ReassignCenterModal.tsx index 7b031467..39e47ce4 100644 --- a/src/components/ReassignCenterModal.tsx +++ b/src/components/ReassignCenterModal.tsx @@ -218,7 +218,7 @@ const ReassignCenterModal: React.FC = ({ primaryBtnClick={handleReassign} primaryBtnDisabled={checkedCenters.length === 0} > - + = ({ }) => { console.log(userType); const [selectedState, setSelectedState] = React.useState([]); + const [blockMembershipIdList, setBlockMembershipIdList] = React.useState([]); + const [centerMembershipIdList, setCenterMembershipIdList] = React.useState([]); + + const [selectedStateCode, setSelectedStateCode] = useState(""); const [selectedDistrict, setSelectedDistrict] = React.useState([]); const [selectedDistrictCode, setSelectedDistrictCode] = useState(""); @@ -107,8 +115,9 @@ const UserTable: React.FC = ({ const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [isReassignCohortModalOpen, setIsReassignCohortModalOpen] = useState(false); const [centers, setCenters] = useState([]); - const [blockFieldId, setBlockFieldId] = useState(""); + const [userName, setUserName] = useState(""); const [blocks, setBlocks] = useState([]); + const [userCohort, setUserCohorts] = useState ("") const [selectedUserId, setSelectedUserId] = useState(""); const [block, setBlock] = useState(""); @@ -501,7 +510,22 @@ const UserTable: React.FC = ({ const handleDelete = (rowData: any) => { setIsDeleteModalOpen(true); + console.log(rowData) + setUserName(rowData?.name) + console.log(userName) + + setBlockMembershipIdList(rowData.blockMembershipIdList) + setCenterMembershipIdList(rowData.centerMembershipIdList) setSelectedUserId(rowData.userId); + if(userType===Role.TEAM_LEADERS) + { + setUserCohorts(rowData.blocks) + console.log(userCohort) + + } + else{ + setUserCohorts(rowData.centers) + } //const userData=""; console.log("Delete row:", rowData.userId); @@ -552,7 +576,6 @@ const UserTable: React.FC = ({ fieldName: "blocks", }; const response = await getStateBlockDistrictList(object); - setBlockFieldId(response?.result?.fieldId); //console.log(blockFieldId) const result = response?.result?.values; console.log(result) @@ -773,7 +796,17 @@ const UserTable: React.FC = ({ // ); const cohortNames = response?.result?.cohortData ?.filter((cohort: Cohort) => cohort.type !== "BLOCK" && cohort?.cohortMemberStatus!=="archived") // Filter out cohorts with type 'block' - .map((cohort: Cohort) => cohort.name); // + .map((cohort: Cohort) => cohort.name); + const centerMembershipIdList = response?.result?.cohortData + ?.filter((cohort: Cohort) => cohort.type !== "BLOCK" && cohort?.cohortMemberStatus!=="archived") // Filter out cohorts with type 'block' + .map((cohort: Cohort) => cohort.cohortMembershipId); + const blockMembershipIdList = response?.result?.cohortData + ?.filter((cohort: Cohort) => cohort.type === "BLOCK" && cohort?.cohortMemberStatus!=="archived") // Filter out cohorts with type 'block' + .map((cohort: Cohort) => cohort.cohortMembershipId); + // const cohortMembershipId=response?.result?.cohortData?.cohortMembershipId; + console.log(blockMembershipIdList) + console.log(centerMembershipIdList) + let finalArray; if (cohortNames?.length >= 1) { @@ -783,6 +816,9 @@ const UserTable: React.FC = ({ // console.log(finalArray) return { ...user, + centerMembershipIdList: centerMembershipIdList, + blockMembershipIdList: blockMembershipIdList, + centers: finalArray ? finalArray?.join(" , ") : "-", }; }) @@ -855,6 +891,7 @@ const UserTable: React.FC = ({ setOtherReason(""); setIsDeleteModalOpen(false); setConfirmButtonDisable(true); + }; const handleCloseReassignModal = () => { // setSelectedReason(""); @@ -874,10 +911,58 @@ const UserTable: React.FC = ({ status: "archived", }, }; - const response = await deleteUser(userId, userData); - if (response) { + const cohortDeletionResponse = await deleteUser(userId, userData); + 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, + }); + + }); + } + 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) + + // 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) { @@ -999,6 +1084,11 @@ const UserTable: React.FC = ({ setOtherReason={setOtherReason} confirmButtonDisable={confirmButtonDisable} setConfirmButtonDisable={setConfirmButtonDisable} + centers={userCohort} + userId={selectedUserId} + userName={userName} + + /> => { let apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/search`; @@ -119,4 +123,24 @@ export const bulkCreateCohortMembers = async (payload: any): Promise => { console.error('Error in bulk creating cohort members', error); throw error; } -}; \ No newline at end of file +}; + + +export const updateCohortMemberStatus = async ({ + memberStatus, + statusReason, + membershipId, +}: UpdateCohortMemberStatusParams): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohortmember/update/${membershipId}`; + try { + const response = await put(apiUrl, { + status: memberStatus, + statusReason, + }); + console.log('data', response?.data); + return response?.data; + } catch (error) { + console.error('error in attendance report api ', error); + // throw error; + } +};