mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
re-structure to monorepo.
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
// @ts-nocheck
|
||||
import React, { useCallback } from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { DialogContent } from '@/components';
|
||||
|
||||
import { useSettingsReceipts, useSaveSettings } from '@/hooks/query';
|
||||
import ReferenceNumberForm from '@/containers/JournalNumber/ReferenceNumberForm';
|
||||
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
|
||||
import { compose, saveInvoke } from '@/utils';
|
||||
import {
|
||||
transformFormToSettings,
|
||||
transformSettingsToForm,
|
||||
} from '@/containers/JournalNumber/utils';
|
||||
|
||||
/**
|
||||
* Receipt number dialog's content.
|
||||
*/
|
||||
function ReceiptNumberDialogContent({
|
||||
// #ownProps
|
||||
receiptId,
|
||||
onConfirm,
|
||||
initialValues,
|
||||
|
||||
// #withSettings
|
||||
nextNumber,
|
||||
numberPrefix,
|
||||
autoIncrement,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const [referenceFormValues, setReferenceFormValues] = React.useState(null);
|
||||
|
||||
const { isLoading: isSettingsLoading } = useSettingsReceipts();
|
||||
const { mutateAsync: saveSettingsMutate } = useSaveSettings();
|
||||
|
||||
// Handle the form submit.
|
||||
const handleSubmitForm = (values, { setSubmitting }) => {
|
||||
const handleSuccess = () => {
|
||||
setSubmitting(false);
|
||||
closeDialog('receipt-number-form');
|
||||
saveInvoke(onConfirm, values);
|
||||
};
|
||||
const handleErrors = () => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
if (values.incrementMode === 'manual-transaction') {
|
||||
handleSuccess();
|
||||
return;
|
||||
}
|
||||
// Transformes the form values to settings to save it.
|
||||
const options = transformFormToSettings(values, 'sales_receipts');
|
||||
|
||||
saveSettingsMutate({ options }).then(handleSuccess).catch(handleErrors);
|
||||
};
|
||||
|
||||
const handleClose = useCallback(() => {
|
||||
closeDialog('receipt-number-form');
|
||||
}, [closeDialog]);
|
||||
|
||||
// Handle form change.
|
||||
const handleChange = (values) => {
|
||||
setReferenceFormValues(values);
|
||||
};
|
||||
|
||||
// Description.
|
||||
const description =
|
||||
referenceFormValues?.incrementMode === 'auto'
|
||||
? intl.get('receipt.auto_increment.auto')
|
||||
: intl.get('receipt.auto_increment.manually');
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isSettingsLoading}>
|
||||
<ReferenceNumberForm
|
||||
initialValues={{
|
||||
...transformSettingsToForm({
|
||||
nextNumber,
|
||||
numberPrefix,
|
||||
autoIncrement,
|
||||
}),
|
||||
...initialValues,
|
||||
}}
|
||||
onSubmit={handleSubmitForm}
|
||||
onClose={handleClose}
|
||||
onChange={handleChange}
|
||||
description={description}
|
||||
/>
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettings(({ receiptSettings }) => ({
|
||||
nextNumber: receiptSettings?.nextNumber,
|
||||
numberPrefix: receiptSettings?.numberPrefix,
|
||||
autoIncrement: receiptSettings?.autoIncrement,
|
||||
})),
|
||||
)(ReceiptNumberDialogContent);
|
||||
@@ -0,0 +1,42 @@
|
||||
// @ts-nocheck
|
||||
import React, { lazy } from 'react';
|
||||
import { Dialog, DialogSuspense, FormattedMessage as T } from '@/components';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import { compose, saveInvoke } from '@/utils';
|
||||
|
||||
const ReceiptNumberDialogContent = lazy(
|
||||
() => import('./ReceiptNumberDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Sale receipt number dialog.
|
||||
*/
|
||||
function ReceiptNumberDialog({
|
||||
dialogName,
|
||||
payload: { initialFormValues = {} },
|
||||
isOpen,
|
||||
onConfirm,
|
||||
}) {
|
||||
const handleConfirm = (values) => {
|
||||
saveInvoke(onConfirm, values);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={<T id={'receipt_number_settings'} />}
|
||||
autoFocus={true}
|
||||
canEscapeKeyClose={true}
|
||||
isOpen={isOpen}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<ReceiptNumberDialogContent
|
||||
initialValues={{ ...initialFormValues }}
|
||||
onConfirm={handleConfirm}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(ReceiptNumberDialog);
|
||||
Reference in New Issue
Block a user