67 lines
1.5 KiB
TypeScript
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;
|
|
}
|
|
}
|
|
}; |