github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/build-blockchain-insurance-app-master/web/src/insurance/reducers/contractTemplatesReducer.js (about)

     1  'use strict';
     2  
     3  import * as ContractTemplateActionType from '../actions/contractTemplateActionTypes';
     4  import * as initialState from './initialState';
     5  
     6  export default function contractTemplateReducer(state = initialState.contractTemplates, action) {
     7    switch (action.type) {
     8      case ContractTemplateActionType.LOAD_CONTRACT_TYPES_SUCCESS:
     9        return Object.assign({}, state, {
    10          contractTypes: [...action.contractTypes]
    11        });
    12      case ContractTemplateActionType.CREATE_CONTRACT_TYPE_SUCCESS:
    13        return Object.assign({}, state, {
    14          contractTypes: [...state.contractTypes, action.contractType]
    15        });
    16      case ContractTemplateActionType.SET_CONTRACT_TYPE_ACTIVE_SUCCESS:
    17        {
    18          let contractTypesWithout = state.contractTypes.filter(ct => ct.uuid !== action.uuid);
    19          let newContractType = state.contractTypes.find(ct => ct.uuid === action.uuid);
    20          return Object.assign({}, state, {
    21            contractTypes: [
    22              ...contractTypesWithout,
    23              Object.assign({}, newContractType, { active: action.active })
    24            ]
    25          });
    26        }
    27      default:
    28        return state;
    29    }
    30  }