From 3fc3bbf304baa19c4c88032c21a7c6f5ae435f81 Mon Sep 17 00:00:00 2001 From: elijahladdie Date: Wed, 2 Oct 2024 16:00:33 +0200 Subject: [PATCH] adding undrop trainee feature --- src/Mutations/manageStudentMutations.tsx | 7 +- src/pages/AdminTraineeDashboard.tsx | 225 +++++++++++++++++------ src/pages/Organization/AdminLogin.tsx | 2 + 3 files changed, 177 insertions(+), 57 deletions(-) diff --git a/src/Mutations/manageStudentMutations.tsx b/src/Mutations/manageStudentMutations.tsx index 91ed66327..6dd41b8f4 100644 --- a/src/Mutations/manageStudentMutations.tsx +++ b/src/Mutations/manageStudentMutations.tsx @@ -21,7 +21,12 @@ export const DROP_TRAINEE = gql` dropTrainee(traineeId: $traineeId, reason: $reason, date: $date) } `; - +// Define the mutation +export const UNDROP_TRAINEE = gql` + mutation UndropTrainee($traineeId: String!) { + undropTrainee(traineeId: $traineeId) + } +`; export const GET_TRAINEES_QUERY = gql` query GetTrainees($orgToken: String) { getTrainees(orgToken: $orgToken) { diff --git a/src/pages/AdminTraineeDashboard.tsx b/src/pages/AdminTraineeDashboard.tsx index ec9be2bc3..4f2eb4b7f 100644 --- a/src/pages/AdminTraineeDashboard.tsx +++ b/src/pages/AdminTraineeDashboard.tsx @@ -27,6 +27,7 @@ import { GET_TEAM_QUERY, ADD_MEMBER_TO_TEAM, GET_GITHUB_STATISTICS, + UNDROP_TRAINEE, } from '../Mutations/manageStudentMutations'; import { useNavigate } from 'react-router-dom'; @@ -69,6 +70,8 @@ function AdminTraineeDashboard() { const [editTeam, setEditTeam] = useState(''); const [inviteEmail, setInviteEmail] = useState(''); const [buttonLoading, setButtonLoading] = useState(false); + const [restoreTraineeModel, setRestoreTraineeModel] = useState(false); + const [toggle, setToggle] = useState(false); const [showOptions, setShowOptions] = useState(false); const options: any = []; @@ -80,9 +83,11 @@ function AdminTraineeDashboard() { const { traineeData, setAllTrainees } = useTraineesContext() || []; const [actionTraineeOptions, setActionTraineeOptions] = useState(null); const modalRef = useRef(null); - - const [selectedTraineeId, setSelectedTraineeId]= useState() - + // restoreTraineeModel + // restoreTraineeMod + // unDropTrainee + // restoreMemberFromCohort + const [selectedTraineeId, setSelectedTraineeId] = useState(); useEffect(() => { const handleClickOutside = (event: any) => { @@ -167,7 +172,10 @@ function AdminTraineeDashboard() { const newState = !removeTraineeModel; setRemoveTraineeModel(newState); }; - + const restoreTraineeMod = () => { + const newState = !restoreTraineeModel; + setRestoreTraineeModel(newState); + }; const removeModel = () => { const newState = !registerTraineeModel; setRegisterTraineeModel(newState); @@ -263,18 +271,18 @@ function AdminTraineeDashboard() { } > - + className={`${ + row.original?.Status?.status === 'drop' + ? 'bg-gray-500' + : 'bg-black' + } text-white rounded-xl px-3`} + onClick={() => { + setSelectedTraineeId(row.original?.email); + handleClickOpen2(); + }} + > + {row.original?.Status?.status === 'drop' ? 'Dropped' : 'View'} + ); }, @@ -295,8 +303,9 @@ function AdminTraineeDashboard() { /> {selectedRow === row.original.email && (
+ ref={modalRef} + className="absolute z-50 w-64 p-4 mt-2 overflow-hidden border border-gray-300 rounded-lg shadow-md dropdown right-4 bg-light-bg max-h-30 dark:bg-dark-bg" + > <>
@@ -362,30 +371,58 @@ function AdminTraineeDashboard() {
-
{ - dropModel(row.original.email); - setdropTraineeID(row.original.userId); - setReason(row.original.reason); - toggleOptions(row.original.email); - }} - > - -
- Drop{' '} - <> -
- Drop trainee - + {row.original?.Status?.status !== 'drop' ? ( +
{ + dropModel(row.original.email); + setdropTraineeID(row.original.userId); + setReason(row.original.reason); + toggleOptions(row.original.email); + }} + > + +
+ Drop + {row.original.status} + <> +
+ Drop trainee + +
-
+ ) : ( +
{ + restoreTraineeMod(); + setdropTraineeID(row.original.userId); + setReason(row.original.reason); + toggleOptions(row.original.email); + }} + > + +
+ Restore{' '} + <> +
+ Restore Dropped Trainee + +
+
+ )}
{ + setTimeout(() => { + setButtonLoading(false); + if (data.undropTrainee) { + // Check the response structure + refetch(); + toast.success('Trainee Undropped successfully'); + setDropTraineeModel(false); + } else { + toast.error('Failed to undrop trainee'); + } + }, 1000); + }, + onError: (err) => { + setTimeout(() => { + setButtonLoading(false); + console.error('Mutation error:', err); // Log the error + toast.error(err.message); + }, 500); + }, + }); const [removeMemberFromCohort] = useMutation( REMOVE_MEMBER_FROM_COHORT_MUTATION, { @@ -657,7 +719,6 @@ function AdminTraineeDashboard() { teamOptions[index].label = team?.name; }); } - return ( <> @@ -671,20 +732,21 @@ function AdminTraineeDashboard() { className="rounded-lg" fullWidth > - {traineeData?.map((data:any) => { - if (data.email === selectedTraineeId) { - return + {traineeData?.map((data: any) => { + if (data.email === selectedTraineeId) { + return ( + + ); } - } - )} + })}
{/* =========================== End:: AddTraineeModel =============================== */} + {/* =========================== Start:: RestoreTraineeModel =============================== */} + +
+
+
+

+ {t('restore Trainee')} +

+
+
+
+
+
+

+ {t('Are you sure you want to undrop this trainee?')} +

+
+ +
+ + +
+
+
+
+
+ {/* =========================== End:: RemoveTraineeModel =============================== */}
@@ -1522,4 +1635,4 @@ function AdminTraineeDashboard() { ); } -export default AdminTraineeDashboard; \ No newline at end of file +export default AdminTraineeDashboard; diff --git a/src/pages/Organization/AdminLogin.tsx b/src/pages/Organization/AdminLogin.tsx index 2303954c7..57523b159 100644 --- a/src/pages/Organization/AdminLogin.tsx +++ b/src/pages/Organization/AdminLogin.tsx @@ -106,6 +106,8 @@ function AdminLogin() { }, onError: (err) => { /* istanbul ignore next */ + console.log(err.message); + if (err.networkError) toast.error('There was a problem contacting the server'); else if (err.message.toLowerCase() !== 'invalid credential') {