Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 70fde43801 | |||
| adb8e51adf | |||
| 09f19b178f | |||
| 98cfe69afb |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "api",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
@@ -27,7 +27,7 @@
|
||||
"@nestjs/passport": "^10.0.3",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@noahspan/azure-database": "^3.1.2",
|
||||
"@noahspan/noahspan-modules": "^1.0.0",
|
||||
"@noahspan/noahspan-modules": "^1.1.5",
|
||||
"@schematics/angular": "^17.3.7",
|
||||
"dotenv": "^16.4.7",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
|
||||
@@ -44,11 +44,11 @@ import configuration from './config/configuration';
|
||||
provide: APP_FILTER,
|
||||
useClass: HttpExceptionFilter
|
||||
},
|
||||
{
|
||||
provide: APP_GUARD,
|
||||
useClass: AuthGuard
|
||||
},
|
||||
Reflector
|
||||
// {
|
||||
// provide: APP_GUARD,
|
||||
// useClass: AuthGuard
|
||||
// },
|
||||
// Reflector
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
39
api/src/log/interceptors/log.interceptor.ts
Normal file
39
api/src/log/interceptors/log.interceptor.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
||||
import { Observable, map } from 'rxjs';
|
||||
|
||||
export class LogInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, handler: CallHandler): Observable<any> {
|
||||
const req = context.switchToHttp().getRequest();
|
||||
const authHeader = req.headers.authorization;
|
||||
const token = authHeader && authHeader.split(' ')[1];
|
||||
|
||||
if (!token) {
|
||||
return handler.handle().pipe(
|
||||
map((data) => {
|
||||
if (data.length) {
|
||||
const logs = data.map((log) => {
|
||||
return {
|
||||
partitionKey: log.partitionKey,
|
||||
rowKey: log.rowKey,
|
||||
pilotId: log.pilotId,
|
||||
pilotName: log.pilotName,
|
||||
date: log.date,
|
||||
aircraftMakeModel: log.aircraftMakeModel,
|
||||
routeFrom: log.routeFrom,
|
||||
routeTo: log.routeTo,
|
||||
durationOfFlight: log.durationOfFlight,
|
||||
notes: log.notes
|
||||
};
|
||||
});
|
||||
|
||||
return logs;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return handler.handle().pipe(map((data) => data));
|
||||
}
|
||||
}
|
||||
@@ -7,20 +7,22 @@ import {
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards
|
||||
UseGuards,
|
||||
UseInterceptors
|
||||
} from '@nestjs/common';
|
||||
import { LogDto } from './log.dto';
|
||||
import { Log } from './log.entity';
|
||||
import { LogService } from './log.service';
|
||||
import { CustomError } from '../error/customError';
|
||||
import { Public } from '@noahspan/noahspan-modules';
|
||||
import { AuthGuard } from '@noahspan/noahspan-modules';
|
||||
import { LogInterceptor } from './interceptors/log.interceptor';
|
||||
|
||||
|
||||
@Controller('logs')
|
||||
@UseInterceptors(new LogInterceptor())
|
||||
export class LogController {
|
||||
constructor(private readonly logService: LogService) {}
|
||||
|
||||
@Public()
|
||||
@Get(':partitionKey/:rowKey')
|
||||
async find(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@@ -35,7 +37,6 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Get()
|
||||
async findAll(): Promise<Log[]> {
|
||||
try {
|
||||
@@ -47,6 +48,7 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Post()
|
||||
async create(@Body() logDto: LogDto): Promise<Log> {
|
||||
try {
|
||||
@@ -62,6 +64,7 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Put(':partitionKey/:rowKey')
|
||||
async update(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@@ -81,6 +84,7 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Delete(':partitionKey/:rowKey')
|
||||
async delete(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
|
||||
@@ -16,10 +16,12 @@ export class PilotInterceptor implements NestInterceptor {
|
||||
partitionKey: pilot.partitionKey,
|
||||
rowKey: pilot.rowKey,
|
||||
id: pilot.id,
|
||||
name: pilot.name
|
||||
name: pilot.name,
|
||||
certificates: pilot.certificates,
|
||||
endorsements: pilot.endorsements
|
||||
};
|
||||
});
|
||||
console.log(pilots)
|
||||
|
||||
return pilots;
|
||||
} else {
|
||||
return data;
|
||||
|
||||
@@ -7,13 +7,14 @@ import {
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import { PilotDto } from './pilot.dto';
|
||||
import { Pilot } from './pilot.entity';
|
||||
import { PilotService } from './pilot.service';
|
||||
import { CustomError } from '../error/customError';
|
||||
import { Public } from '@noahspan/noahspan-modules'
|
||||
import { AuthGuard } from '@noahspan/noahspan-modules'
|
||||
import { PilotInterceptor } from './interceptors/pilot.interceptor';
|
||||
|
||||
@Controller('pilots')
|
||||
@@ -21,7 +22,6 @@ import { PilotInterceptor } from './interceptors/pilot.interceptor';
|
||||
export class PilotController {
|
||||
constructor(private readonly pilotService: PilotService) {}
|
||||
|
||||
@Public()
|
||||
@Get(':partitionKey/:rowKey')
|
||||
async find(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@@ -36,7 +36,6 @@ export class PilotController {
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Get()
|
||||
async findAll() {
|
||||
try {
|
||||
@@ -48,6 +47,7 @@ export class PilotController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Post()
|
||||
async create(@Body() pilotDto: PilotDto) {
|
||||
try {
|
||||
@@ -78,6 +78,7 @@ export class PilotController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Put(':partitionKey/:rowKey')
|
||||
async update(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@@ -112,6 +113,7 @@ export class PilotController {
|
||||
}
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Delete(':partitionKey/:rowKey')
|
||||
async delete(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "app",
|
||||
"private": true,
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -13,7 +13,7 @@
|
||||
"dependencies": {
|
||||
"@azure/msal-browser": "^4.0.1",
|
||||
"@azure/msal-react": "^3.0.1",
|
||||
"@noahspan/noahspan-components": "^1.4.0",
|
||||
"@noahspan/noahspan-components": "^1.5.1",
|
||||
"axios": "^1.7.2",
|
||||
"dotenv": "^16.4.7",
|
||||
"react": "^18.3.1",
|
||||
|
||||
@@ -19,11 +19,7 @@ const App = () => {
|
||||
<>
|
||||
<SiteNav />
|
||||
<Routes>
|
||||
<Route path="/pilots" element={
|
||||
<ProtectedRoute>
|
||||
<Pilots />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
<Route path="/pilots" element={<Pilots />} />
|
||||
<Route path="/" element={<Logbook />} />
|
||||
</Routes>
|
||||
</>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ export interface ILogbookEntry {
|
||||
rowKey: string;
|
||||
id: string;
|
||||
pilotId: string;
|
||||
pilotName: string;
|
||||
date: string;
|
||||
aircraftMakeModel: string;
|
||||
aircraftIdentity: string;
|
||||
@@ -24,4 +25,5 @@ export interface ILogbookEntry {
|
||||
night: number | null;
|
||||
solo: number | null;
|
||||
pilotInCommand: number | null;
|
||||
notes: string;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,9 @@ import {
|
||||
IconName,
|
||||
Spinner,
|
||||
Table,
|
||||
Typography
|
||||
theme,
|
||||
Typography,
|
||||
useMediaQuery
|
||||
} from '@noahspan/noahspan-components';
|
||||
import { initialState, reducer } from './reducer';
|
||||
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
||||
@@ -21,12 +23,14 @@ import { FormMode } from '../../enums/formMode';
|
||||
import ActionMenu from '../actionMenu/ActionMenu';
|
||||
import ConfirmationDialog from '../confirmationDialog/ConfirmationDialog';
|
||||
import { ILogbookEntry } from './ILogbookEntry';
|
||||
import LogbookCard from '../logbookCard/LogbookCard';
|
||||
|
||||
const Logbook: React.FC<unknown> = () => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
const httpClient: AxiosInstance = useHttpClient();
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
const { getAccessToken } = useAccessToken();
|
||||
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||
|
||||
const getLogbookEntries = async () => {
|
||||
try {
|
||||
@@ -129,10 +133,70 @@ const Logbook: React.FC<unknown> = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const columns: ColumnDef<ILogbookEntry>[] = [
|
||||
const unauthColumns: ColumnDef<ILogbookEntry>[] = [
|
||||
{
|
||||
accessorKey: 'pilotName',
|
||||
header: 'Pilot'
|
||||
header: 'Pilot',
|
||||
},
|
||||
{
|
||||
accessorKey: 'date',
|
||||
header: 'Date'
|
||||
},
|
||||
{
|
||||
accessorKey: 'aircraftMakeModel',
|
||||
header: 'Aircraft Make & Model'
|
||||
},
|
||||
{
|
||||
id: 'route',
|
||||
header: 'Route of Flight',
|
||||
meta: {
|
||||
headerAlign: 'center'
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
accessorKey: 'routeFrom',
|
||||
header: 'From'
|
||||
},
|
||||
{
|
||||
accessorKey: 'routeTo',
|
||||
header: 'To'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
accessorKey: 'durationOfFlight',
|
||||
header: 'Duration Of Flight',
|
||||
meta: {
|
||||
align: 'right',
|
||||
headerAlign: 'right'
|
||||
},
|
||||
cell: (info: any) =>
|
||||
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||
},
|
||||
{
|
||||
accessorKey: 'notes',
|
||||
header: 'Notes'
|
||||
},
|
||||
{
|
||||
header: 'Actions',
|
||||
meta: {
|
||||
align: 'center',
|
||||
headerAlign: 'center'
|
||||
},
|
||||
cell: (info: any) => (
|
||||
<ActionMenu
|
||||
id={info.row.original.rowKey}
|
||||
onDelete={onDeleteEntry}
|
||||
onOpenCloseForm={onOpenCloseEntryForm}
|
||||
/>
|
||||
)
|
||||
}
|
||||
]
|
||||
|
||||
const authColumns: ColumnDef<ILogbookEntry>[] = [
|
||||
{
|
||||
accessorKey: 'pilotName',
|
||||
header: 'Pilot',
|
||||
},
|
||||
{
|
||||
accessorKey: 'date',
|
||||
@@ -144,7 +208,7 @@ const Logbook: React.FC<unknown> = () => {
|
||||
},
|
||||
{
|
||||
accessorKey: 'aircraftIdentity',
|
||||
header: 'Aircraft Identity'
|
||||
header: 'Aircraft Identity',
|
||||
},
|
||||
{
|
||||
id: 'route',
|
||||
@@ -359,10 +423,10 @@ const Logbook: React.FC<unknown> = () => {
|
||||
return (
|
||||
<Box sx={{ margin: '20px' }}>
|
||||
<Grid container spacing={2}>
|
||||
<Grid size={11}>
|
||||
<Grid size={isMedium ? 11 : 6}>
|
||||
<Typography variant="h4">Logbook</Typography>
|
||||
</Grid>
|
||||
<Grid display="flex" justifyContent="right" size={1}>
|
||||
<Grid display="flex" justifyContent="right" size={isMedium ? 1 : 6}>
|
||||
{isAuthenticated &&
|
||||
<Button
|
||||
onClick={() => onOpenCloseEntryForm(FormMode.ADD)}
|
||||
@@ -389,9 +453,12 @@ const Logbook: React.FC<unknown> = () => {
|
||||
)}
|
||||
{!state.isLoading && (
|
||||
<Grid size={12}>
|
||||
{state.entries.length > 0 && (
|
||||
<Table columns={columns} data={state.entries} />
|
||||
{isMedium && state.entries.length > 0 && (
|
||||
<Table columns={isAuthenticated ? authColumns : unauthColumns} data={state.entries} />
|
||||
)}
|
||||
{!isMedium && state.entries.length > 0 &&
|
||||
<LogbookCard logs={state.entries} onDelete={onDeleteEntry} onOpenCloseForm={onOpenCloseEntryForm} />
|
||||
}
|
||||
</Grid>
|
||||
)}
|
||||
{state.isLoading && !state.alert && (
|
||||
|
||||
74
app/src/components/logbookCard/LogbookCard.tsx
Normal file
74
app/src/components/logbookCard/LogbookCard.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import { Card, CardContent, CardHeader, Grid, Typography } from "@noahspan/noahspan-components";
|
||||
import { LogbookCardProps } from "./LogbookCardProps.interface";
|
||||
import { useEffect } from "react";
|
||||
import ActionMenu from "../actionMenu/ActionMenu";
|
||||
|
||||
|
||||
const LogbookCard = ({ logs, onDelete, onOpenCloseForm }: LogbookCardProps) => {
|
||||
return (
|
||||
<Grid container spacing={2}>
|
||||
{logs.map((log) => {
|
||||
return (
|
||||
<Grid size={12}>
|
||||
<Card key={log.rowKey}>
|
||||
<CardHeader
|
||||
action={<ActionMenu id={log.rowKey} onDelete={onDelete} onOpenCloseForm={onOpenCloseForm} />}
|
||||
subheader={log.pilotName}
|
||||
title={log.date}
|
||||
slotProps={{
|
||||
subheader: {
|
||||
fontSize: '16px'
|
||||
},
|
||||
title: {
|
||||
fontSize: '24px',
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<CardContent>
|
||||
<Grid container spacing={1}>
|
||||
<Grid size={12}>
|
||||
<Typography variant="subtitle2">Aircraft Make and Model</Typography>
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<Typography variant="body1">{log.aircraftMakeModel}</Typography>
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<Typography variant="subtitle2">Route From</Typography>
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<Typography variant="body1">{log.routeFrom}</Typography>
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<Typography variant="subtitle2">Route To</Typography>
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<Typography variant="body1">{log.routeTo}</Typography>
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<Typography variant="subtitle2">Duration Of Flight</Typography>
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<Typography variant="body1">{log.durationOfFlight}</Typography>
|
||||
</Grid>
|
||||
{log.notes &&
|
||||
<>
|
||||
<Grid size={12}>
|
||||
<Typography variant="subtitle2">Notes</Typography>
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<Typography variant="body1">{log.notes}</Typography>
|
||||
</Grid>
|
||||
</>
|
||||
}
|
||||
</Grid>
|
||||
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Grid>
|
||||
)
|
||||
})}
|
||||
</Grid>
|
||||
)
|
||||
}
|
||||
|
||||
export default LogbookCard;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { FormMode } from "../../enums/formMode";
|
||||
import { ILogbookEntry } from "../logbook/ILogbookEntry";
|
||||
|
||||
export interface LogbookCardProps {
|
||||
logs: ILogbookEntry[];
|
||||
onDelete: (entryId: string) => void;
|
||||
onOpenCloseForm: (formMode: FormMode, id: string) => void;
|
||||
}
|
||||
29
app/src/components/pilotCard/PilotCard.tsx
Normal file
29
app/src/components/pilotCard/PilotCard.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Card, CardContent, CardHeader, Grid, Typography } from "@noahspan/noahspan-components"
|
||||
import { PilotCardProps } from "./PilotCardProps.interface"
|
||||
import ActionMenu from "../actionMenu/ActionMenu"
|
||||
|
||||
const PilotCard = ({ pilots, onDelete, onOpenCloseForm }: PilotCardProps) => {
|
||||
return (
|
||||
<Grid container spacing={2}>
|
||||
{pilots.map((pilot) => {
|
||||
return (
|
||||
<Grid size={12}>
|
||||
<Card key={pilot.rowKey}>
|
||||
<CardHeader
|
||||
action={<ActionMenu id={pilot.rowKey} onDelete={onDelete} onOpenCloseForm={onOpenCloseForm} />}
|
||||
title={pilot.name}
|
||||
slotProps={{
|
||||
title: {
|
||||
fontSize: '24px',
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
</Grid>
|
||||
)
|
||||
})}
|
||||
</Grid>
|
||||
)
|
||||
}
|
||||
|
||||
export default PilotCard;
|
||||
8
app/src/components/pilotCard/PilotCardProps.interface.ts
Normal file
8
app/src/components/pilotCard/PilotCardProps.interface.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { FormMode } from "../../enums/formMode";
|
||||
import { Pilot } from "../pilots/Pilot.interface";
|
||||
|
||||
export interface PilotCardProps {
|
||||
pilots: Pilot[];
|
||||
onDelete: (entryId: string) => void;
|
||||
onOpenCloseForm: (formMode: FormMode, id: string) => void;
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useForm, Controller, FormProvider } from 'react-hook-form';
|
||||
import {
|
||||
Accordion,
|
||||
Button,
|
||||
DatePicker,
|
||||
Drawer,
|
||||
Grid,
|
||||
Icon,
|
||||
IconButton,
|
||||
IconName,
|
||||
PeoplePicker,
|
||||
Select,
|
||||
StateSelect,
|
||||
TextField,
|
||||
Typography
|
||||
theme,
|
||||
Typography,
|
||||
useMediaQuery
|
||||
} from '@noahspan/noahspan-components';
|
||||
import { IPilotFormProps } from './IPilotFormProps';
|
||||
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
||||
@@ -64,6 +63,7 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
||||
});
|
||||
const [isDisabled, setIsDisabled] = useState<boolean>(false);
|
||||
const [isError, setIsError] = useState<boolean>(false);
|
||||
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||
|
||||
const onPeoplePickerSearch = async (
|
||||
_event: React.SyntheticEvent,
|
||||
@@ -113,7 +113,6 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
||||
};
|
||||
|
||||
const onSubmit = async (data: unknown) => {
|
||||
console.log(data)
|
||||
try {
|
||||
setIsLoading(true);
|
||||
|
||||
@@ -167,7 +166,7 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
||||
|
||||
pilot.certificates = JSON.parse(pilot.certificates);
|
||||
pilot.endorsements = JSON.parse(pilot.endorsements)
|
||||
console.log(pilot)
|
||||
|
||||
setSelectedPerson({
|
||||
userPrincipalName: pilot.id,
|
||||
displayName: pilot.name
|
||||
@@ -193,7 +192,7 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
||||
PaperProps={{
|
||||
sx: {
|
||||
padding: '30px',
|
||||
width: '33%'
|
||||
width: isMedium ? '33%' : '75%'
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -208,10 +207,10 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
||||
<Icon iconName={IconName.XMARK} />
|
||||
</IconButton>
|
||||
</Grid>
|
||||
<Grid size={3}>
|
||||
<Grid size={isMedium ? 3 : 12}>
|
||||
<Typography variant="h6">Name *</Typography>
|
||||
</Grid>
|
||||
<Grid size={9}>
|
||||
<Grid size={isMedium ? 9 : 12}>
|
||||
<PeoplePicker
|
||||
disabled={isDisabled}
|
||||
loading={isPeoplePickerLoading}
|
||||
@@ -221,172 +220,178 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
||||
value={selectedPerson}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid size={3}>
|
||||
<Typography variant="h6">Address *</Typography>
|
||||
</Grid>
|
||||
<Grid size={9}>
|
||||
<Controller
|
||||
name="address"
|
||||
control={methods.control}
|
||||
rules={{ required: 'An address is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
error={methods.formState.errors.address ? true : false}
|
||||
fullWidth
|
||||
helperText={
|
||||
methods.formState.errors.address
|
||||
? methods.formState.errors.address.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
{isAuthenticated &&
|
||||
<>
|
||||
<Grid size={isMedium ? 3 : 12}>
|
||||
<Typography variant="h6">Address *</Typography>
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 9 : 12}>
|
||||
<Controller
|
||||
name="address"
|
||||
control={methods.control}
|
||||
rules={{ required: 'An address is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
error={methods.formState.errors.address ? true : false}
|
||||
fullWidth
|
||||
helperText={
|
||||
methods.formState.errors.address
|
||||
? methods.formState.errors.address.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid size={3}>
|
||||
<Typography variant="h6">City *</Typography>
|
||||
</Grid>
|
||||
<Grid size={9}>
|
||||
<Controller
|
||||
name="city"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A city is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
error={methods.formState.errors.city ? true : false}
|
||||
fullWidth
|
||||
helperText={
|
||||
methods.formState.errors.city
|
||||
? methods.formState.errors.city.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 3 : 12}>
|
||||
<Typography variant="h6">City *</Typography>
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 9 : 12}>
|
||||
<Controller
|
||||
name="city"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A city is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
error={methods.formState.errors.city ? true : false}
|
||||
fullWidth
|
||||
helperText={
|
||||
methods.formState.errors.city
|
||||
? methods.formState.errors.city.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid size={3}>
|
||||
<Typography variant="h6">State *</Typography>
|
||||
</Grid>
|
||||
<Grid size={9}>
|
||||
<Controller
|
||||
name="state"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A state must be selected' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<StateSelect
|
||||
disabled={isDisabled}
|
||||
// error={methods.formState.errors.state ? true : false}
|
||||
fullWidth
|
||||
// helperText={
|
||||
// methods.formState.errors.state
|
||||
// ? methods.formState.errors.state.message?.toString()
|
||||
// : undefined
|
||||
// }
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
variant="outlined"
|
||||
data-testid="pilot-form-state-dropdown"
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 3 : 12}>
|
||||
<Typography variant="h6">State *</Typography>
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 9 : 12}>
|
||||
<Controller
|
||||
name="state"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A state must be selected' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<StateSelect
|
||||
disabled={isDisabled}
|
||||
// error={methods.formState.errors.state ? true : false}
|
||||
fullWidth
|
||||
// helperText={
|
||||
// methods.formState.errors.state
|
||||
// ? methods.formState.errors.state.message?.toString()
|
||||
// : undefined
|
||||
// }
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
variant="outlined"
|
||||
data-testid="pilot-form-state-dropdown"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid size={3}>
|
||||
<Typography variant="h6">Postal Code *</Typography>
|
||||
</Grid>
|
||||
<Grid size={9}>
|
||||
<Controller
|
||||
name="postalCode"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A postal code is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
error={methods.formState.errors.postalCode ? true : false}
|
||||
fullWidth
|
||||
helperText={
|
||||
methods.formState.errors.postalCode
|
||||
? methods.formState.errors.postalCode.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 3 : 12}>
|
||||
<Typography variant="h6">Postal Code *</Typography>
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 9 : 12}>
|
||||
<Controller
|
||||
name="postalCode"
|
||||
control={methods.control}
|
||||
rules={{ required: 'A postal code is required' }}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
error={methods.formState.errors.postalCode ? true : false}
|
||||
fullWidth
|
||||
helperText={
|
||||
methods.formState.errors.postalCode
|
||||
? methods.formState.errors.postalCode.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid size={3}>
|
||||
<Typography variant="h6">Email</Typography>
|
||||
</Grid>
|
||||
<Grid size={9}>
|
||||
<Controller
|
||||
name="email"
|
||||
control={methods.control}
|
||||
rules={{
|
||||
pattern: {
|
||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
||||
message: 'Invalid email address'
|
||||
}
|
||||
}}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
fullWidth
|
||||
error={methods.formState.errors.email ? true : false}
|
||||
helperText={
|
||||
methods.formState.errors.email
|
||||
? methods.formState.errors.email.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 3 : 12}>
|
||||
<Typography variant="h6">Email</Typography>
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 9 : 12}>
|
||||
<Controller
|
||||
name="email"
|
||||
control={methods.control}
|
||||
rules={{
|
||||
pattern: {
|
||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
||||
message: 'Invalid email address'
|
||||
}
|
||||
}}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
fullWidth
|
||||
error={methods.formState.errors.email ? true : false}
|
||||
helperText={
|
||||
methods.formState.errors.email
|
||||
? methods.formState.errors.email.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid size={3}>
|
||||
<Typography variant="h6">Phone Number</Typography>
|
||||
</Grid>
|
||||
<Grid size={9}>
|
||||
<Controller
|
||||
name="phone"
|
||||
control={methods.control}
|
||||
rules={{
|
||||
pattern: {
|
||||
value: /^[0-9]{3}[-\s\.][0-9]{3}[-\s\.][0-9]{4}$/i,
|
||||
message: 'Enter phone number as 123-456-7890'
|
||||
}
|
||||
}}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
fullWidth
|
||||
error={methods.formState.errors.phone ? true : false}
|
||||
helperText={
|
||||
methods.formState.errors.phone
|
||||
? methods.formState.errors.phone.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 3 : 12}>
|
||||
<Typography variant="h6">Phone Number</Typography>
|
||||
</Grid>
|
||||
<Grid size={isMedium ? 9 : 12}>
|
||||
<Controller
|
||||
name="phone"
|
||||
control={methods.control}
|
||||
rules={{
|
||||
pattern: {
|
||||
value: /^[0-9]{3}[-\s\.][0-9]{3}[-\s\.][0-9]{4}$/i,
|
||||
message: 'Enter phone number as 123-456-7890'
|
||||
}
|
||||
}}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<TextField
|
||||
disabled={isDisabled}
|
||||
fullWidth
|
||||
error={methods.formState.errors.phone ? true : false}
|
||||
helperText={
|
||||
methods.formState.errors.phone
|
||||
? methods.formState.errors.phone.message
|
||||
: undefined
|
||||
}
|
||||
onChange={onChange}
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
</>
|
||||
}
|
||||
{isAuthenticated &&
|
||||
<Grid size={12}>
|
||||
<PilotFormMedical
|
||||
isDisabled={isDisabled}
|
||||
/>
|
||||
</Grid>
|
||||
}
|
||||
<Grid size={12}>
|
||||
<PilotFormCertificates isDisabled={isDisabled} mode={mode} />
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<PilotFormMedical
|
||||
isDisabled={isDisabled}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<PilotFormCertificates isDisabled={isDisabled} />
|
||||
</Grid>
|
||||
<Grid size={12}>
|
||||
<PilotFormEndorsements isDisabled={isDisabled} />
|
||||
<PilotFormEndorsements isDisabled={isDisabled} mode={mode} />
|
||||
</Grid>
|
||||
<Grid display="flex" gap={2} justifyContent="right" size={12}>
|
||||
<Button
|
||||
|
||||
@@ -8,12 +8,14 @@ import {
|
||||
IconName,
|
||||
Select,
|
||||
TextField,
|
||||
Typography
|
||||
Typography,
|
||||
} from '@noahspan/noahspan-components';
|
||||
import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
|
||||
import { FormMode } from '../../enums/formMode';
|
||||
|
||||
const PilotFormCertificates = ({
|
||||
isDisabled
|
||||
isDisabled,
|
||||
mode
|
||||
}: PilotFormCertificatesProps ) => {
|
||||
const {
|
||||
control,
|
||||
@@ -30,9 +32,11 @@ const PilotFormCertificates = ({
|
||||
container
|
||||
spacing={2}
|
||||
>
|
||||
<Grid size={12}>
|
||||
<Typography variant="h5">Certificates</Typography>
|
||||
</Grid>
|
||||
{fields.length > 0 || mode !== FormMode.VIEW &&
|
||||
<Grid size={12}>
|
||||
<Typography variant="h5">Certificates</Typography>
|
||||
</Grid>
|
||||
}
|
||||
{fields.length > 0 && (
|
||||
<>
|
||||
<Grid size={4}>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { FormMode } from "../../enums/formMode";
|
||||
|
||||
export interface PilotFormCertificatesProps {
|
||||
isDisabled: boolean;
|
||||
mode: FormMode;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,10 @@ import {
|
||||
Typography
|
||||
} from '@noahspan/noahspan-components';
|
||||
import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
|
||||
import { FormMode } from '../../enums/formMode';
|
||||
|
||||
const PilotFormEndorsements = ({
|
||||
mode,
|
||||
isDisabled
|
||||
}: PilotFormEndorsementsProps) => {
|
||||
const {
|
||||
@@ -30,9 +32,11 @@ const PilotFormEndorsements = ({
|
||||
container
|
||||
spacing={2}
|
||||
>
|
||||
<Grid size={12}>
|
||||
<Typography variant="h5">Endorsements</Typography>
|
||||
</Grid>
|
||||
{fields.length > 0 || mode !== FormMode.VIEW &&
|
||||
<Grid size={12}>
|
||||
<Typography variant="h5">Endorsements</Typography>
|
||||
</Grid>
|
||||
}
|
||||
{fields.length > 0 && (
|
||||
<>
|
||||
<Grid size={8}>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { FormMode } from "../../enums/formMode";
|
||||
|
||||
export interface PilotFormEndorsementsProps {
|
||||
isDisabled: boolean;
|
||||
mode: FormMode;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DatePicker, Grid, Select, Typography } from '@noahspan/noahspan-components';
|
||||
import { DatePicker, Grid, Select, theme, Typography, useMediaQuery } from '@noahspan/noahspan-components';
|
||||
import { Controller, useFormContext } from "react-hook-form"
|
||||
import { PilotFormMedicalProps } from "./PilotFormMedicalProps.interface";
|
||||
|
||||
@@ -7,17 +7,18 @@ const PilotFormMedical = ({ isDisabled }: PilotFormMedicalProps) => {
|
||||
control,
|
||||
formState: { errors },
|
||||
setValue
|
||||
} = useFormContext()
|
||||
} = useFormContext();
|
||||
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||
|
||||
return (
|
||||
<Grid container spacing={2}>
|
||||
<Grid size={12}>
|
||||
<Typography variant="h5">Medical</Typography>
|
||||
</Grid>
|
||||
<Grid size={3}>
|
||||
<Grid size={isMedium ? 3 : 12}>
|
||||
<Typography variant="h6">Class</Typography>
|
||||
</Grid>
|
||||
<Grid size={9}>
|
||||
<Grid size={isMedium ? 9 : 12}>
|
||||
<Controller
|
||||
name="medicalClass"
|
||||
control={control}
|
||||
@@ -53,10 +54,10 @@ const PilotFormMedical = ({ isDisabled }: PilotFormMedicalProps) => {
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid size={3}>
|
||||
<Grid size={isMedium ? 3 : 12}>
|
||||
<Typography variant="h6">Expiration</Typography>
|
||||
</Grid>
|
||||
<Grid size={9}>
|
||||
<Grid size={isMedium ? 9 : 12}>
|
||||
<Controller
|
||||
name="medicalExpiration"
|
||||
control={control}
|
||||
|
||||
@@ -9,7 +9,9 @@ import {
|
||||
Icon,
|
||||
IconName,
|
||||
Table,
|
||||
Typography
|
||||
theme,
|
||||
Typography,
|
||||
useMediaQuery
|
||||
} from '@noahspan/noahspan-components';
|
||||
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
||||
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
||||
@@ -20,21 +22,19 @@ import { Pilot } from './Pilot.interface';
|
||||
import { initialState, reducer } from './reducer';
|
||||
import ActionMenu from '../actionMenu/ActionMenu';
|
||||
import ConfirmationDialog from '../confirmationDialog/ConfirmationDialog';
|
||||
import PilotCard from '../pilotCard/PilotCard';
|
||||
|
||||
const Pilots: React.FC<unknown> = () => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
const httpClient: AxiosInstance = useHttpClient();
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
const { getAccessToken } = useAccessToken();
|
||||
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||
|
||||
const getPilots = async () => {
|
||||
try {
|
||||
const config = isAuthenticated
|
||||
? { headers: { Authorization: await getAccessToken() } }
|
||||
: {};
|
||||
const response: AxiosResponse = await httpClient.get(
|
||||
`api/pilots`,
|
||||
config
|
||||
`api/pilots`
|
||||
);
|
||||
|
||||
if (response.data.length > 0) {
|
||||
@@ -147,18 +147,18 @@ const Pilots: React.FC<unknown> = () => {
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && !state.isFormOpen) {
|
||||
if (!state.isFormOpen) {
|
||||
getPilots();
|
||||
}
|
||||
}, [isAuthenticated, state.isFormOpen]);
|
||||
}, [state.isFormOpen]);
|
||||
|
||||
return (
|
||||
<Box sx={{ margin: '20px' }}>
|
||||
<Grid container spacing={2}>
|
||||
<Grid size={11}>
|
||||
<Grid size={isMedium ? 11 : 6}>
|
||||
<Typography variant="h4">Pilots</Typography>
|
||||
</Grid>
|
||||
<Grid display="flex" justifyContent="right" size={1}>
|
||||
<Grid display="flex" justifyContent="right" size={isMedium ? 1 : 6}>
|
||||
{isAuthenticated &&
|
||||
<Button
|
||||
onClick={() => onOpenClosePilotForm(FormMode.ADD)}
|
||||
@@ -184,7 +184,12 @@ const Pilots: React.FC<unknown> = () => {
|
||||
</Grid>
|
||||
)}
|
||||
<Grid size={12}>
|
||||
{state.pilots.length > 0 && <Table columns={columns} data={state.pilots} />}
|
||||
{isMedium && state.pilots.length > 0 &&
|
||||
<Table columns={columns} data={state.pilots} />
|
||||
}
|
||||
{!isMedium && state.pilots.length > 0 &&
|
||||
<PilotCard pilots={state.pilots} onDelete={onDeleteEntry} onOpenCloseForm={onOpenClosePilotForm} />
|
||||
}
|
||||
</Grid>
|
||||
</Grid>
|
||||
{state.isFormOpen && (
|
||||
|
||||
@@ -34,15 +34,12 @@ const SiteNav = () => {
|
||||
{
|
||||
name: 'Logbook',
|
||||
url: '/'
|
||||
}
|
||||
];
|
||||
|
||||
if (isAuthenticated) {
|
||||
pages.push({
|
||||
},
|
||||
{
|
||||
name: 'Pilots',
|
||||
url: '/pilots'
|
||||
})
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
setPages(pages)
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ version: '3.8'
|
||||
|
||||
services:
|
||||
azurite:
|
||||
container_name: azurite
|
||||
container_name: azurite-flying
|
||||
image: mcr.microsoft.com/azure-storage/azurite
|
||||
ports:
|
||||
- '10000:10000'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@noahspan/flying",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"scripts": {
|
||||
"start": "concurrently 'npm run start:azure -w api' 'wait-on tcp:0.0.0.0:7071 && npm run dev -w app'",
|
||||
"format": "prettier --write \"**/src/**/*.ts\" \"**/test/**/*.ts\"",
|
||||
|
||||
603
pnpm-lock.yaml
generated
603
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user