feature : Puschases & Sales / fix : tasks

This commit is contained in:
elforjani3
2020-09-04 00:41:22 +02:00
92 changed files with 4642 additions and 1610 deletions

View File

@@ -66,27 +66,7 @@ export const deleteBill = ({ id }) => {
};
export const submitBill = ({ form }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
ApiService.post('purchases/bills', form)
.then((response) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
resolve(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
reject(data?.errors);
});
});
return (dispatch) => ApiService.post('purchases/bills', form);
};
export const fetchBill = ({ id }) => {
@@ -94,12 +74,11 @@ export const fetchBill = ({ id }) => {
new Promise((resovle, reject) => {
ApiService.get(`purchases/bills/${id}`)
.then((response) => {
const { bill } = response.data;
dispatch({
type: t.BILL_SET,
payload: {
id,
bill: response.data.bill,
},
payload: { id, bill },
});
resovle(response);
})
@@ -112,25 +91,5 @@ export const fetchBill = ({ id }) => {
};
export const editBill = (id, form) => {
return (dispatch) =>
new Promise((resolve, rejcet) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
ApiService.post(`purchases/bills/${id}`, form)
.then((response) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
resolve(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
rejcet(data?.errors);
});
});
return (dispatch) => ApiService.post(`purchases/bills/${id}`, form);
};

View File

@@ -37,9 +37,13 @@ const reducer = createReducer(initialState, {
[t.BILLS_ITEMS_SET]: (state, action) => {
const { bills } = action.payload;
const _bills = {};
bills.forEach((bill) => {
const oldBill = state.items[bill.id] || {};
_bills[bill.id] = {
...defaultBill,
...oldBill,
...bill,
};
});
@@ -59,7 +63,6 @@ const reducer = createReducer(initialState, {
[t.BILLS_PAGE_SET]: (state, action) => {
const { customViewId, bills, pagination } = action.payload;
const viewId = customViewId || -1;
const view = state.views[viewId] || {};
@@ -95,8 +98,6 @@ const reducer = createReducer(initialState, {
},
};
},
});
export default createTableQueryReducers('bills', reducer);

View File

@@ -1,30 +1,37 @@
import { createSelector } from '@reduxjs/toolkit';
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
const billTableQuery = (state) => {
return state.bills.tableQuery;
};
export const getBillTableQuery = createSelector(
paginationLocationQuery,
billTableQuery,
(locationQuery, tableQuery) => {
return {
...locationQuery,
...tableQuery,
};
},
);
const billTableQuery = (state) => state.bills.tableQuery;
const billPageSelector = (state, props, query) => {
const viewId = state.bills.currentViewId;
return state.bills.views?.[viewId]?.pages?.[query.page];
};
const billItemsSelector = (state) => state.bills.items;
const billItemsSelector = (state) => {
return state.bills.items;
const billByIdSelector = (state, props) => state.bills.items[props.billId];
const billPaginationSelector = (state, props) => {
const viewId = state.bills.currentViewId;
return state.bills.views?.[viewId];
};
export const getBillTableQueryFactory = () =>
createSelector(
paginationLocationQuery,
billTableQuery,
(locationQuery, tableQuery) => {
return {
...locationQuery,
...tableQuery,
};
},
);
/**
* Get current page bills items.
* @return {Array}
*/
export const getBillCurrentPageFactory = () =>
createSelector(billPageSelector, billItemsSelector, (billPage, billItems) => {
return typeof billPage === 'object'
@@ -32,20 +39,14 @@ export const getBillCurrentPageFactory = () =>
: [];
});
const billByIdSelector = (state, props) => {
return state.bills.items[props.billId];
};
/**
* Retrieve bill details of the given bill id.
*/
export const getBillByIdFactory = () =>
createSelector(billByIdSelector, (bill) => {
return bill;
});
const billPaginationSelector = (state, props) => {
const viewId = state.bills.currentViewId;
return state.bills.views?.[viewId];
};
export const getBillPaginationMetaFactory = () =>
createSelector(billPaginationSelector, (billPage) => {
return billPage?.paginationMeta || {};