Skip to content
Snippets Groups Projects
Commit a4f94d5a authored by Abdelsamad, Mouaz R (UG - SISC)'s avatar Abdelsamad, Mouaz R (UG - SISC)
Browse files

Merge branch 'airlineDashUpdate' of https://gitlab.surrey.ac.uk/ma03081/COM3014

parents a88f5fa6 cdc7fbf2
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,8 @@ import { useLoaderData } from 'react-router'; ...@@ -2,8 +2,8 @@ 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';
import { Link } from 'react-router-dom';
function Flights() { function Flights() {
const data = useLoaderData() as ICustomerDashboardData | IAirlineDashboardData; const data = useLoaderData() as ICustomerDashboardData | IAirlineDashboardData;
...@@ -14,11 +14,13 @@ function Flights() { ...@@ -14,11 +14,13 @@ function Flights() {
<div className='flights'> <div className='flights'>
<div className='flex-row'> <div className='flex-row'>
<span className='flights-title'>Upcoming Flights</span> <span className='flights-title'>Upcoming Flights</span>
<button type='submit' className='view-more'>View more</button> <Link to={"/"}>
<button type='button' className='view-more'>View more</button>
</Link>
</div> </div>
<div className='flight-list'> <div className='flight-list'>
{data.upcomingFlights.length > 0 {data.upcomingFlights.length > 0
? data.upcomingFlights.map((flight) => { ? data.upcomingFlights.slice(0,3).map((flight) => {
return <FlightCard key={flight.id} flight={flight}></FlightCard> return <FlightCard key={flight.id} flight={flight}></FlightCard>
}) })
: <div>No Upcoming Flights</div>} : <div>No Upcoming Flights</div>}
...@@ -28,11 +30,11 @@ function Flights() { ...@@ -28,11 +30,11 @@ function Flights() {
<div className='flights'> <div className='flights'>
<div className='flex-row'> <div className='flex-row'>
<span className='flights-title'>Flights History</span> <span className='flights-title'>Flights History</span>
<button type='submit' className='view-more'>View more</button> <button type='button' className='view-more'>View more</button>
</div> </div>
<div className='flight-list'> <div className='flight-list'>
{data.upcomingFlights.length > 0 {data.upcomingFlights.length > 0
? data.flightsHistory.map((flight) => { ? data.flightsHistory.slice(0,3).map((flight) => {
return <FlightCard key={flight.id} flight={flight}></FlightCard> return <FlightCard key={flight.id} flight={flight}></FlightCard>
}) })
: <div>No Flights History</div>} : <div>No Flights History</div>}
...@@ -43,8 +45,20 @@ function Flights() { ...@@ -43,8 +45,20 @@ function Flights() {
} else { } else {
return ( return (
<> <>
<div> <div className='flights'>
<FlightCreationForm></FlightCreationForm> <div className='flex-row'>
<span className='flights-title'>Upcoming Flights</span>
<Link to="/register-flight">
<button type='button' className='add-flight'>Add flight</button>
</Link>
</div>
<div className='flight-list'>
{data.flightList.length > 0
? data.flightList.slice(0,3).map((flight) => {
return <FlightCard key={flight.id} flight={flight}></FlightCard>
})
: <div>No Flights have been created yet.</div>}
</div>
</div> </div>
</> </>
); );
......
...@@ -20,6 +20,7 @@ import { GetFlightData } from './services/Flight/Flight.ts'; ...@@ -20,6 +20,7 @@ import { GetFlightData } from './services/Flight/Flight.ts';
import { GetFlightList } from './services/FlightList/FlightList.ts'; import { GetFlightList } from './services/FlightList/FlightList.ts';
import { GetBookingList } from './services/BookingList/BookingList.ts'; import { GetBookingList } from './services/BookingList/BookingList.ts';
import './index.scss'; import './index.scss';
import FlightCreationForm from './components/FlightCreationForm/FlightCreationForm.tsx';
const router = createBrowserRouter([ const router = createBrowserRouter([
{ {
...@@ -76,6 +77,10 @@ const router = createBrowserRouter([ ...@@ -76,6 +77,10 @@ const router = createBrowserRouter([
path: 'booking/list', path: 'booking/list',
loader: GetBookingList, loader: GetBookingList,
element: <BookingList></BookingList> element: <BookingList></BookingList>
},
{
path: 'register-flight',
element: <FlightCreationForm></FlightCreationForm>
} }
] ]
} }
......
import Api from "../../helpers/Api";
import { getSearchParam } from "../../helpers/SearchParams";
export interface ISeat {
id: number;
classType: number;
seatNumber: string;
isAvailable: boolean;
}
export interface ISeats {
$id: string;
$values: ISeat[];
}
export interface IFlight {
id: number;
origin: string;
destination: string;
arrivalTime: string;
departureTime: string;
economyCapacity: number;
businessCapacity: number;
economyPrice: number;
businessPrice: number;
seats: ISeats
}
export interface IAirlineDashboardData { export interface IAirlineDashboardData {
type: 'airline' type: 'airline'
flightList: IFlight[];
} }
export async function GetAirlineDashboardData(): Promise<IAirlineDashboardData> { export async function GetAirlineDashboardData({request}: {request: Request}): Promise<IAirlineDashboardData> {
return { try {
type: 'airline' const id = getSearchParam(request.url, 'id');
}; const result = await Api.get(`Flight?airlineId=${id}`, { withCredentials: true });
return result.data;
} catch (error) {
throw error;
}
} }
import Api from "../../helpers/Api";
export interface ISeat { export interface ISeat {
id: number; id: number;
classType: number; classType: number;
...@@ -30,9 +32,17 @@ export interface ICustomerDashboardData { ...@@ -30,9 +32,17 @@ export interface ICustomerDashboardData {
} }
export async function GetCustomerDashboardData(): Promise<ICustomerDashboardData> { export async function GetCustomerDashboardData(): Promise<ICustomerDashboardData> {
return { try {
type: 'customer', const upcomingFlights = Api.get('', {withCredentials: true});
upcomingFlights: [], const flightsHistory = Api.get('', {withCredentials: true});
flightsHistory: [] const [uData, hData] = await Promise.all([upcomingFlights, flightsHistory]);
return {
type: 'customer',
upcomingFlights: uData.data,
flightsHistory: hData.data
};
} catch (error) {
throw error;
} }
} }
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