import * as modalActions from '../actions/modal.actions'; import { Modal, PickUpStoreSelector } from '../models/modal.interface'; import { State } from './'; export const initialModalState: Modal = { pickUpStoreSelector: { open: false, deliveryPOS: null, entry: null, fulfillmentType: null, stores: [], section: null } }; export interface ModalState extends Modal {} export function ModalReducer(state = initialModalState, action: modalActions.ModalActions): ModalState { switch (action.type) { case modalActions.OPEN_PICK_UP_STORE_SELECTOR: { const payload = { ...state, pickUpStoreSelector: { open: true, deliveryPOS: action['deliveryPOS'], entry: action['entry'], fulfillmentType: action['fulfillmentType'], stores: [], section: action['section'] } }; return {...state, ...payload }; } case modalActions.CLOSE_PICK_UP_STORE_SELECTOR: { const payload = { ...state, pickUpStoreSelector: { open: false, deliveryPOS: null, entry: null, fulfillmentType: null, stores: [], section: null } }; return {...state, ...payload }; } case modalActions.LOAD_STORE_PICK_UP_SUCCESS: { const stores = (!action['stores'] || action['stores'].length < 0) ? [] : action['stores']; const payload = { ...state, pickUpStoreSelector: { ...state.pickUpStoreSelector, stores: [...stores] } }; return payload; } default: { return state; } } } export const getPickUpStoreSelector = (state: State): PickUpStoreSelector => state.modal.pickUpStoreSelector; export const getPickUpStores = (state: State): Array => state.modal.pickUpStoreSelector.stores;