Skip to content

Commit 57c1c9c

Browse files
UwicyezaGelijahladdie
authored andcommitted
admin remove user (#498)
^
1 parent f0d1c91 commit 57c1c9c

File tree

10 files changed

+348
-28
lines changed

10 files changed

+348
-28
lines changed

package-lock.json

Lines changed: 214 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
"file-loader": "^6.2.0",
151151
"graphql": "^16.7.1",
152152
"html-webpack-plugin": "^5.5.0",
153-
"husky": "^8.0.1",
153+
"husky": "^8.0.3",
154154
"install": "^0.13.0",
155155
"jest": "^28.1.3",
156156
"jest-axe": "^8.0.0",

public/locales/en/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,5 +345,6 @@
345345
"Documentation updated successfully": "Documentation updated successfully",
346346
"Please fill all fields": "Please fill all fields",
347347
"Boost your organization": "Boost your organizations productivity with Pulse",
348-
"Please wait to be added to a program or cohort": "Please wait to be added to a program or cohort"
348+
"Please wait to be added to a program or cohort": "Please wait to be added to a program or cohort",
349+
"Are you sure you want to delete this user?": "Are you sure you want to delete this user?"
349350
}

public/locales/fr/translation.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@
463463
"Provide Quantity range between 1-2": "Fournir une gamme de quantité comprise entre 1-2",
464464
"Provide Professional_Skills range between 1-2": "Fournir une gamme de compétences professionnelles comprise entre 1-2",
465465
"Sprint Ratings": "Sprint Notations",
466-
"Please wait to be added to a program or cohort":"Veuillez attendre d'être ajouté à un programme ou à une cohorte",
467-
"Enter all the required information":"Entrez toutes les informations requises"
466+
"Please wait to be added to a program or cohort": "Veuillez attendre d'être ajouté à un programme ou à une cohorte",
467+
"Enter all the required information": "Entrez toutes les informations requises",
468+
"Are you sure you want to delete this user?": "Êtes-vous sûr de vouloir supprimer cet utilisateur ?"
468469
}

public/locales/kn/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,5 +452,6 @@
452452
"Provide Professional_Skills range between 1-2": "Tanga ubuhanga buri hagati ya 1-2",
453453
"Sprint Ratings": "Amanota ya Sprint",
454454
"Please wait to be added to a program or cohort": "Tegereza tukongere muri porogarame cyangwa itsinda",
455-
"Enter all the required information": "Shyiramo amakuru yose asabwa"
455+
"Enter all the required information": "Shyiramo amakuru yose asabwa",
456+
"Are you sure you want to delete this user?": "urashaka kwemeza ikigikorwa cyo gusiba uyumuntu ?"
456457
}

src/components/DataTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function DataTable({ data, columns, title, loading }: TableData) {
143143
colSpan={columns.length}
144144
className="px-6 py-4 text-sm text-center text-gray-500 dark:text-gray-300 "
145145
>
146-
Loading...
146+
A Loading...
147147
</td>
148148
</tr>
149149
)}
@@ -183,4 +183,4 @@ function DataTable({ data, columns, title, loading }: TableData) {
183183
);
184184
}
185185

186-
export default DataTable;
186+
export default DataTable;

src/components/InvitationTable.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ function DataTableStats({ data, columns, error, loading }: TableData) {
6262
};
6363

6464
return (
65-
<div
66-
className={``}
67-
>
68-
<div className="flex items-center justify-between pb-6 ">
69-
</div>
65+
<div className="">
66+
<div className="flex items-center justify-between pb-6 " />
7067
<div style={{ overflowX: 'auto' }}>
7168
<table className="min-w-full leading-normal" {...getTableProps()}>
7269
<thead>
@@ -178,5 +175,4 @@ function DataTableStats({ data, columns, error, loading }: TableData) {
178175
);
179176
}
180177

181-
182178
export default DataTableStats;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { gql } from '@apollo/client';
2+
3+
const DELETE_USER_MUTATION = gql`
4+
mutation DeleteUser($input: DeleteUserInput!) {
5+
deleteUser(input: $input) {
6+
message
7+
}
8+
}
9+
`;
10+
11+
export default DELETE_USER_MUTATION;

src/containers/admin-dashBoard/ManagerRoles.tsx

Lines changed: 110 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import rolemanagement from '../../dummyData/rolemanagement.json';
77
import useDocumentTitle from '../../hook/useDocumentTitle';
88
import Button from './../../components/Buttons';
99
import devs from '../../dummyData/rolemanagement.json';
10+
import DELETE_USER_MUTATION from '../admin-dashBoard/DeleteUserMutation';
1011
import CREATE_ROLE_MUTATION from '../admin-dashBoard/createRoleMutation';
1112
import GET_ROLE_QUERY from '../admin-dashBoard/GetRolesQuery';
1213
import 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);
@@ -151,14 +180,13 @@ const AdminSission = () => {
151180
}, 1000);
152181
},
153182
});
154-
/* istanbul ignore next */
183+
/* istanbul ignore next */
155184
const [fetchData2] = useLazyQuery(GET_ROLE_QUERY, {
156185
variables: {
157186
orgToken: localStorage.getItem('orgToken'),
158187
},
159188
});
160189

161-
162190
useEffect(() => {
163191
fetchData2({
164192
fetchPolicy: 'network-only',
@@ -225,17 +253,30 @@ const AdminSission = () => {
225253
accessor: '',
226254
/* istanbul ignore next */
227255
Cell: ({ row }: any) => (
228-
<p
229-
className="text-red-500 whitespace-no-wrap cursor-pointer"
230-
onClick={
231-
/* istanbul ignore next */ () => {
232-
/* istanbul ignore next */
233-
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+
}
234264
}
235-
}
236-
>
237-
{t('Assign')}
238-
</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>
239280
),
240281
},
241282
];
@@ -253,12 +294,68 @@ const AdminSission = () => {
253294
name: 'ttl',
254295
},
255296
];
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+
256318
/* istanbul ignore next */
257319
return (
258320
<>
259321
{users && allRoless ? (
260322
<>
261323
{/* ... 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>
262359
{/* =========================== Start:: delete Session Model =============================== */}
263360
<div
264361
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 ${

src/pages/invitation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,4 +704,4 @@ function Invitation() {
704704
);
705705
}
706706

707-
export default Invitation;
707+
export default Invitation;

0 commit comments

Comments
 (0)