Skip to content

Commit 2cd73bf

Browse files
authored
Merge pull request #2587 from tekdi/feat-lead-mapping-new
Feat lead mapping new to 13 qa feat
2 parents f704f06 + 60ab2a8 commit 2cd73bf

File tree

8 files changed

+1609
-262
lines changed

8 files changed

+1609
-262
lines changed

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

Lines changed: 185 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
DialogContent,
2121
DialogActions,
2222
IconButton,
23+
CircularProgress
2324
} from '@mui/material';
2425
import PaginatedTable from '@/components/PaginatedTable/PaginatedTable';
2526
import { Button } from '@mui/material';
@@ -46,11 +47,13 @@ import restoreIcon from '../../public/images/restore_user.svg';
4647
import { showToastMessage } from '@/components/Toastify';
4748
import ConfirmationPopup from '@/components/ConfirmationPopup';
4849
import EmailSearchUser from '@shared-lib-v2/MapUser/EmailSearchUser';
50+
import EditSearchUser from '@shared-lib-v2/MapUser/EditSearchUser';
4951
import {
5052
enhanceUiSchemaWithGrid,
5153
splitUserData,
5254
} from '@shared-lib-v2/DynamicForm/components/DynamicFormCallback';
5355
import { enrollUserTenant } from '@shared-lib-v2/MapUser/MapService';
56+
import { updateUser } from '@shared-lib-v2/DynamicForm/services/CreateUserService';
5457

5558
const ContentCreator = () => {
5659
const [archiveToActiveOpen, setArchiveToActiveOpen] = useState(false);
@@ -200,6 +203,14 @@ const ContentCreator = () => {
200203
const [isMappingInProgress, setIsMappingInProgress] = useState(false);
201204
const [userDetails, setUserDetails] = useState<any>(null);
202205

206+
//edit modal variables
207+
const [editModalOpen, setEditModalOpen] = useState(false);
208+
const [selectedUserIdEdit, setSelectedUserIdEdit] = useState<
209+
string | null
210+
>(null);
211+
const [selectedUserRow, setSelectedUserRow] = useState<any>(null);
212+
const [isEditInProgress, setIsEditInProgress] = useState(false);
213+
203214
const searchData = async (formData: any, newPage: any) => {
204215
if (formData) {
205216
formData = Object.fromEntries(
@@ -360,37 +371,32 @@ const ContentCreator = () => {
360371
};
361372
// Define actions
362373
const actions = [
363-
// {
364-
// icon: (
365-
// <Box
366-
// sx={{
367-
// display: 'flex',
368-
// flexDirection: 'column',
369-
// alignItems: 'center',
370-
// cursor: 'pointer',
371-
// // backgroundColor: 'rgb(227, 234, 240)',
372-
// justifyContent: 'center',
373-
// padding: '10px',
374-
// }}
375-
// title="Edit Content Creator"
376-
// >
377-
// <Image src={editIcon} alt="" />
378-
// </Box>
379-
// ),
380-
// callback: (row: any) => {
381-
// console.log('row:', row);
382-
// console.log('AddSchema', addSchema);
383-
// console.log('AddUISchema', addUiSchema);
384-
385-
// let tempFormData = extractMatchingKeys(row, addSchema);
386-
// console.log('tempFormData', tempFormData);
387-
// setPrefilledAddFormData(tempFormData);
388-
// setIsEdit(true);
389-
// setEditableUserId(row?.userId);
390-
// handleOpenModal();
391-
// },
392-
// show: (row) => row.tenantStatus !== 'archived',
393-
// },
374+
{
375+
icon: (
376+
<Box
377+
sx={{
378+
display: 'flex',
379+
flexDirection: 'column',
380+
alignItems: 'center',
381+
cursor: 'pointer',
382+
// backgroundColor: 'rgb(227, 234, 240)',
383+
justifyContent: 'center',
384+
padding: '10px',
385+
}}
386+
title="Edit Content Creator"
387+
>
388+
<Image src={editIcon} alt="" />
389+
</Box>
390+
),
391+
callback: (row: any) => {
392+
setIsEditInProgress(true);
393+
setEditModalOpen(true);
394+
setSelectedUserIdEdit(row?.userId);
395+
setSelectedUserRow(row);
396+
setIsEditInProgress(false);
397+
},
398+
show: (row) => row.tenantStatus !== 'archived',
399+
},
394400
// {
395401
// icon: (
396402
// <Box
@@ -790,7 +796,7 @@ const ContentCreator = () => {
790796
}}
791797
roleId={roleId}
792798
tenantId={tenantId}
793-
type="leader"
799+
type="content-creator"
794800
/>
795801
</Box>
796802
)}
@@ -823,6 +829,153 @@ const ContentCreator = () => {
823829
)}
824830
</DialogActions>
825831
</Dialog>
832+
833+
{/* Edit Modal Dialog */}
834+
<Dialog
835+
open={editModalOpen}
836+
onClose={(event, reason) => {
837+
// Prevent closing on backdrop click
838+
if (reason !== 'backdropClick') {
839+
setSelectedUserIdEdit(null); // Reset user selection when dialog closes
840+
setSelectedUserRow(null); // Reset user row selection when dialog closes
841+
setIsEditInProgress(true);
842+
}
843+
}}
844+
maxWidth={false}
845+
fullWidth={true}
846+
PaperProps={{
847+
sx: {
848+
width: '100%',
849+
maxWidth: '100%',
850+
maxHeight: '100vh',
851+
},
852+
}}
853+
>
854+
<DialogTitle
855+
sx={{
856+
display: 'flex',
857+
justifyContent: 'space-between',
858+
alignItems: 'center',
859+
borderBottom: '1px solid #eee',
860+
p: 2,
861+
}}
862+
>
863+
<Typography variant="h1" component="div">
864+
{t('Edit User as Content Creator')}
865+
</Typography>
866+
<IconButton
867+
aria-label="close"
868+
onClick={() => setEditModalOpen(false)}
869+
sx={{
870+
color: (theme) => theme.palette.grey[500],
871+
}}
872+
>
873+
<CloseIcon />
874+
</IconButton>
875+
</DialogTitle>
876+
<DialogContent sx={{ p: 3, overflowY: 'auto' }}>
877+
{isEditInProgress ? (
878+
<Box sx={{ mb: 3 }}>
879+
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', minHeight: '150px' }}>
880+
<CircularProgress />
881+
<Typography variant="h1" component="div" sx={{ mt: 2 }}>
882+
{t('Saving...')}
883+
</Typography>
884+
</Box>
885+
</Box>
886+
) : (
887+
<Box sx={{ mb: 3 }}>
888+
<EditSearchUser
889+
onUserDetails={async(userDetails) => {
890+
console.log('############# userDetails', userDetails);
891+
if (selectedUserIdEdit) {
892+
setIsEditInProgress(true);
893+
try {
894+
const { userData, customFields } =
895+
splitUserData(userDetails);
896+
897+
delete userData.email;
898+
899+
const object = {
900+
userData: userData,
901+
customFields: customFields,
902+
};
903+
904+
//update user details
905+
const updateUserResponse = await updateUser(selectedUserIdEdit, object);
906+
console.log(
907+
'######### updatedResponse',
908+
updateUserResponse
909+
);
910+
911+
if (
912+
updateUserResponse &&
913+
updateUserResponse?.status == 200
914+
) {
915+
// getNotification(editableUserId, profileUpdateNotificationKey);
916+
showToastMessage(t(successUpdateMessage), 'success');
917+
// telemetryCallbacks(telemetryUpdateKey);
918+
// Refresh the data
919+
searchData(prefilledFormData, 0);
920+
} else {
921+
// console.error('Error update user:', error);
922+
showToastMessage(t(failureUpdateMessage), 'error');
923+
}
924+
} catch (error) {
925+
console.error('Error creating cohort member:', error);
926+
showToastMessage(
927+
error?.response?.data?.params?.errmsg ||
928+
t(failureCreateMessage),
929+
'error'
930+
);
931+
} finally {
932+
setIsEditInProgress(false);
933+
setEditModalOpen(false);
934+
}
935+
} else if (!selectedUserIdEdit) {
936+
showToastMessage('Please search and select a user', 'error');
937+
} else {
938+
showToastMessage('Please select a center', 'error');
939+
}
940+
}}
941+
selectedUserRow={selectedUserRow}
942+
schema={addSchema}
943+
uiSchema={addUiSchema}
944+
userId={selectedUserIdEdit}
945+
roleId={roleId}
946+
tenantId={tenantId}
947+
type="content-creator"
948+
/>
949+
</Box>
950+
)}
951+
</DialogContent>
952+
<DialogActions sx={{ p: 2, borderTop: '1px solid #eee' }}>
953+
<Button
954+
sx={{
955+
backgroundColor: '#FFC107',
956+
color: '#000',
957+
fontFamily: 'Poppins',
958+
fontWeight: 500,
959+
fontSize: '14px',
960+
height: '40px',
961+
lineHeight: '20px',
962+
letterSpacing: '0.1px',
963+
textAlign: 'center',
964+
verticalAlign: 'middle',
965+
'&:hover': {
966+
backgroundColor: '#ffb300',
967+
},
968+
width: '100%',
969+
}}
970+
disabled={!selectedUserIdEdit || isEditInProgress}
971+
form="dynamic-form-id"
972+
type="submit"
973+
>
974+
{t('COMMON.SAVE')}
975+
</Button>
976+
</DialogActions>
977+
</Dialog>
978+
826979
</>
827980
);
828981
};

0 commit comments

Comments
 (0)