mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
re-structure to monorepo.
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import ReferenceNumberForm from '@/containers/JournalNumber/ReferenceNumberForm';
|
||||
import { useSaveSettings } from '@/hooks/query';
|
||||
import { WarehouseTransferNumberDialogProvider } from './WarehouseTransferNumberDialogProvider';
|
||||
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withSettingsActions from '@/containers/Settings/withSettingsActions';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { compose } from '@/utils';
|
||||
import {
|
||||
transformFormToSettings,
|
||||
transformSettingsToForm,
|
||||
} from '@/containers/JournalNumber/utils';
|
||||
|
||||
/**
|
||||
* Warehouse transfer no dialog content.
|
||||
*/
|
||||
function WarehouseTransferNumberDialogContent({
|
||||
// #ownProps
|
||||
initialValues,
|
||||
onConfirm,
|
||||
|
||||
// #withSettings
|
||||
nextNumber,
|
||||
numberPrefix,
|
||||
autoIncrement,
|
||||
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { mutateAsync: saveSettings } = useSaveSettings();
|
||||
const [referenceFormValues, setReferenceFormValues] = React.useState(null);
|
||||
|
||||
// Handle the submit form.
|
||||
const handleSubmitForm = (values, { setSubmitting }) => {
|
||||
// Handle the form success.
|
||||
const handleSuccess = () => {
|
||||
setSubmitting(false);
|
||||
closeDialog('warehouse-transfer-no-form');
|
||||
onConfirm(values);
|
||||
};
|
||||
|
||||
// Handle the form errors.
|
||||
const handleErrors = () => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
if (values.incrementMode === 'manual-transaction') {
|
||||
handleSuccess();
|
||||
return;
|
||||
}
|
||||
// Transformes the form values to settings to save it.
|
||||
const options = transformFormToSettings(values, 'warehouse_transfers');
|
||||
|
||||
// Save the settings.
|
||||
saveSettings({ options }).then(handleSuccess).catch(handleErrors);
|
||||
};
|
||||
|
||||
// Handle the dialog close.
|
||||
const handleClose = () => {
|
||||
closeDialog('warehouse-transfer-no-form');
|
||||
};
|
||||
|
||||
// Handle form change.
|
||||
const handleChange = (values) => {
|
||||
setReferenceFormValues(values);
|
||||
};
|
||||
// Description.
|
||||
const description =
|
||||
referenceFormValues?.incrementMode === 'auto'
|
||||
? intl.get('warehouse_transfer.auto_increment.auto')
|
||||
: intl.get('warehouse_transfer.auto_increment.manually');
|
||||
|
||||
return (
|
||||
<WarehouseTransferNumberDialogProvider>
|
||||
<ReferenceNumberForm
|
||||
initialValues={{
|
||||
...transformSettingsToForm({
|
||||
nextNumber,
|
||||
numberPrefix,
|
||||
autoIncrement,
|
||||
}),
|
||||
...initialValues,
|
||||
}}
|
||||
description={description}
|
||||
onSubmit={handleSubmitForm}
|
||||
onClose={handleClose}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</WarehouseTransferNumberDialogProvider>
|
||||
);
|
||||
}
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettingsActions,
|
||||
withSettings(({ warehouseTransferSettings }) => ({
|
||||
autoIncrement: warehouseTransferSettings?.autoIncrement,
|
||||
nextNumber: warehouseTransferSettings?.nextNumber,
|
||||
numberPrefix: warehouseTransferSettings?.numberPrefix,
|
||||
})),
|
||||
)(WarehouseTransferNumberDialogContent);
|
||||
@@ -0,0 +1,35 @@
|
||||
// @ts-nocheck
|
||||
import React, { createContext } from 'react';
|
||||
import { DialogContent } from '@/components';
|
||||
import { useSettingsWarehouseTransfers } from '@/hooks/query';
|
||||
|
||||
const WarehouseTransferNumberDilaogContext = createContext();
|
||||
|
||||
/**
|
||||
* Warehouse transfer number dialog provier.
|
||||
*/
|
||||
function WarehouseTransferNumberDialogProvider({ query, ...props }) {
|
||||
const { isLoading: isSettingsLoading } = useSettingsWarehouseTransfers();
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
isSettingsLoading,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isSettingsLoading}>
|
||||
<WarehouseTransferNumberDilaogContext.Provider
|
||||
value={provider}
|
||||
{...props}
|
||||
/>
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useWarehouseTransferNumberDialogContext = () =>
|
||||
React.useContext(WarehouseTransferNumberDilaogContext);
|
||||
|
||||
export {
|
||||
WarehouseTransferNumberDialogProvider,
|
||||
useWarehouseTransferNumberDialogContext,
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Dialog, DialogSuspense, FormattedMessage as T } from '@/components';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import { compose, saveInvoke } from '@/utils';
|
||||
|
||||
const WarehouseTransferNumberDialogContent = React.lazy(
|
||||
() => import('./WarehouseTransferNumberDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Warehouse transfer number dialog.
|
||||
*/
|
||||
function WarehouseTransferNumberDilaog({
|
||||
dialogName,
|
||||
payload: { initialFormValues },
|
||||
isOpen,
|
||||
onConfirm,
|
||||
}) {
|
||||
const handleConfirm = (values) => {
|
||||
saveInvoke(onConfirm, values);
|
||||
};
|
||||
return (
|
||||
<Dialog
|
||||
title={<T id={'warehouse_transfer_no_settings'} />}
|
||||
name={dialogName}
|
||||
autoFocus={true}
|
||||
canEscapeKeyClose={true}
|
||||
isOpen={isOpen}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<WarehouseTransferNumberDialogContent
|
||||
initialValues={{ ...initialFormValues }}
|
||||
onConfirm={handleConfirm}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogRedux())(WarehouseTransferNumberDilaog);
|
||||
Reference in New Issue
Block a user