refactoring: expenses landing list.

refactoring: customers landing list.
refactoring: vendors landing list.
refactoring: manual journals landing list.
This commit is contained in:
a.bouhuolia
2021-02-10 18:35:19 +02:00
parent 6e10ed0721
commit c68b4ca9ba
170 changed files with 2835 additions and 4430 deletions

View File

@@ -1,134 +1,12 @@
import ApiService from 'services/ApiService';
import t from 'store/types';
export const submitCustomer = ({ form }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.post('customers', form)
.then((response) => {
resolve(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
reject(data?.errors);
});
});
/**
* Sets the customers table state.
*/
export const setCustomersTableState = (queries) => {
return {
type: t.CUSTOMERS_TABLE_STATE_SET,
payload: { queries },
};
};
export const editCustomer = ({ form, id }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.post(`customers/${id}`, form)
.then((response) => {
resolve(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
reject(data?.errors);
});
});
};
export const fetchCustomers = ({ query }) => {
return (dispatch, getState) =>
new Promise((resolve, reject) => {
const pageQuery = getState().customers.tableQuery;
dispatch({
type: t.CUSTOMERS_TABLE_LOADING,
payload: { loading: true },
});
ApiService.get(`customers`, { params: { ...pageQuery, ...query } })
.then((response) => {
dispatch({
type: t.CUSTOMERS_PAGE_SET,
payload: {
customers: response.data.customers,
customViewId:
response.data?.filter_meta?.view?.custom_view_id || -1,
paginationMeta: response.data.pagination,
},
});
dispatch({
type: t.CUSTOMERS_ITEMS_SET,
payload: {
customers: response.data.customers,
},
});
dispatch({
type: t.CUSTOMERS_PAGINATION_SET,
payload: {
pagination: response.data.pagination,
customViewId:
response.data?.filter_meta?.view?.custom_view_id || -1,
},
});
dispatch({
type: t.CUSTOMERS_TABLE_LOADING,
payload: { loading: false },
});
resolve(response);
})
.catch((error) => {
reject(error);
});
});
};
export const fetchCustomer = ({ id }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.get(`customers/${id}`)
.then((response) => {
dispatch({
type: t.CUSTOMER_SET,
payload: {
id,
customer: response.data.customer,
},
});
resolve(response);
})
.catch((error) => {
reject(error);
});
});
};
export const deleteCustomer = ({ id }) => {
return (dispatch) =>
new Promise((resovle, reject) => {
ApiService.delete(`customers/${id}`)
.then((response) => {
dispatch({
type: t.CUSTOMER_DELETE,
payload: { id },
});
resovle(response);
})
.catch((error) => {
reject(error.response.data.errors || []);
});
});
};
export const deleteBulkCustomers = ({ ids }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.delete('customers', { params: { ids } })
.then((response) => {
dispatch({
type: t.CUSTOMERS_BULK_DELETE,
payload: { ids },
});
resolve(response);
})
.catch((error) => {
reject(error.response.data.errors || []);
});
});
};