Compare commits
24 Commits
v1.0.0
...
feature/71
| Author | SHA1 | Date | |
|---|---|---|---|
| c6e98314a6 | |||
| d4be759dab | |||
| 113ccbf440 | |||
| e99f3ecafe | |||
| c5cb63e457 | |||
| 432dbb178f | |||
| e09566e270 | |||
| 08498a64d8 | |||
| 70fde43801 | |||
| adb8e51adf | |||
| 09f19b178f | |||
| 98cfe69afb | |||
| cd08444c5f | |||
| c3af2ec8ce | |||
| 393364feb6 | |||
| 8f1dc5cb61 | |||
| 032cd4665f | |||
| 99019ddeef | |||
| 80f0e5437c | |||
| 80cfa52413 | |||
| 07575302cc | |||
| c765b06404 | |||
| 280067648f | |||
| 0ff30e9761 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "api",
|
"name": "api",
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@azure/storage-blob": "^12.27.0",
|
||||||
"@microsoft/microsoft-graph-client": "^3.0.7",
|
"@microsoft/microsoft-graph-client": "^3.0.7",
|
||||||
"@nestjs/axios": "^3.0.3",
|
"@nestjs/axios": "^3.0.3",
|
||||||
"@nestjs/common": "^10.0.0",
|
"@nestjs/common": "^10.0.0",
|
||||||
@@ -27,12 +28,14 @@
|
|||||||
"@nestjs/passport": "^10.0.3",
|
"@nestjs/passport": "^10.0.3",
|
||||||
"@nestjs/platform-express": "^10.0.0",
|
"@nestjs/platform-express": "^10.0.0",
|
||||||
"@noahspan/azure-database": "^3.1.2",
|
"@noahspan/azure-database": "^3.1.2",
|
||||||
"@noahspan/noahspan-modules": "^1.0.0",
|
"@noahspan/noahspan-modules": "^1.1.5",
|
||||||
"@schematics/angular": "^17.3.7",
|
"@schematics/angular": "^17.3.7",
|
||||||
|
"@types/multer": "^1.4.12",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"uuid": "^10.0.0"
|
"uuid": "^10.0.0",
|
||||||
|
"uuidv4": "^6.2.13"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@microsoft/microsoft-graph-types": "^2.40.0",
|
"@microsoft/microsoft-graph-types": "^2.40.0",
|
||||||
|
|||||||
@@ -44,11 +44,6 @@ import configuration from './config/configuration';
|
|||||||
provide: APP_FILTER,
|
provide: APP_FILTER,
|
||||||
useClass: HttpExceptionFilter
|
useClass: HttpExceptionFilter
|
||||||
},
|
},
|
||||||
{
|
|
||||||
provide: APP_GUARD,
|
|
||||||
useClass: AuthGuard
|
|
||||||
},
|
|
||||||
Reflector
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
68
api/src/file/file.service.ts
Normal file
68
api/src/file/file.service.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import { BlobServiceClient, BlockBlobClient } from '@azure/storage-blob';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
|
@Injectable() export class FileService {
|
||||||
|
constructor(private readonly configService: ConfigService) {}
|
||||||
|
|
||||||
|
private containerName: string;
|
||||||
|
|
||||||
|
private streamToBuffer(readableStream: NodeJS.ReadableStream) {
|
||||||
|
return new Promise<Buffer>((resolve, reject) => {
|
||||||
|
const chunks = [];
|
||||||
|
|
||||||
|
readableStream.on('data', (data) => {
|
||||||
|
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
|
||||||
|
});
|
||||||
|
readableStream.on('end', () => {
|
||||||
|
resolve(Buffer.concat(chunks));
|
||||||
|
});
|
||||||
|
readableStream.on('error', reject)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async getBlobServiceInstance() {
|
||||||
|
const connectionString = this.configService.get<string>('azureStorageConnectionString');
|
||||||
|
const blobServiceClient: BlobServiceClient = await BlobServiceClient.fromConnectionString(connectionString)
|
||||||
|
|
||||||
|
return blobServiceClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getBlobClient(fileName: string): Promise<BlockBlobClient> {
|
||||||
|
const blobService = await this.getBlobServiceInstance();
|
||||||
|
const containerName = this.containerName;
|
||||||
|
const containerClient = blobService.getContainerClient(containerName);
|
||||||
|
const blockBlobClient = containerClient.getBlockBlobClient(fileName);
|
||||||
|
|
||||||
|
return blockBlobClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
async uploadFile(file: Express.Multer.File, containerName: string, rowKey: string): Promise<string> {
|
||||||
|
this.containerName = containerName;
|
||||||
|
|
||||||
|
const blockBlobClient = await this.getBlobClient(`${rowKey}/${file.originalname}`);
|
||||||
|
const fileUrl = blockBlobClient.url;
|
||||||
|
|
||||||
|
await blockBlobClient.uploadData(file.buffer);
|
||||||
|
|
||||||
|
return fileUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
async downloadFile(containerName: string, rowKey: string, fileName: string): Promise<string> {
|
||||||
|
this.containerName = containerName;
|
||||||
|
|
||||||
|
const blockBlobClient = await this.getBlobClient(`${rowKey}/${fileName}`);
|
||||||
|
const downloadBlockBlobResponse = await blockBlobClient.download();
|
||||||
|
const downloaded: string = (await this.streamToBuffer(downloadBlockBlobResponse.readableStreamBody)).toString()
|
||||||
|
|
||||||
|
return downloaded
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteFile(containerName: string, rowKey:string, fileName: string): Promise<void> {
|
||||||
|
this.containerName = containerName;
|
||||||
|
|
||||||
|
const blockBlobClient = await this.getBlobClient(`${rowKey}/${fileName}`);
|
||||||
|
|
||||||
|
await blockBlobClient.deleteIfExists();
|
||||||
|
}
|
||||||
|
}
|
||||||
41
api/src/log/interceptors/log.interceptor.ts
Normal file
41
api/src/log/interceptors/log.interceptor.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
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];
|
||||||
|
console.log(token)
|
||||||
|
|
||||||
|
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,
|
||||||
|
tracks: log.tracks,
|
||||||
|
notes: log.notes
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return logs;
|
||||||
|
} else {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return handler.handle().pipe(map((data) => data));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,20 +7,31 @@ import {
|
|||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
UseGuards
|
Query,
|
||||||
|
StreamableFile,
|
||||||
|
UploadedFile,
|
||||||
|
UseGuards,
|
||||||
|
UseInterceptors
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { LogDto } from './log.dto';
|
import { LogDto } from './log.dto';
|
||||||
import { Log } from './log.entity';
|
import { Log } from './log.entity';
|
||||||
import { LogService } from './log.service';
|
import { LogService } from './log.service';
|
||||||
import { CustomError } from '../error/customError';
|
import { CustomError } from '../error/customError';
|
||||||
import { Public } from '@noahspan/noahspan-modules';
|
import { AuthGuard } from '@noahspan/noahspan-modules';
|
||||||
|
import { LogInterceptor } from './interceptors/log.interceptor';
|
||||||
|
import { FileService } from '../file/file.service';
|
||||||
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
|
|
||||||
@Controller('logs')
|
@Controller('logs')
|
||||||
export class LogController {
|
export class LogController {
|
||||||
constructor(private readonly logService: LogService) {}
|
constructor(
|
||||||
|
private readonly fileService: FileService,
|
||||||
|
private readonly logService: LogService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
|
||||||
@Get(':partitionKey/:rowKey')
|
@Get(':partitionKey/:rowKey')
|
||||||
|
@UseInterceptors(new LogInterceptor())
|
||||||
async find(
|
async find(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
@Param('rowKey') rowKey: string
|
@Param('rowKey') rowKey: string
|
||||||
@@ -34,8 +45,8 @@ export class LogController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public()
|
|
||||||
@Get()
|
@Get()
|
||||||
|
@UseInterceptors(new LogInterceptor())
|
||||||
async findAll(): Promise<Log[]> {
|
async findAll(): Promise<Log[]> {
|
||||||
try {
|
try {
|
||||||
return await this.logService.findAll();
|
return await this.logService.findAll();
|
||||||
@@ -46,6 +57,7 @@ export class LogController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Body() logDto: LogDto): Promise<Log> {
|
async create(@Body() logDto: LogDto): Promise<Log> {
|
||||||
try {
|
try {
|
||||||
@@ -61,6 +73,7 @@ export class LogController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Put(':partitionKey/:rowKey')
|
@Put(':partitionKey/:rowKey')
|
||||||
async update(
|
async update(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
@@ -80,6 +93,7 @@ export class LogController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Delete(':partitionKey/:rowKey')
|
@Delete(':partitionKey/:rowKey')
|
||||||
async delete(
|
async delete(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
@@ -93,4 +107,42 @@ export class LogController {
|
|||||||
throw new HttpException(customError.message, customError.statusCode);
|
throw new HttpException(customError.message, customError.statusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Post(':partitionKey/:rowKey/track')
|
||||||
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
|
async createTrack(@Param('rowKey') rowKey: string, @UploadedFile() file: Express.Multer.File) {
|
||||||
|
try {
|
||||||
|
const containerName = 'tracks';
|
||||||
|
const url = await this.fileService.uploadFile(file, containerName, rowKey);
|
||||||
|
|
||||||
|
return { url }
|
||||||
|
} catch (error) {
|
||||||
|
const customError = error as CustomError;
|
||||||
|
|
||||||
|
throw new HttpException(customError.message, customError.statusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':partitionKey/:rowKey/track')
|
||||||
|
async downloadTrack(@Param('rowKey') rowKey: string, @Query('fileName') fileName: string): Promise<string> {
|
||||||
|
const containerName = 'tracks';
|
||||||
|
const downloadedFile: string = await this.fileService.downloadFile(containerName, rowKey, fileName)
|
||||||
|
|
||||||
|
return downloadedFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Delete(':partitionKey/:rowKey/track')
|
||||||
|
async deleteTrack(@Param('rowKey') rowKey: string, @Query('fileName') fileName: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const containerName = 'tracks';
|
||||||
|
|
||||||
|
return await this.fileService.deleteFile(containerName, rowKey, fileName)
|
||||||
|
} catch (error) {
|
||||||
|
const customError = error as CustomError;
|
||||||
|
|
||||||
|
throw new HttpException(customError.message, customError.statusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,6 @@ export class LogDto {
|
|||||||
night: number;
|
night: number;
|
||||||
solo: number;
|
solo: number;
|
||||||
pilotInCommand: number;
|
pilotInCommand: number;
|
||||||
|
tracks: string[];
|
||||||
notes: string;
|
notes: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,5 +24,6 @@ export class Log {
|
|||||||
instrumentApproaches?: number | null;
|
instrumentApproaches?: number | null;
|
||||||
instrumentHolds?: number | null;
|
instrumentHolds?: number | null;
|
||||||
instrumentNavTrack?: number | null;
|
instrumentNavTrack?: number | null;
|
||||||
|
tracks?: string[];
|
||||||
notes?: string;
|
notes?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { LogService } from './log.service';
|
|||||||
import { AzureTableStorageModule } from '@noahspan/azure-database';
|
import { AzureTableStorageModule } from '@noahspan/azure-database';
|
||||||
import { Log } from './log.entity';
|
import { Log } from './log.entity';
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
|
import { FileService } from '../file/file.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -22,6 +23,10 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
controllers: [LogController],
|
controllers: [LogController],
|
||||||
providers: [LogService]
|
providers: [
|
||||||
|
ConfigService,
|
||||||
|
FileService,
|
||||||
|
LogService
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class LogModule {}
|
export class LogModule {}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ async function bootstrap() {
|
|||||||
const httpService = new HttpService();
|
const httpService = new HttpService();
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
|
||||||
|
app.enableCors();
|
||||||
app.setGlobalPrefix('api');
|
app.setGlobalPrefix('api');
|
||||||
app.useGlobalFilters(new HttpExceptionFilter());
|
app.useGlobalFilters(new HttpExceptionFilter());
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
export class Certificate {
|
export class Certificate {
|
||||||
partitionKey: string;
|
|
||||||
rowKey: string;
|
|
||||||
type: string;
|
type: string;
|
||||||
issueDate: Date;
|
issueDate: string;
|
||||||
number?: string;
|
number: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { Repository, InjectRepository } from '@noahspan/azure-database';
|
|
||||||
import { Certificate } from './certificate.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class CertificateService {
|
|
||||||
private readonly partitionKey: string = 'certificate';
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Certificate)
|
|
||||||
private readonly certificateRepository: Repository<Certificate>
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async find(rowKey: string): Promise<Certificate> {
|
|
||||||
return await this.certificateRepository.find(this.partitionKey, rowKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll(): Promise<Certificate[]> {
|
|
||||||
return await this.certificateRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(certificate: Certificate): Promise<Certificate> {
|
|
||||||
return await this.certificateRepository.create(certificate);
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(rowKey: string, certificate: Certificate): Promise<Certificate> {
|
|
||||||
return await this.certificateRepository.update(
|
|
||||||
this.partitionKey,
|
|
||||||
rowKey,
|
|
||||||
certificate
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async delete(rowKey: string): Promise<void> {
|
|
||||||
await this.certificateRepository.delete(this.partitionKey, rowKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
export class Endorsement {
|
export class Endorsement {
|
||||||
partitionkey: string;
|
|
||||||
rowKey: string;
|
|
||||||
type: string;
|
type: string;
|
||||||
issueDate: Date;
|
issueDate: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import { InjectRepository, Repository } from '@noahspan/azure-database';
|
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { Endorsement } from './endorsement.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class EndosementService {
|
|
||||||
private readonly partitionKey: string = 'endorsement';
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Endorsement)
|
|
||||||
private readonly endorsementRepository: Repository<Endorsement>
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async find(rowKey: string): Promise<Endorsement> {
|
|
||||||
return await this.endorsementRepository.find(this.partitionKey, rowKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll(): Promise<Endorsement[]> {
|
|
||||||
return await this.endorsementRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(endorsement: Endorsement): Promise<Endorsement> {
|
|
||||||
return await this.endorsementRepository.create(endorsement);
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(rowKey: string, endorsement: Endorsement): Promise<Endorsement> {
|
|
||||||
return await this.endorsementRepository.update(
|
|
||||||
this.partitionKey,
|
|
||||||
rowKey,
|
|
||||||
endorsement
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async delete(rowKey: string): Promise<void> {
|
|
||||||
await this.endorsementRepository.delete(this.partitionKey, rowKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,18 +16,15 @@ export class PilotInterceptor implements NestInterceptor {
|
|||||||
partitionKey: pilot.partitionKey,
|
partitionKey: pilot.partitionKey,
|
||||||
rowKey: pilot.rowKey,
|
rowKey: pilot.rowKey,
|
||||||
id: pilot.id,
|
id: pilot.id,
|
||||||
name: pilot.name
|
name: pilot.name,
|
||||||
|
certificates: pilot.certificates,
|
||||||
|
endorsements: pilot.endorsements
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return pilots;
|
return pilots;
|
||||||
} else {
|
} else {
|
||||||
return {
|
return data;
|
||||||
partitionKey: data.partitionKey,
|
|
||||||
rowKey: data.rowKey,
|
|
||||||
id: data.id,
|
|
||||||
name: data.name
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
export class Medical {
|
|
||||||
partitionKey: string;
|
|
||||||
rowKey: string;
|
|
||||||
certificateClass: string;
|
|
||||||
certificateExpiration: Date;
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// import { Injectable } from '@nestjs/common';
|
|
||||||
// import { Repository, InjectRepository } from '@noahspan/azure-database';
|
|
||||||
// import { Medical } from './medical.entity';
|
|
||||||
|
|
||||||
// @Injectable()
|
|
||||||
// export class MedicalService {
|
|
||||||
// private readonly partitionKey: string = 'medical';
|
|
||||||
|
|
||||||
// constructor(
|
|
||||||
// @InjectRepository(Medical)
|
|
||||||
// private readonly profileRepository: Repository<Medical>
|
|
||||||
// ) {}
|
|
||||||
|
|
||||||
// async find(rowKey: string): Promise<Medical> {
|
|
||||||
// return this.profileRepository.find(this.partitionKey, rowKey);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async findAll(): Promise<Medical[]> {
|
|
||||||
// return this.profileRepository.findAll();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async create(profile: Medical): Promise<Medical> {
|
|
||||||
// return this.profileRepository.create(profile);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async update(rowKey: string, profile: Medical): Promise<Medical> {
|
|
||||||
// return this.profileRepository.update(this.partitionKey, rowKey, profile);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async delete(rowKey: string) {
|
|
||||||
// return this.profileRepository.delete(this.partitionKey, rowKey);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -8,14 +8,17 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
|
UseInterceptors,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { PilotDto } from './pilot.dto';
|
import { PilotDto } from './pilot.dto';
|
||||||
import { Pilot } from './pilot.entity';
|
import { Pilot } from './pilot.entity';
|
||||||
import { PilotService } from './pilot.service';
|
import { PilotService } from './pilot.service';
|
||||||
import { CustomError } from '../error/customError';
|
import { CustomError } from '../error/customError';
|
||||||
import { AuthGuard } from '@nestjs/passport'
|
import { AuthGuard } from '@noahspan/noahspan-modules'
|
||||||
|
import { PilotInterceptor } from './interceptors/pilot.interceptor';
|
||||||
|
|
||||||
@Controller('pilots')
|
@Controller('pilots')
|
||||||
|
@UseInterceptors(new PilotInterceptor())
|
||||||
export class PilotController {
|
export class PilotController {
|
||||||
constructor(private readonly pilotService: PilotService) {}
|
constructor(private readonly pilotService: PilotService) {}
|
||||||
|
|
||||||
@@ -44,12 +47,28 @@ export class PilotController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Body() pilotDto: PilotDto) {
|
async create(@Body() pilotDto: PilotDto) {
|
||||||
try {
|
try {
|
||||||
const pilot = new Pilot();
|
let pilot = new Pilot();
|
||||||
|
|
||||||
Object.assign(pilot, pilotDto);
|
pilot = {
|
||||||
|
partitionKey: pilotDto.partitionKey,
|
||||||
|
rowKey: pilotDto.rowKey,
|
||||||
|
id: pilotDto.id,
|
||||||
|
name: pilotDto.name,
|
||||||
|
address: pilotDto.address,
|
||||||
|
city: pilotDto.city,
|
||||||
|
state: pilotDto.state,
|
||||||
|
postalCode: pilotDto.postalCode,
|
||||||
|
email: pilotDto.email,
|
||||||
|
phone: pilotDto.phone,
|
||||||
|
medicalClass: pilotDto.medicalClass,
|
||||||
|
medicalExpiration: pilotDto.medicalExpiration,
|
||||||
|
certificates: JSON.stringify(pilotDto.certificates),
|
||||||
|
endorsements: JSON.stringify(pilotDto.endorsements)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.pilotService.create(pilot);
|
return await this.pilotService.create(pilot);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -59,6 +78,7 @@ export class PilotController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Put(':partitionKey/:rowKey')
|
@Put(':partitionKey/:rowKey')
|
||||||
async update(
|
async update(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
@@ -66,9 +86,24 @@ export class PilotController {
|
|||||||
@Body() pilotDto: PilotDto
|
@Body() pilotDto: PilotDto
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const pilot = new Pilot();
|
let pilot = new Pilot();
|
||||||
|
|
||||||
Object.assign(pilot, pilotDto);
|
pilot = {
|
||||||
|
partitionKey: pilotDto.partitionKey,
|
||||||
|
rowKey: pilotDto.rowKey,
|
||||||
|
id: pilotDto.id,
|
||||||
|
name: pilotDto.name,
|
||||||
|
address: pilotDto.address,
|
||||||
|
city: pilotDto.city,
|
||||||
|
state: pilotDto.state,
|
||||||
|
postalCode: pilotDto.postalCode,
|
||||||
|
email: pilotDto.email,
|
||||||
|
phone: pilotDto.phone,
|
||||||
|
medicalClass: pilotDto.medicalClass,
|
||||||
|
medicalExpiration: pilotDto.medicalExpiration,
|
||||||
|
certificates: JSON.stringify(pilotDto.certificates),
|
||||||
|
endorsements: JSON.stringify(pilotDto.endorsements)
|
||||||
|
}
|
||||||
|
|
||||||
return await this.pilotService.update(partitionKey, rowKey, pilot);
|
return await this.pilotService.update(partitionKey, rowKey, pilot);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -78,6 +113,7 @@ export class PilotController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Delete(':partitionKey/:rowKey')
|
@Delete(':partitionKey/:rowKey')
|
||||||
async delete(
|
async delete(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { Certificate } from "./certificate/certificate.entity";
|
||||||
|
import { Endorsement } from "./endorsement/endorsement.entity";
|
||||||
|
|
||||||
export class PilotDto {
|
export class PilotDto {
|
||||||
partitionKey: string;
|
partitionKey: string;
|
||||||
rowKey: string;
|
rowKey: string;
|
||||||
@@ -9,4 +12,8 @@ export class PilotDto {
|
|||||||
postalCode: string;
|
postalCode: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
phone?: string;
|
phone?: string;
|
||||||
|
medicalClass?: string;
|
||||||
|
medicalExpiration?: string;
|
||||||
|
certificates: Certificate;
|
||||||
|
endorsements: Endorsement
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,8 @@ export class Pilot {
|
|||||||
@EntityString() postalCode?: string;
|
@EntityString() postalCode?: string;
|
||||||
@EntityString() email?: string;
|
@EntityString() email?: string;
|
||||||
@EntityString() phone?: string;
|
@EntityString() phone?: string;
|
||||||
|
@EntityString() medicalClass?: string;
|
||||||
|
@EntityString() medicalExpiration: string;
|
||||||
|
@EntityString() certificates: string;
|
||||||
|
@EntityString() endorsements: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
# Flying
|
|
||||||
|
|
||||||
A pilot's logbook for tracking flight hours.
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
@@ -13,16 +13,23 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@azure/msal-browser": "^4.0.1",
|
"@azure/msal-browser": "^4.0.1",
|
||||||
"@azure/msal-react": "^3.0.1",
|
"@azure/msal-react": "^3.0.1",
|
||||||
"@noahspan/noahspan-components": "^0.8.9",
|
"@noahspan/noahspan-components": "1.6.0",
|
||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"react": "^18.3.1",
|
"install": "^0.13.0",
|
||||||
"react-dom": "^18.3.1",
|
"leaflet": "^1.9.4",
|
||||||
|
"pure-react-carousel": "^1.32.0",
|
||||||
|
"react": "19.0.0-rc.1",
|
||||||
|
"react-dom": "19.0.0-rc.1",
|
||||||
"react-hook-form": "^7.51.4",
|
"react-hook-form": "^7.51.4",
|
||||||
"react-router-dom": "^6.23.0"
|
"react-leaflet": "^5.0.0",
|
||||||
|
"react-leaflet-kml": "^2.1.2",
|
||||||
|
"react-router-dom": "^6.23.0",
|
||||||
|
"swiper": "^11.2.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@microsoft/microsoft-graph-types": "^2.40.0",
|
"@microsoft/microsoft-graph-types": "^2.40.0",
|
||||||
|
"@types/leaflet": "^1.9.16",
|
||||||
"@types/react": "^18.2.66",
|
"@types/react": "^18.2.66",
|
||||||
"@types/react-dom": "^18.2.22",
|
"@types/react-dom": "^18.2.22",
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
|
|||||||
@@ -19,11 +19,7 @@ const App = () => {
|
|||||||
<>
|
<>
|
||||||
<SiteNav />
|
<SiteNav />
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/pilots" element={
|
<Route path="/pilots" element={<Pilots />} />
|
||||||
<ProtectedRoute>
|
|
||||||
<Pilots />
|
|
||||||
</ProtectedRoute>
|
|
||||||
} />
|
|
||||||
<Route path="/" element={<Logbook />} />
|
<Route path="/" element={<Logbook />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { IActionMenuProps } from './IActionMenuProps';
|
import { IActionMenuProps } from './IActionMenuProps';
|
||||||
import {
|
import {
|
||||||
EllipsisVerticalIcon,
|
|
||||||
EyeIcon,
|
|
||||||
IconButton,
|
IconButton,
|
||||||
|
Icon,
|
||||||
|
IconName,
|
||||||
ListItemIcon,
|
ListItemIcon,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem
|
||||||
PenIcon,
|
|
||||||
TrashIcon
|
|
||||||
} from '@noahspan/noahspan-components';
|
} from '@noahspan/noahspan-components';
|
||||||
import { FormMode } from '../../enums/formMode';
|
import { FormMode } from '../../enums/formMode';
|
||||||
|
import { useIsAuthenticated } from '@azure/msal-react';
|
||||||
|
|
||||||
const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => {
|
const ActionMenu = ({ id, onDelete, onOpenCloseForm, onOpenCloseTracks }: IActionMenuProps) => {
|
||||||
const [anchorElAction, setAnchorElAction] = useState<null | HTMLElement>(
|
const [anchorElAction, setAnchorElAction] = useState<null | HTMLElement>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
const isAuthenticated = useIsAuthenticated();
|
||||||
|
|
||||||
const onOpenActionMenu = (event: React.MouseEvent<HTMLElement>) => {
|
const onOpenActionMenu = (event: React.MouseEvent<HTMLElement>) => {
|
||||||
setAnchorElAction(event.currentTarget);
|
setAnchorElAction(event.currentTarget);
|
||||||
@@ -29,7 +29,7 @@ const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<IconButton onClick={onOpenActionMenu}>
|
<IconButton onClick={onOpenActionMenu}>
|
||||||
<EllipsisVerticalIcon size="sm" />
|
<Icon iconName={IconName.ELLIPSIS_VERTICAL} size="sm" />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Menu
|
<Menu
|
||||||
anchorEl={anchorElAction}
|
anchorEl={anchorElAction}
|
||||||
@@ -37,25 +37,42 @@ const ActionMenu = ({ id, onDelete, onOpenCloseForm }: IActionMenuProps) => {
|
|||||||
open={Boolean(anchorElAction)}
|
open={Boolean(anchorElAction)}
|
||||||
onClose={onCloseActionMenu}
|
onClose={onCloseActionMenu}
|
||||||
>
|
>
|
||||||
<MenuItem onClick={() => onOpenCloseForm(FormMode.EDIT, id)}>
|
{isAuthenticated &&
|
||||||
<ListItemIcon>
|
<>
|
||||||
<PenIcon size="lg" />
|
<MenuItem onClick={() => onOpenCloseForm(FormMode.EDIT, id)}>
|
||||||
</ListItemIcon>
|
<ListItemIcon>
|
||||||
<ListItemText>Edit</ListItemText>
|
<Icon iconName={IconName.PEN} size="lg" />
|
||||||
</MenuItem>
|
</ListItemIcon>
|
||||||
|
<ListItemText>Edit</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
{onOpenCloseTracks &&
|
||||||
|
<MenuItem onClick={() => onOpenCloseTracks!(FormMode.EDIT, id)}>
|
||||||
|
<ListItemIcon>
|
||||||
|
<Icon iconName={IconName.MAP_LOCATION_DOT} size="lg" />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText>Tracks</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
|
||||||
|
}
|
||||||
<MenuItem onClick={() => onOpenCloseForm(FormMode.VIEW, id)}>
|
<MenuItem onClick={() => onOpenCloseForm(FormMode.VIEW, id)}>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<EyeIcon size="lg" />
|
<Icon iconName={IconName.EYE} size="lg" />
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText>View</ListItemText>
|
<ListItemText>View</ListItemText>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<hr className="my-3" />
|
{isAuthenticated &&
|
||||||
<MenuItem onClick={() => onDelete(id)}>
|
<>
|
||||||
<ListItemIcon>
|
<hr className="my-3" />
|
||||||
<TrashIcon size="lg" />
|
<MenuItem onClick={() => onDelete(id)}>
|
||||||
</ListItemIcon>
|
<ListItemIcon>
|
||||||
<ListItemText>Delete</ListItemText>
|
<Icon iconName={IconName.TRASH} size="lg" />
|
||||||
</MenuItem>
|
</ListItemIcon>
|
||||||
|
<ListItemText>Delete</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
</>
|
||||||
|
}
|
||||||
</Menu>
|
</Menu>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ export interface IActionMenuProps {
|
|||||||
id: string;
|
id: string;
|
||||||
onDelete: (entryId: string) => void;
|
onDelete: (entryId: string) => void;
|
||||||
onOpenCloseForm: (formMode: FormMode, id: string) => void;
|
onOpenCloseForm: (formMode: FormMode, id: string) => void;
|
||||||
|
onOpenCloseTracks?: (formMode: FormMode, id: string) => void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
CircleCheckIcon,
|
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogContentText,
|
DialogContentText,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
Spinner,
|
Icon,
|
||||||
XmarkIcon
|
IconName,
|
||||||
|
Spinner
|
||||||
} from '@noahspan/noahspan-components';
|
} from '@noahspan/noahspan-components';
|
||||||
import { IDialogConfirmationProps } from './IConfirmationDialogProps';
|
import { IDialogConfirmationProps } from './IConfirmationDialogProps';
|
||||||
|
|
||||||
@@ -34,13 +34,13 @@ const ConfirmationDialog = ({
|
|||||||
{isLoading && <Spinner />}
|
{isLoading && <Spinner />}
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={onCancel} variant="outlined" startIcon={<XmarkIcon />}>
|
<Button onClick={onCancel} variant="outlined" startIcon={<Icon iconName={IconName.XMARK} />}>
|
||||||
No
|
No
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={onConfirm}
|
onClick={onConfirm}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
startIcon={<CircleCheckIcon />}
|
startIcon={<Icon iconName={IconName.CIRCLE_CHECK} />}
|
||||||
>
|
>
|
||||||
Yes
|
Yes
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
53
app/src/components/logTrackMaps/LogTrackMaps.css
Normal file
53
app/src/components/logTrackMaps/LogTrackMaps.css
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#app {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: #eee;
|
||||||
|
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-wrapper {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-slide {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
background: #fff;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-slide img {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-pagination-bullet {
|
||||||
|
background-color: #000000;
|
||||||
|
height: 13px;
|
||||||
|
width: 13px;
|
||||||
|
border: 2px solid #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swiper-pagination-bullet-active {
|
||||||
|
box-shadow: 0 0 0 1px #000000;
|
||||||
|
}
|
||||||
84
app/src/components/logTrackMaps/LogTrackMaps.tsx
Normal file
84
app/src/components/logTrackMaps/LogTrackMaps.tsx
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { LogTrackMapsProps } from './LogTrackMapsProps.interface';
|
||||||
|
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
||||||
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
||||||
|
import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
||||||
|
import { useIsAuthenticated } from '@azure/msal-react';
|
||||||
|
import { Swiper, SwiperSlide } from 'swiper/react';
|
||||||
|
import { Pagination } from 'swiper/modules';
|
||||||
|
import { MapContainer, TileLayer } from 'react-leaflet';
|
||||||
|
import ReactLeafletKml from 'react-leaflet-kml';
|
||||||
|
import 'swiper/css';
|
||||||
|
import 'swiper/css/pagination';
|
||||||
|
import 'swiper/css';
|
||||||
|
import './LogTrackMaps.css';
|
||||||
|
import 'leaflet/dist/leaflet.css';
|
||||||
|
|
||||||
|
const LogTrackMaps = ({ rowKey, trackUrls }: LogTrackMapsProps) => {
|
||||||
|
const [tracks, setTracks] = useState<any[]>([])
|
||||||
|
const httpClient: AxiosInstance = useHttpClient();
|
||||||
|
const { getAccessToken } = useAccessToken();
|
||||||
|
const isAuthenticated = useIsAuthenticated();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getTracks = async () => {
|
||||||
|
const convertedTracks: any[] = []
|
||||||
|
|
||||||
|
for (const trackUrl of trackUrls) {
|
||||||
|
const trackUrlSplit = trackUrl.split('/')
|
||||||
|
const filename = trackUrlSplit[trackUrlSplit.length - 1];
|
||||||
|
const config = isAuthenticated
|
||||||
|
? { headers: { Authorization: await getAccessToken() } }
|
||||||
|
: {};
|
||||||
|
const response: AxiosResponse = await httpClient.get(
|
||||||
|
`api/logs/log/${rowKey}/track?fileName=${filename}`,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
const kml = new DOMParser().parseFromString(response.data, 'text/xml')
|
||||||
|
// const converted = toGeoJSON.kml(dom);
|
||||||
|
|
||||||
|
// rewind(converted, false);
|
||||||
|
|
||||||
|
convertedTracks.push(kml);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTracks(convertedTracks)
|
||||||
|
}
|
||||||
|
|
||||||
|
getTracks();
|
||||||
|
}, [trackUrls])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Swiper
|
||||||
|
spaceBetween={30}
|
||||||
|
pagination={{
|
||||||
|
clickable: true,
|
||||||
|
}}
|
||||||
|
modules={[Pagination]}
|
||||||
|
className="mySwiper"
|
||||||
|
>
|
||||||
|
{tracks.length > 0 && tracks.map((track) => {
|
||||||
|
return (
|
||||||
|
<SwiperSlide>
|
||||||
|
<MapContainer
|
||||||
|
center={[45.14489, -93.21019]}
|
||||||
|
scrollWheelZoom={false}
|
||||||
|
style={{ height: '500px', width: '100%' }}
|
||||||
|
zoom={8}
|
||||||
|
>
|
||||||
|
<TileLayer
|
||||||
|
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||||
|
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||||
|
/>
|
||||||
|
<ReactLeafletKml kml={track} />
|
||||||
|
</MapContainer>
|
||||||
|
</SwiperSlide>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</Swiper>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LogTrackMaps;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export interface LogTrackMapsProps {
|
||||||
|
rowKey: string;
|
||||||
|
trackUrls: string[];
|
||||||
|
}
|
||||||
198
app/src/components/logTracks/LogTracks.tsx
Normal file
198
app/src/components/logTracks/LogTracks.tsx
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
import { useEffect, useReducer } from "react";
|
||||||
|
import { Button, Drawer, Grid, Icon, IconButton, IconName, TextField, theme, Typography, useMediaQuery } from "@noahspan/noahspan-components";
|
||||||
|
import { useHttpClient } from "../../hooks/httpClient/UseHttpClient";
|
||||||
|
import { AxiosInstance, AxiosResponse } from "axios";
|
||||||
|
import { useAccessToken } from "../../hooks/accessToken/UseAcessToken";
|
||||||
|
import { LogTracksProps } from "./LogTracksProps.interface";
|
||||||
|
import { FormMode } from "../../enums/formMode";
|
||||||
|
import { useIsAuthenticated } from "@azure/msal-react";
|
||||||
|
import { ILogbookEntry } from "../logbook/ILogbookEntry";
|
||||||
|
import ConfirmationDialog from "../confirmationDialog/ConfirmationDialog";
|
||||||
|
import { initialState, reducer } from "./reducer";
|
||||||
|
import LogTrackMaps from "../logTrackMaps/LogTrackMaps";
|
||||||
|
|
||||||
|
const LogTracks = ({ isDrawerOpen, mode, onOpenClose, selectedRowKey }: LogTracksProps) => {
|
||||||
|
const [state, dispatch] = useReducer(reducer, initialState)
|
||||||
|
const httpClient: AxiosInstance = useHttpClient();
|
||||||
|
const { getAccessToken } = useAccessToken();
|
||||||
|
const isAuthenticated = useIsAuthenticated();
|
||||||
|
|
||||||
|
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||||
|
|
||||||
|
const getConfig = async () => {
|
||||||
|
const config = isAuthenticated
|
||||||
|
? { headers: { Authorization: await getAccessToken() } }
|
||||||
|
: {};
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLog = async (): Promise<ILogbookEntry> => {
|
||||||
|
const logResponse: AxiosResponse = await httpClient.get(
|
||||||
|
`api/logs/log/${selectedRowKey}`,
|
||||||
|
await getConfig()
|
||||||
|
);
|
||||||
|
const logData: ILogbookEntry = logResponse.data;
|
||||||
|
|
||||||
|
return logData
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleFileUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
try {
|
||||||
|
dispatch({ type: 'SET_IS_LOADING', payload: true})
|
||||||
|
|
||||||
|
const file = event.target.files![0]
|
||||||
|
const formData = new FormData();
|
||||||
|
const config = await getConfig();
|
||||||
|
const formDataConfig = {
|
||||||
|
headers: {
|
||||||
|
...config.headers,
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
const uploadResponse: AxiosResponse = await httpClient.post(`api/logs/log/${selectedRowKey}/track`, formData, formDataConfig);
|
||||||
|
const uploadUrl = uploadResponse.data.url;
|
||||||
|
const log = await getLog();
|
||||||
|
const tracks: string[] = JSON.parse(log.tracks!);
|
||||||
|
|
||||||
|
tracks.push(uploadUrl)
|
||||||
|
log.tracks = JSON.stringify(tracks);
|
||||||
|
await httpClient.put(`api/logs/log/${selectedRowKey}`, log, config);
|
||||||
|
|
||||||
|
const updatedLog = await getLog();
|
||||||
|
|
||||||
|
dispatch({ type: 'SET_TRACKS', payload: JSON.parse(updatedLog.tracks!) })
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
} finally {
|
||||||
|
dispatch({ type: 'SET_IS_LOADING', payload: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCancel = () => {
|
||||||
|
onOpenClose(FormMode.CANCEL)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onDeleteTrack = async (fileName: string, index: number) => {
|
||||||
|
dispatch({ type: 'SET_ON_DELETE_TRACK', payload: { isConfirmDialogOpen: true, selectedTrack: { fileName: fileName, index: index }}})
|
||||||
|
}
|
||||||
|
|
||||||
|
const onConfirmDialogConfirm = async () => {
|
||||||
|
try {
|
||||||
|
const config = await getConfig();
|
||||||
|
|
||||||
|
await httpClient.delete(`api/logs/log/${selectedRowKey}/track?fileName=${state.selectedTrack!.fileName}`, config);
|
||||||
|
|
||||||
|
const log = await getLog();
|
||||||
|
const tracks: string[] = JSON.parse(log.tracks!);
|
||||||
|
|
||||||
|
tracks.splice(state.selectedTrack!.index, 1);
|
||||||
|
log.tracks = JSON.stringify(tracks);
|
||||||
|
await httpClient.put(`api/logs/log/${selectedRowKey}`, log, config);
|
||||||
|
|
||||||
|
const updatedLog = await getLog();
|
||||||
|
|
||||||
|
dispatch({ type: 'SET_TRACKS', payload: JSON.parse(updatedLog.tracks!) })
|
||||||
|
dispatch({ type: 'SET_IS_CONFIRM_DIALOG_OPEN', payload: false })
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onConfirmDialogCancel = async () => {
|
||||||
|
dispatch({ type: 'SET_IS_CONFIRM_DIALOG_OPEN', payload: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const updateTracks = async () => {
|
||||||
|
const log = await getLog();
|
||||||
|
|
||||||
|
dispatch({ type: 'SET_TRACKS', payload: JSON.parse(log.tracks!) });
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTracks();
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer
|
||||||
|
open={isDrawerOpen}
|
||||||
|
anchor='right'
|
||||||
|
PaperProps={{
|
||||||
|
sx: {
|
||||||
|
padding: '30px',
|
||||||
|
width: isMedium ? '33%' : '75%'
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Grid container spacing={2}>
|
||||||
|
<Grid size={11}>
|
||||||
|
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Tracks`}</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid display="flex" justifyContent="right" size={1}>
|
||||||
|
<IconButton onClick={onCancel}>
|
||||||
|
<Icon iconName={IconName.XMARK} />
|
||||||
|
</IconButton>
|
||||||
|
</Grid>
|
||||||
|
{mode === FormMode.EDIT &&
|
||||||
|
<>
|
||||||
|
{state.tracks.length > 0 && state.tracks.map((track, index) => {
|
||||||
|
const trackSplit = track.split('/')
|
||||||
|
const filename = trackSplit[trackSplit.length - 1];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Grid size={11}>
|
||||||
|
<TextField disabled={true} fullWidth value={filename} />
|
||||||
|
</Grid>
|
||||||
|
<Grid size={1}>
|
||||||
|
<IconButton onClick={() => onDeleteTrack(filename, index)}><Icon iconName={IconName.TRASH} /></IconButton>
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
<Grid display='flex' gap={2} justifyContent='right' size={12}>
|
||||||
|
<Button
|
||||||
|
startIcon={<Icon iconName={IconName.XMARK} />}
|
||||||
|
variant="outlined"
|
||||||
|
onClick={onCancel}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
{mode.toString() !== FormMode.VIEW ? 'Cancel' : 'Close'}
|
||||||
|
</Button>
|
||||||
|
{mode.toString() !== FormMode.VIEW && (
|
||||||
|
<Button
|
||||||
|
component='label'
|
||||||
|
loading={state.isLoading}
|
||||||
|
startIcon={<Icon iconName={IconName.UPLOAD} />}
|
||||||
|
variant='contained'
|
||||||
|
>
|
||||||
|
Upload Track
|
||||||
|
<input hidden onChange={handleFileUpload} type='file' />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
{mode === FormMode.VIEW &&
|
||||||
|
<LogTrackMaps rowKey={selectedRowKey!} trackUrls={state.tracks} />
|
||||||
|
}
|
||||||
|
</Grid>
|
||||||
|
{state.isConfirmDialogOpen && (
|
||||||
|
<ConfirmationDialog
|
||||||
|
contentText="Are you sure you want to delete this track?"
|
||||||
|
isLoading={state.isConfirmDialogLoading}
|
||||||
|
isOpen={state.isConfirmDialogOpen}
|
||||||
|
onCancel={onConfirmDialogCancel}
|
||||||
|
onConfirm={onConfirmDialogConfirm}
|
||||||
|
title="Confirm Delete"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</Drawer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LogTracks;
|
||||||
8
app/src/components/logTracks/LogTracksProps.interface.ts
Normal file
8
app/src/components/logTracks/LogTracksProps.interface.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { FormMode } from "../../enums/formMode";
|
||||||
|
|
||||||
|
export interface LogTracksProps {
|
||||||
|
isDrawerOpen: boolean;
|
||||||
|
mode: FormMode;
|
||||||
|
onOpenClose: (mode: FormMode) => void;
|
||||||
|
selectedRowKey: string | undefined;
|
||||||
|
}
|
||||||
10
app/src/components/logTracks/LogTracksState.interface.ts
Normal file
10
app/src/components/logTracks/LogTracksState.interface.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export interface LogTracksState {
|
||||||
|
isConfirmDialogOpen: boolean;
|
||||||
|
isConfirmDialogLoading: boolean;
|
||||||
|
isLoading: boolean;
|
||||||
|
selectedTrack: {
|
||||||
|
fileName: string,
|
||||||
|
index: number
|
||||||
|
} | undefined;
|
||||||
|
tracks: string[];
|
||||||
|
}
|
||||||
55
app/src/components/logTracks/reducer.ts
Normal file
55
app/src/components/logTracks/reducer.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { LogTracksState } from "./LogTracksState.interface";
|
||||||
|
|
||||||
|
type Action =
|
||||||
|
| { type: 'SET_IS_CONFIRM_DIALOG_OPEN'; payload: boolean }
|
||||||
|
| { type: 'SET_IS_CONFORM_DIALOG_LOADING'; payload: boolean }
|
||||||
|
| { type: 'SET_IS_LOADING'; payload: boolean }
|
||||||
|
| { type: 'SET_ON_DELETE_TRACK'; payload: { isConfirmDialogOpen: boolean, selectedTrack: { fileName: string, index: number } }}
|
||||||
|
| { type: 'SET_TRACKS'; payload: string[] };
|
||||||
|
|
||||||
|
export const initialState: LogTracksState = {
|
||||||
|
isConfirmDialogOpen: false,
|
||||||
|
isConfirmDialogLoading: false,
|
||||||
|
isLoading: false,
|
||||||
|
selectedTrack: undefined,
|
||||||
|
tracks: []
|
||||||
|
}
|
||||||
|
|
||||||
|
export const reducer = (state: LogTracksState, action: Action): LogTracksState => {
|
||||||
|
switch (action.type) {
|
||||||
|
case 'SET_IS_CONFIRM_DIALOG_OPEN': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isConfirmDialogOpen: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'SET_IS_CONFORM_DIALOG_LOADING': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isConfirmDialogLoading: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'SET_IS_LOADING': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isLoading: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'SET_ON_DELETE_TRACK': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isConfirmDialogOpen: action.payload.isConfirmDialogOpen,
|
||||||
|
selectedTrack: action.payload.selectedTrack
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'SET_TRACKS': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
tracks: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
|
import { ColumnDef } from "@noahspan/noahspan-components";
|
||||||
|
|
||||||
export interface ILogbookEntry {
|
export interface ILogbookEntry {
|
||||||
partitionKey: string;
|
partitionKey: string;
|
||||||
rowKey: string;
|
rowKey: string;
|
||||||
id: string;
|
id: string;
|
||||||
pilotId: string;
|
pilotId: string;
|
||||||
|
pilotName: string;
|
||||||
date: string;
|
date: string;
|
||||||
aircraftMakeModel: string;
|
aircraftMakeModel: string;
|
||||||
aircraftIdentity: string;
|
aircraftIdentity: string;
|
||||||
@@ -24,4 +27,6 @@ export interface ILogbookEntry {
|
|||||||
night: number | null;
|
night: number | null;
|
||||||
solo: number | null;
|
solo: number | null;
|
||||||
pilotInCommand: number | null;
|
pilotInCommand: number | null;
|
||||||
|
tracks: string | undefined;
|
||||||
|
notes: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
|
import { ColumnDef } from '@noahspan/noahspan-components';
|
||||||
import { FormMode } from '../../enums/formMode';
|
import { FormMode } from '../../enums/formMode';
|
||||||
import { Alert } from '../../interfaces/Alert.interface';
|
import { Alert } from '../../interfaces/Alert.interface';
|
||||||
import { ILogbookEntry } from './ILogbookEntry';
|
import { ILogbookEntry } from './ILogbookEntry';
|
||||||
|
|
||||||
export interface ILogbookState {
|
export interface ILogbookState {
|
||||||
alert: Alert | undefined;
|
alert: Alert | undefined;
|
||||||
|
columns: ColumnDef<ILogbookEntry>[];
|
||||||
entries: ILogbookEntry[];
|
entries: ILogbookEntry[];
|
||||||
formMode: FormMode;
|
formMode: FormMode;
|
||||||
isConfirmDialogLoading: boolean;
|
isConfirmDialogLoading: boolean;
|
||||||
isConfirmDialogOpen: boolean;
|
isConfirmDialogOpen: boolean;
|
||||||
isFormOpen: boolean;
|
isFormOpen: boolean;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
isTracksOpen: boolean;
|
||||||
selectedEntryId: string | undefined;
|
selectedEntryId: string | undefined;
|
||||||
|
tracksMode: FormMode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
ColumnDef,
|
ColumnDef,
|
||||||
Grid,
|
Grid,
|
||||||
PlusIcon,
|
Icon,
|
||||||
|
IconButton,
|
||||||
|
IconName,
|
||||||
Spinner,
|
Spinner,
|
||||||
Table,
|
Table,
|
||||||
Typography
|
theme,
|
||||||
|
Typography,
|
||||||
|
useMediaQuery
|
||||||
} from '@noahspan/noahspan-components';
|
} from '@noahspan/noahspan-components';
|
||||||
import { initialState, reducer } from './reducer';
|
import { initialState, reducer } from './reducer';
|
||||||
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
||||||
@@ -17,21 +21,57 @@ import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
|||||||
import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
||||||
import { useIsAuthenticated } from '@azure/msal-react';
|
import { useIsAuthenticated } from '@azure/msal-react';
|
||||||
import { FormMode } from '../../enums/formMode';
|
import { FormMode } from '../../enums/formMode';
|
||||||
|
import { authColumns, unauthColumns } from './columns';
|
||||||
import ActionMenu from '../actionMenu/ActionMenu';
|
import ActionMenu from '../actionMenu/ActionMenu';
|
||||||
import ConfirmationDialog from '../confirmationDialog/ConfirmationDialog';
|
import ConfirmationDialog from '../confirmationDialog/ConfirmationDialog';
|
||||||
import { ILogbookEntry } from './ILogbookEntry';
|
import { ILogbookEntry } from './ILogbookEntry';
|
||||||
|
import LogbookCard from '../logbookCard/LogbookCard';
|
||||||
|
import LogTracks from '../logTracks/LogTracks';
|
||||||
|
|
||||||
const Logbook: React.FC<unknown> = () => {
|
const Logbook: React.FC<unknown> = () => {
|
||||||
const [state, dispatch] = useReducer(reducer, initialState);
|
const [state, dispatch] = useReducer(reducer, initialState);
|
||||||
const httpClient: AxiosInstance = useHttpClient();
|
const httpClient: AxiosInstance = useHttpClient();
|
||||||
const isAuthenticated = useIsAuthenticated();
|
const isAuthenticated = useIsAuthenticated();
|
||||||
const { getAccessToken } = useAccessToken();
|
const { getAccessToken } = useAccessToken();
|
||||||
|
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||||
|
const actionsColumn: ColumnDef<ILogbookEntry> = {
|
||||||
|
header: 'Actions',
|
||||||
|
meta: {
|
||||||
|
align: 'center',
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
cell: (info: any) => (
|
||||||
|
<ActionMenu
|
||||||
|
id={info.row.original.rowKey}
|
||||||
|
onDelete={onDeleteEntry}
|
||||||
|
onOpenCloseForm={onOpenCloseEntryForm}
|
||||||
|
onOpenCloseTracks={onOpenCloseTracks}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const tracksColumn: ColumnDef<ILogbookEntry> = {
|
||||||
|
accessorKey: 'tracks',
|
||||||
|
header: 'Tracks',
|
||||||
|
cell: (info: any) => {
|
||||||
|
if (info.row.original.tracks && info.row.original.tracks.length > 0) {
|
||||||
|
return (
|
||||||
|
<IconButton onClick={() => onOpenCloseTracks(FormMode.VIEW, info.row.original.rowKey)}><Icon iconName={IconName.MAP_LOCATION_DOT} /></IconButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const getLogbookEntries = async () => {
|
const getLogbookEntries = async () => {
|
||||||
try {
|
try {
|
||||||
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
dispatch({ type: 'SET_IS_LOADING', payload: true });
|
||||||
|
|
||||||
const response: AxiosResponse = await httpClient.get(`api/logs`);
|
const config = isAuthenticated
|
||||||
|
? { headers: { Authorization: await getAccessToken() } }
|
||||||
|
: {};
|
||||||
|
const response: AxiosResponse = await httpClient.get(`api/logs`, config);
|
||||||
|
const entries: ILogbookEntry[] = response.data;
|
||||||
|
|
||||||
|
entries.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
|
||||||
|
|
||||||
if (response.data.length > 0) {
|
if (response.data.length > 0) {
|
||||||
dispatch({ type: 'SET_ENTRIES', payload: response.data });
|
dispatch({ type: 'SET_ENTRIES', payload: response.data });
|
||||||
@@ -83,6 +123,34 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onOpenCloseTracks = (mode: FormMode, rowKey?: string) => {
|
||||||
|
switch(mode) {
|
||||||
|
case FormMode.EDIT:
|
||||||
|
case FormMode.VIEW:
|
||||||
|
dispatch({
|
||||||
|
type: 'SET_OPEN_CLOSE_TRACKS',
|
||||||
|
payload: {
|
||||||
|
tracksMode: mode,
|
||||||
|
isTracksOpen: true,
|
||||||
|
selectedRowKey: rowKey
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
break;
|
||||||
|
case FormMode.CANCEL:
|
||||||
|
dispatch({
|
||||||
|
type: 'SET_OPEN_CLOSE_TRACKS',
|
||||||
|
payload: {
|
||||||
|
tracksMode: mode,
|
||||||
|
isTracksOpen: false,
|
||||||
|
selectedRowKey: undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onDeleteEntry = (entryId: string) => {
|
const onDeleteEntry = (entryId: string) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'SET_DELETE',
|
type: 'SET_DELETE',
|
||||||
@@ -125,264 +193,48 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const columns: ColumnDef<ILogbookEntry>[] = [
|
useEffect(() => {
|
||||||
{
|
let newColumns: ColumnDef<ILogbookEntry>[];
|
||||||
accessorKey: 'pilotName',
|
|
||||||
header: 'Pilot'
|
if (isAuthenticated) {
|
||||||
},
|
newColumns = [...authColumns];
|
||||||
{
|
} else {
|
||||||
accessorKey: 'date',
|
newColumns = [...unauthColumns];
|
||||||
header: 'Date'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'aircraftMakeModel',
|
|
||||||
header: 'Aircraft Make & Model'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'aircraftIdentity',
|
|
||||||
header: 'Aircraft Identity'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
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() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'singleEngineLand',
|
|
||||||
header: 'Single Engine Land',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info: any) =>
|
|
||||||
info.getValue() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'landings',
|
|
||||||
header: 'Landings',
|
|
||||||
meta: {
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
accessorKey: 'landingsDay',
|
|
||||||
header: 'Day',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'landingsNight',
|
|
||||||
header: 'Night',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'instrument',
|
|
||||||
header: 'Instrument',
|
|
||||||
meta: {
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentActual',
|
|
||||||
header: 'Actual',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info) =>
|
|
||||||
info.getValue() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentSimulated',
|
|
||||||
header: 'Simulated',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info) =>
|
|
||||||
info.getValue() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentApproaches',
|
|
||||||
header: 'Approaches',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentHolds',
|
|
||||||
header: 'Holds',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'instrumentNavTrack',
|
|
||||||
header: 'Nav/Track',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'experienceTraining',
|
|
||||||
header: 'Type of pilot experience or training',
|
|
||||||
meta: {
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
accessorKey: 'groundTrainingReceived',
|
|
||||||
header: 'Ground Training Received',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info) =>
|
|
||||||
info.getValue() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'flightTrainingReceived',
|
|
||||||
header: 'Flight Training Received',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info) =>
|
|
||||||
info.getValue() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'crossCountry',
|
|
||||||
header: 'Cross Country',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info) =>
|
|
||||||
info.getValue() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'night',
|
|
||||||
header: 'Night',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info) =>
|
|
||||||
info.getValue() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'solo',
|
|
||||||
header: 'Solo',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info) =>
|
|
||||||
info.getValue() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'pilotInCommand',
|
|
||||||
header: 'Pilot In Command',
|
|
||||||
meta: {
|
|
||||||
align: 'right',
|
|
||||||
headerAlign: 'right'
|
|
||||||
},
|
|
||||||
cell: (info) =>
|
|
||||||
info.getValue() !== null
|
|
||||||
? parseFloat(info.getValue()).toFixed(1)
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'notes',
|
|
||||||
header: 'Notes'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: 'Actions',
|
|
||||||
meta: {
|
|
||||||
align: 'center',
|
|
||||||
headerAlign: 'center'
|
|
||||||
},
|
|
||||||
cell: (info) => (
|
|
||||||
<ActionMenu
|
|
||||||
id={info.row.original.rowKey}
|
|
||||||
onDelete={onDeleteEntry}
|
|
||||||
onOpenCloseForm={onOpenCloseEntryForm}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
const actionsColumnExists = newColumns.find((column) => column.id === 'actions');
|
||||||
|
const tracksColumnExists = newColumns.find((column) => column.id === 'actions');
|
||||||
|
|
||||||
|
if (!actionsColumnExists) {
|
||||||
|
newColumns.push(actionsColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tracksColumnExists) {
|
||||||
|
const notesColumnIndex = newColumns.findIndex((column) => column.id === 'notes')
|
||||||
|
|
||||||
|
newColumns.splice(notesColumnIndex, 0, tracksColumn)
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch({ type: 'SET_COLUMNS', payload: newColumns })
|
||||||
|
}, [isAuthenticated])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!state.isFormOpen) {
|
if (!state.isFormOpen) {
|
||||||
getLogbookEntries();
|
getLogbookEntries();
|
||||||
}
|
}
|
||||||
}, [state.isFormOpen]);
|
}, [state.isFormOpen, state.isTracksOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ margin: '20px' }}>
|
<Box sx={{ margin: '20px' }}>
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<Grid size={11}>
|
<Grid size={isMedium ? 11 : 6}>
|
||||||
<Typography variant="h4">Logbook</Typography>
|
<Typography variant="h4">Logbook</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid display="flex" justifyContent="right" size={1}>
|
<Grid display="flex" justifyContent="right" size={isMedium ? 1 : 6}>
|
||||||
{isAuthenticated &&
|
{isAuthenticated &&
|
||||||
<Button
|
<Button
|
||||||
onClick={() => onOpenCloseEntryForm(FormMode.ADD)}
|
onClick={() => onOpenCloseEntryForm(FormMode.ADD)}
|
||||||
startIcon={<PlusIcon />}
|
startIcon={<Icon iconName={IconName.PLUS} />}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
data-testid="pilot-add-button"
|
data-testid="pilot-add-button"
|
||||||
>
|
>
|
||||||
@@ -405,9 +257,12 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
)}
|
)}
|
||||||
{!state.isLoading && (
|
{!state.isLoading && (
|
||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
{state.entries.length > 0 && (
|
{isMedium && state.columns && state.columns.length > 0 && state.entries.length > 0 && (
|
||||||
<Table columns={columns} data={state.entries} />
|
<Table columns={state.columns} data={state.entries} />
|
||||||
)}
|
)}
|
||||||
|
{!isMedium && state.entries.length > 0 &&
|
||||||
|
<LogbookCard logs={state.entries} onDelete={onDeleteEntry} onOpenCloseForm={onOpenCloseEntryForm} />
|
||||||
|
}
|
||||||
</Grid>
|
</Grid>
|
||||||
)}
|
)}
|
||||||
{state.isLoading && !state.alert && (
|
{state.isLoading && !state.alert && (
|
||||||
@@ -439,6 +294,14 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
title="Confirm Delete"
|
title="Confirm Delete"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{state.isTracksOpen &&
|
||||||
|
<LogTracks
|
||||||
|
isDrawerOpen={state.isTracksOpen}
|
||||||
|
mode={state.tracksMode}
|
||||||
|
onOpenClose={(mode) => onOpenCloseTracks(mode)}
|
||||||
|
selectedRowKey={state.selectedEntryId}
|
||||||
|
/>
|
||||||
|
}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
252
app/src/components/logbook/columns.tsx
Normal file
252
app/src/components/logbook/columns.tsx
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
Icon,
|
||||||
|
IconButton,
|
||||||
|
IconName
|
||||||
|
} from '@noahspan/noahspan-components';
|
||||||
|
import { ILogbookEntry } from './ILogbookEntry';
|
||||||
|
|
||||||
|
const pilotName: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'pilotName',
|
||||||
|
accessorKey: 'pilotName',
|
||||||
|
header: 'Pilot'
|
||||||
|
}
|
||||||
|
const date: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'date',
|
||||||
|
accessorKey: 'date',
|
||||||
|
header: 'Date'
|
||||||
|
}
|
||||||
|
const aircraftMakeModel: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'aircraftMakeModel',
|
||||||
|
accessorKey: 'aircraftMakeModel',
|
||||||
|
header: 'Aircraft Make & Model'
|
||||||
|
}
|
||||||
|
const route: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'route',
|
||||||
|
header: 'Route of Flight',
|
||||||
|
meta: {
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: 'routeFrom',
|
||||||
|
accessorKey: 'routeFrom',
|
||||||
|
header: 'From'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'routeTo',
|
||||||
|
accessorKey: 'routeTo',
|
||||||
|
header: 'To'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
const durationOfFlight: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'durationOfFlight',
|
||||||
|
accessorKey: 'durationOfFlight',
|
||||||
|
header: 'Duration Of Flight',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
}
|
||||||
|
const notes: ColumnDef<ILogbookEntry> = {
|
||||||
|
id: 'notes',
|
||||||
|
accessorKey: 'notes',
|
||||||
|
header: 'Notes'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const unauthColumns: ColumnDef<ILogbookEntry>[] = [
|
||||||
|
pilotName,
|
||||||
|
date,
|
||||||
|
aircraftMakeModel,
|
||||||
|
route,
|
||||||
|
durationOfFlight,
|
||||||
|
notes
|
||||||
|
]
|
||||||
|
|
||||||
|
export const authColumns: ColumnDef<ILogbookEntry>[] = [
|
||||||
|
pilotName,
|
||||||
|
date,
|
||||||
|
aircraftMakeModel,
|
||||||
|
{
|
||||||
|
id: 'aircraftIdentity',
|
||||||
|
accessorKey: 'aircraftIdentity',
|
||||||
|
header: 'Aircraft Identity',
|
||||||
|
},
|
||||||
|
route,
|
||||||
|
durationOfFlight,
|
||||||
|
{
|
||||||
|
id: 'singleEngineLand',
|
||||||
|
accessorKey: 'singleEngineLand',
|
||||||
|
header: 'Single Engine Land',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'landings',
|
||||||
|
header: 'Landings',
|
||||||
|
meta: {
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: 'landingsDay',
|
||||||
|
accessorKey: 'landingsDay',
|
||||||
|
header: 'Day',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'landingsNight',
|
||||||
|
accessorKey: 'landingsNight',
|
||||||
|
header: 'Night',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrument',
|
||||||
|
header: 'Instrument',
|
||||||
|
meta: {
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: 'instrumentActual',
|
||||||
|
accessorKey: 'instrumentActual',
|
||||||
|
header: 'Actual',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrumentSimulated',
|
||||||
|
accessorKey: 'instrumentSimulated',
|
||||||
|
header: 'Simulated',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrumentApproaches',
|
||||||
|
accessorKey: 'instrumentApproaches',
|
||||||
|
header: 'Approaches',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrumentHolds',
|
||||||
|
accessorKey: 'instrumentHolds',
|
||||||
|
header: 'Holds',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'instrumentNavTrack',
|
||||||
|
accessorKey: 'instrumentNavTrack',
|
||||||
|
header: 'Nav/Track',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'experienceTraining',
|
||||||
|
header: 'Type of pilot experience or training',
|
||||||
|
meta: {
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: 'groundTrainingReceived',
|
||||||
|
accessorKey: 'groundTrainingReceived',
|
||||||
|
header: 'Ground Training Received',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'flightTrainingReceived',
|
||||||
|
accessorKey: 'flightTrainingReceived',
|
||||||
|
header: 'Flight Training Received',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'crossCountry',
|
||||||
|
accessorKey: 'crossCountry',
|
||||||
|
header: 'Cross Country',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'night',
|
||||||
|
accessorKey: 'night',
|
||||||
|
header: 'Night',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'solo',
|
||||||
|
accessorKey: 'solo',
|
||||||
|
header: 'Solo',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'pilotInCommand',
|
||||||
|
accessorKey: 'pilotInCommand',
|
||||||
|
header: 'Pilot In Command',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
notes
|
||||||
|
]
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
|
import { ColumnDef } from '@noahspan/noahspan-components';
|
||||||
import { FormMode } from '../../enums/formMode';
|
import { FormMode } from '../../enums/formMode';
|
||||||
import { Alert } from '../../interfaces/Alert.interface';
|
import { Alert } from '../../interfaces/Alert.interface';
|
||||||
import { ILogbookEntry } from './ILogbookEntry';
|
import { ILogbookEntry } from './ILogbookEntry';
|
||||||
import { ILogbookState } from './ILogbookState';
|
import { ILogbookState } from './ILogbookState';
|
||||||
|
|
||||||
type Action =
|
type Action =
|
||||||
|
| { type: 'SET_COLUMNS'; payload: ColumnDef<ILogbookEntry>[] }
|
||||||
| {
|
| {
|
||||||
type: 'SET_DELETE';
|
type: 'SET_DELETE';
|
||||||
payload: {
|
payload: {
|
||||||
@@ -23,17 +25,21 @@ type Action =
|
|||||||
selectedEntryId: string | undefined;
|
selectedEntryId: string | undefined;
|
||||||
isFormOpen: boolean;
|
isFormOpen: boolean;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
| { type: 'SET_OPEN_CLOSE_TRACKS'; payload: { tracksMode: FormMode, selectedRowKey: string | undefined, isTracksOpen: boolean; }};
|
||||||
|
|
||||||
export const initialState: ILogbookState = {
|
export const initialState: ILogbookState = {
|
||||||
alert: undefined,
|
alert: undefined,
|
||||||
|
columns: [],
|
||||||
entries: [],
|
entries: [],
|
||||||
formMode: FormMode.CANCEL,
|
formMode: FormMode.CANCEL,
|
||||||
isConfirmDialogLoading: false,
|
isConfirmDialogLoading: false,
|
||||||
isConfirmDialogOpen: false,
|
isConfirmDialogOpen: false,
|
||||||
isFormOpen: false,
|
isFormOpen: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
selectedEntryId: undefined
|
isTracksOpen: false,
|
||||||
|
selectedEntryId: undefined,
|
||||||
|
tracksMode: FormMode.CANCEL
|
||||||
};
|
};
|
||||||
|
|
||||||
export const reducer = (
|
export const reducer = (
|
||||||
@@ -41,6 +47,12 @@ export const reducer = (
|
|||||||
action: Action
|
action: Action
|
||||||
): ILogbookState => {
|
): ILogbookState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case 'SET_COLUMNS': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
columns: action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
case 'SET_DELETE': {
|
case 'SET_DELETE': {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@@ -86,6 +98,14 @@ export const reducer = (
|
|||||||
selectedEntryId: action.payload.selectedEntryId
|
selectedEntryId: action.payload.selectedEntryId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case 'SET_OPEN_CLOSE_TRACKS': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
tracksMode: action.payload.tracksMode,
|
||||||
|
isTracksOpen: action.payload.isTracksOpen,
|
||||||
|
selectedEntryId: action.payload.selectedRowKey
|
||||||
|
}
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
@@ -4,13 +4,15 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Drawer,
|
Drawer,
|
||||||
Grid,
|
Grid,
|
||||||
|
Icon,
|
||||||
IconButton,
|
IconButton,
|
||||||
|
IconName,
|
||||||
PeoplePicker,
|
PeoplePicker,
|
||||||
SaveIcon,
|
|
||||||
StateSelect,
|
StateSelect,
|
||||||
TextField,
|
TextField,
|
||||||
|
theme,
|
||||||
Typography,
|
Typography,
|
||||||
XmarkIcon
|
useMediaQuery
|
||||||
} from '@noahspan/noahspan-components';
|
} from '@noahspan/noahspan-components';
|
||||||
import { IPilotFormProps } from './IPilotFormProps';
|
import { IPilotFormProps } from './IPilotFormProps';
|
||||||
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
||||||
@@ -19,6 +21,9 @@ import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
|||||||
import { useIsAuthenticated } from '@azure/msal-react';
|
import { useIsAuthenticated } from '@azure/msal-react';
|
||||||
import { FormMode } from '../../enums/formMode';
|
import { FormMode } from '../../enums/formMode';
|
||||||
import { Person } from '@microsoft/microsoft-graph-types';
|
import { Person } from '@microsoft/microsoft-graph-types';
|
||||||
|
import PilotFormCertificates from '../pilotFormCertificates/PilotFormCertificates';
|
||||||
|
import PilotFormEndorsements from '../pilotFormEndorsements/PilotFormEndorsements';
|
||||||
|
import PilotFormMedical from '../pilotFormMedical/PilotFormMedical';
|
||||||
|
|
||||||
const PilotForm: React.FC<IPilotFormProps> = ({
|
const PilotForm: React.FC<IPilotFormProps> = ({
|
||||||
pilotId,
|
pilotId,
|
||||||
@@ -47,13 +52,18 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
|||||||
state: '',
|
state: '',
|
||||||
postalCode: '',
|
postalCode: '',
|
||||||
email: '',
|
email: '',
|
||||||
phone: ''
|
phone: '',
|
||||||
|
medicalClass: '',
|
||||||
|
medicalExpiration: '',
|
||||||
|
certificates: [],
|
||||||
|
endorsements: []
|
||||||
};
|
};
|
||||||
const methods = useForm({
|
const methods = useForm({
|
||||||
defaultValues: defaultValues
|
defaultValues: defaultValues
|
||||||
});
|
});
|
||||||
const [isDisabled, setIsDisabled] = useState<boolean>(false);
|
const [isDisabled, setIsDisabled] = useState<boolean>(false);
|
||||||
const [isError, setIsError] = useState<boolean>(false);
|
const [isError, setIsError] = useState<boolean>(false);
|
||||||
|
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||||
|
|
||||||
const onPeoplePickerSearch = async (
|
const onPeoplePickerSearch = async (
|
||||||
_event: React.SyntheticEvent,
|
_event: React.SyntheticEvent,
|
||||||
@@ -154,6 +164,9 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
|||||||
);
|
);
|
||||||
const pilot = response.data;
|
const pilot = response.data;
|
||||||
|
|
||||||
|
pilot.certificates = JSON.parse(pilot.certificates);
|
||||||
|
pilot.endorsements = JSON.parse(pilot.endorsements)
|
||||||
|
|
||||||
setSelectedPerson({
|
setSelectedPerson({
|
||||||
userPrincipalName: pilot.id,
|
userPrincipalName: pilot.id,
|
||||||
displayName: pilot.name
|
displayName: pilot.name
|
||||||
@@ -179,25 +192,25 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
|||||||
PaperProps={{
|
PaperProps={{
|
||||||
sx: {
|
sx: {
|
||||||
padding: '30px',
|
padding: '30px',
|
||||||
width: '33%'
|
width: isMedium ? '33%' : '75%'
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<form onSubmit={methods.handleSubmit(onSubmit)}>
|
<form onSubmit={methods.handleSubmit(onSubmit)} style={{ paddingBottom: '50px' }}>
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<Grid size={11}>
|
<Grid size={11}>
|
||||||
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Pilot`}</Typography>
|
<Typography variant="h4">{`${mode.toString().toLowerCase().charAt(0).toUpperCase() + mode.toString().slice(1).toLowerCase()} Pilot`}</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid display="flex" justifyContent="right" size={1}>
|
<Grid display="flex" justifyContent="right" size={1}>
|
||||||
<IconButton onClick={onCancel}>
|
<IconButton onClick={onCancel}>
|
||||||
<XmarkIcon />
|
<Icon iconName={IconName.XMARK} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid size={3}>
|
<Grid size={isMedium ? 3 : 12}>
|
||||||
<Typography variant="h6">Name *</Typography>
|
<Typography variant="h6">Name *</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid size={9}>
|
<Grid size={isMedium ? 9 : 12}>
|
||||||
<PeoplePicker
|
<PeoplePicker
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
loading={isPeoplePickerLoading}
|
loading={isPeoplePickerLoading}
|
||||||
@@ -207,161 +220,178 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
|||||||
value={selectedPerson}
|
value={selectedPerson}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid size={3}>
|
{isAuthenticated &&
|
||||||
<Typography variant="h6">Address *</Typography>
|
<>
|
||||||
</Grid>
|
<Grid size={isMedium ? 3 : 12}>
|
||||||
<Grid size={9}>
|
<Typography variant="h6">Address *</Typography>
|
||||||
<Controller
|
</Grid>
|
||||||
name="address"
|
<Grid size={isMedium ? 9 : 12}>
|
||||||
control={methods.control}
|
<Controller
|
||||||
rules={{ required: 'An address is required' }}
|
name="address"
|
||||||
render={({ field: { onChange, value } }) => (
|
control={methods.control}
|
||||||
<TextField
|
rules={{ required: 'An address is required' }}
|
||||||
disabled={isDisabled}
|
render={({ field: { onChange, value } }) => (
|
||||||
error={methods.formState.errors.address ? true : false}
|
<TextField
|
||||||
fullWidth
|
disabled={isDisabled}
|
||||||
helperText={
|
error={methods.formState.errors.address ? true : false}
|
||||||
methods.formState.errors.address
|
fullWidth
|
||||||
? methods.formState.errors.address.message
|
helperText={
|
||||||
: undefined
|
methods.formState.errors.address
|
||||||
}
|
? methods.formState.errors.address.message
|
||||||
onChange={onChange}
|
: undefined
|
||||||
value={value}
|
}
|
||||||
|
onChange={onChange}
|
||||||
|
value={value}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
</Grid>
|
||||||
/>
|
<Grid size={isMedium ? 3 : 12}>
|
||||||
</Grid>
|
<Typography variant="h6">City *</Typography>
|
||||||
<Grid size={3}>
|
</Grid>
|
||||||
<Typography variant="h6">City *</Typography>
|
<Grid size={isMedium ? 9 : 12}>
|
||||||
</Grid>
|
<Controller
|
||||||
<Grid size={9}>
|
name="city"
|
||||||
<Controller
|
control={methods.control}
|
||||||
name="city"
|
rules={{ required: 'A city is required' }}
|
||||||
control={methods.control}
|
render={({ field: { onChange, value } }) => (
|
||||||
rules={{ required: 'A city is required' }}
|
<TextField
|
||||||
render={({ field: { onChange, value } }) => (
|
disabled={isDisabled}
|
||||||
<TextField
|
error={methods.formState.errors.city ? true : false}
|
||||||
disabled={isDisabled}
|
fullWidth
|
||||||
error={methods.formState.errors.city ? true : false}
|
helperText={
|
||||||
fullWidth
|
methods.formState.errors.city
|
||||||
helperText={
|
? methods.formState.errors.city.message
|
||||||
methods.formState.errors.city
|
: undefined
|
||||||
? methods.formState.errors.city.message
|
}
|
||||||
: undefined
|
onChange={onChange}
|
||||||
}
|
value={value}
|
||||||
onChange={onChange}
|
/>
|
||||||
value={value}
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
</Grid>
|
||||||
/>
|
<Grid size={isMedium ? 3 : 12}>
|
||||||
</Grid>
|
<Typography variant="h6">State *</Typography>
|
||||||
<Grid size={3}>
|
</Grid>
|
||||||
<Typography variant="h6">State *</Typography>
|
<Grid size={isMedium ? 9 : 12}>
|
||||||
</Grid>
|
<Controller
|
||||||
<Grid size={9}>
|
name="state"
|
||||||
<Controller
|
control={methods.control}
|
||||||
name="state"
|
rules={{ required: 'A state must be selected' }}
|
||||||
control={methods.control}
|
render={({ field: { onChange, value } }) => (
|
||||||
rules={{ required: 'A state must be selected' }}
|
<StateSelect
|
||||||
render={({ field: { onChange, value } }) => (
|
disabled={isDisabled}
|
||||||
<StateSelect
|
// error={methods.formState.errors.state ? true : false}
|
||||||
disabled={isDisabled}
|
fullWidth
|
||||||
// error={methods.formState.errors.state ? true : false}
|
// helperText={
|
||||||
fullWidth
|
// methods.formState.errors.state
|
||||||
// helperText={
|
// ? methods.formState.errors.state.message?.toString()
|
||||||
// methods.formState.errors.state
|
// : undefined
|
||||||
// ? methods.formState.errors.state.message?.toString()
|
// }
|
||||||
// : undefined
|
onChange={onChange}
|
||||||
// }
|
value={value}
|
||||||
onChange={onChange}
|
variant="outlined"
|
||||||
value={value}
|
data-testid="pilot-form-state-dropdown"
|
||||||
variant="outlined"
|
/>
|
||||||
data-testid="pilot-form-state-dropdown"
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
</Grid>
|
||||||
/>
|
<Grid size={isMedium ? 3 : 12}>
|
||||||
</Grid>
|
<Typography variant="h6">Postal Code *</Typography>
|
||||||
<Grid size={3}>
|
</Grid>
|
||||||
<Typography variant="h6">Postal Code *</Typography>
|
<Grid size={isMedium ? 9 : 12}>
|
||||||
</Grid>
|
<Controller
|
||||||
<Grid size={9}>
|
name="postalCode"
|
||||||
<Controller
|
control={methods.control}
|
||||||
name="postalCode"
|
rules={{ required: 'A postal code is required' }}
|
||||||
control={methods.control}
|
render={({ field: { onChange, value } }) => (
|
||||||
rules={{ required: 'A postal code is required' }}
|
<TextField
|
||||||
render={({ field: { onChange, value } }) => (
|
disabled={isDisabled}
|
||||||
<TextField
|
error={methods.formState.errors.postalCode ? true : false}
|
||||||
disabled={isDisabled}
|
fullWidth
|
||||||
error={methods.formState.errors.postalCode ? true : false}
|
helperText={
|
||||||
fullWidth
|
methods.formState.errors.postalCode
|
||||||
helperText={
|
? methods.formState.errors.postalCode.message
|
||||||
methods.formState.errors.postalCode
|
: undefined
|
||||||
? methods.formState.errors.postalCode.message
|
}
|
||||||
: undefined
|
onChange={onChange}
|
||||||
}
|
value={value}
|
||||||
onChange={onChange}
|
/>
|
||||||
value={value}
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
</Grid>
|
||||||
/>
|
<Grid size={isMedium ? 3 : 12}>
|
||||||
</Grid>
|
<Typography variant="h6">Email</Typography>
|
||||||
<Grid size={3}>
|
</Grid>
|
||||||
<Typography variant="h6">Email</Typography>
|
<Grid size={isMedium ? 9 : 12}>
|
||||||
</Grid>
|
<Controller
|
||||||
<Grid size={9}>
|
name="email"
|
||||||
<Controller
|
control={methods.control}
|
||||||
name="email"
|
rules={{
|
||||||
control={methods.control}
|
pattern: {
|
||||||
rules={{
|
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
||||||
pattern: {
|
message: 'Invalid email address'
|
||||||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
}
|
||||||
message: 'Invalid email address'
|
}}
|
||||||
}
|
render={({ field: { onChange, value } }) => (
|
||||||
}}
|
<TextField
|
||||||
render={({ field: { onChange, value } }) => (
|
disabled={isDisabled}
|
||||||
<TextField
|
fullWidth
|
||||||
disabled={isDisabled}
|
error={methods.formState.errors.email ? true : false}
|
||||||
fullWidth
|
helperText={
|
||||||
error={methods.formState.errors.email ? true : false}
|
methods.formState.errors.email
|
||||||
helperText={
|
? methods.formState.errors.email.message
|
||||||
methods.formState.errors.email
|
: undefined
|
||||||
? methods.formState.errors.email.message
|
}
|
||||||
: undefined
|
onChange={onChange}
|
||||||
}
|
value={value}
|
||||||
onChange={onChange}
|
/>
|
||||||
value={value}
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
</Grid>
|
||||||
/>
|
<Grid size={isMedium ? 3 : 12}>
|
||||||
</Grid>
|
<Typography variant="h6">Phone Number</Typography>
|
||||||
<Grid size={3}>
|
</Grid>
|
||||||
<Typography variant="h6">Phone Number</Typography>
|
<Grid size={isMedium ? 9 : 12}>
|
||||||
</Grid>
|
<Controller
|
||||||
<Grid size={9}>
|
name="phone"
|
||||||
<Controller
|
control={methods.control}
|
||||||
name="phone"
|
rules={{
|
||||||
control={methods.control}
|
pattern: {
|
||||||
rules={{
|
value: /^[0-9]{3}[-\s\.][0-9]{3}[-\s\.][0-9]{4}$/i,
|
||||||
pattern: {
|
message: 'Enter phone number as 123-456-7890'
|
||||||
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
|
||||||
render={({ field: { onChange, value } }) => (
|
disabled={isDisabled}
|
||||||
<TextField
|
fullWidth
|
||||||
disabled={isDisabled}
|
error={methods.formState.errors.phone ? true : false}
|
||||||
fullWidth
|
helperText={
|
||||||
error={methods.formState.errors.phone ? true : false}
|
methods.formState.errors.phone
|
||||||
helperText={
|
? methods.formState.errors.phone.message
|
||||||
methods.formState.errors.phone
|
: undefined
|
||||||
? methods.formState.errors.phone.message
|
}
|
||||||
: undefined
|
onChange={onChange}
|
||||||
}
|
value={value}
|
||||||
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}>
|
||||||
|
<PilotFormEndorsements isDisabled={isDisabled} mode={mode} />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid display="flex" gap={2} justifyContent="right" size={12}>
|
<Grid display="flex" gap={2} justifyContent="right" size={12}>
|
||||||
<Button
|
<Button
|
||||||
@@ -370,7 +400,7 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
|||||||
? isDisabled
|
? isDisabled
|
||||||
: false
|
: false
|
||||||
}
|
}
|
||||||
startIcon={<XmarkIcon />}
|
startIcon={<Icon iconName={IconName.XMARK} />}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onClick={onCancel}
|
onClick={onCancel}
|
||||||
data-testid="pilot-cancel-button"
|
data-testid="pilot-cancel-button"
|
||||||
@@ -381,7 +411,7 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
|||||||
{mode.toString() !== FormMode.VIEW && (
|
{mode.toString() !== FormMode.VIEW && (
|
||||||
<Button
|
<Button
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
startIcon={<SaveIcon />}
|
startIcon={<Icon iconName={IconName.SAVE} />}
|
||||||
size="small"
|
size="small"
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
@@ -392,111 +422,6 @@ const PilotForm: React.FC<IPilotFormProps> = ({
|
|||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
{/* {pilotId && (
|
|
||||||
<>
|
|
||||||
<div className="col-span-1">
|
|
||||||
<Typography variant="h6">Last Review</Typography>
|
|
||||||
</div>
|
|
||||||
<div className="col-span-3">
|
|
||||||
<Controller
|
|
||||||
name="lastReview"
|
|
||||||
control={methods.control}
|
|
||||||
render={({ field }) => {
|
|
||||||
return (
|
|
||||||
<DatePicker
|
|
||||||
handleDateChanged={(date: string) => {
|
|
||||||
methods.setValue('lastReview', date);
|
|
||||||
}}
|
|
||||||
inputProps={{
|
|
||||||
value: field.value
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)} */}
|
|
||||||
{/* {pilotId && (
|
|
||||||
<>
|
|
||||||
<div className="col-span-4">
|
|
||||||
<Typography variant="h5">Medical</Typography>
|
|
||||||
<hr className="my-3" />
|
|
||||||
</div>
|
|
||||||
<div className="col-span-1">
|
|
||||||
<Typography variant="h6">Class</Typography>
|
|
||||||
</div>
|
|
||||||
<div className="col-span-3">
|
|
||||||
<Controller
|
|
||||||
name="medicalClass"
|
|
||||||
control={methods.control}
|
|
||||||
render={({ field }) => {
|
|
||||||
return (
|
|
||||||
<Select
|
|
||||||
labelProps={{
|
|
||||||
className:
|
|
||||||
'before:content-none after:content-none'
|
|
||||||
}}
|
|
||||||
{...field}
|
|
||||||
>
|
|
||||||
<Option key="first" value="First">
|
|
||||||
First
|
|
||||||
</Option>
|
|
||||||
<Option key="second" value="Second">
|
|
||||||
Second
|
|
||||||
</Option>
|
|
||||||
<Option key="third" value="Third">
|
|
||||||
Third
|
|
||||||
</Option>
|
|
||||||
<Option key="basicMed" value="Basic Med">
|
|
||||||
Basic Med
|
|
||||||
</Option>
|
|
||||||
</Select>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="col-span-1">
|
|
||||||
<Typography variant="h6">Expiration Date</Typography>
|
|
||||||
</div>
|
|
||||||
<div className="col-span-3">
|
|
||||||
<Controller
|
|
||||||
name="medicalExpiration"
|
|
||||||
control={methods.control}
|
|
||||||
render={({ field }) => {
|
|
||||||
return (
|
|
||||||
<DatePicker
|
|
||||||
handleDateChanged={(date: string) => {
|
|
||||||
methods.setValue('medicalExpiration', date);
|
|
||||||
}}
|
|
||||||
inputProps={{
|
|
||||||
value: field.value
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{pilotId && (
|
|
||||||
<>
|
|
||||||
<div className="col-span-4">
|
|
||||||
<Typography variant="h5">Certificates</Typography>
|
|
||||||
<hr className="my-3" />
|
|
||||||
</div>
|
|
||||||
<PilotFormCertificates certificates={[]} />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{pilotId && (
|
|
||||||
<>
|
|
||||||
<div className="col-span-4">
|
|
||||||
<Typography variant="h5">Endorsements</Typography>
|
|
||||||
<hr className="my-3" />
|
|
||||||
</div>
|
|
||||||
<PilotFormEndorsements endorsements={[]} />
|
|
||||||
</>
|
|
||||||
)} */}
|
|
||||||
</form>
|
</form>
|
||||||
</FormProvider>
|
</FormProvider>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
import { Certificate } from './certificate.type';
|
|
||||||
|
|
||||||
export interface IPilotFormCertificates {
|
|
||||||
certificates: Certificate[];
|
|
||||||
}
|
|
||||||
@@ -1,134 +1,164 @@
|
|||||||
// import { IPilotFormCertificates } from './IPilotFormCertificates';
|
import { PilotFormCertificatesProps } from './PilotFormCertificatesProps.interface';
|
||||||
// import {
|
import {
|
||||||
// Button,
|
Button,
|
||||||
// DatePicker,
|
DatePicker,
|
||||||
// Input,
|
Grid,
|
||||||
// Option,
|
Icon,
|
||||||
// PlusIcon,
|
IconButton,
|
||||||
// Select,
|
IconName,
|
||||||
// TrashIcon,
|
Select,
|
||||||
// Typography
|
TextField,
|
||||||
// } from '@noahspan/noahspan-components';
|
Typography,
|
||||||
// import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
|
} from '@noahspan/noahspan-components';
|
||||||
|
import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
|
||||||
|
import { FormMode } from '../../enums/formMode';
|
||||||
|
|
||||||
// const PilotFormCertificates: React.FC<IPilotFormCertificates> = ({
|
const PilotFormCertificates = ({
|
||||||
// certificates
|
isDisabled,
|
||||||
// }: IPilotFormCertificates) => {
|
mode
|
||||||
// const {
|
}: PilotFormCertificatesProps ) => {
|
||||||
// control,
|
const {
|
||||||
// formState: { errors },
|
control,
|
||||||
// setValue
|
formState: { errors },
|
||||||
// } = useFormContext();
|
} = useFormContext();
|
||||||
|
|
||||||
// const { fields, append, remove } = useFieldArray({
|
const { fields, append, remove } = useFieldArray({
|
||||||
// name: 'certificates',
|
name: 'certificates',
|
||||||
// control
|
control
|
||||||
// });
|
});
|
||||||
|
|
||||||
// return (
|
return (
|
||||||
// <>
|
<Grid
|
||||||
// {fields.length > 0 && (
|
container
|
||||||
// <>
|
spacing={2}
|
||||||
// <div className="col-span-1">
|
>
|
||||||
// <Typography variant="h6">Type</Typography>
|
{fields.length > 0 || mode !== FormMode.VIEW &&
|
||||||
// </div>
|
<Grid size={12}>
|
||||||
// <div className="col-span-1">
|
<Typography variant="h5">Certificates</Typography>
|
||||||
// <Typography variant="h6">Number</Typography>
|
</Grid>
|
||||||
// </div>
|
}
|
||||||
// <div className="col-span-1">
|
{fields.length > 0 && (
|
||||||
// <Typography variant="h6">Date of Issue</Typography>
|
<>
|
||||||
// </div>
|
<Grid size={4}>
|
||||||
// <div className="col-span-1"></div>
|
<Typography variant="h6">Type</Typography>
|
||||||
// </>
|
</Grid>
|
||||||
// )}
|
<Grid size={4}>
|
||||||
// {fields.map((field, index) => {
|
<Typography variant="h6">Number</Typography>
|
||||||
// return (
|
</Grid>
|
||||||
// <>
|
<Grid size={3}>
|
||||||
// <div className="col-span-1">
|
<Typography variant="h6">Date of Issue</Typography>
|
||||||
// <Controller
|
</Grid>
|
||||||
// name={`certificates.${index}.type`}
|
<Grid size={1}>
|
||||||
// control={control}
|
</Grid>
|
||||||
// render={({ field }) => {
|
{fields.map((field, index) => {
|
||||||
// return (
|
return (
|
||||||
// <Select label="Type" {...field}>
|
<>
|
||||||
// <Option key="student" value="Student">
|
<Grid size={4}>
|
||||||
// Student
|
<Controller
|
||||||
// </Option>
|
name={`certificates.${index}.type`}
|
||||||
// <Option key="private" value="Private">
|
control={control}
|
||||||
// Private
|
render={({ field: { onChange, value } }) => {
|
||||||
// </Option>
|
return (
|
||||||
// <Option key="instrument" value="Instrument">
|
<Select
|
||||||
// Instrument
|
disabled={isDisabled}
|
||||||
// </Option>
|
fullWidth
|
||||||
// <Option key="recreational" value="Recreational">
|
onChange={onChange}
|
||||||
// Recreational
|
options={
|
||||||
// </Option>
|
[
|
||||||
// <Option key="sport" value="Sport">
|
{
|
||||||
// Sport
|
label: 'Student',
|
||||||
// </Option>
|
value: 'student'
|
||||||
// </Select>
|
},
|
||||||
// );
|
{
|
||||||
// }}
|
label: 'Private',
|
||||||
// />
|
value: 'private'
|
||||||
// </div>
|
},
|
||||||
// <div className="col-span-1">
|
{
|
||||||
// <Controller
|
label: 'Instrument',
|
||||||
// name={`certificates.${index}.number`}
|
value: 'instrument'
|
||||||
// control={control}
|
},
|
||||||
// render={({ field }) => {
|
{
|
||||||
// return <Input label="Number" {...field} />;
|
label: 'Recreational',
|
||||||
// }}
|
value: 'recreational'
|
||||||
// />
|
},
|
||||||
// </div>
|
{
|
||||||
// <div className="col-span-1">
|
label: 'Sport',
|
||||||
// <Controller
|
value: 'sport'
|
||||||
// name={`certificates.${index}.dateOfIssue`}
|
}
|
||||||
// control={control}
|
]
|
||||||
// render={({ field }) => {
|
}
|
||||||
// return (
|
value={value}
|
||||||
// <DatePicker
|
/>
|
||||||
// handleDateChanged={(date: string) => {
|
);
|
||||||
// setValue(`certificates.${index}.dateOfIssue`, date);
|
}}
|
||||||
// }}
|
/>
|
||||||
// inputProps={{
|
</Grid>
|
||||||
// value: field.value
|
<Grid size={4}>
|
||||||
// }}
|
<Controller
|
||||||
// />
|
name={`certificates.${index}.number`}
|
||||||
// );
|
control={control}
|
||||||
// }}
|
render={({ field: { onChange, value } }) => {
|
||||||
// />
|
return (
|
||||||
// </div>
|
<TextField
|
||||||
// <div className="col-span-1">
|
disabled={isDisabled}
|
||||||
// <Button
|
fullWidth
|
||||||
// className="flex items-center gap-3"
|
onChange={onChange}
|
||||||
// onClick={() => remove(index)}
|
value={value}
|
||||||
// variant="outlined"
|
/>
|
||||||
// >
|
)
|
||||||
// <TrashIcon size="lg" />
|
}}
|
||||||
// Delete
|
/>
|
||||||
// </Button>
|
</Grid>
|
||||||
// </div>
|
<Grid size={3}>
|
||||||
// </>
|
<Controller
|
||||||
// );
|
name={`certificates.${index}.dateOfIssue`}
|
||||||
// })}
|
control={control}
|
||||||
// <div className="col-span-4">
|
render={({ field: { onChange, value } }) => {
|
||||||
// <Button
|
return (
|
||||||
// className="flex items-center gap-3"
|
<DatePicker
|
||||||
// onClick={() => {
|
disabled={isDisabled}
|
||||||
// append({
|
onChange={onChange}
|
||||||
// type: '',
|
value={value}
|
||||||
// number: '',
|
/>
|
||||||
// dateOfIssue: null
|
);
|
||||||
// });
|
}}
|
||||||
// }}
|
/>
|
||||||
// variant="outlined"
|
</Grid>
|
||||||
// >
|
<Grid size={1}>
|
||||||
// <PlusIcon size="lg" />
|
<IconButton
|
||||||
// Add Certificate
|
disabled={isDisabled}
|
||||||
// </Button>
|
onClick={() => remove(index)}
|
||||||
// </div>
|
sx={{
|
||||||
// </>
|
marginTop: '-5px'
|
||||||
// );
|
}}
|
||||||
// };
|
>
|
||||||
|
<Icon iconName={IconName.TRASH} size='sm' />
|
||||||
|
</IconButton>
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{!isDisabled &&
|
||||||
|
<Grid display="flex" justifyContent="right" size={12}>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
append({
|
||||||
|
type: '',
|
||||||
|
number: '',
|
||||||
|
dateOfIssue: null
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
startIcon={<Icon iconName={IconName.PLUS} />}
|
||||||
|
variant="contained"
|
||||||
|
>
|
||||||
|
Add Certificate
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
}
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// export default PilotFormCertificates;
|
export default PilotFormCertificates;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { FormMode } from "../../enums/formMode";
|
||||||
|
|
||||||
|
export interface PilotFormCertificatesProps {
|
||||||
|
isDisabled: boolean;
|
||||||
|
mode: FormMode;
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
export type Certificate = {
|
|
||||||
type: string;
|
|
||||||
number: string;
|
|
||||||
dateOfIssue: Date;
|
|
||||||
};
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import { Endorsement } from './endorsement.type';
|
|
||||||
|
|
||||||
export interface IPilotFormEndorsements {
|
|
||||||
endorsements: Endorsement[];
|
|
||||||
}
|
|
||||||
@@ -1,120 +1,139 @@
|
|||||||
// import { IPilotFormEndorsements } from './IPilotFormEndorsements';
|
import { PilotFormEndorsementsProps } from './PilotFormEndorsementsProps.interface';
|
||||||
// import {
|
import {
|
||||||
// Button,
|
Button,
|
||||||
// DatePicker,
|
DatePicker,
|
||||||
// Input,
|
Grid,
|
||||||
// Option,
|
Icon,
|
||||||
// PlusIcon,
|
IconButton,
|
||||||
// Select,
|
IconName,
|
||||||
// TrashIcon,
|
Select,
|
||||||
// Typography
|
Typography
|
||||||
// } from '@noahspan/noahspan-components';
|
} from '@noahspan/noahspan-components';
|
||||||
// import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
|
import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
|
||||||
|
import { FormMode } from '../../enums/formMode';
|
||||||
|
|
||||||
// const PilotFormEndorsements: React.FC<IPilotFormEndorsements> = ({
|
const PilotFormEndorsements = ({
|
||||||
// endorsements
|
mode,
|
||||||
// }: IPilotFormEndorsements) => {
|
isDisabled
|
||||||
// const {
|
}: PilotFormEndorsementsProps) => {
|
||||||
// control,
|
const {
|
||||||
// formState: { errors },
|
control,
|
||||||
// setValue
|
formState: { errors },
|
||||||
// } = useFormContext();
|
setValue
|
||||||
|
} = useFormContext();
|
||||||
|
|
||||||
// const { fields, append, remove } = useFieldArray({
|
const { fields, append, remove } = useFieldArray({
|
||||||
// name: 'endorsements',
|
name: 'endorsements',
|
||||||
// control
|
control
|
||||||
// });
|
});
|
||||||
|
|
||||||
// return (
|
return (
|
||||||
// <>
|
<Grid
|
||||||
// {fields.length > 0 && (
|
container
|
||||||
// <>
|
spacing={2}
|
||||||
// <div className="col-span-1">
|
>
|
||||||
// <Typography variant="h6">Type</Typography>
|
{fields.length > 0 || mode !== FormMode.VIEW &&
|
||||||
// </div>
|
<Grid size={12}>
|
||||||
// <div className="col-span-1">
|
<Typography variant="h5">Endorsements</Typography>
|
||||||
// <Typography variant="h6">Date of Issue</Typography>
|
</Grid>
|
||||||
// </div>
|
}
|
||||||
// <div className="col-span-1"></div>
|
{fields.length > 0 && (
|
||||||
// <div className="col-span-1"></div>
|
<>
|
||||||
// </>
|
<Grid size={8}>
|
||||||
// )}
|
<Typography variant="h6">Type</Typography>
|
||||||
// {fields.map((field, index) => {
|
</Grid>
|
||||||
// return (
|
<Grid size={3}>
|
||||||
// <>
|
<Typography variant="h6">Date of Issue</Typography>
|
||||||
// <div className="col-span-1">
|
</Grid>
|
||||||
// <Controller
|
<Grid size={1}></Grid>
|
||||||
// name={`endorsements.${index}.type`}
|
{fields.map((field, index) => {
|
||||||
// control={control}
|
return (
|
||||||
// render={({ field }) => {
|
<>
|
||||||
// return (
|
<Grid size={8}>
|
||||||
// <Select label="Type" {...field}>
|
<Controller
|
||||||
// <Option key="complex" value="Complex">
|
name={`endorsements.${index}.type`}
|
||||||
// Complex
|
control={control}
|
||||||
// </Option>
|
render={({ field: { onChange, value } }) => {
|
||||||
// <Option key="highPerformance" value="High Performance">
|
return (
|
||||||
// High Performance
|
<Select
|
||||||
// </Option>
|
disabled={isDisabled}
|
||||||
// <Option key="highAltitude" value="High Altitude">
|
fullWidth
|
||||||
// High Altitude
|
onChange={onChange}
|
||||||
// </Option>
|
options={
|
||||||
// <Option key="tailwheel" value="Tailwheel">
|
[
|
||||||
// Tailwheel
|
{
|
||||||
// </Option>
|
label: 'Complex',
|
||||||
// </Select>
|
value: 'complex'
|
||||||
// );
|
},
|
||||||
// }}
|
{
|
||||||
// />
|
label: 'High Performance',
|
||||||
// </div>
|
value: 'highPerfomance'
|
||||||
// <div className="col-span-1">
|
},
|
||||||
// <Controller
|
{
|
||||||
// name={`endorsements.${index}.dateOfIssue`}
|
label: 'High Altitude',
|
||||||
// control={control}
|
value: 'highAltitude'
|
||||||
// render={({ field }) => {
|
},
|
||||||
// return (
|
{
|
||||||
// <DatePicker
|
label: 'Tailwheel',
|
||||||
// handleDateChanged={(date: string) => {
|
value: 'tailwheel'
|
||||||
// setValue(`endorsements.${index}.dateOfIssue`, date);
|
}
|
||||||
// }}
|
]
|
||||||
// inputProps={{
|
}
|
||||||
// value: field.value
|
value={value ? value : ''}
|
||||||
// }}
|
/>
|
||||||
// />
|
);
|
||||||
// );
|
}}
|
||||||
// }}
|
/>
|
||||||
// />
|
</Grid>
|
||||||
// </div>
|
<Grid size={3}>
|
||||||
// <div className="col-span-1">
|
<Controller
|
||||||
// <Button
|
name={`endorsements.${index}.dateOfIssue`}
|
||||||
// className="flex items-center gap-3"
|
control={control}
|
||||||
// onClick={() => remove(index)}
|
render={({ field: { onChange, value } }) => {
|
||||||
// variant="outlined"
|
return (
|
||||||
// >
|
<DatePicker
|
||||||
// <TrashIcon size="lg" />
|
disabled={isDisabled}
|
||||||
// Delete
|
onChange={onChange}
|
||||||
// </Button>
|
value={value}
|
||||||
// </div>
|
/>
|
||||||
// </>
|
);
|
||||||
// );
|
}}
|
||||||
// })}
|
/>
|
||||||
// <div className="col-span-4">
|
</Grid>
|
||||||
// <Button
|
<Grid size={1}>
|
||||||
// className="flex items-center gap-3"
|
<IconButton
|
||||||
// onClick={() => {
|
disabled={isDisabled}
|
||||||
// append({
|
onClick={() => remove(index)}
|
||||||
// type: '',
|
sx={{
|
||||||
// number: '',
|
marginTop: '-5px'
|
||||||
// dateOfIssue: null
|
}}
|
||||||
// });
|
>
|
||||||
// }}
|
<Icon iconName={IconName.TRASH} size="sm" />
|
||||||
// variant="outlined"
|
</IconButton>
|
||||||
// >
|
</Grid>
|
||||||
// <PlusIcon size="lg" />
|
</>
|
||||||
// Add Endorsement
|
);
|
||||||
// </Button>
|
})}
|
||||||
// </div>
|
</>
|
||||||
// </>
|
)}
|
||||||
// );
|
{!isDisabled &&
|
||||||
// };
|
<Grid display="flex" justifyContent="right" size={12}>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
append({
|
||||||
|
type: '',
|
||||||
|
dateOfIssue: null
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
startIcon={<Icon iconName={IconName.PLUS} />}
|
||||||
|
variant="contained"
|
||||||
|
>
|
||||||
|
Add Endorsement
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
}
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// export default PilotFormEndorsements;
|
export default PilotFormEndorsements;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { FormMode } from "../../enums/formMode";
|
||||||
|
|
||||||
|
export interface PilotFormEndorsementsProps {
|
||||||
|
isDisabled: boolean;
|
||||||
|
mode: FormMode;
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
export type Endorsement = {
|
|
||||||
type: string;
|
|
||||||
number: string;
|
|
||||||
dateOfIssue: Date;
|
|
||||||
};
|
|
||||||
79
app/src/components/pilotFormMedical/PilotFormMedical.tsx
Normal file
79
app/src/components/pilotFormMedical/PilotFormMedical.tsx
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import { DatePicker, Grid, Select, theme, Typography, useMediaQuery } from '@noahspan/noahspan-components';
|
||||||
|
import { Controller, useFormContext } from "react-hook-form"
|
||||||
|
import { PilotFormMedicalProps } from "./PilotFormMedicalProps.interface";
|
||||||
|
|
||||||
|
const PilotFormMedical = ({ isDisabled }: PilotFormMedicalProps) => {
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
formState: { errors },
|
||||||
|
setValue
|
||||||
|
} = useFormContext();
|
||||||
|
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid container spacing={2}>
|
||||||
|
<Grid size={12}>
|
||||||
|
<Typography variant="h5">Medical</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid size={isMedium ? 3 : 12}>
|
||||||
|
<Typography variant="h6">Class</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid size={isMedium ? 9 : 12}>
|
||||||
|
<Controller
|
||||||
|
name="medicalClass"
|
||||||
|
control={control}
|
||||||
|
render={({ field: { onChange, value } }) => {
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
disabled={isDisabled}
|
||||||
|
fullWidth
|
||||||
|
onChange={onChange}
|
||||||
|
options={
|
||||||
|
[
|
||||||
|
{
|
||||||
|
label: 'First',
|
||||||
|
value: 'first'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Second',
|
||||||
|
value: 'second'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Third',
|
||||||
|
value: 'third'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Basic Med',
|
||||||
|
value: 'basicMed'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
value={value ? value : ''}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid size={isMedium ? 3 : 12}>
|
||||||
|
<Typography variant="h6">Expiration</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid size={isMedium ? 9 : 12}>
|
||||||
|
<Controller
|
||||||
|
name="medicalExpiration"
|
||||||
|
control={control}
|
||||||
|
render={({ field: { onChange, value } }) => {
|
||||||
|
return (
|
||||||
|
<DatePicker
|
||||||
|
disabled={isDisabled}
|
||||||
|
onChange={onChange}
|
||||||
|
value={value}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PilotFormMedical
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export interface PilotFormMedicalProps {
|
||||||
|
isDisabled: boolean;
|
||||||
|
}
|
||||||
@@ -5,19 +5,13 @@ import {
|
|||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
ColumnDef,
|
ColumnDef,
|
||||||
EllipsisVerticalIcon,
|
|
||||||
EyeIcon,
|
|
||||||
Grid,
|
Grid,
|
||||||
IconButton,
|
Icon,
|
||||||
ListItemIcon,
|
IconName,
|
||||||
ListItemText,
|
|
||||||
Menu,
|
|
||||||
MenuItem,
|
|
||||||
PenIcon,
|
|
||||||
PlusIcon,
|
|
||||||
Table,
|
Table,
|
||||||
TrashIcon,
|
theme,
|
||||||
Typography
|
Typography,
|
||||||
|
useMediaQuery
|
||||||
} from '@noahspan/noahspan-components';
|
} from '@noahspan/noahspan-components';
|
||||||
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
||||||
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
||||||
@@ -28,23 +22,21 @@ import { Pilot } from './Pilot.interface';
|
|||||||
import { initialState, reducer } from './reducer';
|
import { initialState, reducer } from './reducer';
|
||||||
import ActionMenu from '../actionMenu/ActionMenu';
|
import ActionMenu from '../actionMenu/ActionMenu';
|
||||||
import ConfirmationDialog from '../confirmationDialog/ConfirmationDialog';
|
import ConfirmationDialog from '../confirmationDialog/ConfirmationDialog';
|
||||||
|
import PilotCard from '../pilotCard/PilotCard';
|
||||||
|
|
||||||
const Pilots: React.FC<unknown> = () => {
|
const Pilots: React.FC<unknown> = () => {
|
||||||
const [state, dispatch] = useReducer(reducer, initialState);
|
const [state, dispatch] = useReducer(reducer, initialState);
|
||||||
const httpClient: AxiosInstance = useHttpClient();
|
const httpClient: AxiosInstance = useHttpClient();
|
||||||
const isAuthenticated = useIsAuthenticated();
|
const isAuthenticated = useIsAuthenticated();
|
||||||
const { getAccessToken } = useAccessToken();
|
const { getAccessToken } = useAccessToken();
|
||||||
|
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
|
||||||
|
|
||||||
const getPilots = async () => {
|
const getPilots = async () => {
|
||||||
try {
|
try {
|
||||||
const config = isAuthenticated
|
|
||||||
? { headers: { Authorization: await getAccessToken() } }
|
|
||||||
: {};
|
|
||||||
const response: AxiosResponse = await httpClient.get(
|
const response: AxiosResponse = await httpClient.get(
|
||||||
`api/pilots`,
|
`api/pilots`
|
||||||
config
|
|
||||||
);
|
);
|
||||||
console.log(response.data)
|
|
||||||
if (response.data.length > 0) {
|
if (response.data.length > 0) {
|
||||||
dispatch({ type: 'SET_PILOTS', payload: response.data });
|
dispatch({ type: 'SET_PILOTS', payload: response.data });
|
||||||
|
|
||||||
@@ -144,7 +136,7 @@ const Pilots: React.FC<unknown> = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Actions',
|
header: 'Actions',
|
||||||
cell: (info) => (
|
cell: (info: any) => (
|
||||||
<ActionMenu
|
<ActionMenu
|
||||||
id={info.row.original.rowKey}
|
id={info.row.original.rowKey}
|
||||||
onDelete={onDeleteEntry}
|
onDelete={onDeleteEntry}
|
||||||
@@ -155,22 +147,22 @@ const Pilots: React.FC<unknown> = () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isAuthenticated && !state.isFormOpen) {
|
if (!state.isFormOpen) {
|
||||||
getPilots();
|
getPilots();
|
||||||
}
|
}
|
||||||
}, [isAuthenticated, state.isFormOpen]);
|
}, [state.isFormOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ margin: '20px' }}>
|
<Box sx={{ margin: '20px' }}>
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<Grid size={11}>
|
<Grid size={isMedium ? 11 : 6}>
|
||||||
<Typography variant="h4">Pilots</Typography>
|
<Typography variant="h4">Pilots</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid display="flex" justifyContent="right" size={1}>
|
<Grid display="flex" justifyContent="right" size={isMedium ? 1 : 6}>
|
||||||
{isAuthenticated &&
|
{isAuthenticated &&
|
||||||
<Button
|
<Button
|
||||||
onClick={() => onOpenClosePilotForm(FormMode.ADD)}
|
onClick={() => onOpenClosePilotForm(FormMode.ADD)}
|
||||||
startIcon={<PlusIcon />}
|
startIcon={<Icon iconName={IconName.PLUS} />}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
data-testid="pilot-add-button"
|
data-testid="pilot-add-button"
|
||||||
>
|
>
|
||||||
@@ -192,7 +184,12 @@ const Pilots: React.FC<unknown> = () => {
|
|||||||
</Grid>
|
</Grid>
|
||||||
)}
|
)}
|
||||||
<Grid size={12}>
|
<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>
|
||||||
</Grid>
|
</Grid>
|
||||||
{state.isFormOpen && (
|
{state.isFormOpen && (
|
||||||
|
|||||||
@@ -1,30 +1,25 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { ISiteNavProps } from './ISiteNavProps';
|
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useAppContext } from '../../hooks/appContext/UseAppContext';
|
import { useAppContext } from '../../hooks/appContext/UseAppContext';
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
Button,
|
Button,
|
||||||
|
Icon,
|
||||||
IconButton,
|
IconButton,
|
||||||
|
IconName,
|
||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
Navbar,
|
Navbar,
|
||||||
PlaneIcon,
|
|
||||||
SignOutIcon,
|
|
||||||
Spinner,
|
Spinner,
|
||||||
Typography
|
Typography
|
||||||
} from '@noahspan/noahspan-components';
|
} from '@noahspan/noahspan-components';
|
||||||
import { useIsAuthenticated, useMsal } from '@azure/msal-react';
|
import { useIsAuthenticated, useMsal } from '@azure/msal-react';
|
||||||
import { InteractionStatus } from '@azure/msal-browser';
|
|
||||||
import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
import { useAccessToken } from '../../hooks/accessToken/UseAcessToken';
|
||||||
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
import { useHttpClient } from '../../hooks/httpClient/UseHttpClient';
|
||||||
import { AxiosInstance, AxiosResponse } from 'axios';
|
import { AxiosInstance, AxiosResponse } from 'axios';
|
||||||
import { User } from '@microsoft/microsoft-graph-types';
|
import { User } from '@microsoft/microsoft-graph-types';
|
||||||
import { EventMessage, EventPayload, EventType } from '@azure/msal-browser';
|
|
||||||
|
|
||||||
type EventPayloadExtended = EventPayload & { accessToken: string };
|
const SiteNav = () => {
|
||||||
|
|
||||||
const SiteNav: React.FC<unknown> = () => {
|
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
const [userPhoto, setUserPhoto] = useState<string>();
|
const [userPhoto, setUserPhoto] = useState<string>();
|
||||||
const [pages, setPages] = useState<{ name: string; url: string; }[]>([]);
|
const [pages, setPages] = useState<{ name: string; url: string; }[]>([]);
|
||||||
@@ -39,15 +34,12 @@ const SiteNav: React.FC<unknown> = () => {
|
|||||||
{
|
{
|
||||||
name: 'Logbook',
|
name: 'Logbook',
|
||||||
url: '/'
|
url: '/'
|
||||||
}
|
},
|
||||||
];
|
{
|
||||||
|
|
||||||
if (isAuthenticated) {
|
|
||||||
pages.push({
|
|
||||||
name: 'Pilots',
|
name: 'Pilots',
|
||||||
url: '/pilots'
|
url: '/pilots'
|
||||||
})
|
}
|
||||||
}
|
];
|
||||||
|
|
||||||
setPages(pages)
|
setPages(pages)
|
||||||
};
|
};
|
||||||
@@ -98,7 +90,7 @@ const SiteNav: React.FC<unknown> = () => {
|
|||||||
const Settings = () => {
|
const Settings = () => {
|
||||||
return (
|
return (
|
||||||
<MenuItem onClick={handleSignOut}>
|
<MenuItem onClick={handleSignOut}>
|
||||||
<SignOutIcon />
|
<Icon iconName={IconName.SIGN_OUT} />
|
||||||
<Typography sx={{ marginLeft: '10px', textAlign: 'center' }}>
|
<Typography sx={{ marginLeft: '10px', textAlign: 'center' }}>
|
||||||
Sign Out
|
Sign Out
|
||||||
</Typography>
|
</Typography>
|
||||||
@@ -146,7 +138,7 @@ const SiteNav: React.FC<unknown> = () => {
|
|||||||
handlePageClick={handlePageClick}
|
handlePageClick={handlePageClick}
|
||||||
handleSignIn={handleSignIn}
|
handleSignIn={handleSignIn}
|
||||||
isAuthenticated={isAuthenticated}
|
isAuthenticated={isAuthenticated}
|
||||||
logo={<PlaneIcon size="2x" />}
|
logo={<Icon iconName={IconName.PLANE} size="2x" />}
|
||||||
pages={pages}
|
pages={pages}
|
||||||
settings={<Settings />}
|
settings={<Settings />}
|
||||||
userPhoto={userPhoto}
|
userPhoto={userPhoto}
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
@tailwind base;
|
body {
|
||||||
@tailwind components;
|
background-color: #f2f2f2;
|
||||||
@tailwind utilities;
|
|
||||||
|
|
||||||
@layer base {
|
|
||||||
body {
|
|
||||||
@apply bg-[#fafaf9];
|
|
||||||
@apply text-black;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Vite + React + TS</title>
|
<title>Flying</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
@@ -3,11 +3,10 @@ import ReactDOM from 'react-dom/client';
|
|||||||
import App from './App.tsx';
|
import App from './App.tsx';
|
||||||
import AppContextProvider from './context/appContext/AppContextProvider.tsx';
|
import AppContextProvider from './context/appContext/AppContextProvider.tsx';
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import './index.css';
|
|
||||||
import '@noahspan/noahspan-components/noahspan-components.css';
|
|
||||||
import { AuthenticationResult, EventMessage, EventType, PublicClientApplication } from '@azure/msal-browser';
|
import { AuthenticationResult, EventMessage, EventType, PublicClientApplication } from '@azure/msal-browser';
|
||||||
import { MsalProvider } from '@azure/msal-react';
|
import { MsalProvider } from '@azure/msal-react';
|
||||||
import { msalConfig } from './auth/msalConfig';
|
import { msalConfig } from './auth/msalConfig';
|
||||||
|
import './index.css';
|
||||||
|
|
||||||
const msalInstance: PublicClientApplication = new PublicClientApplication(msalConfig);
|
const msalInstance: PublicClientApplication = new PublicClientApplication(msalConfig);
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ version: '3.8'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
azurite:
|
azurite:
|
||||||
container_name: azurite
|
container_name: azurite-flying
|
||||||
image: mcr.microsoft.com/azure-storage/azurite
|
image: mcr.microsoft.com/azure-storage/azurite
|
||||||
ports:
|
ports:
|
||||||
- '10000:10000'
|
- '10000:10000'
|
||||||
- '10001:10001'
|
- '10001:10001'
|
||||||
- '10002:10002'
|
- '10002:10002'
|
||||||
command: 'azurite --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0 --loose'
|
command: 'azurite --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0 --loose --skipApiVersionCheck'
|
||||||
|
volumes:
|
||||||
|
- ./azurite-flying:/data
|
||||||
|
|
||||||
api:
|
api:
|
||||||
container_name: flying-api
|
container_name: flying-api
|
||||||
@@ -18,7 +20,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- '3000:3000'
|
- '3000:3000'
|
||||||
env_file:
|
env_file:
|
||||||
- ./api/.env
|
- ./api/.env.compose
|
||||||
|
|
||||||
app:
|
app:
|
||||||
container_name: flying-app
|
container_name: flying-app
|
||||||
@@ -27,7 +29,6 @@ services:
|
|||||||
target: app
|
target: app
|
||||||
ports:
|
ports:
|
||||||
- '8080:8080'
|
- '8080:8080'
|
||||||
# env_file:
|
|
||||||
# - ./app/.env
|
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
azurite-flying:
|
||||||
@@ -59,6 +59,11 @@ locals {
|
|||||||
prod = "noahspanflyingprod"
|
prod = "noahspanflyingprod"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage_containers = {
|
||||||
|
test = ["tracks"]
|
||||||
|
prod = ["tracks"]
|
||||||
|
}
|
||||||
|
|
||||||
storage_tables = {
|
storage_tables = {
|
||||||
test = ["logs", "pilots"]
|
test = ["logs", "pilots"]
|
||||||
prod = ["logs", "pilots"]
|
prod = ["logs", "pilots"]
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ output "storage_account_name" {
|
|||||||
value = local.storage_account_name[var.environment]
|
value = local.storage_account_name[var.environment]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "storage_containers" {
|
||||||
|
value = local.storage_containers[var.environment]
|
||||||
|
}
|
||||||
|
|
||||||
output "storage_tables" {
|
output "storage_tables" {
|
||||||
value = local.storage_tables[var.environment]
|
value = local.storage_tables[var.environment]
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
|
module "storage" {
|
||||||
|
source = "github.com/noahspannbauer/noahspan-terraform/modules/storage"
|
||||||
|
resource_group_name = var.RESOURCE_GROUP_NAME
|
||||||
|
storage_account_name = module.environment.storage_account_name
|
||||||
|
storage_containers = module.environment.storage_containers
|
||||||
|
storage_tables = module.environment.storage_tables
|
||||||
|
}
|
||||||
|
|
||||||
module "container_app" {
|
module "container_app" {
|
||||||
source = "github.com/noahspannbauer/noahspan-terraform/modules/container_app"
|
source = "github.com/noahspannbauer/noahspan-terraform/modules/container_app"
|
||||||
app_subdomain_name = var.APP_SUBDOMAIN_NAME
|
app_subdomain_name = var.APP_SUBDOMAIN_NAME
|
||||||
@@ -17,7 +25,6 @@ module "container_app" {
|
|||||||
domain_name = var.DOMAIN_NAME
|
domain_name = var.DOMAIN_NAME
|
||||||
log_analytics_workspace_name = module.environment.log_analytics_workspace_name
|
log_analytics_workspace_name = module.environment.log_analytics_workspace_name
|
||||||
resource_group_name = var.RESOURCE_GROUP_NAME
|
resource_group_name = var.RESOURCE_GROUP_NAME
|
||||||
storage_account_name = module.environment.storage_account_name
|
storage_account_primary_connection_string = module.storage.storage_account_primary_connection_string
|
||||||
storage_tables = module.environment.storage_tables
|
|
||||||
tenant_id = var.TENANT_ID
|
tenant_id = var.TENANT_ID
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@noahspan/flying",
|
"name": "@noahspan/flying",
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "concurrently 'npm run start:azure -w api' 'wait-on tcp:0.0.0.0:7071 && npm run dev -w app'",
|
"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\"",
|
"format": "prettier --write \"**/src/**/*.ts\" \"**/test/**/*.ts\"",
|
||||||
|
|||||||
1955
pnpm-lock.yaml
generated
1955
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user