Skip to content

Commit

Permalink
Check for errors in main list page
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Jun 21, 2023
1 parent 51b156c commit 79b09ed
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/components/egress/EgressRequestList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import Accordion from '@mui/material/Accordion';
import AccordionSummary from '@mui/material/AccordionSummary';
import AccordionDetails from '@mui/material/AccordionDetails';
import Alert from '@mui/material/Alert';
import Typography from '@mui/material/Typography';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import Snackbar from '@mui/material/Snackbar';
Expand Down Expand Up @@ -55,6 +56,7 @@ function EgressRequestList() {
const [decision, setDecision] = useState('');
const [isEditable, setIsEditable] = useState(false);
const [isDownloadable, setIsDownloadable] = useState(false);
const [fatalErrorMessages, setfatalErrorMessages] = useState([]);
const [openNotification, setOpenNotification] = useState(false);
const [notificationMessage, setNotificationMessage] = useState('');
const [userRole, setUserRole] = useState('');
Expand All @@ -78,9 +80,19 @@ function EgressRequestList() {
}
};

const appendFatalErrorMessage = (errorMessage) => {
setfatalErrorMessages((current) => [...current, errorMessage]);
};

// Fetch all egress requests
const getAllEgressRequests = async () => {
const requestsApiResult = await API.graphql(graphqlOperation(listRequests));
let requestsApiResult;
try {
requestsApiResult = await API.graphql(graphqlOperation(listRequests));
} catch (err) {
appendFatalErrorMessage(err.errors[0].message);
return [];
}
const data = requestsApiResult.data.listRequests;
const dataLength = data.length;

Expand Down Expand Up @@ -114,8 +126,7 @@ function EgressRequestList() {
}
}
} else {
setNotificationMessage('No available requests to view');
setOpenNotification(true);
appendFatalErrorMessage('No available requests to view');
}
return data;
};
Expand All @@ -127,8 +138,7 @@ function EgressRequestList() {
} else if (groups.includes(awsconfig.egress_rit_role)) {
setUserRole('reviewer_2');
} else {
setNotificationMessage('User role cannot be determined. Please contact an administrator');
setOpenNotification(true);
appendFatalErrorMessage('User role cannot be determined. Please contact an administrator');
}
};

Expand All @@ -140,8 +150,7 @@ function EgressRequestList() {
if (cognitoGroups) {
determineRole(cognitoGroups);
} else {
setNotificationMessage('You are not authorised to access this application');
setOpenNotification(true);
appendFatalErrorMessage('You are not authorised to access this application');
}
};

Expand Down Expand Up @@ -326,6 +335,9 @@ function EgressRequestList() {

return (
<>
{fatalErrorMessages.map((m) => (
<Alert severity="error">{m}</Alert>
))}
<div>
<div
style={{
Expand Down

0 comments on commit 79b09ed

Please sign in to comment.