@@ -7,6 +7,7 @@ import rolemanagement from '../../dummyData/rolemanagement.json';
77import useDocumentTitle from '../../hook/useDocumentTitle' ;
88import Button from './../../components/Buttons' ;
99import devs from '../../dummyData/rolemanagement.json' ;
10+ import DELETE_USER_MUTATION from '../admin-dashBoard/DeleteUserMutation' ;
1011import CREATE_ROLE_MUTATION from '../admin-dashBoard/createRoleMutation' ;
1112import GET_ROLE_QUERY from '../admin-dashBoard/GetRolesQuery' ;
1213import ASSIGN_ROLE_MUTATION from '../admin-dashBoard/AssignRolesMutation' ;
@@ -26,7 +27,6 @@ const AdminSission = () => {
2627 useDocumentTitle ( 'Roles & Access' ) ;
2728 const [ addMemberModel , setAddMemberModel ] = useState ( false ) ;
2829 const [ deleteModel , setDeleteModel ] = useState ( false ) ;
29-
3030 const [ GetAllRoles ] = useLazyQuery ( GET_ROLE_QUERY ) ;
3131 const [ developers , setDevelopers ] = useState ( devs ) ;
3232 const [ tabName , setTabName ] = useState ( 'all' ) ;
@@ -42,9 +42,12 @@ const AdminSission = () => {
4242 const [ createUserRole ] = useMutation ( CREATE_ROLE_MUTATION ) ;
4343 const [ updateUserRole ] = useMutation ( ASSIGN_ROLE_MUTATION ) ;
4444 const [ findFilter , setFindFilter ] = useState ( '' ) ;
45+ const [ loggedUser , setLoggedUser ] = useState ( '' ) ;
4546 const [ allRoles , setallRoles ] = useState < any > ( ) ;
4647 const [ selectingTTL , setSelectingTTL ] = useState ( false ) ;
4748 const [ selectedTeamId , setSelectedTeamId ] = useState ( '' ) ;
49+ const [ deleteConfirmationModel , setDeleteConfirmationModel ] = useState ( false ) ; // Modal for confirming deletion
50+
4851 const { loading, error, data } = useQuery ( GET_TEAMS , {
4952 variables : { orgToken : localStorage . getItem ( 'orgToken' ) } ,
5053 } ) ;
@@ -61,6 +64,32 @@ const AdminSission = () => {
6164 let newState = ! deleteModel ;
6265 setDeleteModel ( newState ) ;
6366 } ;
67+
68+ const [ deleteUser ] = useMutation ( DELETE_USER_MUTATION , {
69+ onCompleted : ( data ) => {
70+ if ( data . deleteUser . message ) {
71+ toast . success ( 'User deleted successfully' ) ;
72+ setToggle ( ! toggle ) ; // Refresh or update state
73+ } else {
74+ toast . error ( 'Failed to delete user' ) ;
75+ }
76+ } ,
77+ onError : ( error ) => {
78+ toast . error ( error . message ) ;
79+ } ,
80+ } ) ;
81+
82+ useEffect ( ( ) => {
83+ // Fetch the auth details from local storage
84+ const authData = localStorage . getItem ( 'auth' ) ;
85+
86+ if ( authData ) {
87+ const parsedAuthData = JSON . parse ( authData ) ;
88+ const userId = parsedAuthData . userId ;
89+ setLoggedUser ( userId ) ;
90+ }
91+ } , [ ] ) ;
92+
6493 useEffect ( ( ) => {
6594 if ( tabName === 'all' ) {
6695 setDataDev ( rolemanagement ) ;
@@ -224,17 +253,30 @@ const AdminSission = () => {
224253 accessor : '' ,
225254 /* istanbul ignore next */
226255 Cell : ( { row } : any ) => (
227- < p
228- className = "text-red-500 whitespace-no-wrap cursor-pointer"
229- onClick = {
230- /* istanbul ignore next */ ( ) => {
231- /* istanbul ignore next */
232- removeAssignModel ( row . original ) ;
256+ < div className = "flex gap-4" >
257+ < p
258+ className = "text-red-500 whitespace-no-wrap cursor-pointer"
259+ onClick = {
260+ /* istanbul ignore next */ ( ) => {
261+ /* istanbul ignore next */
262+ removeAssignModel ( row . original ) ;
263+ }
233264 }
234- }
235- >
236- { t ( 'Assign' ) }
237- </ p >
265+ >
266+ { t ( 'Assign' ) }
267+ </ p >
268+ < p
269+ className = "text-red-500 whitespace-no-wrap cursor-pointer"
270+ onClick = {
271+ /* istanbul ignore next */ ( ) => {
272+ /* istanbul ignore next */
273+ handleDeleteUser ( row . original . id ) ;
274+ }
275+ }
276+ >
277+ { t ( 'Delete' ) }
278+ </ p >
279+ </ div >
238280 ) ,
239281 } ,
240282 ] ;
@@ -252,12 +294,68 @@ const AdminSission = () => {
252294 name : 'ttl' ,
253295 } ,
254296 ] ;
297+
298+ const handleDeleteUser = ( userId : any ) => {
299+ if ( loggedUser === userId ) {
300+ toast . warn ( 'You can not delete your self!' ) ;
301+ } else {
302+ setSelectedUser ( { id : userId , role : 'user' } ) ;
303+ setDeleteConfirmationModel ( true ) ;
304+ }
305+ } ;
306+
307+ const confirmDeleteUser = ( ) => {
308+ deleteUser ( {
309+ variables : {
310+ input : { id : selectedUser . id } ,
311+ context : { userId : selectedUser . id } ,
312+ } ,
313+ } ) ;
314+ setDeleteConfirmationModel ( false ) ;
315+ } ;
316+ console . log ( selectedUser ) ;
317+
255318 /* istanbul ignore next */
256319 return (
257320 < >
258321 { users && allRoless ? (
259322 < >
260323 { /* ... Existing code ... */ }
324+ { /* =========================== Start:: Delete Confirmation Modal =============================== */ }
325+ < div
326+ className = { `w-screen h-screen bg-black bg-opacity-30 backdrop-blur-sm fixed top-0 left-0 z-20 flex items-center justify-center px-4 ${
327+ deleteConfirmationModel === true ? 'block' : 'hidden'
328+ } `}
329+ >
330+ < div className = "bg-white dark:bg-dark-bg w-full sm:w-3/4 md:w-1/2 xl:w-4/12 rounded-lg p-4 pb-8" >
331+ < div className = "card-title w-full flex justify-center items-center flex-col" >
332+ < h3 className = "font-bold text-sm text-gray-700 dark:text-white text-center w-11/12" >
333+ { t ( 'Are you sure you want to delete this user?' ) }
334+ </ h3 >
335+ < hr className = " bg-primary border-b my-3 w-full" />
336+ </ div >
337+ < div className = "card-body" >
338+ < div className = "w-full flex justify-between" >
339+ < Button
340+ variant = "info"
341+ size = "sm"
342+ style = "w-[30%] md:w-1/4 text-sm font-sans"
343+ onClick = { ( ) => setDeleteConfirmationModel ( false ) }
344+ >
345+ { t ( 'Cancel' ) }
346+ </ Button >
347+ < Button
348+ variant = "primary"
349+ size = "sm"
350+ style = "w-[30%] md:w-1/4 text-sm font-sans"
351+ onClick = { confirmDeleteUser }
352+ >
353+ { t ( 'Confirm' ) }
354+ </ Button >
355+ </ div >
356+ </ div >
357+ </ div >
358+ </ div >
261359 { /* =========================== Start:: delete Session Model =============================== */ }
262360 < div
263361 className = { `w-screen h-screen bg-black bg-opacity-30 backdrop-blur-sm fixed top-0 left-0 z-20 flex items-center justify-center px-4 ${
0 commit comments