Guest User

Untitled

a guest
Aug 5th, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {
  2.   APP__HANDLINE_CREATE_CATEGORY_FORM,
  3.   APP__HANDLINE_CREATE_TASK_FORM,
  4.   APP__SET_ACTIVE_CATEGORY_ID,
  5.   // AppTypes,
  6. } from "../types/app-types";
  7. import { IAppReducer } from "../interface/reducers-interface/appReducerInterface";
  8.  
  9. const initialState = {
  10.   appData: {
  11.     showCreateCategoryForm: false,
  12.     showCreateTaskForm: false,
  13.     activeCategoryID: 0,
  14.   },
  15. };
  16.  
  17. interface IhandlerCategoryForm {
  18.   type: typeof APP__HANDLINE_CREATE_CATEGORY_FORM;
  19.   payload: boolean;
  20. }
  21. interface IhandlerTaskForm {
  22.   type: typeof APP__HANDLINE_CREATE_TASK_FORM;
  23.   payload: boolean;
  24. }
  25.  
  26. interface IselectActiveCategory {
  27.   type: typeof APP__SET_ACTIVE_CATEGORY_ID;
  28.   payload: number;
  29. }
  30.  
  31. export type AppTypes = IhandlerCategoryForm | IhandlerTaskForm | IselectActiveCategory;
  32.  
  33. export type initialStateType = typeof initialState;
  34.  
  35. export const appReducer = (state = initialState, action: AppTypes): initialStateType => {
  36.  
  37.  
  38.  
  39.  
  40.   switch (action.type) {
  41.     case APP__HANDLINE_CREATE_CATEGORY_FORM:
  42.       return { ...state, appData: { ...state.appData, showCreateCategoryForm: action.payload } };
  43.     case APP__HANDLINE_CREATE_TASK_FORM:
  44.       return { ...state, appData: { ...state.appData, showCreateTaskForm: action.payload } };
  45.     case APP__SET_ACTIVE_CATEGORY_ID:
  46.       return { ...state, appData: { ...state.appData, activeCategoryID: action.payload } };
  47.  
  48.     default:
  49.       return state;
  50.   }
  51. };
  52.  
Advertisement
Add Comment
Please, Sign In to add comment