Skip to content
Snippets Groups Projects
Commit ea81025a authored by Cross, Liam (UG - Comp Sci & Elec Eng)'s avatar Cross, Liam (UG - Comp Sci & Elec Eng)
Browse files

Integrate flight form and add API interceptor

parent cfcf015c
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import { useLoaderData } from 'react-router'; ...@@ -2,6 +2,7 @@ import { useLoaderData } from 'react-router';
import { ICustomerDashboardData } from '../../../services/Dashboard/CustomerDashboard'; import { ICustomerDashboardData } from '../../../services/Dashboard/CustomerDashboard';
import { IAirlineDashboardData } from '../../../services/Dashboard/AirlineDashboard'; import { IAirlineDashboardData } from '../../../services/Dashboard/AirlineDashboard';
import FlightCard from '../FlightCard/FlightCard'; import FlightCard from '../FlightCard/FlightCard';
import FlightCreationForm from '../../FlightCreationForm/FlightCreationForm';
import './Flights.scss'; import './Flights.scss';
function Flights() { function Flights() {
...@@ -43,7 +44,7 @@ function Flights() { ...@@ -43,7 +44,7 @@ function Flights() {
return ( return (
<> <>
<div> <div>
todo airline dashboard <FlightCreationForm></FlightCreationForm>
</div> </div>
</> </>
); );
......
...@@ -6,7 +6,13 @@ ...@@ -6,7 +6,13 @@
height: 100%; height: 100%;
} }
.register-card { .inner-flight-form {
width: 20vw; display: flex;
min-width: 350px; gap: 1rem;
}
.form-col {
display: flex;
flex-direction: column;
gap: 1rem;
} }
import { useState } from 'react'; import { useState } from 'react';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import './FlightCreationForm.scss';
interface IFlightCreationForm { interface IFlightCreationForm {
origin: string; origin: string;
...@@ -27,46 +28,51 @@ function FlightCreationForm() { ...@@ -27,46 +28,51 @@ function FlightCreationForm() {
<> <>
<div className='flightCreationForm'> <div className='flightCreationForm'>
<form onSubmit={handleSubmit(onSubmit)}> <form onSubmit={handleSubmit(onSubmit)}>
<div className='card register-card'> <div className='card flight-form-card'>
<div className='inner-flight-form'>
<div className='form-col'>
<div className='form-group'>
<label>Origin</label>
<input type='text' placeholder='Enter origin' {...register('origin', { required: true })} />
</div>
<div className='form-group'>
<label>Destination</label>
<input type='text' placeholder='Enter destination' {...register('destination', { required: true })} />
</div>
<div className='form-group'> <div className='form-group'>
<label>Origin</label> <label>Departure Time</label>
<input type='text' placeholder='Enter origin' {...register('origin', { required: true })} /> <input type='datetime-local' placeholder='Enter departure time' {...register('departure', { required: true })} />
</div> </div>
<div className='form-group'>
<label>Destination</label>
<input type='text' placeholder='Enter destination' {...register('destination', { required: true })} />
</div>
<div className='form-group'> <div className='form-group'>
<label>Departure Time</label> <label>Arrival Time</label>
<input type='datetime-local' placeholder='Enter departure time' {...register('departure', { required: true })} /> <input type='datetime-local' placeholder='Enter arrival time' {...register('arrival', { required: true })} />
</div> </div>
</div>
<div className='form-group'>
<label>Arrival Time</label>
<input type='datetime-local' placeholder='Enter arrival time' {...register('arrival', { required: true })} />
</div>
<div className='form-group'> <div className='form-col'>
<label>Economy Class Capacity</label> <div className='form-group'>
<input type='number' placeholder='Enter capacity' {...register('economyCapacity', { required: true })} /> <label>Economy Class Capacity</label>
</div> <input type='number' placeholder='Enter capacity' {...register('economyCapacity', { required: true })} />
</div>
<div className='form-group'> <div className='form-group'>
<label>Business Class Capacity</label> <label>Business Class Capacity</label>
<input type='number' placeholder='Enter capacity' {...register('businessCapacity', { required: true })} /> <input type='number' placeholder='Enter capacity' {...register('businessCapacity', { required: true })} />
</div> </div>
<div className='form-group'> <div className='form-group'>
<label>Economy Class Price</label> <label>Economy Class Price</label>
<input type='number' placeholder='Enter price' {...register('economyPrice', { required: true })} /> <input type='number' placeholder='Enter price' {...register('economyPrice', { required: true })} />
</div> </div>
<div className='form-group'> <div className='form-group'>
<label>Business Class Price</label> <label>Business Class Price</label>
<input type='number' placeholder='Enter price' {...register('businessPrice', { required: true })} /> <input type='number' placeholder='Enter price' {...register('businessPrice', { required: true })} />
</div>
</div>
</div> </div>
<div className='form-group'> <div className='form-group'>
......
...@@ -16,7 +16,7 @@ export interface IRegisterForm { ...@@ -16,7 +16,7 @@ export interface IRegisterForm {
} }
export function Register() { export function Register() {
const { giveAuth, updateUser, user } = useAuth(); const { giveAuth, updateUser } = useAuth();
const navigate = useNavigate(); const navigate = useNavigate();
const [error, setError] = useState(''); const [error, setError] = useState('');
const { register, handleSubmit } = useForm<IRegisterForm>({mode: 'onChange'}); const { register, handleSubmit } = useForm<IRegisterForm>({mode: 'onChange'});
......
import axios from 'axios'; import axios from 'axios';
import { AxiosError, AxiosRequestConfig } from 'axios';
import { AuthoriseUser } from '../services/Authorise/Authorise';
export default axios.create({ const Api = axios.create({
baseURL: 'http://localhost:5267/api/' baseURL: 'http://localhost:5267/api/'
}); });
Api.interceptors.response.use(
(response) => response, // Normal success logic
(error: AxiosError) => {
if (error.request.status === 401) { // If 401 (Unauthorized)
AuthoriseUser().then(() => { // Re-auth
return Api.request(error.config as AxiosRequestConfig); // Redo the request
});
} else {
throw error; // Otherwise throw error as normal
}
}
);
export default Api;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment