use some status information to handle errors better

This commit is contained in:
Sven Czarnian
2022-11-05 00:10:27 +01:00
parent 47c09f2fdd
commit df0a6ade57
6 changed files with 107 additions and 24 deletions

View File

@@ -4,7 +4,7 @@ import { useNavigate } from 'react-router-dom';
import { AuthContext, TimeContext } from '../contexts';
import { Configuration } from '../services';
import { Airport } from '../services';
import { AirportOverview, IAuthState } from '../types';
import { AirportOverview, BackendReturnStatus, IAuthState } from '../types';
export const NavBar: React.FC = () => {
const [timestamp, setTimestamp] = useState<string>('');
@@ -63,7 +63,9 @@ export const NavBar: React.FC = () => {
const updateMenuItems = async () => {
if (currentAuth.current === undefined || !currentAuth.current.valid) return [];
Airport.all().then((airports) => {
Airport.all().then((response) => {
if (response.status !== BackendReturnStatus.Ok) return [];
const newMenuTree: { label: string; items?: any[]; command?: () => void }[] = [
{
label: 'Airports',
@@ -72,12 +74,12 @@ export const NavBar: React.FC = () => {
];
// create the airports subtree
const airportSubtree = firBasedSubMenu(airports, '/sequence');
const airportSubtree = firBasedSubMenu(response.airports, '/sequence');
newMenuTree[0].items = airportSubtree;
// collect all configuration airports
const configurationAirports: AirportOverview[] = [];
airports.forEach((airport) => {
response.airports.forEach((airport) => {
const idx = currentAuth.current?.user.airportConfigurationAccess.findIndex((value) => airport.icao === value);
if (idx !== -1) configurationAirports.push(airport);
});