maccounter
40 строк · 1.1 Кб
1import { appInitialState } from '@store/app-store/appInitialState'
2import { getCurrentTimePeriod } from '@store/app-store/utils'
3import { AnyAction } from 'redux'
4import { appActionTypes } from '@store/app-store/actionTypes'
5
6// eslint-disable-next-line default-param-last
7const appReducer = (state = appInitialState, action?: AnyAction) => {
8switch (action?.type) {
9case appActionTypes.setTimePeriod:
10return {
11...state,
12timePeriod: action?.payload,
13}
14case appActionTypes.setModalIsActive:
15return {
16...state,
17modal: {
18...state.modal,
19isActive: action?.payload,
20},
21}
22default:
23return state
24}
25}
26
27export const setTimePeriod = () => ({
28type: appActionTypes.setTimePeriod,
29payload: getCurrentTimePeriod(),
30})
31
32export const setModalIsActive = (payload: boolean) => ({
33type: appActionTypes.setModalIsActive,
34payload,
35})
36
37export type SetTimePeriod = typeof setTimePeriod
38export type SetModalIsActive = typeof setModalIsActive
39
40export default appReducer
41