-
@@ -430,13 +429,13 @@ const Applications = (props: any) => {
menuPlacement="top"
className="sm:text-sm w-13 rounded-bt-rd absolute active dark:bg-dark-frame-bg"
options={[
- { value: '5', label: '5' },
- { value: '50', label: '50' },
- { value: '100', label: '100' },
- { value: '500', label: '500' },
- { value: '1000', label: '1000' },
+ { value: "5", label: "5" },
+ { value: "50", label: "50" },
+ { value: "100", label: "100" },
+ { value: "500", label: "500" },
+ { value: "1000", label: "1000" },
]}
- defaultValue={{ value: '', label: '5' }}
+ defaultValue={{ value: "", label: "5" }}
onChange={(e: any) =>
setPagination({
page: 1,
@@ -495,7 +494,7 @@ const Applications = (props: any) => {
pagination.page >=
Math.ceil(
myApplications?.data?.totalCount /
- pagination.pageSize,
+ pagination.pageSize
)
}
>
@@ -508,7 +507,7 @@ const Applications = (props: any) => {
pageSize: pagination.pageSize,
page: Math.ceil(
myApplications?.data?.totalCount /
- pagination.pageSize,
+ pagination.pageSize
),
})
}
@@ -516,7 +515,7 @@ const Applications = (props: any) => {
pagination.page >=
Math.ceil(
myApplications?.data?.totalCount /
- pagination.pageSize,
+ pagination.pageSize
)
}
>
@@ -542,6 +541,7 @@ const Applications = (props: any) => {
const mapState = (state: any) => ({
myApplications: state.myApplications,
currentApplication: state.currentApplication,
+ loading: state.myApplications.loading,
});
export default connect(mapState, {
diff --git a/src/pages/Applications/AdminViewApplications.tsx b/src/pages/Applications/AdminViewApplications.tsx
index d29d6dc1d..3d2921e9c 100644
--- a/src/pages/Applications/AdminViewApplications.tsx
+++ b/src/pages/Applications/AdminViewApplications.tsx
@@ -1,11 +1,12 @@
import React, { useState, useEffect } from 'react';
-import { Link } from 'react-router-dom';
+import { Link, useNavigate } from 'react-router-dom';
import NavBar from '../../components/sidebar/navHeader';
import { fetchApplications } from '../../redux/actions/adminListApplications';
import { HiDotsVertical } from 'react-icons/hi';
import { Pagination } from 'flowbite-react';
const ListApplications = () => {
+ const navigate = useNavigate();
const [applications, setApplications]: any = useState();
const [activePage, setActivePage] = useState(1);
@@ -20,8 +21,15 @@ const ListApplications = () => {
useEffect(() => {
const applicationsData = async () => {
- const data = await fetchApplications();
- const slicedData = data?.applications.slice(
+ const { data, error } = await fetchApplications();
+ console.log(error);
+ // if(error){
+ // setTimeout(() => {
+ // navigate('/login');
+ // }, 5000);
+ // return;
+ // }
+ const slicedData = data?.data?.applications.slice(
(activePage - 1) * itemsCountPerPage,
activePage * itemsCountPerPage
);
diff --git a/src/pages/programs/Programs.tsx b/src/pages/programs/Programs.tsx
index 8d123e0d9..c81298807 100644
--- a/src/pages/programs/Programs.tsx
+++ b/src/pages/programs/Programs.tsx
@@ -5,7 +5,7 @@ import { connect } from "react-redux";
import { createProgramAction } from "../../redux/actions/createProgramAction";
import { useAppDispatch, useAppSelector } from "../../hooks/hooks";
import programSchema from "../../validation/programSchema";
-import { Link } from "react-router-dom";
+import { Link, useNavigate } from "react-router-dom";
import { HiDotsVertical } from "react-icons/hi";
import * as AiIcons from "react-icons/ai";
import {
@@ -23,6 +23,7 @@ import { useTheme } from "../../hooks/darkmode";
import {debounce} from "lodash"
const Programs = (props: any) => {
+ const navigate = useNavigate();
const { createProgramStates, fetchProgramStates, deleteProgramStates } =
props;
const { theme, setTheme } = useTheme();
@@ -249,7 +250,13 @@ const Programs = (props: any) => {
};
useEffect(() => {
- props.fetchPrograms(input);
+ const { data, error } = props.fetchPrograms(input);
+ // if (error) {
+ // setTimeout(() => {
+ // navigate('/login');
+ // }, 5000);
+ // return;
+ // }
}, [page, itemsPerPage]);
diff --git a/src/redux/actions/adminListApplications.ts b/src/redux/actions/adminListApplications.ts
index 9350dbcbe..f95ae1db6 100644
--- a/src/redux/actions/adminListApplications.ts
+++ b/src/redux/actions/adminListApplications.ts
@@ -3,74 +3,81 @@ import { toast } from 'react-toastify';
export const fetchApplications = async () => {
- const response = await axios({
- url: process.env.BACKEND_URL,
- method: 'post',
- data: {
- query: `
- query AdminViewApplications {
- adminViewApplications {
- applications {
- _id
- firstName
- lastName
- email
- telephone
- availability_for_interview
- gender
- resume
- comments
- address
- status
- formUrl
- dateOfSubmission
- associatedFormData {
+ try{
+
+ const response = await axios({
+ url: process.env.BACKEND_URL,
+ method: 'post',
+ data: {
+ query: `
+ query AdminViewApplications {
+ adminViewApplications {
+ applications {
_id
- title
- description
- link
- jobpost {
+ firstName
+ lastName
+ email
+ telephone
+ availability_for_interview
+ gender
+ resume
+ comments
+ address
+ status
+ formUrl
+ dateOfSubmission
+ associatedFormData {
_id
title
- cycle {
- id
- name
- startDate
- endDate
- }
- program {
+ description
+ link
+ jobpost {
_id
title
+ cycle {
+ id
+ name
+ startDate
+ endDate
+ }
+ program {
+ _id
+ title
+ description
+ mainObjective
+ requirements
+ modeOfExecution
+ duration
+ }
+ cohort {
+ id
+ title
+ start
+ end
+ }
+ link
description
- mainObjective
- requirements
- modeOfExecution
- duration
- }
- cohort {
- id
- title
- start
- end
+ label
}
- link
- description
- label
}
}
}
}
- }
- `,
- },
- });
-
- if (response.data.errors) {
- toast.error('Error fetching applications');
- return;
+ `,
+ },
+ });
+
+ if (response.data.errors) {
+ console.log(response.data.errors);
+ toast.error(response.data.errors[0].message);
+ return {data: null, error:response.data.errors[0].message };
+ }
+
+ return { data: response.data.data.adminViewApplications, error: null };
+ } catch (error: any) {
+ toast.error("An unexpected error occurred");
+ return { data: null, error: error.message };
}
-
- return response.data.data.adminViewApplications;
};
type Status = {
diff --git a/src/redux/actions/applications.ts b/src/redux/actions/applications.ts
index 511a74d51..4f66c5401 100644
--- a/src/redux/actions/applications.ts
+++ b/src/redux/actions/applications.ts
@@ -1,3 +1,4 @@
+import { ViewSingleApplication } from './adminListApplications';
import {
fetchMyApplications,
deleteOwnApplication,
@@ -19,6 +20,7 @@ export const getMyApplications =
const response = await axios.post('/', {
query: `query ViewAllOwnApplications($filter: ApplicationFilter, $pagination: PaginationInput) {
viewAllOwnApplications(filter: $filter, pagination: $pagination) {
+ message
totalCount
applications {
_id
@@ -55,23 +57,24 @@ export const getMyApplications =
},
});
if (response.data.data.viewAllOwnApplications != null) {
+ let toastShown = false
dispatch({
type: fetchMyApplications.FETCH_MYAPPLICATIONS_SUCCESS,
data: response.data.data.viewAllOwnApplications,
- message: 'success',
+ message: response.data.data.viewAllOwnApplications.message,
});
+ toast.success(response.data.data.viewAllOwnApplications.message)
return response.data.data;
} else {
dispatch({
type: fetchMyApplications.FETCH_MYAPPLICATIONS_FAIL,
error: response.data.errors[0].message,
});
- toast.error(response.data.errors[0].message);
-
+ toast.error(response.data.errors[0].message);
return response.data.data;
}
} catch (err: any) {
- toast.error(err.message);
+ console.error(err.message);
}
};
diff --git a/src/redux/actions/fetchProgramsAction.ts b/src/redux/actions/fetchProgramsAction.ts
index 6ae088e99..806c75e98 100644
--- a/src/redux/actions/fetchProgramsAction.ts
+++ b/src/redux/actions/fetchProgramsAction.ts
@@ -43,7 +43,9 @@ export const fetchPrograms = (pageDetails: any) => {
}
if (response.data.errors) {
- toast.error("Programs could not be fetched");
+ console.log(response.data.errors)
+ toast.error(response.data.errors[0].message);
+ return {data: null, error:response.data.errors[0].message };
let mess;
response.data.errors.map((b: any) => {
@@ -55,7 +57,7 @@ export const fetchPrograms = (pageDetails: any) => {
});
}
} catch (error) {
- toast.error("Programs could not be fetched");
+ toast.error("Oops! unexpected error occured");
dispatch({
type: fetchProgramType.FETCH_PROGRAM_FAIL,
diff --git a/src/redux/reducers/applicationReducer.ts b/src/redux/reducers/applicationReducer.ts
index 16cf36e68..7cdaacdb7 100644
--- a/src/redux/reducers/applicationReducer.ts
+++ b/src/redux/reducers/applicationReducer.ts
@@ -19,15 +19,7 @@ const initialState = {
success: false,
error: null,
message: null,
- data: null,
-};
-
-const applicationState = {
- loading: false,
- success: false,
- error: null,
- message: null,
- data: null,
+ data: { applications: [] },
};
export const applicationsReducer = (
@@ -37,6 +29,7 @@ export const applicationsReducer = (
switch (action.type) {
case fetchMyApplications.FETCH_MYAPPLICATIONS_LOADING:
return {
+ ...state,
loading: true,
success: false,
error: null,