index.js 756 B

1234567891011121314151617181920212223242526272829
  1. import { createReducer } from '@reduxjs/toolkit';
  2. import {
  3. actionCategoriesSuccess,
  4. actionCategoriesReject,
  5. actionCategorySuccess,
  6. actionCategoryReject,
  7. } from '../action';
  8. const initialState = { categories: [], category: {} };
  9. const reducerCategories = createReducer(initialState, {
  10. [actionCategoriesSuccess]: (state, { payload: categories }) => {
  11. const category = state.category;
  12. return { categories, category };
  13. },
  14. [actionCategoriesReject]: (state, _) => {
  15. return state;
  16. },
  17. [actionCategorySuccess]: (state, { payload: category }) => {
  18. const categories = state.category;
  19. return { categories, category };
  20. },
  21. [actionCategoryReject]: (state, _) => {
  22. return state;
  23. },
  24. });
  25. export default reducerCategories;