mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { DialogContent } from 'components';
|
||||
import { useSaveSettings, useSettingsPaymentReceives } from 'hooks/query';
|
||||
|
||||
import ReferenceNumberForm from 'containers/JournalNumber/ReferenceNumberForm';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import withSettingsActions from 'containers/Settings/withSettingsActions';
|
||||
import withSettings from 'containers/Settings/withSettings';
|
||||
|
||||
import { saveInvoke, compose } from 'utils';
|
||||
import {
|
||||
transformFormToSettings,
|
||||
transformSettingsToForm,
|
||||
} from 'containers/JournalNumber/utils';
|
||||
|
||||
/**
|
||||
* Payment receive number dialog's content.
|
||||
*/
|
||||
function PaymentNumberDialogContent({
|
||||
// #withSettings
|
||||
nextNumber,
|
||||
numberPrefix,
|
||||
autoIncrement,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
|
||||
// #ownProps
|
||||
onConfirm,
|
||||
initialValues,
|
||||
}) {
|
||||
const [referenceFormValues, setReferenceFormValues] = React.useState(null);
|
||||
|
||||
const { isLoading: isSettingsLoading } = useSettingsPaymentReceives();
|
||||
const { mutateAsync: saveSettingsMutate } = useSaveSettings();
|
||||
|
||||
const initialFormValues = {
|
||||
...transformSettingsToForm({
|
||||
nextNumber,
|
||||
numberPrefix,
|
||||
autoIncrement,
|
||||
}),
|
||||
...initialValues,
|
||||
};
|
||||
|
||||
// Handle submit form.
|
||||
const handleSubmitForm = (values, { setSubmitting }) => {
|
||||
// Transformes the form values to settings to save it.
|
||||
const options = transformFormToSettings(values, 'payment_receives');
|
||||
|
||||
const handleSuccess = () => {
|
||||
setSubmitting(false);
|
||||
closeDialog('payment-receive-number-form');
|
||||
|
||||
saveInvoke(onConfirm, values);
|
||||
};
|
||||
const handleErrors = () => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
if (values.incrementMode === 'manual-transaction') {
|
||||
handleSuccess();
|
||||
return;
|
||||
}
|
||||
saveSettingsMutate({ options }).then(handleSuccess).catch(handleErrors);
|
||||
};
|
||||
|
||||
const handleClose = useCallback(() => {
|
||||
closeDialog('payment-receive-number-form');
|
||||
}, [closeDialog]);
|
||||
|
||||
// Handle form change.
|
||||
const handleChange = (values) => {
|
||||
setReferenceFormValues(values);
|
||||
};
|
||||
|
||||
// Description.
|
||||
const description =
|
||||
referenceFormValues?.incrementMode === 'auto'
|
||||
? intl.get('payment_receive.auto_increment.auto')
|
||||
: intl.get('payment_receive.auto_increment.manually');
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isSettingsLoading}>
|
||||
<ReferenceNumberForm
|
||||
initialValues={initialFormValues}
|
||||
onSubmit={handleSubmitForm}
|
||||
onClose={handleClose}
|
||||
onChange={handleChange}
|
||||
description={description}
|
||||
/>
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettingsActions,
|
||||
withSettings(({ paymentReceiveSettings }) => ({
|
||||
nextNumber: paymentReceiveSettings?.nextNumber,
|
||||
numberPrefix: paymentReceiveSettings?.numberPrefix,
|
||||
autoIncrement: paymentReceiveSettings?.autoIncrement,
|
||||
})),
|
||||
)(PaymentNumberDialogContent);
|
||||
38
src/containers/Dialogs/PaymentReceiveNumberDialog/index.js
Normal file
38
src/containers/Dialogs/PaymentReceiveNumberDialog/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import React, { lazy } from 'react';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import { Dialog, DialogSuspense } from 'components';
|
||||
import withDialogRedux from 'components/DialogReduxConnect';
|
||||
import { saveInvoke, compose } from 'utils';
|
||||
|
||||
const PaymentReceiveNumbereDialogContent = lazy(() =>
|
||||
import('./PaymentReceiveNumberDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Payment receive number dialog.
|
||||
*/
|
||||
function PaymentReceiveNumberDialog({
|
||||
dialogName,
|
||||
payload: { initialFormValues },
|
||||
isOpen,
|
||||
onConfirm
|
||||
}) {
|
||||
return (
|
||||
<Dialog
|
||||
title={<T id={'payment_number_settings'} />}
|
||||
name={dialogName}
|
||||
autoFocus={true}
|
||||
canEscapeKeyClose={true}
|
||||
isOpen={isOpen}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<PaymentReceiveNumbereDialogContent
|
||||
initialValues={initialFormValues}
|
||||
onConfirm={(values) => saveInvoke(onConfirm, values)}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(PaymentReceiveNumberDialog);
|
||||
Reference in New Issue
Block a user