feat: deliver status in invoice.

This commit is contained in:
elforjani3
2020-12-16 11:55:39 +02:00
parent 6388d4d48e
commit 57d05102a9
5 changed files with 84 additions and 26 deletions

View File

@@ -232,11 +232,13 @@ function InvoiceForm({
); );
return ( return (
<div className={classNames( <div
className={classNames(
CLASSES.PAGE_FORM, CLASSES.PAGE_FORM,
CLASSES.PAGE_FORM_STRIP_STYLE, CLASSES.PAGE_FORM_STRIP_STYLE,
CLASSES.PAGE_FORM_INVOICE CLASSES.PAGE_FORM_INVOICE,
)}> )}
>
<Formik <Formik
validationSchema={ validationSchema={
isNewMode ? CreateInvoiceFormSchema : EditInvoiceFormSchema isNewMode ? CreateInvoiceFormSchema : EditInvoiceFormSchema
@@ -244,7 +246,7 @@ function InvoiceForm({
initialValues={initialValues} initialValues={initialValues}
onSubmit={handleSubmit} onSubmit={handleSubmit}
> >
{({ isSubmitting }) => ( {({ isSubmitting, values }) => (
<Form> <Form>
<InvoiceFormHeader <InvoiceFormHeader
onInvoiceNumberChanged={handleInvoiceNumberChanged} onInvoiceNumberChanged={handleInvoiceNumberChanged}

View File

@@ -38,11 +38,13 @@ function InvoiceList({
//#withInvoiceActions //#withInvoiceActions
requestFetchInvoiceTable, requestFetchInvoiceTable,
requestDeleteInvoice, requestDeleteInvoice,
requestDeliverInvoice,
addInvoiceTableQueries, addInvoiceTableQueries,
}) { }) {
const history = useHistory(); const history = useHistory();
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const [deleteInvoice, setDeleteInvoice] = useState(false); const [deleteInvoice, setDeleteInvoice] = useState(false);
const [deliverInvoice, setDeliverInvoice] = useState(false);
const [selectedRows, setSelectedRows] = useState([]); const [selectedRows, setSelectedRows] = useState([]);
useEffect(() => { useEffect(() => {
@@ -88,6 +90,34 @@ function InvoiceList({
}); });
}, [deleteInvoice, requestDeleteInvoice, formatMessage]); }, [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) => { const handleEditInvoice = useCallback((invoice) => {
history.push(`/invoices/${invoice.id}/edit`); history.push(`/invoices/${invoice.id}/edit`);
}); });
@@ -127,6 +157,7 @@ function InvoiceList({
<InvoicesDataTable <InvoicesDataTable
onDeleteInvoice={handleDeleteInvoice} onDeleteInvoice={handleDeleteInvoice}
onEditInvoice={handleEditInvoice} onEditInvoice={handleEditInvoice}
onDeliverInvoice={handleDeliverInvoice}
onSelectedRowsChange={handleSelectedRowsChange} onSelectedRowsChange={handleSelectedRowsChange}
/> />
</Route> </Route>
@@ -145,6 +176,18 @@ function InvoiceList({
<T id={'once_delete_this_invoice_you_will_able_to_restore_it'} /> <T id={'once_delete_this_invoice_you_will_able_to_restore_it'} />
</p> </p>
</Alert> </Alert>
<Alert
cancelButtonText={<T id={'cancel'} />}
confirmButtonText={<T id={'deliver'} />}
intent={Intent.WARNING}
isOpen={deliverInvoice}
onCancel={handleCancelDeliverInvoice}
onConfirm={handleConfirmInvoiceDeliver}
>
<p>
<T id={'are_sure_to_deliver_this_invoice'} />
</p>
</Alert>
</DashboardPageContent> </DashboardPageContent>
</DashboardInsider> </DashboardInsider>
); );

View File

@@ -50,6 +50,7 @@ function InvoicesDataTable({
// #OwnProps // #OwnProps
onEditInvoice, onEditInvoice,
onDeleteInvoice, onDeleteInvoice,
onDeliverInvoice,
onSelectedRowsChange, onSelectedRowsChange,
}) { }) {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
@@ -82,6 +83,12 @@ function InvoicesDataTable({
text={formatMessage({ id: 'edit_invoice' })} text={formatMessage({ id: 'edit_invoice' })}
onClick={handleEditInvoice(invoice)} onClick={handleEditInvoice(invoice)}
/> />
<If condition={!invoice.is_delivered}>
<MenuItem
text={formatMessage({ id: 'mark_as_delivered' })}
onClick={() => onDeliverInvoice(invoice)}
/>
</If>
<MenuItem <MenuItem
text={formatMessage({ id: 'delete_invoice' })} text={formatMessage({ id: 'delete_invoice' })}
intent={Intent.DANGER} intent={Intent.DANGER}

View File

@@ -6,6 +6,7 @@ import {
fetchInvoice, fetchInvoice,
fetchInvoicesTable, fetchInvoicesTable,
fetchDueInvoices, fetchDueInvoices,
deliverInvoice,
} from 'store/Invoice/invoices.actions'; } from 'store/Invoice/invoices.actions';
import t from 'store/types'; import t from 'store/types';
@@ -18,6 +19,7 @@ const mapDipatchToProps = (dispatch) => ({
requestDeleteInvoice: (id) => dispatch(deleteInvoice({ id })), requestDeleteInvoice: (id) => dispatch(deleteInvoice({ id })),
requestFetchDueInvoices: (customerId) => requestFetchDueInvoices: (customerId) =>
dispatch(fetchDueInvoices({ customerId })), dispatch(fetchDueInvoices({ customerId })),
requestDeliverInvoice: (id) => dispatch(deliverInvoice({ id })),
changeInvoiceView: (id) => changeInvoiceView: (id) =>
dispatch({ dispatch({
type: t.INVOICES_SET_CURRENT_VIEW, type: t.INVOICES_SET_CURRENT_VIEW,

View File

@@ -121,7 +121,8 @@ 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`, { ApiService.get(`sales/invoices/payable`, {
params: { customer_id: customerId }, params: { customer_id: customerId },
}) })
@@ -149,3 +150,6 @@ export const fetchDueInvoices = ({ customerId }) => (dispatch) => new Promise((r
reject(data?.errors); reject(data?.errors);
}); });
}); });
export const deliverInvoice = ({ id }) => {
return (dispatch) => ApiService.post(`sales/invoices/${id}/deliver`);
};