Skip to content

Commit f140840

Browse files
authored
Merge pull request #2603 from Rushikesh-Sonawane99/release-1.15.0
Issue #Issue #PS-6231 chore: Delete/Activate users in lap
2 parents e1a5086 + c562cb8 commit f140840

File tree

14 files changed

+1387
-791
lines changed

14 files changed

+1387
-791
lines changed

apps/admin-app-repo/public/locales/en/common.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@
169169
"MOVED_TO_DIFFERENT_ROLE": "Moved to a different role",
170170
"NO_MOBILIZER_FOUND": "No Mentor Found",
171171
"MAP": "Map",
172-
"NEXT": "Next"
172+
"NEXT": "Next",
173+
"USER_BATCHES": "{{name}} belongs to below batches",
174+
"DELETE_FROM_BATCH_WARNING": "Do you want to delete user from above center's batches?"
173175
},
174176
"LOGIN_PAGE": {
175177
"USERNAME": "Username",
@@ -554,7 +556,10 @@
554556
"CONFIRM_TO_ACTIVATE": "Are you sure you want to activate this user again?",
555557
"WORKING_LOCATION": "Working Location",
556558
"CATCHMENT_AREA": "Catchment Area",
557-
"TYPE_OF_BATCH": "Type of Batch"
559+
"TYPE_OF_BATCH": "Type of Batch",
560+
"BELONG_TO_MULTIPLE_CENTERS": "belongs to below centers",
561+
"DO_YOU_WANT_TO_DELETE_MULTIPLE_CENTERS": "Do you want to delete user from all centers?",
562+
"DO_YOU_WANT_TO_DELETE_FROM_LOCATION": "Do you want to delete user from this location?"
558563
},
559564
"FORM_ERROR_MESSAGES": {
560565
"INVALID_INPUT": "Invalid Input.",

apps/admin-app-repo/src/components/DeleteDetails.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface DeleteDetailsProps {
2222
reason: string;
2323
setReason: (reason: string) => void;
2424
isForFacilitator?: boolean;
25+
customLabel?: string;
2526
}
2627

2728
const DeleteDetails: React.FC<DeleteDetailsProps> = ({
@@ -34,8 +35,12 @@ const DeleteDetails: React.FC<DeleteDetailsProps> = ({
3435
reason,
3536
setReason,
3637
isForFacilitator = false,
38+
customLabel
3739
}) => {
3840
const { t } = useTranslation();
41+
const centerCount = center?.split(',')
42+
?.map((c: string) => c.trim())
43+
?.filter(Boolean)?.length || 0;
3944
return (
4045
<>
4146
<Box
@@ -47,7 +52,7 @@ const DeleteDetails: React.FC<DeleteDetailsProps> = ({
4752
}}
4853
>
4954
<Typography fontWeight="bold">
50-
{ firstName } { lastName } {center? t("FORM.BELONG_TO"): t("FORM.WAS_BELONG_TO")}
55+
{ firstName } { lastName } {center? (centerCount > 1? t("FORM.BELONG_TO_MULTIPLE_CENTERS"): t("FORM.BELONG_TO")): t("FORM.WAS_BELONG_TO")}
5156
</Typography>
5257
<TextField fullWidth value={center? center: village} disabled sx={{ mt: 1 }} />
5358
</Box>
@@ -59,7 +64,7 @@ const DeleteDetails: React.FC<DeleteDetailsProps> = ({
5964
onChange={(e) => setChecked(e.target.checked)}
6065
/>
6166
}
62-
label={t('FORM.DO_YOU_WANT_TO_DELETE')}
67+
label={customLabel || (centerCount > 1 ? t('FORM.DO_YOU_WANT_TO_DELETE_MULTIPLE_CENTERS') : t('FORM.DO_YOU_WANT_TO_DELETE'))}
6368
sx={{ mb: checked ? 2 : 0 }}
6469
/>
6570

apps/admin-app-repo/src/pages/user-content-creator.tsx

Lines changed: 85 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import PaginatedTable from '@/components/PaginatedTable/PaginatedTable';
2626
import { Button } from '@mui/material';
2727
import SimpleModal from '@/components/SimpleModal';
2828
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
29-
import { deleteUser } from '@/services/UserService';
29+
import { deleteUser } from '@shared-lib-v2/MapUser/DeleteUser';
3030
import editIcon from '../../public/images/editIcon.svg';
3131
import deleteIcon from '../../public/images/deleteIcon.svg';
3232
import Image from 'next/image';
@@ -358,8 +358,11 @@ const ContentCreator = () => {
358358

359359
const archiveToactive = async () => {
360360
try {
361-
const resp = await deleteUser(editableUserId, {
362-
userData: { status: 'active' },
361+
const resp = await deleteUser({
362+
userId: editableUserId,
363+
roleId: roleId,
364+
tenantId: tenantId,
365+
status: 'active',
363366
});
364367
setArchiveToActiveOpen(false);
365368
searchData(prefilledFormData, currentPage);
@@ -397,73 +400,85 @@ const ContentCreator = () => {
397400
},
398401
show: (row) => row.tenantStatus !== 'archived',
399402
},
400-
// {
401-
// icon: (
402-
// <Box
403-
// sx={{
404-
// display: 'flex',
405-
// flexDirection: 'column',
406-
// alignItems: 'center',
407-
// cursor: 'pointer',
408-
// // backgroundColor: 'rgb(227, 234, 240)',
409-
// justifyContent: 'center',
410-
// padding: '10px',
411-
// }}
412-
// title="Delete Content Creator"
413-
// >
414-
// {' '}
415-
// <Image src={deleteIcon} alt="" />
416-
// </Box>
417-
// ),
418-
// callback: async (row: any) => {
419-
// console.log('row:', row);
420-
// setEditableUserId(row?.userId);
421-
// const userId = row?.userId;
422-
// const response = await updateUserTenantStatus(userId, tenantId, {
423-
// status: 'archived'
424-
// });
425-
// setPrefilledFormData({});
426-
// searchData(prefilledFormData, currentPage);
427-
// setOpenModal(false);
428-
// },
429-
// show: (row) => row.tenantStatus !== 'archived',
430-
// },
431-
// {
432-
// icon: (
433-
// <Box
434-
// sx={{
435-
// display: 'flex',
436-
// flexDirection: 'column',
437-
// alignItems: 'center',
438-
// cursor: 'pointer',
439-
// // backgroundColor: 'rgb(227, 234, 240)',
440-
// justifyContent: 'center',
441-
// padding: '10px',
442-
// }}
443-
// title="Reactivate Content Creator"
444-
// >
445-
// {' '}
446-
// <Image src={restoreIcon} alt="" />
447-
// </Box>
448-
// ),
449-
// callback: async (row: any) => {
450-
// const findState = row?.customFields.find((item) => {
451-
// if (item.label === 'STATE') {
452-
// return item;
453-
// }
454-
// });
455-
// setState(findState?.selectedValues[0]?.value);
456-
// console.log('row:', findState);
457-
// setFirstName(row?.firstName);
458-
// setLastName(row?.lastName);
459-
// setEditableUserId(row?.userId);
460-
// const userId = row?.userId;
461-
// // const response = await archiveToactive(userId);
462-
// setArchiveToActiveOpen(true);
463-
// setPrefilledFormData({});
464-
// },
465-
// show: (row) => row.tenantStatus !== 'active',
466-
// },
403+
{
404+
icon: (
405+
<Box
406+
sx={{
407+
display: 'flex',
408+
flexDirection: 'column',
409+
alignItems: 'center',
410+
cursor: 'pointer',
411+
// backgroundColor: 'rgb(227, 234, 240)',
412+
justifyContent: 'center',
413+
padding: '10px',
414+
}}
415+
title="Delete Content Creator"
416+
>
417+
{' '}
418+
<Image src={deleteIcon} alt="" />
419+
</Box>
420+
),
421+
callback: async (row: any) => {
422+
console.log('row:', row);
423+
setEditableUserId(row?.userId);
424+
const userId = row?.userId;
425+
try {
426+
const response = await deleteUser({
427+
userId,
428+
roleId,
429+
tenantId,
430+
});
431+
if (response?.responseCode === 200) {
432+
showToastMessage(t('COMMON.USER_DELETE_SUCCSSFULLY'), 'success');
433+
setPrefilledFormData({});
434+
searchData(prefilledFormData, currentPage);
435+
} else {
436+
showToastMessage(t('COMMON.FAILED_TO_DELETE_USER'), 'error');
437+
}
438+
} catch (error) {
439+
console.error('Error deleting user:', error);
440+
showToastMessage(t('COMMON.FAILED_TO_DELETE_USER'), 'error');
441+
}
442+
setOpenModal(false);
443+
},
444+
show: (row) => row.tenantStatus !== 'archived',
445+
},
446+
{
447+
icon: (
448+
<Box
449+
sx={{
450+
display: 'flex',
451+
flexDirection: 'column',
452+
alignItems: 'center',
453+
cursor: 'pointer',
454+
// backgroundColor: 'rgb(227, 234, 240)',
455+
justifyContent: 'center',
456+
padding: '10px',
457+
}}
458+
title="Reactivate Content Creator"
459+
>
460+
{' '}
461+
<Image src={restoreIcon} alt="" />
462+
</Box>
463+
),
464+
callback: async (row: any) => {
465+
const findState = row?.customFields.find((item) => {
466+
if (item.label === 'STATE') {
467+
return item;
468+
}
469+
});
470+
setState(findState?.selectedValues[0]?.value);
471+
console.log('row:', findState);
472+
setFirstName(row?.firstName);
473+
setLastName(row?.lastName);
474+
setEditableUserId(row?.userId);
475+
const userId = row?.userId;
476+
// const response = await archiveToactive(userId);
477+
setArchiveToActiveOpen(true);
478+
setPrefilledFormData({});
479+
},
480+
show: (row) => row.tenantStatus !== 'active',
481+
},
467482
];
468483

469484
// Pagination handlers

0 commit comments

Comments
 (0)