Skip to content

Commit 607d8b6

Browse files
committed
fix(#290): fix add trainee in cohort
1 parent 70ce042 commit 607d8b6

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/pages/Cohort/CohortDetailPage.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getCohort, getAllTraineeApplicants, acceptTrainee } from "../../redux/a
88
import { useAppDispatch, useAppSelector } from "../../hooks/hooks";
99
import { useParams } from "react-router-dom";
1010
import { Spinner } from "flowbite-react";
11+
import { toast } from "react-toastify";
1112

1213
const CohortsDetailPage = () => {
1314
const [anchorEl, setAnchorEl] = useState(null);
@@ -37,8 +38,12 @@ const CohortsDetailPage = () => {
3738
const handleAddTraineeModal = async () => {
3839
setLoading(true);
3940
try {
40-
await dispatch(getAllTraineeApplicants());
41-
setAddTrainee(true);
41+
const result = await dispatch(getAllTraineeApplicants());
42+
if (result.error) {
43+
toast.error(result.error);
44+
} else {
45+
setAddTrainee(true);
46+
}
4247
} catch (error) {
4348
console.error("Error adding trainee:", error);
4449
} finally {

src/redux/actions/cohortActions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,20 @@ export const getAllTraineeApplicants = () => async (dispatch: any) => {
238238
_id
239239
email
240240
cohort
241+
applicationPhase
241242
}
242243
}
243244
`
244245
}
245246
});
246247
const traineeApplicants = await response.data.data.getAllTraineeApplicant;
247-
dispatch(creator(GET_ALL_TRAINEES, traineeApplicants));
248+
const admittedTrainees = traineeApplicants?.filter((trainee: any) => trainee?.applicationPhase === "Admitted");
249+
if (admittedTrainees.length === 0) {
250+
return { error: 'No trainees found' };
251+
} else {
252+
dispatch(creator(GET_ALL_TRAINEES, admittedTrainees));
253+
return { data: admittedTrainees };
254+
}
248255
} catch (error) {
249256
console.error('Error fetching trainee applicants:', error);
250257
}

0 commit comments

Comments
 (0)