Skip to content

Commit

Permalink
Merge pull request #157 from AkshataKatwal16/admin
Browse files Browse the repository at this point in the history
Issue feat: Modify send email notification payload  with key value pair of replacement
  • Loading branch information
itsvick authored Aug 24, 2024
2 parents 38ed193 + b012b39 commit 5a1884b
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 23 deletions.
4 changes: 3 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?"


},
Expand Down
22 changes: 17 additions & 5 deletions src/components/CommonUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,27 @@ const CommonUserModal: React.FC<UserModalProps> = ({
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
}

}

Expand All @@ -391,7 +403,7 @@ const CommonUserModal: React.FC<UserModalProps> = ({
receipients: userType === FormContextType.STUDENT?[adminInfo?.email]: [formData?.email],

};
if (replacements && sendTo) {
if (Object.keys(replacements).length !== 0 && sendTo) {

const response = await sendCredentialService({
isQueue,
Expand Down
90 changes: 83 additions & 7 deletions src/components/DeleteUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +27,11 @@ interface DeleteUserModalProps {
handleDeleteAction: any;
confirmButtonDisable: boolean;
setConfirmButtonDisable: any;
centers:any;
userId?:string;
userType?:string;
userName?:string

}

const DeleteUserModal: React.FC<DeleteUserModalProps> = ({
Expand All @@ -36,39 +44,105 @@ const DeleteUserModal: React.FC<DeleteUserModalProps> = ({
handleDeleteAction,
confirmButtonDisable = true,
setConfirmButtonDisable,
centers,
userId,
userName
}) => {
console.log(userName)
const { t } = useTranslation();
const theme = useTheme<any>();
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<HTMLInputElement>) => {
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 (
<>
<CustomModal
open={open}
handleClose={onClose}
handleClose={handleClose}
title={t("COMMON.DELETE_USER")}
subtitle={t("COMMON.REASON_FOR_DELETION")}
// subtitle={t("COMMON.REASON_FOR_DELETION")}
primaryBtnText={t("COMMON.DELETE_USER_WITH_REASON")}
// secondaryBtnText="Cancel"
primaryBtnClick={handleDeleteAction}
primaryBtnDisabled={confirmButtonDisable}
primaryBtnClick={wrappedHandleDeleteAction}
primaryBtnDisabled={ confirmButtonDisable}
// secondaryBtnClick={handleSecondaryClick}
>
<>
<Box padding={"0 1rem"}>
{ centers!=="-" && (<Box
sx={{
border: '1px solid #ccc',
borderRadius: '8px',
padding: '16px',
width: 'fit-content',
backgroundColor: '#f9f9f9',
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)',
}}
>
<Typography variant="body1" sx={{ marginBottom: '12px', fontWeight: 'bold', color: '#333' }}>
{t("COMMON.USER_COHORTS", {name: userName})}
</Typography>

<Box
sx={{
border: '1px solid #ddd',
borderRadius: '8px',
padding: '8px',
marginBottom: '16px',
backgroundColor: '#fff',
maxHeight: '200px',
overflowY: 'auto',
}}
>
{centers}
</Box>

<FormControlLabel
control={
<Checkbox
checked={checkedCohortDeletion}
onChange={handleChange}
color="primary"
/>
}
label= {t("COMMON.DELETE_COHORT_WARNING")}
sx={{ marginTop: '12px', color: '#555' }}
/>
</Box>)
}

{checkedCohortDeletion && ( <Box padding={"0 1rem"}>
<Typography id="modal-subtitle" variant="h2" marginTop= "10px">
{ t("COMMON.REASON_FOR_DELETION")} </Typography>

{reasons?.map((option) => (
<>
<Box
Expand Down Expand Up @@ -98,6 +172,8 @@ const DeleteUserModal: React.FC<DeleteUserModalProps> = ({
</>
))}
</Box>
)
}
</>
</CustomModal>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReassignCenterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const ReassignCenterModal: React.FC<ReassignCohortModalProps> = ({
primaryBtnClick={handleReassign}
primaryBtnDisabled={checkedCenters.length === 0}
>
<Box sx={{ p: 3 }}>
<Box sx={{ p: 1 }}>
<TextField
sx={{
backgroundColor: theme.palette.warning["A700"],
Expand Down
102 changes: 96 additions & 6 deletions src/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import CommonUserModal from "./CommonUserModal";
import { useQuery } from "@tanstack/react-query";
import ReassignCenterModal from "./ReassignCenterModal";
import { getCenterList, getStateBlockDistrictList } from "@/services/MasterDataService";
import { updateCohortMemberStatus } from "@/services/CohortService/cohortService";
type UserDetails = {
userId: any;
username: any;
Expand All @@ -44,7 +45,9 @@ type UserDetails = {
blocks?: any;
stateCode?:any;
districtCode?:any;
blockCode?:any
blockCode?:any;
centerMembershipIdList?:any;
blockMembershipIdList?:any
};
type FilterDetails = {
role: any;
Expand All @@ -66,6 +69,7 @@ interface Cohort {
type: string;
customField: any[];
cohortMemberStatus?:string
cohortMembershipId?:string
}
interface UserTableProps {
role: string;
Expand All @@ -87,6 +91,10 @@ const UserTable: React.FC<UserTableProps> = ({
}) => {
console.log(userType);
const [selectedState, setSelectedState] = React.useState<string[]>([]);
const [blockMembershipIdList, setBlockMembershipIdList] = React.useState<string[]>([]);
const [centerMembershipIdList, setCenterMembershipIdList] = React.useState<string[]>([]);


const [selectedStateCode, setSelectedStateCode] = useState("");
const [selectedDistrict, setSelectedDistrict] = React.useState<string[]>([]);
const [selectedDistrictCode, setSelectedDistrictCode] = useState("");
Expand All @@ -107,8 +115,9 @@ const UserTable: React.FC<UserTableProps> = ({
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [isReassignCohortModalOpen, setIsReassignCohortModalOpen] = useState(false);
const [centers, setCenters] = useState<CenterProp[]>([]);
const [blockFieldId, setBlockFieldId] = useState("");
const [userName, setUserName] = useState("");
const [blocks, setBlocks] = useState<FieldProp[]>([]);
const [userCohort, setUserCohorts] = useState ("")

const [selectedUserId, setSelectedUserId] = useState("");
const [block, setBlock] = useState("");
Expand Down Expand Up @@ -501,7 +510,22 @@ const UserTable: React.FC<UserTableProps> = ({

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);
Expand Down Expand Up @@ -552,7 +576,6 @@ const UserTable: React.FC<UserTableProps> = ({
fieldName: "blocks",
};
const response = await getStateBlockDistrictList(object);
setBlockFieldId(response?.result?.fieldId);
//console.log(blockFieldId)
const result = response?.result?.values;
console.log(result)
Expand Down Expand Up @@ -773,7 +796,17 @@ const UserTable: React.FC<UserTableProps> = ({
// );
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) {
Expand All @@ -783,6 +816,9 @@ const UserTable: React.FC<UserTableProps> = ({
// console.log(finalArray)
return {
...user,
centerMembershipIdList: centerMembershipIdList,
blockMembershipIdList: blockMembershipIdList,

centers: finalArray ? finalArray?.join(" , ") : "-",
};
})
Expand Down Expand Up @@ -855,6 +891,7 @@ const UserTable: React.FC<UserTableProps> = ({
setOtherReason("");
setIsDeleteModalOpen(false);
setConfirmButtonDisable(true);

};
const handleCloseReassignModal = () => {
// setSelectedReason("");
Expand All @@ -874,10 +911,58 @@ const UserTable: React.FC<UserTableProps> = ({
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) {
Expand Down Expand Up @@ -999,6 +1084,11 @@ const UserTable: React.FC<UserTableProps> = ({
setOtherReason={setOtherReason}
confirmButtonDisable={confirmButtonDisable}
setConfirmButtonDisable={setConfirmButtonDisable}
centers={userCohort}
userId={selectedUserId}
userName={userName}


/>
<ReassignCenterModal
open={isReassignCohortModalOpen}
Expand Down
Loading

0 comments on commit 5a1884b

Please sign in to comment.