diff --git a/packages/webapp/src/components/DialogsContainer.tsx b/packages/webapp/src/components/DialogsContainer.tsx index 7b6fa7cf1..9e334af78 100644 --- a/packages/webapp/src/components/DialogsContainer.tsx +++ b/packages/webapp/src/components/DialogsContainer.tsx @@ -17,8 +17,8 @@ import AllocateLandedCostDialog from '@/containers/Dialogs/AllocateLandedCostDia import InvoicePdfPreviewDialog from '@/containers/Dialogs/InvoicePdfPreviewDialog'; import EstimatePdfPreviewDialog from '@/containers/Dialogs/EstimatePdfPreviewDialog'; import ReceiptPdfPreviewDialog from '@/containers/Dialogs/ReceiptPdfPreviewDialog'; -import MoneyInDialog from '@/containers/Dialogs/MoneyInDialog'; -import MoneyOutDialog from '@/containers/Dialogs/MoneyOutDialog'; +import MoneyInDialog from '@/containers/CashFlow/MoneyInDialog'; +import MoneyOutDialog from '@/containers/CashFlow/MoneyOutDialog'; import BadDebtDialog from '@/containers/Dialogs/BadDebtDialog'; import NotifyInvoiceViaSMSDialog from '@/containers/Dialogs/NotifyInvoiceViaSMSDialog'; import NotifyReceiptViaSMSDialog from '@/containers/Dialogs/NotifyReceiptViaSMSDialog'; diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInContentFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInContentFields.tsx similarity index 95% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInContentFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInContentFields.tsx index 15ebc9f95..ee862b763 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInContentFields.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInContentFields.tsx @@ -1,9 +1,15 @@ // @ts-nocheck import React from 'react'; + import OwnerContributionFormFields from './OwnerContribution/OwnerContributionFormFields'; import OtherIncomeFormFields from './OtherIncome/OtherIncomeFormFields'; import TransferFromAccountFormFields from './TransferFromAccount/TransferFromAccountFormFields'; +/** + * + * @param param0 + * @returns + */ export default function MoneyInContentFields({ accountType }) { const handleTransactionType = () => { switch (accountType) { @@ -19,6 +25,5 @@ export default function MoneyInContentFields({ accountType }) { break; } }; - return {handleTransactionType()}; } diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInDialogContent.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInDialogContent.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInDialogContent.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInDialogContent.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInDialogProvider.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInDialogProvider.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInDialogProvider.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInDialogProvider.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFloatingActions.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFloatingActions.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFloatingActions.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFloatingActions.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInForm.schema.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInForm.schema.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInForm.schema.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInForm.schema.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInForm.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInForm.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInForm.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInForm.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFormContent.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormContent.tsx similarity index 79% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFormContent.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormContent.tsx index d107daafb..2e5edf5e5 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFormContent.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormContent.tsx @@ -5,6 +5,7 @@ import { Form } from 'formik'; import MoneyInFormFields from './MoneyInFormFields'; import MoneyInFormDialog from './MoneyInFormDialog'; import MoneyInFloatingActions from './MoneyInFloatingActions'; +import { MoneyInOutSyncIncrementSettingsToForm } from '../_components'; /** * Money In form content. @@ -15,6 +16,7 @@ export default function MoneyInFormContent() { + ); } diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFormDialog.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormDialog.tsx similarity index 73% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFormDialog.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormDialog.tsx index 3207b2352..d401865dd 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFormDialog.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormDialog.tsx @@ -11,12 +11,9 @@ export default function MoneyInFormDialog() { const { setFieldValue } = useFormikContext(); // Update the form once the transaction number form submit confirm. - const handleTransactionNumberFormConfirm = ({ - incrementNumber, - manually, - }) => { - setFieldValue('transaction_number', incrementNumber || ''); - setFieldValue('transaction_number_manually', manually); + const handleTransactionNumberFormConfirm = (settings) => { + setFieldValue('transaction_number', settings.transactionNumber); + setFieldValue('transaction_number_manually', settings.transactionNumber); }; return ( diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormFields.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/MoneyInFormFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormFields.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx similarity index 71% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx index ce479225b..06ccffea0 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx @@ -16,14 +16,12 @@ import { InputPrependText, MoneyInputGroup, FieldRequiredHint, - Icon, Col, Row, If, FeatureCan, BranchSelect, BranchSelectButton, - InputPrependButton, ExchangeRateMutedField, } from '@/components'; import { DateInput } from '@blueprintjs/datetime'; @@ -35,65 +33,26 @@ import { momentFormatter, tansformDateValue, handleDateChange, - compose, } from '@/utils'; import { useMoneyInDailogContext } from '../MoneyInDialogProvider'; import { - useObserveTransactionNoSettings, useSetPrimaryBranchToForm, useForeignAccount, BranchRowDivider, } from '../utils'; -import withSettings from '@/containers/Settings/withSettings'; -import withDialogActions from '@/containers/Dialog/withDialogActions'; +import { MoneyInOutTransactionNoField } from '../../_components'; /** * Other income form fields. */ -function OtherIncomeFormFields({ - // #withDialogActions - openDialog, - - // #withSettings - transactionAutoIncrement, - transactionNumberPrefix, - transactionNextNumber, -}) { +export default function OtherIncomeFormFields() { // Money in dialog context. const { accounts, account, branches } = useMoneyInDailogContext(); - const { values } = useFormikContext(); - const amountFieldRef = useAutofocus(); - const isForeigAccount = useForeignAccount(); - // Handle tranaction number changing. - const handleTransactionNumberChange = () => { - openDialog('transaction-number-form'); - }; - - // Handle transaction no. field blur. - const handleTransactionNoBlur = (form, field) => (event) => { - const newValue = event.target.value; - - if (field.value !== newValue && transactionAutoIncrement) { - openDialog('transaction-number-form', { - initialFormValues: { - manualTransactionNo: newValue, - incrementMode: 'manual-transaction', - }, - }); - } - }; - - // Syncs transaction number settings with form. - useObserveTransactionNoSettings( - transactionNumberPrefix, - transactionNextNumber, - ); - // Sets the primary branch to form. useSetPrimaryBranchToForm(); @@ -149,42 +108,7 @@ function OtherIncomeFormFields({ {/*------------ Transaction number -----------*/} - - {({ form, field, meta: { error, touched } }) => ( - } - intent={inputIntent({ error, touched })} - helperText={} - className={'form-group--transaction_number'} - > - - - , - }} - tooltip={true} - tooltipProps={{ - content: ( - - ), - position: Position.BOTTOM_LEFT, - }} - /> - - - )} - + {/*------------ amount -----------*/} @@ -298,12 +222,3 @@ function OtherIncomeFormFields({ ); } - -export default compose( - withDialogActions, - withSettings(({ cashflowSetting }) => ({ - transactionAutoIncrement: cashflowSetting?.autoIncrement, - transactionNextNumber: cashflowSetting?.nextNumber, - transactionNumberPrefix: cashflowSetting?.numberPrefix, - })), -)(OtherIncomeFormFields); diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx similarity index 71% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx index e12598955..204de591b 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx @@ -17,11 +17,9 @@ import { InputPrependText, MoneyInputGroup, FieldRequiredHint, - Icon, Col, Row, If, - InputPrependButton, ExchangeRateMutedField, BranchSelect, BranchSelectButton, @@ -35,31 +33,20 @@ import { momentFormatter, tansformDateValue, handleDateChange, - compose, } from '@/utils'; import { useMoneyInDailogContext } from '../MoneyInDialogProvider'; import { - useObserveTransactionNoSettings, useSetPrimaryBranchToForm, useForeignAccount, BranchRowDivider, } from '../../MoneyInDialog/utils'; -import withSettings from '@/containers/Settings/withSettings'; -import withDialogActions from '@/containers/Dialog/withDialogActions'; +import { MoneyInOutTransactionNoField } from '../../_components'; /** /** * Owner contribution form fields. */ -function OwnerContributionFormFields({ - // #withDialogActions - openDialog, - - // #withSettings - transactionAutoIncrement, - transactionNumberPrefix, - transactionNextNumber, -}) { +export default function OwnerContributionFormFields() { // Money in dialog context. const { accounts, account, branches } = useMoneyInDailogContext(); @@ -69,31 +56,6 @@ function OwnerContributionFormFields({ const isForeigAccount = useForeignAccount(); - // Handle tranaction number changing. - const handleTransactionNumberChange = () => { - openDialog('transaction-number-form'); - }; - - // Handle transaction no. field blur. - const handleTransactionNoBlur = (form, field) => (event) => { - const newValue = event.target.value; - - if (field.value !== newValue && transactionAutoIncrement) { - openDialog('transaction-number-form', { - initialFormValues: { - manualTransactionNo: newValue, - incrementMode: 'manual-transaction', - }, - }); - } - }; - - // Syncs transaction number settings with form. - useObserveTransactionNoSettings( - transactionNumberPrefix, - transactionNextNumber, - ); - // Sets the primary branch to form. useSetPrimaryBranchToForm(); @@ -148,42 +110,7 @@ function OwnerContributionFormFields({ {/*------------ Transaction number -----------*/} - - {({ form, field, meta: { error, touched } }) => ( - } - intent={inputIntent({ error, touched })} - helperText={} - className={'form-group--transaction_number'} - > - - - , - }} - tooltip={true} - tooltipProps={{ - content: ( - - ), - position: Position.BOTTOM_LEFT, - }} - /> - - - )} - + {/*------------ amount -----------*/} @@ -294,12 +221,3 @@ function OwnerContributionFormFields({ ); } - -export default compose( - withDialogActions, - withSettings(({ cashflowSetting }) => ({ - transactionAutoIncrement: cashflowSetting?.autoIncrement, - transactionNextNumber: cashflowSetting?.nextNumber, - transactionNumberPrefix: cashflowSetting?.numberPrefix, - })), -)(OwnerContributionFormFields); diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/TransactionTypeFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransactionTypeFields.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/TransactionTypeFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/TransactionTypeFields.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx similarity index 71% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx index 54539bd0c..0aba83da9 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx @@ -17,11 +17,9 @@ import { InputPrependText, MoneyInputGroup, FieldRequiredHint, - Icon, Col, Row, If, - InputPrependButton, ExchangeRateMutedField, FeatureCan, BranchSelect, @@ -35,30 +33,20 @@ import { momentFormatter, tansformDateValue, handleDateChange, - compose, } from '@/utils'; import { useMoneyInDailogContext } from '../MoneyInDialogProvider'; import { - useObserveTransactionNoSettings, useSetPrimaryBranchToForm, useForeignAccount, BranchRowDivider, } from '../../MoneyInDialog/utils'; -import withSettings from '@/containers/Settings/withSettings'; -import withDialogActions from '@/containers/Dialog/withDialogActions'; + +import { MoneyInOutTransactionNoField } from '../../_components'; /** * Transfer from account form fields. */ -function TransferFromAccountFormFields({ - // #withDialogActions - openDialog, - - // #withSettings - transactionAutoIncrement, - transactionNumberPrefix, - transactionNextNumber, -}) { +export default function TransferFromAccountFormFields() { // Money in dialog context. const { accounts, account, branches } = useMoneyInDailogContext(); @@ -67,33 +55,9 @@ function TransferFromAccountFormFields({ const { values } = useFormikContext(); - // Handle tranaction number changing. - const handleTransactionNumberChange = () => { - openDialog('transaction-number-form'); - }; - - // Handle transaction no. field blur. - const handleTransactionNoBlur = (form, field) => (event) => { - const newValue = event.target.value; - - if (field.value !== newValue && transactionAutoIncrement) { - openDialog('transaction-number-form', { - initialFormValues: { - manualTransactionNo: newValue, - incrementMode: 'manual-transaction', - }, - }); - } - }; - // Sets the primary branch to form. useSetPrimaryBranchToForm(); - // Syncs transaction number settings with form. - useObserveTransactionNoSettings( - transactionNumberPrefix, - transactionNextNumber, - ); return ( @@ -145,42 +109,7 @@ function TransferFromAccountFormFields({ {/*------------ Transaction number -----------*/} - - {({ form, field, meta: { error, touched } }) => ( - } - intent={inputIntent({ error, touched })} - helperText={} - className={'form-group--transaction_number'} - > - - - , - }} - tooltip={true} - tooltipProps={{ - content: ( - - ), - position: Position.BOTTOM_LEFT, - }} - /> - - - )} - + {/*------------ amount -----------*/} @@ -296,12 +225,3 @@ function TransferFromAccountFormFields({ ); } - -export default compose( - withDialogActions, - withSettings(({ cashflowSetting }) => ({ - transactionAutoIncrement: cashflowSetting?.autoIncrement, - transactionNextNumber: cashflowSetting?.nextNumber, - transactionNumberPrefix: cashflowSetting?.numberPrefix, - })), -)(TransferFromAccountFormFields); diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/index.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/index.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/index.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/index.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyInDialog/utils.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/utils.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyInDialog/utils.tsx rename to packages/webapp/src/containers/CashFlow/MoneyInDialog/utils.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutContentFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutContentFields.tsx similarity index 99% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutContentFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutContentFields.tsx index 88f2b9769..5f0f18876 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutContentFields.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutContentFields.tsx @@ -20,7 +20,6 @@ function MoneyOutContentFields({ accountType }) { break; } }; - return {handleTransactionType()}; } diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutDialogContent.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutDialogContent.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutDialogContent.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutDialogContent.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutDialogProvider.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutDialogProvider.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutDialogProvider.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutDialogProvider.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutFloatingActions.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFloatingActions.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutFloatingActions.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFloatingActions.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutForm.schema.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutForm.schema.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutForm.schema.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutForm.schema.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutForm.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutForm.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutForm.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutForm.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutFormContent.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFormContent.tsx similarity index 65% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutFormContent.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFormContent.tsx index ba8414ca7..41eb1eb83 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutFormContent.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFormContent.tsx @@ -3,8 +3,10 @@ import React from 'react'; import { Form } from 'formik'; import MoneyOutFormFields from './MoneyOutFormFields'; -import MoneyOutFormDialog from './MoneyOutFormDialog' +import MoneyOutFormDialog from './MoneyOutFormDialog'; import MoneyOutFloatingActions from './MoneyOutFloatingActions'; +import { MoneyInOutSyncIncrementSettingsToForm } from '../_components'; + /** * Money out form content. */ @@ -12,8 +14,9 @@ export default function MoneyOutFormContent() { return (
- + + ); } diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutFormDialog.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFormDialog.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutFormDialog.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFormDialog.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFormFields.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/MoneyOutFormFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFormFields.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/OtherExpense/OtherExpnseFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/OtherExpense/OtherExpnseFormFields.tsx similarity index 71% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/OtherExpense/OtherExpnseFormFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/OtherExpense/OtherExpnseFormFields.tsx index a828bcab4..bfbdf845c 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/OtherExpense/OtherExpnseFormFields.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/OtherExpense/OtherExpnseFormFields.tsx @@ -16,11 +16,9 @@ import { InputPrependText, MoneyInputGroup, FieldRequiredHint, - Icon, Col, Row, If, - InputPrependButton, FeatureCan, BranchSelect, BranchSelectButton, @@ -35,31 +33,21 @@ import { momentFormatter, tansformDateValue, handleDateChange, - compose, } from '@/utils'; import { CLASSES } from '@/constants/classes'; import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider'; import { - useObserveTransactionNoSettings, useSetPrimaryBranchToForm, useForeignAccount, BranchRowDivider, } from '../utils'; -import withSettings from '@/containers/Settings/withSettings'; -import withDialogActions from '@/containers/Dialog/withDialogActions'; + +import { MoneyInOutTransactionNoField } from '../../_components'; /** * Other expense form fields. */ -function OtherExpnseFormFields({ - // #withDialogActions - openDialog, - - // #withSettings - transactionAutoIncrement, - transactionNumberPrefix, - transactionNextNumber, -}) { +export default function OtherExpnseFormFields() { // Money in dialog context. const { accounts, account, branches } = useMoneyOutDialogContext(); @@ -68,31 +56,6 @@ function OtherExpnseFormFields({ const amountFieldRef = useAutofocus(); - // Handle tranaction number changing. - const handleTransactionNumberChange = () => { - openDialog('transaction-number-form'); - }; - - // Handle transaction no. field blur. - const handleTransactionNoBlur = (form, field) => (event) => { - const newValue = event.target.value; - - if (field.value !== newValue && transactionAutoIncrement) { - openDialog('transaction-number-form', { - initialFormValues: { - manualTransactionNo: newValue, - incrementMode: 'manual-transaction', - }, - }); - } - }; - - // Syncs transaction number settings with form. - useObserveTransactionNoSettings( - transactionNumberPrefix, - transactionNextNumber, - ); - // Sets the primary branch to form. useSetPrimaryBranchToForm(); @@ -147,42 +110,7 @@ function OtherExpnseFormFields({ {/*------------ Transaction number -----------*/} - - {({ form, field, meta: { error, touched } }) => ( - } - intent={inputIntent({ error, touched })} - helperText={} - className={'form-group--transaction_number'} - > - - - , - }} - tooltip={true} - tooltipProps={{ - content: ( - - ), - position: Position.BOTTOM_LEFT, - }} - /> - - - )} - + {/*------------ amount -----------*/} @@ -296,12 +224,3 @@ function OtherExpnseFormFields({ ); } - -export default compose( - withDialogActions, - withSettings(({ cashflowSetting }) => ({ - transactionAutoIncrement: cashflowSetting?.autoIncrement, - transactionNextNumber: cashflowSetting?.nextNumber, - transactionNumberPrefix: cashflowSetting?.numberPrefix, - })), -)(OtherExpnseFormFields); diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/OwnerDrawings/OwnerDrawingsFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/OwnerDrawings/OwnerDrawingsFormFields.tsx similarity index 71% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/OwnerDrawings/OwnerDrawingsFormFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/OwnerDrawings/OwnerDrawingsFormFields.tsx index bbdd0c783..8630c5b03 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/OwnerDrawings/OwnerDrawingsFormFields.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/OwnerDrawings/OwnerDrawingsFormFields.tsx @@ -17,8 +17,6 @@ import { InputPrependText, MoneyInputGroup, FieldRequiredHint, - InputPrependButton, - Icon, If, Col, Row, @@ -34,30 +32,19 @@ import { momentFormatter, tansformDateValue, handleDateChange, - compose, } from '@/utils'; import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider'; import { - useObserveTransactionNoSettings, useSetPrimaryBranchToForm, useForeignAccount, BranchRowDivider, } from '../../MoneyOutDialog/utils'; -import withSettings from '@/containers/Settings/withSettings'; -import withDialogActions from '@/containers/Dialog/withDialogActions'; +import { MoneyInOutTransactionNoField } from '../../_components'; /** * Owner drawings form fields. */ -function OwnerDrawingsFormFields({ - // #withDialogActions - openDialog, - - // #withSettings - transactionAutoIncrement, - transactionNumberPrefix, - transactionNextNumber, -}) { +export default function OwnerDrawingsFormFields() { // Money out dialog context. const { accounts, account, branches } = useMoneyOutDialogContext(); const { values } = useFormikContext(); @@ -65,31 +52,6 @@ function OwnerDrawingsFormFields({ const amountFieldRef = useAutofocus(); - // Handle tranaction number changing. - const handleTransactionNumberChange = () => { - openDialog('transaction-number-form'); - }; - - // Handle transaction no. field blur. - const handleTransactionNoBlur = (form, field) => (event) => { - const newValue = event.target.value; - - if (field.value !== newValue && transactionAutoIncrement) { - openDialog('transaction-number-form', { - initialFormValues: { - manualTransactionNo: newValue, - incrementMode: 'manual-transaction', - }, - }); - } - }; - - // Syncs transaction number settings with form. - useObserveTransactionNoSettings( - transactionNumberPrefix, - transactionNextNumber, - ); - // Sets the primary branch to form. useSetPrimaryBranchToForm(); @@ -144,42 +106,7 @@ function OwnerDrawingsFormFields({ {/*------------ Transaction number -----------*/} - - {({ form, field, meta: { error, touched } }) => ( - } - intent={inputIntent({ error, touched })} - helperText={} - className={'form-group--transaction_number'} - > - - - , - }} - tooltip={true} - tooltipProps={{ - content: ( - - ), - position: Position.BOTTOM_LEFT, - }} - /> - - - )} - + {/*------------ amount -----------*/} @@ -291,12 +218,3 @@ function OwnerDrawingsFormFields({ ); } - -export default compose( - withDialogActions, - withSettings(({ cashflowSetting }) => ({ - transactionAutoIncrement: cashflowSetting?.autoIncrement, - transactionNextNumber: cashflowSetting?.nextNumber, - transactionNumberPrefix: cashflowSetting?.numberPrefix, - })), -)(OwnerDrawingsFormFields); diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/TransactionTypeFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/TransactionTypeFields.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/TransactionTypeFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/TransactionTypeFields.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/TransferToAccount/TransferToAccountFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/TransferToAccount/TransferToAccountFormFields.tsx similarity index 73% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/TransferToAccount/TransferToAccountFormFields.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/TransferToAccount/TransferToAccountFormFields.tsx index 164920439..ff8a986e8 100644 --- a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/TransferToAccount/TransferToAccountFormFields.tsx +++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/TransferToAccount/TransferToAccountFormFields.tsx @@ -48,19 +48,12 @@ import { } from '../utils'; import withSettings from '@/containers/Settings/withSettings'; import withDialogActions from '@/containers/Dialog/withDialogActions'; +import { MoneyInOutTransactionNoField } from '../../_components'; /** * Transfer to account form fields. */ -function TransferToAccountFormFields({ - // #withDialogActions - openDialog, - - // #withSettings - transactionAutoIncrement, - transactionNumberPrefix, - transactionNextNumber, -}) { +export default function TransferToAccountFormFields() { // Money in dialog context. const { accounts, account, branches } = useMoneyOutDialogContext(); const { values } = useFormikContext(); @@ -68,31 +61,6 @@ function TransferToAccountFormFields({ const accountRef = useAutofocus(); - // Handle tranaction number changing. - const handleTransactionNumberChange = () => { - openDialog('transaction-number-form'); - }; - - // Handle transaction no. field blur. - const handleTransactionNoBlur = (form, field) => (event) => { - const newValue = event.target.value; - - if (field.value !== newValue && transactionAutoIncrement) { - openDialog('transaction-number-form', { - initialFormValues: { - manualTransactionNo: newValue, - incrementMode: 'manual-transaction', - }, - }); - } - }; - - // Syncs transaction number settings with form. - useObserveTransactionNoSettings( - transactionNumberPrefix, - transactionNextNumber, - ); - // Sets the primary branch to form. useSetPrimaryBranchToForm(); @@ -147,42 +115,7 @@ function TransferToAccountFormFields({ {/*------------ Transaction number -----------*/} - - {({ form, field, meta: { error, touched } }) => ( - } - intent={inputIntent({ error, touched })} - helperText={} - className={'form-group--transaction_number'} - > - - - , - }} - tooltip={true} - tooltipProps={{ - content: ( - - ), - position: Position.BOTTOM_LEFT, - }} - /> - - - )} - + {/*------------ amount -----------*/} @@ -298,11 +231,3 @@ function TransferToAccountFormFields({ ); } -export default compose( - withDialogActions, - withSettings(({ cashflowSetting }) => ({ - transactionAutoIncrement: cashflowSetting?.autoIncrement, - transactionNextNumber: cashflowSetting?.nextNumber, - transactionNumberPrefix: cashflowSetting?.numberPrefix, - })), -)(TransferToAccountFormFields); diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/index.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/index.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/index.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/index.tsx diff --git a/packages/webapp/src/containers/Dialogs/MoneyOutDialog/utils.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/utils.tsx similarity index 100% rename from packages/webapp/src/containers/Dialogs/MoneyOutDialog/utils.tsx rename to packages/webapp/src/containers/CashFlow/MoneyOutDialog/utils.tsx diff --git a/packages/webapp/src/containers/CashFlow/_components.tsx b/packages/webapp/src/containers/CashFlow/_components.tsx new file mode 100644 index 000000000..4b9e7ca86 --- /dev/null +++ b/packages/webapp/src/containers/CashFlow/_components.tsx @@ -0,0 +1,127 @@ +// @ts-nocheck +import React from 'react'; +import { useFormikContext } from 'formik'; +import { InputGroup, Position, ControlGroup } from '@blueprintjs/core'; +import * as R from 'ramda'; + +import { + FFormGroup, + Icon, + InputPrependButton, + FormattedMessage as T, +} from '@/components'; +import { useUpdateEffect } from '@/hooks'; + +import withSettings from '@/containers/Settings/withSettings'; +import withDialogActions from '@/containers/Dialog/withDialogActions'; + +/** + * Syncs cashflow auto-increment settings to the form once update. + */ +export const MoneyInOutSyncIncrementSettingsToForm = R.compose( + withDialogActions, + withSettings(({ cashflowSetting }) => ({ + transactionAutoIncrement: cashflowSetting?.autoIncrement, + transactionNextNumber: cashflowSetting?.nextNumber, + transactionNumberPrefix: cashflowSetting?.numberPrefix, + })), +)( + ({ + // #withSettings + transactionAutoIncrement, + transactionNextNumber, + transactionNumberPrefix, + }) => { + const { setFieldValue } = useFormikContext(); + + useUpdateEffect(() => { + // Do not update if the invoice auto-increment is disabled. + if (!transactionAutoIncrement) return null; + + const transactionNumber = transactionNumber( + transactionNumberPrefix, + transactionNextNumber, + ); + setFieldValue('transaction_number', transactionNumber); + }, [setFieldValue, transactionNumberPrefix, transactionNextNumber]); + + return null; + }, +); + +/** + * Money In/Out transaction number field. + */ +export const MoneyInOutTransactionNoField = R.compose( + withDialogActions, + withSettings(({ cashflowSetting }) => ({ + transactionAutoIncrement: cashflowSetting?.autoIncrement, + transactionNextNumber: cashflowSetting?.nextNumber, + transactionNumberPrefix: cashflowSetting?.numberPrefix, + })), +)( + ({ + // #withDialogActions + openDialog, + + // #withSettings + transactionAutoIncrement, + }) => { + const { values, setFieldValue } = useFormikContext(); + + // Handle tranaction number changing. + const handleTransactionNumberChange = () => { + openDialog('transaction-number-form'); + }; + // Handle transaction no. field blur. + const handleTransactionNoBlur = (event) => { + const newValue = event.target.value; + + if (values.transaction_number !== newValue && transactionAutoIncrement) { + openDialog('transaction-number-form', { + initialFormValues: { + onceManualNumber: newValue, + incrementMode: 'manual-transaction', + }, + }); + } + if (!transactionAutoIncrement) { + setFieldValue('transaction_number', values.transaction_number); + setFieldValue('transaction_number_manually', values.transaction_number); + } + }; + + return ( + } + > + + + , + }} + tooltip={true} + tooltipProps={{ + content: ( + + ), + position: Position.BOTTOM_LEFT, + }} + /> + + + ); + }, +); diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeaderFields.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeaderFields.tsx index 0edeaf10a..eda324079 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeaderFields.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeaderFields.tsx @@ -10,7 +10,7 @@ import { ControlGroup, } from '@blueprintjs/core'; import { DateInput } from '@blueprintjs/datetime'; -import { FastField, Field, ErrorMessage, useFormikContext } from 'formik'; +import { FastField, ErrorMessage, useFormikContext } from 'formik'; import * as R from 'ramda'; import {