Skip to content

Commit

Permalink
Fix fault alerts (#182)
Browse files Browse the repository at this point in the history
* correct error messages

* work on resolving fault alerts
  • Loading branch information
MnorbertVii authored Oct 8, 2024
1 parent a0921ad commit 3312bbb
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 240 deletions.
5 changes: 0 additions & 5 deletions src/components/sidebar/sidebarItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ export const sidebarItems1 = [
icon: <Icon icon="akar-icons:globe"></Icon>,
title: "Applications",
},
{
path: "Trainee-applicants",
icon: <Icon icon="ic:round-people"></Icon>,
title: "Trainees-Applicants",
},
{
path: "cohort",
icon: <Icon icon="fa6-solid:graduation-cap"></Icon>,
Expand Down
318 changes: 159 additions & 159 deletions src/pages/Applications.tsx

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions src/pages/Applications/AdminViewApplications.tsx
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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
);
Expand Down
11 changes: 9 additions & 2 deletions src/pages/programs/Programs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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]);


Expand Down
119 changes: 63 additions & 56 deletions src/redux/actions/adminListApplications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
11 changes: 7 additions & 4 deletions src/redux/actions/applications.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ViewSingleApplication } from './adminListApplications';
import {
fetchMyApplications,
deleteOwnApplication,
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
};

Expand Down
6 changes: 4 additions & 2 deletions src/redux/actions/fetchProgramsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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,
Expand Down
11 changes: 2 additions & 9 deletions src/redux/reducers/applicationReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -37,6 +29,7 @@ export const applicationsReducer = (
switch (action.type) {
case fetchMyApplications.FETCH_MYAPPLICATIONS_LOADING:
return {
...state,
loading: true,
success: false,
error: null,
Expand Down

0 comments on commit 3312bbb

Please sign in to comment.