From 71f6740232ed8d490dc191444b6cfa1ffa7f3c84 Mon Sep 17 00:00:00 2001
From: Mouaz Abdelsamad <ma03081@surrey.ac.uk>
Date: Sat, 20 Apr 2024 01:02:14 +0100
Subject: [PATCH] show the flights for the actual airline

---
 client/src/components/Login/Login.tsx             | 3 +++
 client/src/components/Register/Register.tsx       | 3 +++
 client/src/services/Dashboard/AirlineDashboard.ts | 4 ++--
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/client/src/components/Login/Login.tsx b/client/src/components/Login/Login.tsx
index d9190f9..edb5577 100644
--- a/client/src/components/Login/Login.tsx
+++ b/client/src/components/Login/Login.tsx
@@ -5,6 +5,7 @@ import { AxiosError } from 'axios';
 import { useAuth } from '../../hooks/useAuth';
 import { loginUser } from '../../services/Login/Login';
 import { userToDashboard } from '../../helpers/UserType';
+import UserStorage from "../../helpers/UserStorage";
 import './Login.scss';
 
 export interface ILoginForm {
@@ -25,6 +26,8 @@ export function Login() {
       const result = await loginUser(formValue);
       if (result) {
         giveAuth();
+        const userId = result.data.id;
+        UserStorage.storeUserId(userId)
         updateUser(result.data);
         navigate(`/${userToDashboard(result.data)}`);
       } else {
diff --git a/client/src/components/Register/Register.tsx b/client/src/components/Register/Register.tsx
index dd9bd0a..5b85c96 100644
--- a/client/src/components/Register/Register.tsx
+++ b/client/src/components/Register/Register.tsx
@@ -6,6 +6,7 @@ import { registerUser } from '../../services/Register/Register';
 import { useAuth } from '../../hooks/useAuth';
 import './Register.scss';
 import { userToDashboard } from '../../helpers/UserType';
+import UserStorage from "../../helpers/UserStorage";
 
 export interface IRegisterForm {
   name: string;
@@ -37,6 +38,8 @@ export function Register() {
     try {
       const result = await registerUser(formValue);
       giveAuth();
+      const userId = result.data.id;
+      UserStorage.storeUserId(userId)
       updateUser(result.data);
       navigate(`/${userToDashboard(result.data)}`);
     } catch (error) {
diff --git a/client/src/services/Dashboard/AirlineDashboard.ts b/client/src/services/Dashboard/AirlineDashboard.ts
index 4a358bf..b0e1dda 100644
--- a/client/src/services/Dashboard/AirlineDashboard.ts
+++ b/client/src/services/Dashboard/AirlineDashboard.ts
@@ -1,5 +1,5 @@
 import Api from "../../helpers/Api";
-import { getSearchParam } from "../../helpers/SearchParams";
+import UserStorage from "../../helpers/UserStorage";
 
 export interface ISeat {
   id: number;
@@ -33,7 +33,7 @@ export interface IAirlineDashboardData {
 
 export async function GetAirlineDashboardData({request}: {request: Request}): Promise<IAirlineDashboardData> {
   try {
-    const id = getSearchParam(request.url, 'id');
+    const id = UserStorage.getUserId();
     const response = await Api.get(`Flight?airlineId=${id}`, { withCredentials: true });
     const flights = response.data.$values;
     return {
-- 
GitLab