Files
noahspan-portfolio/client/src/components/experienceForm/reducer.ts
noahspannbauer e5219761c2
Some checks failed
Main / changes (push) Successful in 37s
Main / deploy (push) Has been cancelled
Main / build-and-test (push) Has been cancelled
adding skills to experiences, profiles, and projects
2026-07-20 19:28:37 -05:00

67 lines
1.5 KiB
TypeScript

import { Profile } from "../profiles/Profile.interface";
import { Skill } from "../skills/Skill.interface";
import { ExperienceFormState } from "./ExperienceFormState.interface"
type Action =
| { type: 'SET_ERROR'; payload: string | undefined }
| { type: 'SET_IS_DISABLED'; payload: boolean }
| { type: 'SET_IS_LOADING'; payload: boolean }
| { type: 'SET_PROFILE_OPTIONS'; payload: Profile[] }
| { type: 'SET_SELECTED_SKILLS'; payload: Skill[] }
| { type: 'SET_SKILL_OPTIONS'; payload: Skill[] };
export const initialState: ExperienceFormState = {
error: undefined,
isDisabled: false,
isLoading: true,
profileOptions: [],
selectedSkills: [],
skillOptions: []
};
export const reducer = (
state: ExperienceFormState,
action: Action
): ExperienceFormState => {
switch (action.type) {
case 'SET_ERROR': {
return {
...state,
error: action.payload
};
}
case 'SET_IS_DISABLED': {
return {
...state,
isDisabled: action.payload
};
}
case 'SET_IS_LOADING': {
return {
...state,
isLoading: action.payload
};
}
case 'SET_PROFILE_OPTIONS': {
return {
...state,
profileOptions: action.payload
}
}
case 'SET_SELECTED_SKILLS': {
return {
...state,
selectedSkills: action.payload
}
}
case 'SET_SKILL_OPTIONS': {
return {
...state,
skillOptions: action.payload
}
}
default: {
return state;
}
}
};