All files / src/store filters-store.ts

54.55% Statements 6/11
100% Branches 2/2
33.33% Functions 1/3
54.55% Lines 6/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                    2x 2x 2x   2x             2x                     2x        
import { initStore } from './index';
import { format, now, getNextDay } from '../helpers';
 
type FiltersState = {
  parkingLocationId?: string,
  parkingStartDate?: string,
  parkingEndDate?: string,
  parkingPriceSortId?: number
}
 
const configureStore = (_initialState?: FiltersState) => {
  const start = format(now, 'yyyy-MM-dd');
  const finish = format(getNextDay(now), 'yyyy-MM-dd');
 
  const initialState = _initialState || {
    parkingLocationId: null,
    parkingStartDate: start,
    parkingEndDate: finish,
    parkingPriceSortId: 1
  };
 
  const actions = {
    UPDATE_FILTER: (curState: FiltersState, payload: FiltersState) => {
      const newState = { ...curState, ...payload };
      sessionStorage.setItem('ks-filters', JSON.stringify(newState));
      return newState;
    },
    RESET_ALL: () => {
      sessionStorage.removeItem('ks-filters');
      return initialState;
    }
  };
  initStore(actions, initialState);
};
 
export default configureStore;