feat: payment made form in new and edit mode.

This commit is contained in:
Ahmed Bouhuolia
2020-11-01 17:40:40 +02:00
parent f76abb3f79
commit 70269d382a
24 changed files with 812 additions and 551 deletions

View File

@@ -106,7 +106,20 @@ export const fetchPaymentMade = ({ id }) => {
type: t.PAYMENT_MADE_SET,
payload: {
id,
bill_payment: response.data.bill_payment,
paymentMade: response.data.bill_payment,
},
});
dispatch({
type: t.BILLS_PAYABLE_BY_PAYMENT_ID,
payload: {
billPaymentId: id,
bills: response.data.bill_payment.payable_bills,
},
});
dispatch({
type: t.BILLS_ITEMS_SET,
payload: {
bills: response.data.bill_payment.payable_bills,
},
});
resovle(response);
@@ -118,3 +131,17 @@ export const fetchPaymentMade = ({ id }) => {
});
});
};
export const fetchPaymentMadeBills = ({ paymentMadeId }) => (dispatch) => {
return new Promise((resolve, reject) => {
ApiService.get(`purchases/bill_payments/${paymentMadeId}/bills`).then((response) => {
dispatch({
type: t.BILLS_ITEMS_SET,
payload: {
bills: response.data.bills,
},
});
resolve(response);
}).catch((error) => { reject(error) });
});
}

View File

@@ -39,6 +39,17 @@ const reducer = createReducer(initialState, {
};
},
[t.PAYMENT_MADE_SET]: (state, action) => {
const { id, paymentMade } = action.payload;
const _oldPaymentMade = (state.items[id] || {});
state.items[id] = {
...defaultPaymentMade,
..._oldPaymentMade,
...paymentMade,
};
},
[t.PAYMENT_MADE_DELETE]: (state, action) => {
const { id } = action.payload;

View File

@@ -23,6 +23,9 @@ const paymentMadesIds = (state, props) => {
return state.paymentMades.items[props.paymentMadeId];
};
const paymentMadeEntries = (state, props) => props.paymentMadeEntries;
const billsItemsSelector = (state, props) => state.bills.items;
export const getPaymentMadeCurrentPageFactory = () =>
createSelector(
paymentMadesPageSelector,
@@ -54,3 +57,15 @@ export const getPaymentMadeByIdFactory = () =>
createSelector(paymentMadesIds, (payment_Made) => {
return payment_Made;
});
export const getPaymentMadeEntriesDataFactory = () =>
createSelector(
billsItemsSelector,
paymentMadeEntries,
(billsItems, paymentEntries) => {
return Array.isArray(paymentEntries) ?
paymentEntries.map((entry) => ({
...entry, ...(billsItems[entry.bill_id] || {}),
})) : [];
}
)