import { ModalAddresses, CurrentView, Address, Option } from 'checkout/ShippingAddressProps'; const EmptyOption: Option = {label: '', value: ''}; interface State { addresses: Array
; currentView: CurrentView; loadingLabel: string; currentState: Option; currentCountry: Option; modalAddresses: ModalAddresses; currentSelectionId: string; } export const initialState: State = { addresses: [], currentView: 'closed', loadingLabel: '', currentState: EmptyOption, currentCountry: EmptyOption, modalAddresses: null, currentSelectionId: null }; export function reducer(state: State, [type, payload]: [string, any?]): State { switch (type) { case 'SetAddresses': return {...state, addresses: payload}; case 'SetCurrentView': return {...state, currentView: payload}; case 'SetLoadingLabel': return {...state, loadingLabel: payload}; case 'ClearLoadingLabel': return {...state, loadingLabel: ''}; case 'SetCurrentState': return {...state, currentState: payload}; case 'SetCurrentCountry': return {...state, currentCountry: payload}; case 'SetModalAddresses': return {...state, modalAddresses: payload}; case 'SetCurrentSelectionId': return {...state, currentSelectionId: payload}; default: throw new Error(); } }