diff --git a/app/src/components/pilots/Pilot.interface.ts b/app/src/components/pilots/Pilot.interface.ts new file mode 100644 index 0000000..965ed48 --- /dev/null +++ b/app/src/components/pilots/Pilot.interface.ts @@ -0,0 +1,6 @@ +export interface Pilot { + partitionKey: string; + rowKey: string; + id: string; + name: string; +}; \ No newline at end of file diff --git a/app/src/components/pilots/PilotsState.interface.ts b/app/src/components/pilots/PilotsState.interface.ts new file mode 100644 index 0000000..21b35bd --- /dev/null +++ b/app/src/components/pilots/PilotsState.interface.ts @@ -0,0 +1,13 @@ +import { FormMode } from "../../enums/formMode"; +import { Pilot } from "./Pilot.interface"; + +export interface PilotsState { + pilots: Pilot[]; + error: string | undefined; + isConfirmDialogLoading: boolean; + isConfirmDialogOpen: boolean; + isFormOpen: boolean; + isLoading: boolean; + formMode: FormMode; + selectedPilotId: string | undefined; +} \ No newline at end of file diff --git a/app/src/components/pilots/reducer.ts b/app/src/components/pilots/reducer.ts new file mode 100644 index 0000000..8d2ab2c --- /dev/null +++ b/app/src/components/pilots/reducer.ts @@ -0,0 +1,92 @@ +import { FormMode } from "../../enums/formMode"; +import { Pilot } from "./Pilot.interface"; +import { PilotsState } from './PilotsState.interface' + +type Action = + | { + type: 'SET_DELETE'; + payload: { + isConfirmDialogOpen: boolean; + selectedPilotId: string | undefined; + } + } + | { type: 'SET_PILOTS'; payload: Pilot[] } + | { type: 'SET_ERROR'; payload: string | undefined } + | { type: 'SET_FORM_MODE'; payload: FormMode } + | { type: 'SET_IS_CONFIRMATION_DIALOG_LOADING'; payload: boolean } + | { type: 'SET_IS_LOADING'; payload: boolean } + | { + type: 'SET_OPEN_CLOSE_ENTRY_FORM'; + payload: { + formMode: FormMode; + selectedPilotId: string | undefined; + isFormOpen: boolean; + } + } + +export const initialState: PilotsState = { + pilots: [], + error: undefined, + formMode: FormMode.CANCEL, + isConfirmDialogLoading: false, + isConfirmDialogOpen: false, + isFormOpen: false, + isLoading: false, + selectedPilotId: undefined +} + +export const reducer = ( + state: PilotsState, + action: Action +): PilotsState => { + switch (action.type) { + case 'SET_DELETE': { + return { + ...state, + isConfirmDialogOpen: action.payload.isConfirmDialogOpen, + selectedPilotId: action.payload.selectedPilotId + } + } + case 'SET_PILOTS': { + return { + ...state, + pilots: action.payload + } + } + case 'SET_ERROR': { + return { + ...state, + error: action.payload + } + } + case 'SET_FORM_MODE': { + return { + ...state, + formMode: action.payload + } + } + case 'SET_IS_CONFIRMATION_DIALOG_LOADING': { + return { + ...state, + isConfirmDialogLoading: action.payload + } + } + case 'SET_IS_LOADING': { + return { + ...state, + isLoading: action.payload + } + } + case 'SET_OPEN_CLOSE_ENTRY_FORM': { + return { + ...state, + formMode: action.payload.formMode, + isFormOpen: action.payload.isFormOpen, + selectedPilotId: action.payload.selectedPilotId + } + } + default: { + return state; + } + } +}