Skip to content

Commit 6bb501f

Browse files
committed
fix(#290): fix add trainee in cohort
1 parent 01d25fb commit 6bb501f

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/pages/Cohort/CohortDetailPage.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useAppDispatch, useAppSelector } from "../../hooks/hooks";
99
import { useParams } from "react-router-dom";
1010
import { Spinner } from "flowbite-react";
1111
import { CohortDetailSkeleton } from "../../skeletons/singleCohortSketon";
12+
import { toast } from "react-toastify";
1213

1314
const CohortsDetailPage = () => {
1415
const [anchorEl, setAnchorEl] = useState(null);
@@ -38,10 +39,14 @@ const CohortsDetailPage = () => {
3839
const handleAddTraineeModal = async () => {
3940
setLoading(true);
4041
try {
41-
await dispatch(getAllTraineeApplicants());
42-
setAddTrainee(true);
42+
const result = await dispatch(getAllTraineeApplicants());
43+
if (result.error) {
44+
toast.error(result.error);
45+
} else {
46+
setAddTrainee(true);
47+
}
4348
} catch (error) {
44-
console.error("Error adding trainee:", error);
49+
toast.error("Error adding trainee");
4550
} finally {
4651
setLoading(false);
4752
}

src/redux/actions/cohortActions.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,22 @@ export const getAllTraineeApplicants = () => async (dispatch: any) => {
239239
_id
240240
email
241241
cohort
242+
applicationPhase
242243
}
243244
}
244245
`
245246
}
246247
});
247248
const traineeApplicants = await response.data.data.getAllTraineeApplicant;
248-
dispatch(creator(GET_ALL_TRAINEES, traineeApplicants));
249+
const admittedTrainees = traineeApplicants?.filter((trainee: any) => trainee?.applicationPhase === "Admitted");
250+
if (admittedTrainees.length === 0) {
251+
return { error: 'No trainees found' };
252+
} else {
253+
dispatch(creator(GET_ALL_TRAINEES, admittedTrainees));
254+
return { data: admittedTrainees };
255+
}
249256
} catch (error) {
250-
console.error('Error fetching trainee applicants:', error);
257+
toast.error("Error fetching trainee applicants");
251258
}
252259
};
253260

0 commit comments

Comments
 (0)