diff --git a/src/Mutations/manageStudentMutations.tsx b/src/Mutations/manageStudentMutations.tsx index 34b9f4cd9..c0a4d167f 100644 --- a/src/Mutations/manageStudentMutations.tsx +++ b/src/Mutations/manageStudentMutations.tsx @@ -35,7 +35,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 c3e7742e6..aad130c45 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'; @@ -70,6 +71,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 = []; @@ -81,9 +84,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) => { @@ -166,7 +171,10 @@ function AdminTraineeDashboard() { const newState = !removeTraineeModel; setRemoveTraineeModel(newState); }; - + const restoreTraineeMod = () => { + const newState = !restoreTraineeModel; + setRestoreTraineeModel(newState); + }; const removeModel = () => { const newState = !registerTraineeModel; setRegisterTraineeModel(newState); @@ -261,18 +269,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'} + ); }, @@ -293,8 +301,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" + > <>
@@ -360,30 +369,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); + restoreTraineeMod(); + } 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, { @@ -655,7 +718,6 @@ function AdminTraineeDashboard() { teamOptions[index].label = team?.name; }); } - return ( <> @@ -669,20 +731,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 =============================== */}
@@ -1504,15 +1618,15 @@ function AdminTraineeDashboard() {
- {loading? ( - - ):( - 0 ? datum : []} - columns={columns} - loading={loading} - title={t('Trainee list')} - /> + {loading ? ( + + ) : ( + 0 ? datum : []} + columns={columns} + loading={loading} + title={t('Trainee list')} + /> )}
@@ -1524,4 +1638,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') {