mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
80 lines
2.1 KiB
JavaScript
80 lines
2.1 KiB
JavaScript
import React, { useCallback } from 'react';
|
|
import { DialogContent } from 'components';
|
|
import { useQuery, queryCache } from 'react-query';
|
|
|
|
import ReferenceNumberForm from 'containers/JournalNumber/ReferenceNumberForm';
|
|
|
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
|
import withSettings from 'containers/Settings/withSettings';
|
|
import withSettingsActions from 'containers/Settings/withSettingsActions';
|
|
// import withInvoicesActions from 'containers/Sales/Invoice/withInvoiceActions';
|
|
|
|
import { compose, optionsMapToArray } from 'utils';
|
|
|
|
/**
|
|
* invoice number dialog's content.
|
|
*/
|
|
|
|
function InvoiceNumberDialogContent({
|
|
// #withSettings
|
|
nextNumber,
|
|
numberPrefix,
|
|
|
|
// #withSettingsActions
|
|
requestFetchOptions,
|
|
requestSubmitOptions,
|
|
|
|
// #withDialogActions
|
|
closeDialog,
|
|
|
|
// #withInvoicesActions
|
|
// setInvoiceNumberChanged,
|
|
}) {
|
|
const fetchSettings = useQuery(['settings'], () => requestFetchOptions({}));
|
|
|
|
const handleSubmitForm = (values, { setSubmitting }) => {
|
|
const options = optionsMapToArray(values).map((option) => {
|
|
return { key: option.key, ...option, group: 'sales_invoices' };
|
|
});
|
|
|
|
requestSubmitOptions({ options })
|
|
.then(() => {
|
|
setSubmitting(false);
|
|
closeDialog('invoice-number-form');
|
|
|
|
setTimeout(() => {
|
|
queryCache.invalidateQueries('settings');
|
|
// setInvoiceNumberChanged(true);
|
|
}, 250);
|
|
})
|
|
.catch(() => {
|
|
setSubmitting(false);
|
|
});
|
|
};
|
|
|
|
const handleClose = useCallback(() => {
|
|
closeDialog('invoice-number-form');
|
|
}, [closeDialog]);
|
|
|
|
return (
|
|
<DialogContent isLoading={fetchSettings.isFetching}>
|
|
<ReferenceNumberForm
|
|
initialNumber={nextNumber}
|
|
initialPrefix={numberPrefix}
|
|
onSubmit={handleSubmitForm}
|
|
onClose={handleClose}
|
|
/>
|
|
</DialogContent>
|
|
);
|
|
}
|
|
|
|
export default compose(
|
|
withDialogActions,
|
|
withSettingsActions,
|
|
withSettings(({ invoiceSettings }) => ({
|
|
nextNumber: invoiceSettings?.nextNumber,
|
|
numberPrefix: invoiceSettings?.numberPrefix,
|
|
})),
|
|
// withInvoicesActions,
|
|
)(InvoiceNumberDialogContent);
|