|
@@ -4,12 +4,14 @@ import { actionClearCart } from "./cartReducer";
|
|
|
import { categoryApi } from "./categoryReducer";
|
|
|
import { goodsApi } from "./goodsReducer";
|
|
|
import { ordersApi } from "./ordersReducer";
|
|
|
+import { loginApi } from "./authReducer";
|
|
|
|
|
|
const frontEndReducerSlice = createSlice({ //promiseReducer
|
|
|
name: 'frontend', //префикс типа наподобие AUTH_
|
|
|
initialState: {
|
|
|
sidebar: {},
|
|
|
ordersPaging: { fromPage: 0, pageSize: 10 },
|
|
|
+ usersPaging: { fromPage: 0, pageSize: 10 },
|
|
|
goodsPaging: { fromPage: 0, pageSize: 5 }
|
|
|
}, //state={} в параметрах
|
|
|
reducers: {
|
|
@@ -21,14 +23,24 @@ const frontEndReducerSlice = createSlice({ //promiseReducer
|
|
|
let { fromPage, pageSize } = action.payload.page;
|
|
|
fromPage = fromPage ?? state.ordersPaging?.fromPage;
|
|
|
pageSize = pageSize ?? state.ordersPaging?.pageSize;
|
|
|
- state.ordersPaging.fromPage = fromPage;
|
|
|
- state.ordersPaging.pageSize = pageSize;
|
|
|
+ state.ordersPaging = { fromPage, pageSize };
|
|
|
return state;
|
|
|
},
|
|
|
setOrdersSearch(state, action) {
|
|
|
state.ordersSearchStr = action.payload.searchStr;
|
|
|
return state;
|
|
|
},
|
|
|
+ setUsersPaging(state, action) {
|
|
|
+ let { fromPage, pageSize } = action.payload.page;
|
|
|
+ fromPage = fromPage ?? state.usersPaging?.fromPage;
|
|
|
+ pageSize = pageSize ?? state.usersPaging?.pageSize;
|
|
|
+ state.usersPaging = { fromPage, pageSize };
|
|
|
+ return state;
|
|
|
+ },
|
|
|
+ setUsersSearch(state, action) {
|
|
|
+ state.usersSearchStr = action.payload.searchStr;
|
|
|
+ return state;
|
|
|
+ },
|
|
|
setGoodsPaging(state, action) {
|
|
|
let { fromPage, pageSize } = action.payload.page;
|
|
|
fromPage = fromPage ?? state.goodsPaging?.fromPage;
|
|
@@ -52,6 +64,7 @@ const frontEndReducerSlice = createSlice({ //promiseReducer
|
|
|
setCurrentOrder(state, action.payload._id);
|
|
|
return state;
|
|
|
},
|
|
|
+
|
|
|
},
|
|
|
extraReducers: builder => {
|
|
|
builder.addMatcher(goodsApi.endpoints.getGoodsCount.matchFulfilled,
|
|
@@ -66,6 +79,10 @@ const frontEndReducerSlice = createSlice({ //promiseReducer
|
|
|
(state, { payload }) => {
|
|
|
state.orders = { ordersCount: { payload: payload.OrderCount } }
|
|
|
});
|
|
|
+ builder.addMatcher(loginApi.endpoints.getUsersCount.matchFulfilled,
|
|
|
+ (state, { payload }) => {
|
|
|
+ state.users = { usersCount: { payload: payload.UserCount } }
|
|
|
+ });
|
|
|
builder.addMatcher(ordersApi.endpoints.getOrders.matchFulfilled,
|
|
|
(state, data) => {
|
|
|
let a = '';
|
|
@@ -95,6 +112,11 @@ let actionSetOrderSearch = (searchStr) =>
|
|
|
dispatch(frontEndReducerSlice.actions.setOrdersSearch({ searchStr }))
|
|
|
}
|
|
|
|
|
|
+let actionSetUsersSearch = (searchStr) =>
|
|
|
+ async dispatch => {
|
|
|
+ dispatch(frontEndReducerSlice.actions.setUsersSearch({ searchStr }))
|
|
|
+ }
|
|
|
+
|
|
|
let actionSetCurrentCategory = (_id) =>
|
|
|
async dispatch => {
|
|
|
dispatch(frontEndReducerSlice.actions.setCurrentCategory({ _id }))
|
|
@@ -155,8 +177,16 @@ const getOrdersCount = state => {
|
|
|
let result = state.frontend.orders.ordersCount?.payload ?? 0;
|
|
|
return result;
|
|
|
}
|
|
|
+const getUsersCount = state => {
|
|
|
+ let result = state.frontend.users.usersCount?.payload ?? 0;
|
|
|
+ return result;
|
|
|
+}
|
|
|
+let actionSetUsersPaging = ({ fromPage, pageSize }) =>
|
|
|
+ async dispatch => {
|
|
|
+ dispatch(frontEndReducerSlice.actions.setUsersPaging({ page: { fromPage, pageSize } }))
|
|
|
+ }
|
|
|
|
|
|
|
|
|
export { frontEndReducer, actionSetSidebar, actionSetOrdersPaging, actionSetOrderSearch, actionSetGoodsPaging, actionSetGoodsSearch };
|
|
|
export { getCurrentCategory, getCurrentGood, actionSetCurrentCategory, actionSetCurrentGood, getGoodsCount, getCurrentOrder, actionSetCurrentOrder }
|
|
|
-export { getOrdersCount };
|
|
|
+export { getOrdersCount, getUsersCount, actionSetUsersPaging, actionSetUsersSearch };
|