96 switch from azure table storage to sqlite (#97)
* adding typeorm to api * switching to sqlite * switching to sqlite * switching to sqlite * migrating to sqlite * updating terraform * updating infrastructure
This commit was merged in pull request #97.
This commit is contained in:
32
client/src/hooks/accessToken/UseAcessToken.tsx
Normal file
32
client/src/hooks/accessToken/UseAcessToken.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
// import {
|
||||
// AuthenticationResult,
|
||||
// InteractionRequiredAuthError
|
||||
// } from '@azure/msal-browser';
|
||||
// import { useMsal } from '@azure/msal-react';
|
||||
|
||||
// export const useAccessToken = () => {
|
||||
// const { accounts, instance } = useMsal();
|
||||
// const getAccessToken = async () => {
|
||||
// const tokenRequest = {
|
||||
// account: accounts[0],
|
||||
// scopes: [`api://${import.meta.env.VITE_CLIENT_ID}/user_impersonation`]
|
||||
// };
|
||||
|
||||
// try {
|
||||
// const response: AuthenticationResult =
|
||||
// await instance.acquireTokenSilent(tokenRequest);
|
||||
|
||||
// return `Bearer ${response.accessToken}`;
|
||||
// } catch (error) {
|
||||
// if (error instanceof InteractionRequiredAuthError) {
|
||||
// await instance.acquireTokenRedirect(tokenRequest);
|
||||
// }
|
||||
|
||||
// throw error;
|
||||
// }
|
||||
// };
|
||||
|
||||
// return {
|
||||
// getAccessToken
|
||||
// };
|
||||
// };
|
||||
11
client/src/hooks/appContext/UseAppContext.tsx
Normal file
11
client/src/hooks/appContext/UseAppContext.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from 'react';
|
||||
import { AppContext } from '../../context/appContext/AppContext';
|
||||
|
||||
export const useAppContext = () => {
|
||||
const { state, dispatch } = useContext(AppContext);
|
||||
|
||||
return {
|
||||
state,
|
||||
dispatch
|
||||
};
|
||||
};
|
||||
11
client/src/hooks/logbookContext/UseLogbookContext.tsx
Normal file
11
client/src/hooks/logbookContext/UseLogbookContext.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from 'react';
|
||||
import { LogbookContext } from '../../context/logbookContext/LogbookContext';
|
||||
|
||||
export const useLogbookContext = () => {
|
||||
const { state, dispatch } = useContext(LogbookContext);
|
||||
|
||||
return {
|
||||
state,
|
||||
dispatch
|
||||
};
|
||||
};
|
||||
38
client/src/hooks/logs/UseLogs.tsx
Normal file
38
client/src/hooks/logs/UseLogs.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useAuth } from 'react-oidc-context';
|
||||
import { AxiosInstance, AxiosResponse } from "axios";
|
||||
import { LogbookEntry } from "../../components/logbook/LogbookEntry.interface";
|
||||
import httpClient from '../../httpClient/httpClient'
|
||||
|
||||
export const useLogs = () => {
|
||||
const [logs, setLogs] = useState<LogbookEntry[]>();
|
||||
const [logsLoading, setLogsLoading] = useState<boolean>(false);
|
||||
const auth = useAuth()
|
||||
|
||||
useEffect(() => {
|
||||
const getLogs = async () => {
|
||||
try {
|
||||
setLogsLoading(true);
|
||||
|
||||
const response: AxiosResponse = await httpClient.get(
|
||||
`api/logs`
|
||||
);
|
||||
const logs: LogbookEntry[] = response.data;
|
||||
|
||||
logs.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
|
||||
setLogs(logs)
|
||||
} catch (error) {
|
||||
return error;
|
||||
} finally {
|
||||
setLogsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
getLogs();
|
||||
}, [])
|
||||
|
||||
return {
|
||||
logs,
|
||||
logsLoading
|
||||
}
|
||||
}
|
||||
40
client/src/hooks/pilots/UsePilots.tsx
Normal file
40
client/src/hooks/pilots/UsePilots.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { AxiosInstance, AxiosResponse } from 'axios';
|
||||
import httpClient from '../../httpClient/httpClient';
|
||||
|
||||
export const usePilots = () => {
|
||||
const [pilots, setPilots] = useState<any[]>();
|
||||
|
||||
const getPilot = async (pilotId: string) => {
|
||||
try {
|
||||
const response: AxiosResponse = await httpClient.get(
|
||||
`api/pilots/${pilotId}`
|
||||
);
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const getPilots = async () => {
|
||||
try {
|
||||
const response: AxiosResponse = await httpClient.get(
|
||||
`/api/pilots`
|
||||
);
|
||||
|
||||
setPilots(response.data);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
};
|
||||
|
||||
getPilots();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
getPilot,
|
||||
pilots
|
||||
};
|
||||
};
|
||||
66
client/src/hooks/useBreakpoints/UseBreakpoints.tsx
Normal file
66
client/src/hooks/useBreakpoints/UseBreakpoints.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { ScreenSize } from '../../enums/screenSize';
|
||||
|
||||
export const useBreakpoints = () => {
|
||||
const [screenSize, setScreenSize] = useState<ScreenSize>();
|
||||
const windowWidth = window.innerWidth;
|
||||
|
||||
const getWindowSize = (width: number): ScreenSize => {
|
||||
let size!: ScreenSize;
|
||||
|
||||
switch (true) {
|
||||
case width < 640: {
|
||||
size = ScreenSize.SM;
|
||||
console.log('small')
|
||||
break;
|
||||
}
|
||||
case width >= 640: {
|
||||
size = ScreenSize.MD;
|
||||
|
||||
break;
|
||||
}
|
||||
case width >= 1024: {
|
||||
size = ScreenSize.LG
|
||||
|
||||
break;
|
||||
}
|
||||
case width >= 1280: {
|
||||
size = ScreenSize.XL;
|
||||
|
||||
break;
|
||||
}
|
||||
case width >= 1536: {
|
||||
size = ScreenSize.XXL;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
const onWindowResize = () => {
|
||||
const width: number = window.innerWidth;
|
||||
const newScreenSize: ScreenSize = getWindowSize(width);
|
||||
console.log(newScreenSize)
|
||||
setScreenSize(newScreenSize);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
console.log(windowWidth)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
onWindowResize()
|
||||
|
||||
window.addEventListener('resize', onWindowResize);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', onWindowResize);
|
||||
}
|
||||
}, [])
|
||||
|
||||
return {
|
||||
screenSize
|
||||
}
|
||||
}
|
||||
30
client/src/hooks/userRole/UseUserRole.tsx
Normal file
30
client/src/hooks/userRole/UseUserRole.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useOidc } from "../../auth/oidcConfig";
|
||||
import { UserRole } from "../../enums/userRole";
|
||||
|
||||
export const useUserRole = () => {
|
||||
const [userRole, setUserRole] = useState<UserRole>()
|
||||
const { isUserLoggedIn, decodedIdToken } = useOidc();
|
||||
|
||||
useEffect(() => {
|
||||
if (isUserLoggedIn && decodedIdToken) {
|
||||
const idTokenRoles: string[] = decodedIdToken!.roles as string[];
|
||||
|
||||
let newUserRole: string | undefined;
|
||||
|
||||
for (const key in UserRole) {
|
||||
if (UserRole[key as keyof typeof UserRole] === idTokenRoles[0]) {
|
||||
newUserRole = key;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setUserRole(UserRole[newUserRole! as keyof typeof UserRole]);
|
||||
}
|
||||
}, [decodedIdToken, isUserLoggedIn])
|
||||
|
||||
return {
|
||||
userRole
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user