WIP/customers

This commit is contained in:
elforjani3
2020-06-14 13:27:36 +02:00
parent 4d1dd14f8d
commit e20c912a3d
17 changed files with 544 additions and 42 deletions

View File

@@ -0,0 +1,45 @@
import t from 'store/types';
import { createReducer } from '@reduxjs/toolkit';
import { createTableQueryReducers } from 'store/queryReducers';
const initialState = {
items: {},
views: {},
loading: false,
currentViewId: -1,
errors: [],
};
const customersReducer = createReducer(initialState, {
[t.CUSTOMER_SET]: (state, action) => {
const _customers = {};
action.customers.forEach((customer) => {
_customers[customer.id] = customer;
});
state.items = {
...state.items,
..._customers,
};
},
[t.CUSTOMERS_PAGE_SET]: (state, action) => {
const viewId = action.customViewId || -1;
const view = state.views[viewId] || {};
state.views[viewId] = {
...view,
ids: action.customers.map((i) => i.id),
};
},
[t.CUSTOMER_DELETE]: (state, action) => {
if (typeof state.items[action.id] !== 'undefined') {
delete state.items[action.id];
}
},
});
export default createTableQueryReducers('customers', customersReducer);
export const getCustomerById = (state, id) => {
return state.customers[id];
};