Files
noahspan-flying/client/src/components/logForm/reducer.tsx
noahspannbauer 487afb08d6 adding api unit tests (#108)
* adding api unit tests

* adding not signed in alerts to flights and logs
2026-03-08 14:58:24 -05:00

59 lines
1.3 KiB
TypeScript

import { Alert } from '../../interfaces/Alert.interface';
import { LogFormState } from './LogFormState.interface';
type Action =
| { type: 'SET_ALERT'; payload: Alert | undefined }
| { type: 'SET_IS_DISABLED'; payload: boolean }
| { type: 'SET_IS_LOADING'; payload: boolean }
| { type: 'SET_PILOT_OPTIONS'; payload: { label: string; value: string }[] }
| { type: 'SET_SELECTED_PILOT_NAME'; payload: string };
export const initialState: LogFormState = {
alert: undefined,
isDisabled: false,
isLoading: true,
pilotOptions: [],
selectedPilotName: ''
};
export const reducer = (
state: LogFormState,
action: Action
): LogFormState => {
switch (action.type) {
case 'SET_ALERT': {
return {
...state,
alert: action.payload
};
}
case 'SET_IS_DISABLED': {
return {
...state,
isDisabled: action.payload
};
}
case 'SET_IS_LOADING': {
return {
...state,
isLoading: action.payload
};
}
case 'SET_PILOT_OPTIONS': {
return {
...state,
pilotOptions: action.payload
};
}
case 'SET_SELECTED_PILOT_NAME': {
return {
...state,
selectedPilotName: action.payload
};
}
default: {
return state;
}
}
};