From 57d05102a919d4d4ba41a0edfa9292a7cc15666b Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Wed, 16 Dec 2020 11:55:39 +0200 Subject: [PATCH] feat: deliver status in invoice. --- .../containers/Sales/Invoice/InvoiceForm.js | 14 +++--- .../containers/Sales/Invoice/InvoiceList.js | 43 ++++++++++++++++++ .../Sales/Invoice/InvoicesDataTable.js | 7 +++ .../Sales/Invoice/withInvoiceActions.js | 2 + client/src/store/Invoice/invoices.actions.js | 44 ++++++++++--------- 5 files changed, 84 insertions(+), 26 deletions(-) diff --git a/client/src/containers/Sales/Invoice/InvoiceForm.js b/client/src/containers/Sales/Invoice/InvoiceForm.js index 65f65d232..aef1cf6f4 100644 --- a/client/src/containers/Sales/Invoice/InvoiceForm.js +++ b/client/src/containers/Sales/Invoice/InvoiceForm.js @@ -232,11 +232,13 @@ function InvoiceForm({ ); return ( -
+
- {({ isSubmitting }) => ( + {({ isSubmitting, values }) => (
{ @@ -88,6 +90,34 @@ function InvoiceList({ }); }, [deleteInvoice, requestDeleteInvoice, formatMessage]); + // Handle cancel/confirm invoice deliver. + const handleDeliverInvoice = useCallback((invoice) => { + setDeliverInvoice(invoice); + }, []); + + // Handle cancel deliver invoice alert. + const handleCancelDeliverInvoice = useCallback(() => { + setDeliverInvoice(false); + }, []); + + // Handle confirm invoiec deliver. + const handleConfirmInvoiceDeliver = useCallback(() => { + requestDeliverInvoice(deliverInvoice.id) + .then(() => { + setDeliverInvoice(false); + AppToaster.show({ + message: formatMessage({ + id: 'the_invoice_has_been_successfully_delivered', + }), + intent: Intent.SUCCESS, + }); + queryCache.invalidateQueries('invoices-table'); + }) + .catch((error) => { + // setDeliverInvoice(false); + }); + }, [deliverInvoice, requestDeliverInvoice, formatMessage]); + const handleEditInvoice = useCallback((invoice) => { history.push(`/invoices/${invoice.id}/edit`); }); @@ -127,6 +157,7 @@ function InvoiceList({ @@ -145,6 +176,18 @@ function InvoiceList({

+ } + confirmButtonText={} + intent={Intent.WARNING} + isOpen={deliverInvoice} + onCancel={handleCancelDeliverInvoice} + onConfirm={handleConfirmInvoiceDeliver} + > +

+ +

+
); diff --git a/client/src/containers/Sales/Invoice/InvoicesDataTable.js b/client/src/containers/Sales/Invoice/InvoicesDataTable.js index 532ed1555..7944be3be 100644 --- a/client/src/containers/Sales/Invoice/InvoicesDataTable.js +++ b/client/src/containers/Sales/Invoice/InvoicesDataTable.js @@ -50,6 +50,7 @@ function InvoicesDataTable({ // #OwnProps onEditInvoice, onDeleteInvoice, + onDeliverInvoice, onSelectedRowsChange, }) { const { formatMessage } = useIntl(); @@ -82,6 +83,12 @@ function InvoicesDataTable({ text={formatMessage({ id: 'edit_invoice' })} onClick={handleEditInvoice(invoice)} /> + + onDeliverInvoice(invoice)} + /> + ({ requestDeleteInvoice: (id) => dispatch(deleteInvoice({ id })), requestFetchDueInvoices: (customerId) => dispatch(fetchDueInvoices({ customerId })), + requestDeliverInvoice: (id) => dispatch(deliverInvoice({ id })), changeInvoiceView: (id) => dispatch({ type: t.INVOICES_SET_CURRENT_VIEW, diff --git a/client/src/store/Invoice/invoices.actions.js b/client/src/store/Invoice/invoices.actions.js index daa509e08..05be0abbd 100644 --- a/client/src/store/Invoice/invoices.actions.js +++ b/client/src/store/Invoice/invoices.actions.js @@ -121,31 +121,35 @@ export const fetchInvoice = ({ id }) => { }); }; -export const fetchDueInvoices = ({ customerId }) => (dispatch) => new Promise((resovle, reject) => { +export const fetchDueInvoices = ({ customerId }) => (dispatch) => + new Promise((resovle, reject) => { ApiService.get(`sales/invoices/payable`, { params: { customer_id: customerId }, }) - .then((response) => { - dispatch({ - type: t.INVOICES_ITEMS_SET, - payload: { - sales_invoices: response.data.sales_invoices, - }, - }); - if (customerId) { + .then((response) => { dispatch({ - type: t.INVOICES_RECEIVABLE_BY_CUSTOMER_ID, + type: t.INVOICES_ITEMS_SET, payload: { - customerId, - saleInvoices: response.data.sales_invoices, + sales_invoices: response.data.sales_invoices, }, }); - } - resovle(response); - }) - .catch((error) => { - const { response } = error; - const { data } = response; - reject(data?.errors); - }); + if (customerId) { + dispatch({ + type: t.INVOICES_RECEIVABLE_BY_CUSTOMER_ID, + payload: { + customerId, + saleInvoices: response.data.sales_invoices, + }, + }); + } + resovle(response); + }) + .catch((error) => { + const { response } = error; + const { data } = response; + reject(data?.errors); + }); }); +export const deliverInvoice = ({ id }) => { + return (dispatch) => ApiService.post(`sales/invoices/${id}/deliver`); +};