Merge remote-tracking branch 'origin/customers'

This commit is contained in:
Ahmed Bouhuolia
2020-06-21 19:51:18 +02:00
17 changed files with 1360 additions and 69 deletions

View File

@@ -68,6 +68,7 @@ export const fetchCustomers = ({ query }) => {
type: t.CUSTOMER_SET,
customers: response.data.customers.results,
});
dispatch({
type: t.CUSTOMERS_PAGE_SET,
customers: response.data.customers.results,
@@ -91,3 +92,18 @@ export const fetchCustomers = ({ query }) => {
});
});
};
export const deleteCustomer = ({ id }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.delete(`customers/${id}`)
.then((response) => {
dispatch({ type: t.CUSTOMER_DELETE, id });
resolve(response);
})
.catch((error) => {
reject(error.response.data.errors || []);
});
});
};

View File

@@ -36,10 +36,14 @@ const customersReducer = createReducer(initialState, {
delete state.items[action.id];
}
},
[t.CUSTOMERS_TABLE_LOADING]: (state, action) => {
const { loading } = action.payload;
state.loading = !!loading;
},
});
export default createTableQueryReducers('customers', customersReducer);
export const getCustomerById = (state, id) => {
return state.customers[id];
return state.customers.items[id];
};

View File

@@ -1,6 +1,6 @@
import { pickItemsFromIds } from 'store/selectors';
export const getCustomersItems = (state, viewId) => {
const customersView = state.customers.views[viewId || -1];
const customersItems = state.customers.items;