| Total Complexity | 1 |
| Complexity/F | 0 |
| Lines of Code | 39 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { EducationStatus } from "../../models/types"; |
||
| 2 | import { |
||
| 3 | EducationStatusAction, |
||
| 4 | GET_EDUCATION_STATUSES_STARTED, |
||
| 5 | GET_EDUCATION_STATUSES_SUCCEEDED, |
||
| 6 | GET_EDUCATION_STATUSES_FAILED, |
||
| 7 | } from "./educationStatusActions"; |
||
| 8 | import { mapToObject, getId } from "../../helpers/queries"; |
||
| 9 | |||
| 10 | export interface EducationStatusState { |
||
| 11 | byId: { |
||
| 12 | [id: number]: EducationStatus; |
||
| 13 | }; |
||
| 14 | loading: boolean; |
||
| 15 | } |
||
| 16 | |||
| 17 | export const initEducationStatusState = (): EducationStatusState => ({ |
||
| 18 | byId: [], |
||
| 19 | loading: false, |
||
| 20 | }); |
||
| 21 | |||
| 22 | const educationStatusReducer = ( |
||
| 23 | state = initEducationStatusState(), |
||
| 24 | action: EducationStatusAction, |
||
| 25 | ): EducationStatusState => { |
||
| 26 | switch (action.type) { |
||
| 27 | case GET_EDUCATION_STATUSES_STARTED: |
||
| 28 | return { ...state, loading: true }; |
||
| 29 | case GET_EDUCATION_STATUSES_SUCCEEDED: |
||
| 30 | return { byId: mapToObject(action.payload, getId), loading: false }; |
||
| 31 | case GET_EDUCATION_STATUSES_FAILED: |
||
| 32 | return { ...state, loading: false }; |
||
| 33 | default: |
||
| 34 | return state; |
||
| 35 | } |
||
| 36 | }; |
||
| 37 | |||
| 38 | export default educationStatusReducer; |
||
| 39 |