menuItemsReducer.js
1.05 KB
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
38
39
import { FETCH_MENU_ITEMS_REQUEST, FETCH_MENU_ITEMS_SUCCESS, FETCH_MENU_ITEMS_FAIL, CLEAR_ERRORS } from "../constants/menuItemsConstants";
// Room details reducer.
export const menuItemsReducer =
menu =>
(state = { menuItems: [] }, action) => {
const fmir = `${FETCH_MENU_ITEMS_REQUEST}_${menu.toUpperCase()}`;
const fmis = `${FETCH_MENU_ITEMS_SUCCESS}_${menu.toUpperCase()}`;
const fmif = `${FETCH_MENU_ITEMS_FAIL}_${menu.toUpperCase()}`;
const ce = `${CLEAR_ERRORS}_${menu.toUpperCase()}`;
switch (action.type) {
case fmir:
return {
loading: true
};
case fmis:
return {
loading: false,
totalCount: action.payload.meta.pagination.total,
resultsPerPage: action.payload.meta.pagination.pageSize,
menuItems: action.payload.data
};
case fmif:
return {
error: action.payload.error.message
};
case ce:
return {
...state,
error: null
};
default:
return state;
}
};