UNPKG

trc-client-core

Version:
64 lines (52 loc) 2.31 kB
import {Map, fromJS, List} from 'immutable'; import { GAP_REPORT_FETCH, GAP_REPORT_RECEIVE, GAP_REPORT_ERROR, CERTIFICATION_COMPLETION_FETCH, CERTIFICATION_COMPLETION_RECEIVE, CERTIFICATION_COMPLETION_ERROR } from 'trc-client-core/src/constants/ActionTypes' const initialState = Map(); export default function GapReportReducer(state = initialState, action) { var {payload} = action; switch (action.type) { // Fetch Actions case GAP_REPORT_FETCH: return state .set('fetching', true) .set('lastQuery', payload); case CERTIFICATION_COMPLETION_FETCH: return state .set('fetching', true); // Error Actions case GAP_REPORT_ERROR: case CERTIFICATION_COMPLETION_ERROR: return state .set('fetching', false) .set('error', action.payload); // Recieve Actions case GAP_REPORT_RECEIVE: return state .update(payload.pathwayId, value => { const gapReport = fromJS(payload.gapReport); const pathwayCompletion = gapReport.get('pathwayCompletion') || gapReport; return Map({ additonalResources: gapReport.getIn(['careerPlan', 'displayText', 'additonalResource']), certificationMap: gapReport.get('certificationMap'), displayName: gapReport.get('displayName'), footerText: gapReport.getIn(['careerPlan', 'displayText', 'footerText']), headerText: gapReport.getIn(['careerPlan', 'displayText', 'headerText']), learningPlan: gapReport.get('careerPlan'), pathwayCompletion: pathwayCompletion.sortBy(pp => (pp.get('firstName') + pp.get('lastName')).toLowerCase()) }) }) .set('error', null) .set('fetching', false); case CERTIFICATION_COMPLETION_RECEIVE: const {pathwayId, participantId, completions} = payload; return state.setIn([pathwayId, 'certificationCompletion', participantId], fromJS(completions)); default: return state; } }