From da5a76f25230611104ba5efc298c334df64353c3 Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Sun, 2 Mar 2025 11:42:03 -0600 Subject: [PATCH] adding endorsements to pilot form --- .../pilot/certificate/certificate.service.ts | 37 --- .../pilot/endorsement/endorsement.entity.ts | 2 - .../pilot/endorsement/endosement.service.ts | 37 --- api/src/pilot/medical/medical.entity.ts | 6 - api/src/pilot/medical/medical.service.ts | 33 --- api/src/pilot/pilot.controller.ts | 6 +- api/src/pilot/pilot.dto.ts | 2 + api/src/pilot/pilot.entity.ts | 1 + app/src/components/pilotForm/PilotForm.tsx | 52 +--- .../Certificate.interface.ts | 5 - .../PilotFormCertificates.tsx | 33 +-- .../PilotFormCertificatesProps.interface.ts | 3 - .../IPilotFormEndorsements.ts | 5 - .../PilotFormEndorsements.tsx | 247 ++++++++++-------- .../PilotFormEndorsementsProps.interface.ts | 3 + .../pilotFormEndorsements/endorsement.type.ts | 5 - .../pilotFormMedical/PilotFormMedical.tsx | 1 + app/src/components/pilots/Pilots.tsx | 2 +- 18 files changed, 170 insertions(+), 310 deletions(-) delete mode 100644 api/src/pilot/certificate/certificate.service.ts delete mode 100644 api/src/pilot/endorsement/endosement.service.ts delete mode 100644 api/src/pilot/medical/medical.entity.ts delete mode 100644 api/src/pilot/medical/medical.service.ts delete mode 100644 app/src/components/pilotFormCertificates/Certificate.interface.ts delete mode 100644 app/src/components/pilotFormEndorsements/IPilotFormEndorsements.ts create mode 100644 app/src/components/pilotFormEndorsements/PilotFormEndorsementsProps.interface.ts delete mode 100644 app/src/components/pilotFormEndorsements/endorsement.type.ts diff --git a/api/src/pilot/certificate/certificate.service.ts b/api/src/pilot/certificate/certificate.service.ts deleted file mode 100644 index 2d7c83f..0000000 --- a/api/src/pilot/certificate/certificate.service.ts +++ /dev/null @@ -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 - ) {} - - async find(rowKey: string): Promise { - return await this.certificateRepository.find(this.partitionKey, rowKey); - } - - async findAll(): Promise { - return await this.certificateRepository.findAll(); - } - - async create(certificate: Certificate): Promise { - return await this.certificateRepository.create(certificate); - } - - async update(rowKey: string, certificate: Certificate): Promise { - return await this.certificateRepository.update( - this.partitionKey, - rowKey, - certificate - ); - } - - async delete(rowKey: string): Promise { - await this.certificateRepository.delete(this.partitionKey, rowKey); - } -} diff --git a/api/src/pilot/endorsement/endorsement.entity.ts b/api/src/pilot/endorsement/endorsement.entity.ts index 8d37866..f3349e4 100644 --- a/api/src/pilot/endorsement/endorsement.entity.ts +++ b/api/src/pilot/endorsement/endorsement.entity.ts @@ -1,6 +1,4 @@ export class Endorsement { - partitionkey: string; - rowKey: string; type: string; issueDate: Date; } diff --git a/api/src/pilot/endorsement/endosement.service.ts b/api/src/pilot/endorsement/endosement.service.ts deleted file mode 100644 index 2e978c5..0000000 --- a/api/src/pilot/endorsement/endosement.service.ts +++ /dev/null @@ -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 - ) {} - - async find(rowKey: string): Promise { - return await this.endorsementRepository.find(this.partitionKey, rowKey); - } - - async findAll(): Promise { - return await this.endorsementRepository.findAll(); - } - - async create(endorsement: Endorsement): Promise { - return await this.endorsementRepository.create(endorsement); - } - - async update(rowKey: string, endorsement: Endorsement): Promise { - return await this.endorsementRepository.update( - this.partitionKey, - rowKey, - endorsement - ); - } - - async delete(rowKey: string): Promise { - await this.endorsementRepository.delete(this.partitionKey, rowKey); - } -} diff --git a/api/src/pilot/medical/medical.entity.ts b/api/src/pilot/medical/medical.entity.ts deleted file mode 100644 index bff88d9..0000000 --- a/api/src/pilot/medical/medical.entity.ts +++ /dev/null @@ -1,6 +0,0 @@ -export class Medical { - partitionKey: string; - rowKey: string; - certificateClass: string; - certificateExpiration: Date; -} diff --git a/api/src/pilot/medical/medical.service.ts b/api/src/pilot/medical/medical.service.ts deleted file mode 100644 index 61de861..0000000 --- a/api/src/pilot/medical/medical.service.ts +++ /dev/null @@ -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 -// ) {} - -// async find(rowKey: string): Promise { -// return this.profileRepository.find(this.partitionKey, rowKey); -// } - -// async findAll(): Promise { -// return this.profileRepository.findAll(); -// } - -// async create(profile: Medical): Promise { -// return this.profileRepository.create(profile); -// } - -// async update(rowKey: string, profile: Medical): Promise { -// return this.profileRepository.update(this.partitionKey, rowKey, profile); -// } - -// async delete(rowKey: string) { -// return this.profileRepository.delete(this.partitionKey, rowKey); -// } -// } diff --git a/api/src/pilot/pilot.controller.ts b/api/src/pilot/pilot.controller.ts index a29116d..0abf4e5 100644 --- a/api/src/pilot/pilot.controller.ts +++ b/api/src/pilot/pilot.controller.ts @@ -66,7 +66,8 @@ export class PilotController { phone: pilotDto.phone, medicalClass: pilotDto.medicalClass, medicalExpiration: pilotDto.medicalExpiration, - certificates: JSON.stringify(pilotDto.certificates) + certificates: JSON.stringify(pilotDto.certificates), + endorsements: JSON.stringify(pilotDto.endorsements) } return await this.pilotService.create(pilot); @@ -99,7 +100,8 @@ export class PilotController { phone: pilotDto.phone, medicalClass: pilotDto.medicalClass, medicalExpiration: pilotDto.medicalExpiration, - certificates: JSON.stringify(pilotDto.certificates) + certificates: JSON.stringify(pilotDto.certificates), + endorsements: JSON.stringify(pilotDto.endorsements) } return await this.pilotService.update(partitionKey, rowKey, pilot); diff --git a/api/src/pilot/pilot.dto.ts b/api/src/pilot/pilot.dto.ts index 5183b72..7eddeeb 100644 --- a/api/src/pilot/pilot.dto.ts +++ b/api/src/pilot/pilot.dto.ts @@ -1,4 +1,5 @@ import { Certificate } from "./certificate/certificate.entity"; +import { Endorsement } from "./endorsement/endorsement.entity"; export class PilotDto { partitionKey: string; @@ -14,4 +15,5 @@ export class PilotDto { medicalClass?: string; medicalExpiration?: string; certificates: Certificate; + endorsements: Endorsement } diff --git a/api/src/pilot/pilot.entity.ts b/api/src/pilot/pilot.entity.ts index 74b25b3..6b8b7d8 100644 --- a/api/src/pilot/pilot.entity.ts +++ b/api/src/pilot/pilot.entity.ts @@ -14,4 +14,5 @@ export class Pilot { @EntityString() medicalClass?: string; @EntityString() medicalExpiration: string; @EntityString() certificates: string; + @EntityString() endorsements: string; } diff --git a/app/src/components/pilotForm/PilotForm.tsx b/app/src/components/pilotForm/PilotForm.tsx index 8fbfe41..fb19cef 100644 --- a/app/src/components/pilotForm/PilotForm.tsx +++ b/app/src/components/pilotForm/PilotForm.tsx @@ -23,6 +23,7 @@ import { useIsAuthenticated } from '@azure/msal-react'; import { FormMode } from '../../enums/formMode'; 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 = ({ @@ -55,7 +56,8 @@ const PilotForm: React.FC = ({ phone: '', medicalClass: '', medicalExpiration: '', - certificates: [] + certificates: [], + endorsements: [] }; const methods = useForm({ defaultValues: defaultValues @@ -135,7 +137,6 @@ const PilotForm: React.FC = ({ onOpenClose(FormMode.CANCEL); } catch (error) { const axiosError = error as AxiosError; - console.log(axiosError) const responseData = axiosError.response?.data as any; console.log(responseData.message); @@ -163,9 +164,10 @@ const PilotForm: React.FC = ({ config ); const pilot = response.data; - - pilot.certificates = JSON.parse(pilot.certificates); + pilot.certificates = JSON.parse(pilot.certificates); + pilot.endorsements = JSON.parse(pilot.endorsements) + console.log(pilot) setSelectedPerson({ userPrincipalName: pilot.id, displayName: pilot.name @@ -381,7 +383,10 @@ const PilotForm: React.FC = ({ /> - + + + + - + {!isDisabled && + + + + } ); }; diff --git a/app/src/components/pilotFormCertificates/PilotFormCertificatesProps.interface.ts b/app/src/components/pilotFormCertificates/PilotFormCertificatesProps.interface.ts index b0d88cb..99f91a5 100644 --- a/app/src/components/pilotFormCertificates/PilotFormCertificatesProps.interface.ts +++ b/app/src/components/pilotFormCertificates/PilotFormCertificatesProps.interface.ts @@ -1,6 +1,3 @@ -import { Certificate } from './Certificate.interface'; - export interface PilotFormCertificatesProps { - certificates: Certificate[]; isDisabled: boolean; } diff --git a/app/src/components/pilotFormEndorsements/IPilotFormEndorsements.ts b/app/src/components/pilotFormEndorsements/IPilotFormEndorsements.ts deleted file mode 100644 index 7644692..0000000 --- a/app/src/components/pilotFormEndorsements/IPilotFormEndorsements.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Endorsement } from './endorsement.type'; - -export interface IPilotFormEndorsements { - endorsements: Endorsement[]; -} diff --git a/app/src/components/pilotFormEndorsements/PilotFormEndorsements.tsx b/app/src/components/pilotFormEndorsements/PilotFormEndorsements.tsx index 84ba899..30f6c41 100644 --- a/app/src/components/pilotFormEndorsements/PilotFormEndorsements.tsx +++ b/app/src/components/pilotFormEndorsements/PilotFormEndorsements.tsx @@ -1,120 +1,135 @@ -// import { IPilotFormEndorsements } from './IPilotFormEndorsements'; -// import { -// Button, -// DatePicker, -// Input, -// Option, -// PlusIcon, -// Select, -// TrashIcon, -// Typography -// } from '@noahspan/noahspan-components'; -// import { Controller, useFieldArray, useFormContext } from 'react-hook-form'; +import { PilotFormEndorsementsProps } from './PilotFormEndorsementsProps.interface'; +import { + Button, + DatePicker, + Grid, + Icon, + IconButton, + IconName, + Select, + Typography +} from '@noahspan/noahspan-components'; +import { Controller, useFieldArray, useFormContext } from 'react-hook-form'; -// const PilotFormEndorsements: React.FC = ({ -// endorsements -// }: IPilotFormEndorsements) => { -// const { -// control, -// formState: { errors }, -// setValue -// } = useFormContext(); +const PilotFormEndorsements = ({ + isDisabled +}: PilotFormEndorsementsProps) => { + const { + control, + formState: { errors }, + setValue + } = useFormContext(); -// const { fields, append, remove } = useFieldArray({ -// name: 'endorsements', -// control -// }); + const { fields, append, remove } = useFieldArray({ + name: 'endorsements', + control + }); -// return ( -// <> -// {fields.length > 0 && ( -// <> -//
-// Type -//
-//
-// Date of Issue -//
-//
-//
-// -// )} -// {fields.map((field, index) => { -// return ( -// <> -//
-// { -// return ( -// -// ); -// }} -// /> -//
-//
-// { -// return ( -// { -// setValue(`endorsements.${index}.dateOfIssue`, date); -// }} -// inputProps={{ -// value: field.value -// }} -// /> -// ); -// }} -// /> -//
-//
-// -//
-// -// ); -// })} -//
-// -//
-// -// ); -// }; + return ( + + + Endorsements + + {fields.length > 0 && ( + <> + + Type + + + Date of Issue + + + {fields.map((field, index) => { + return ( + <> + + { + return ( +