diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInExchangeRateField.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInExchangeRateField.tsx
new file mode 100644
index 000000000..9f5dc056b
--- /dev/null
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInExchangeRateField.tsx
@@ -0,0 +1,26 @@
+// @ts-nocheck
+import React from 'react';
+import { ExchangeRateMutedField } from '@/components';
+import { useForeignAccount } from './utils';
+import { useFormikContext } from 'formik';
+import { useMoneyInFieldsContext } from './MoneyInFieldsProvider';
+
+export function MoneyInExchangeRateField() {
+ const { account } = useMoneyInFieldsContext();
+ const { values } = useFormikContext();
+
+ const isForeigAccount = useForeignAccount();
+
+ if (!isForeigAccount) return null;
+
+ return (
+
+ );
+}
diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFieldsProvider.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFieldsProvider.tsx
new file mode 100644
index 000000000..22756d430
--- /dev/null
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFieldsProvider.tsx
@@ -0,0 +1,34 @@
+// @ts-nocheck
+import React from 'react';
+import { DialogContent } from '@/components';
+import { useAccount } from '@/hooks/query';
+import { useMoneyInDailogContext } from './MoneyInDialogProvider';
+
+const MoneyInFieldsContext = React.createContext();
+
+/**
+ * Money in dialog provider.
+ */
+function MoneyInFieldsProvider({ ...props }) {
+ const { accountId } = useMoneyInDailogContext();
+
+ // Fetches the specific account details.
+ const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
+ enabled: !!accountId,
+ });
+ // Provider data.
+ const provider = {
+ account,
+ };
+ const isLoading = isAccountLoading;
+
+ return (
+
+
+
+ );
+}
+
+const useMoneyInFieldsContext = () => React.useContext(MoneyInFieldsContext);
+
+export { MoneyInFieldsProvider, useMoneyInFieldsContext };
diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInForm.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInForm.tsx
index e741e8ae5..9bdc1f9ed 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInForm.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInForm.tsx
@@ -53,7 +53,6 @@ function MoneyInForm({
accountId,
accountType,
createCashflowTransactionMutate,
- submitPayload,
} = useMoneyInDailogContext();
// transaction number.
@@ -61,7 +60,6 @@ function MoneyInForm({
transactionNumberPrefix,
transactionNextNumber,
);
-
// Initial form values.
const initialValues = {
...defaultInitialValues,
@@ -95,15 +93,13 @@ function MoneyInForm({
};
return (
-
-
-
-
-
+
+
+
);
}
diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormFields.tsx
index cd1e2a46d..ec6729dcc 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormFields.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/MoneyInFormFields.tsx
@@ -12,17 +12,13 @@ import { useMoneyInDailogContext } from './MoneyInDialogProvider';
* Money in form fields.
*/
function MoneyInFormFields() {
- const { values } = useFormikContext();
-
// Money in dialog context.
- const { accountId } = useMoneyInDailogContext();
+ const { defaultAccountId } = useMoneyInDailogContext();
return (
-
-
-
-
+ {!defaultAccountId && }
+
);
}
diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx
index 11d371cac..d17b47615 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/OtherIncome/OtherIncomeFormFields.tsx
@@ -1,10 +1,9 @@
// @ts-nocheck
import React from 'react';
-import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
+import { FastField, ErrorMessage } from 'formik';
import {
Classes,
FormGroup,
- InputGroup,
TextArea,
Position,
ControlGroup,
@@ -18,14 +17,15 @@ import {
FieldRequiredHint,
Col,
Row,
- If,
FeatureCan,
BranchSelect,
BranchSelectButton,
- ExchangeRateMutedField,
+ FInputGroup,
+ FFormGroup,
+ FTextArea,
+ FMoneyInputGroup,
} from '@/components';
import { DateInput } from '@blueprintjs/datetime';
-import { useAutofocus } from '@/hooks';
import { CLASSES, ACCOUNT_TYPE, Features } from '@/constants';
import {
@@ -36,22 +36,18 @@ import {
} from '@/utils';
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
-import {
- useSetPrimaryBranchToForm,
- useForeignAccount,
- BranchRowDivider,
-} from '../utils';
+import { useSetPrimaryBranchToForm, BranchRowDivider } from '../utils';
import { MoneyInOutTransactionNoField } from '../../_components';
+import { useMoneyInFieldsContext } from '../MoneyInFieldsProvider';
+import { MoneyInExchangeRateField } from '../MoneyInExchangeRateField';
/**
* Other income form fields.
*/
export default function OtherIncomeFormFields() {
// Money in dialog context.
- const { accounts, account, branches } = useMoneyInDailogContext();
- const { values } = useFormikContext();
- const amountFieldRef = useAutofocus();
- const isForeigAccount = useForeignAccount();
+ const { accounts, branches } = useMoneyInDailogContext();
+ const { account } = useMoneyInFieldsContext();
// Sets the primary branch to form.
useSetPrimaryBranchToForm();
@@ -61,17 +57,14 @@ export default function OtherIncomeFormFields() {
- }
- className={classNames('form-group--select-list', Classes.FILL)}
- >
+ }>
-
+
@@ -113,48 +106,25 @@ export default function OtherIncomeFormFields() {
- {/*------------ amount -----------*/}
-
- {({
- form: { values, setFieldValue },
- field: { value },
- meta: { error, touched },
- }) => (
-
+
+ }
labelInfo={}
- intent={inputIntent({ error, touched })}
- helperText={}
- className={'form-group--amount'}
>
-
- {
- setFieldValue('amount', amount);
- }}
- inputRef={(ref) => (amountFieldRef.current = ref)}
- intent={inputIntent({ error, touched })}
- />
+
-
- )}
-
+
+
+
+
+ {/*------------ Exchange rate -----------*/}
+
-
- {/*------------ exchange rate -----------*/}
-
-
{/*------------ other income account -----------*/}
@@ -184,43 +154,24 @@ export default function OtherIncomeFormFields() {
)}
+
{/*------------ Reference -----------*/}
-
- {({ form, field, meta: { error, touched } }) => (
- }
- intent={inputIntent({ error, touched })}
- helperText={}
- className={'form-group--reference-no'}
- >
-
-
- )}
-
+ } name={'reference_no'}>
+
+
- {/*------------ description -----------*/}
-
- {({ field, meta: { error, touched } }) => (
- }
- className={'form-group--description'}
- intent={inputIntent({ error, touched })}
- helperText={}
- >
-
-
- )}
-
+
+ {/*------------ Description -----------*/}
+ }>
+
+
);
}
diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx
index 204de591b..408a72078 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/OwnerContribution/OwnerContributionFormFields.tsx
@@ -1,32 +1,24 @@
// @ts-nocheck
import React from 'react';
-import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
-import {
- Classes,
- FormGroup,
- InputGroup,
- TextArea,
- Position,
- ControlGroup,
-} from '@blueprintjs/core';
+import { FastField, ErrorMessage } from 'formik';
+import { FormGroup, Position, ControlGroup } from '@blueprintjs/core';
import classNames from 'classnames';
-
+import { DateInput } from '@blueprintjs/datetime';
import {
FormattedMessage as T,
AccountsSuggestField,
InputPrependText,
- MoneyInputGroup,
FieldRequiredHint,
Col,
Row,
- If,
- ExchangeRateMutedField,
BranchSelect,
BranchSelectButton,
FeatureCan,
+ FFormGroup,
+ FMoneyInputGroup,
+ FTextArea,
+ FInputGroup,
} from '@/components';
-import { DateInput } from '@blueprintjs/datetime';
-import { useAutofocus } from '@/hooks';
import { ACCOUNT_TYPE, CLASSES, Features } from '@/constants';
import {
inputIntent,
@@ -37,10 +29,11 @@ import {
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
import {
useSetPrimaryBranchToForm,
- useForeignAccount,
BranchRowDivider,
} from '../../MoneyInDialog/utils';
import { MoneyInOutTransactionNoField } from '../../_components';
+import { useMoneyInFieldsContext } from '../MoneyInFieldsProvider';
+import { MoneyInExchangeRateField } from '../MoneyInExchangeRateField';
/**
/**
@@ -48,13 +41,8 @@ import { MoneyInOutTransactionNoField } from '../../_components';
*/
export default function OwnerContributionFormFields() {
// Money in dialog context.
- const { accounts, account, branches } = useMoneyInDailogContext();
-
- const { values } = useFormikContext();
-
- const amountFieldRef = useAutofocus();
-
- const isForeigAccount = useForeignAccount();
+ const { accounts, branches } = useMoneyInDailogContext();
+ const { account } = useMoneyInFieldsContext();
// Sets the primary branch to form.
useSetPrimaryBranchToForm();
@@ -64,21 +52,19 @@ export default function OwnerContributionFormFields() {
- }
- className={classNames('form-group--select-list', Classes.FILL)}
- >
+ }>
-
+
+
{/*------------ Date -----------*/}
@@ -113,47 +99,26 @@ export default function OwnerContributionFormFields() {
- {/*------------ amount -----------*/}
-
- {({
- form: { values, setFieldValue },
- field: { value },
- meta: { error, touched },
- }) => (
-
+
+ }
labelInfo={}
- intent={inputIntent({ error, touched })}
- helperText={}
- className={'form-group--amount'}
>
-
-
- {
- setFieldValue('amount', amount);
- }}
- inputRef={(ref) => (amountFieldRef.current = ref)}
- intent={inputIntent({ error, touched })}
- />
+
+
-
- )}
-
-
- {/*------------ exchange rate -----------*/}
-
-
+
+
+
+
+ {/*------------ Exchange rate -----------*/}
+
+
{/*------------ equity account -----------*/}
@@ -181,43 +146,24 @@ export default function OwnerContributionFormFields() {
)}
+
{/*------------ Reference -----------*/}
-
- {({ form, field, meta: { error, touched } }) => (
- }
- intent={inputIntent({ error, touched })}
- helperText={}
- className={'form-group--reference-no'}
- >
-
-
- )}
-
+ }>
+
+
- {/*------------ description -----------*/}
-
- {({ field, meta: { error, touched } }) => (
- }
- className={'form-group--description'}
- intent={inputIntent({ error, touched })}
- helperText={}
- >
-
-
- )}
-
+
+ {/*------------ Description -----------*/}
+ }>
+
+
);
}
diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransactionTypeFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransactionTypeFields.tsx
index 8a4c37ac4..b9fc9ac8c 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransactionTypeFields.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransactionTypeFields.tsx
@@ -10,6 +10,8 @@ import {
ListSelect,
Col,
Row,
+ FFormGroup,
+ FSelect,
} from '@/components';
import { inputIntent } from '@/utils';
import { CLASSES, getAddMoneyInOptions } from '@/constants';
@@ -21,7 +23,7 @@ import { useMoneyInDailogContext } from './MoneyInDialogProvider';
*/
export default function TransactionTypeFields() {
// Money in dialog context.
- const { cashflowAccounts } = useMoneyInDailogContext();
+ const { cashflowAccounts, setAccountId } = useMoneyInDailogContext();
// Retrieves the add money in button options.
const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []);
@@ -29,6 +31,23 @@ export default function TransactionTypeFields() {
return (
+
+ {/*------------ Transaction type -----------*/}
+ }
+ labelInfo={}
+ >
+
+
+
+
{/*------------ Current account -----------*/}
@@ -46,9 +65,10 @@ export default function TransactionTypeFields() {
>
- form.setFieldValue('cashflow_account_id', id)
- }
+ onAccountSelected={({ id }) => {
+ form.setFieldValue('cashflow_account_id', id);
+ setAccountId(id);
+ }}
inputProps={{
intent: inputIntent({ error, touched }),
}}
@@ -56,39 +76,6 @@ export default function TransactionTypeFields() {
)}
- {/*------------ Transaction type -----------*/}
-
-
-
- {({
- form: { values, setFieldValue },
- field: { value },
- meta: { error, touched },
- }) => (
- }
- labelInfo={}
- helperText={}
- intent={inputIntent({ error, touched })}
- className={classNames(
- CLASSES.FILL,
- 'form-group--transaction_type',
- )}
- >
- {
- setFieldValue('transaction_type', type.value);
- }}
- filterable={false}
- selectedItem={value}
- selectedItemProp={'value'}
- textProp={'name'}
- popoverProps={{ minimal: true }}
- />
-
- )}
-
diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx
index 0aba83da9..047d62e44 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/TransferFromAccount/TransferFromAccountFormFields.tsx
@@ -1,33 +1,27 @@
// @ts-nocheck
import React from 'react';
-import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
+import { FastField, ErrorMessage } from 'formik';
import { DateInput } from '@blueprintjs/datetime';
-import {
- Classes,
- FormGroup,
- InputGroup,
- TextArea,
- Position,
- ControlGroup,
-} from '@blueprintjs/core';
+import { FormGroup, Position, ControlGroup } from '@blueprintjs/core';
import classNames from 'classnames';
import {
FormattedMessage as T,
AccountsSuggestField,
InputPrependText,
- MoneyInputGroup,
FieldRequiredHint,
Col,
Row,
- If,
- ExchangeRateMutedField,
FeatureCan,
BranchSelect,
BranchSelectButton,
+ FMoneyInputGroup,
+ FInputGroup,
+ FFormGroup,
+ FTextArea,
} from '@/components';
-import { useAutofocus } from '@/hooks';
+import { MoneyInOutTransactionNoField } from '../../_components';
+import { MoneyInExchangeRateField } from '../MoneyInExchangeRateField';
import { CLASSES, ACCOUNT_TYPE, Features } from '@/constants';
-
import {
inputIntent,
momentFormatter,
@@ -35,25 +29,19 @@ import {
handleDateChange,
} from '@/utils';
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
+import { useMoneyInFieldsContext } from '../MoneyInFieldsProvider';
import {
useSetPrimaryBranchToForm,
- useForeignAccount,
BranchRowDivider,
} from '../../MoneyInDialog/utils';
-import { MoneyInOutTransactionNoField } from '../../_components';
-
/**
* Transfer from account form fields.
*/
export default function TransferFromAccountFormFields() {
// Money in dialog context.
- const { accounts, account, branches } = useMoneyInDailogContext();
-
- const isForeigAccount = useForeignAccount();
- const amountFieldRef = useAutofocus();
-
- const { values } = useFormikContext();
+ const { accounts, branches } = useMoneyInDailogContext();
+ const { account } = useMoneyInFieldsContext();
// Sets the primary branch to form.
useSetPrimaryBranchToForm();
@@ -63,17 +51,14 @@ export default function TransferFromAccountFormFields() {
- }
- className={classNames('form-group--select-list', Classes.FILL)}
- >
+ } name={'branch_id'}>
-
+
@@ -112,50 +97,27 @@ export default function TransferFromAccountFormFields() {
- {/*------------ amount -----------*/}
-
- {({
- form: { values, setFieldValue },
- field: { value },
- meta: { error, touched },
- }) => (
+ {/*------------ Amount -----------*/}
+
+
}
labelInfo={}
- intent={inputIntent({ error, touched })}
- helperText={}
- className={'form-group--amount'}
>
-
-
- {
- setFieldValue('amount', amount);
- }}
- inputRef={(ref) => (amountFieldRef.current = ref)}
- intent={inputIntent({ error, touched })}
- />
+
+
- )}
-
-
- {/*------------ exchange rate -----------*/}
-
-
+
+
+
+ {/*------------ Exchange rate -----------*/}
+
+
- {/*------------ transfer from account -----------*/}
+ {/*------------ Transfer from account -----------*/}
{({ form, field, meta: { error, touched } }) => (
+
{/*------------ Reference -----------*/}
-
- {({ form, field, meta: { error, touched } }) => (
- }
- intent={inputIntent({ error, touched })}
- helperText={}
- className={'form-group--reference-no'}
- >
-
-
- )}
-
+ }>
+
+
- {/*------------ description -----------*/}
-
- {({ field, meta: { error, touched } }) => (
- }
- className={'form-group--description'}
- intent={inputIntent({ error, touched })}
- helperText={}
- >
-
-
- )}
-
+
+ {/*------------ Description -----------*/}
+ }>
+
+
);
}
diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/index.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/index.tsx
index 18e1bb292..15b48cf4d 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyInDialog/index.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/index.tsx
@@ -3,7 +3,6 @@ import React from 'react';
import intl from 'react-intl-universal';
import { Dialog, DialogSuspense } from '@/components';
import withDialogRedux from '@/components/DialogReduxConnect';
-
import { compose } from '@/utils';
const MoneyInDialogContent = React.lazy(() => import('./MoneyInDialogContent'));
diff --git a/packages/webapp/src/containers/CashFlow/MoneyInDialog/utils.tsx b/packages/webapp/src/containers/CashFlow/MoneyInDialog/utils.tsx
index bd4333dec..d1bc1739c 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyInDialog/utils.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyInDialog/utils.tsx
@@ -6,6 +6,7 @@ import { transactionNumber } from '@/utils';
import { isEqual, isNull, first } from 'lodash';
import { useMoneyInDailogContext } from './MoneyInDialogProvider';
+import { useMoneyInFieldsContext } from './MoneyInFieldsProvider';
export const useObserveTransactionNoSettings = (prefix, nextNumber) => {
const { setFieldValue } = useFormikContext();
@@ -33,7 +34,7 @@ export const useSetPrimaryBranchToForm = () => {
export const useForeignAccount = () => {
const { values } = useFormikContext();
- const { account } = useMoneyInDailogContext();
+ const { account } = useMoneyInFieldsContext();
return (
!isEqual(account.currency_code, values.currency_code) &&
diff --git a/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutContentFields.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutContentFields.tsx
index 5f0f18876..1e8012e3d 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutContentFields.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutContentFields.tsx
@@ -1,13 +1,22 @@
// @ts-nocheck
-import React from 'react';
+import React, { useMemo } from 'react';
+import { useFormikContext } from 'formik';
import OtherExpnseFormFields from './OtherExpense/OtherExpnseFormFields';
import OwnerDrawingsFormFields from './OwnerDrawings/OwnerDrawingsFormFields';
import TransferToAccountFormFields from './TransferToAccount/TransferToAccountFormFields';
+import { MoneyOutFieldsProvider } from './MoneyOutFieldsProvider';
-function MoneyOutContentFields({ accountType }) {
- const handleTransactionType = () => {
- switch (accountType) {
+/**
+ * Money out content fields.
+ * Switches between form fields based on the given transaction type.
+ * @returns {JSX.Element}
+ */
+function MoneyOutContentFields() {
+ const { values } = useFormikContext();
+
+ const transactionType = useMemo(() => {
+ switch (values.transaction_type) {
case 'OwnerDrawing':
return ;
@@ -19,8 +28,12 @@ function MoneyOutContentFields({ accountType }) {
default:
break;
}
- };
- return {handleTransactionType()};
+ }, [values.transaction_type]);
+
+ // Cannot continue if transaction type or account is not selected.
+ if (!values.transaction_type || !values.cashflow_account_id) return null;
+
+ return {transactionType};
}
export default MoneyOutContentFields;
diff --git a/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutDialogProvider.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutDialogProvider.tsx
index 357eb354c..e975e1a55 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutDialogProvider.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutDialogProvider.tsx
@@ -1,11 +1,10 @@
// @ts-nocheck
-import React from 'react';
+import React, { useState } from 'react';
import { DialogContent } from '@/components';
import { Features } from '@/constants';
import { useFeatureCan } from '@/hooks/state';
import {
useAccounts,
- useAccount,
useBranches,
useCreateCashflowTransaction,
useCashflowAccounts,
@@ -17,7 +16,15 @@ const MoneyInDialogContent = React.createContext();
/**
* Money out dialog provider.
*/
-function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
+function MoneyOutProvider({
+ accountId: defaultAccountId,
+ accountType,
+ dialogName,
+ ...props
+}) {
+ // Holds the selected account id of the dialog.
+ const [accountId, setAccountId] = useState(defaultAccountId);
+
// Features guard.
const { featureCan } = useFeatureCan();
const isBranchFeatureCan = featureCan(Features.Branches);
@@ -25,11 +32,6 @@ function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
// Fetches accounts list.
const { isLoading: isAccountsLoading, data: accounts } = useAccounts();
- // Fetches the specific account details.
- const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
- enabled: !!accountId,
- });
-
// Fetches the branches list.
const {
data: branches,
@@ -41,6 +43,7 @@ function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
useCashflowAccounts({}, { keepPreviousData: true });
+ // Mutation to create a new cashflow account.
const { mutateAsync: createCashflowTransactionMutate } =
useCreateCashflowTransaction();
@@ -52,9 +55,11 @@ function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
// Provider data.
const provider = {
- accounts,
- account,
accountId,
+ setAccountId,
+ defaultAccountId,
+
+ accounts,
accountType,
branches,
isAccountsLoading,
@@ -73,8 +78,7 @@ function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
isAccountsLoading ||
isCashFlowAccountsLoading ||
isBranchesLoading ||
- isSettingsLoading ||
- isAccountLoading;
+ isSettingsLoading;
return (
diff --git a/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutExchangeRateField.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutExchangeRateField.tsx
new file mode 100644
index 000000000..cb9134e14
--- /dev/null
+++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutExchangeRateField.tsx
@@ -0,0 +1,31 @@
+// @ts-nocheck
+import React from 'react';
+import { useFormikContext } from 'formik';
+import { useForeignAccount } from './utils';
+import { ExchangeRateMutedField } from '@/components';
+import { useMoneyOutFieldsContext } from './MoneyOutFieldsProvider';
+
+/**
+ * Money-out exchange rate field.
+ * @returns {JSX.Element}
+ */
+export function MoneyOutExchangeRateField() {
+ const { values } = useFormikContext();
+
+ const { account } = useMoneyOutFieldsContext();
+ const isForeigAccount = useForeignAccount();
+
+ // Cannot continue if the account is not foreign account.
+ if (!isForeigAccount) return null;
+
+ return (
+
+ );
+}
diff --git a/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFieldsProvider.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFieldsProvider.tsx
new file mode 100644
index 000000000..e6fbdb4cd
--- /dev/null
+++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFieldsProvider.tsx
@@ -0,0 +1,34 @@
+// @ts-nocheck
+import React from 'react';
+import { DialogContent } from '@/components';
+import { useAccount } from '@/hooks/query';
+import { useMoneyOutDialogContext } from './MoneyOutDialogProvider';
+
+const MoneyOutFieldsContext = React.createContext();
+
+/**
+ * Money out fields dialog provider.
+ */
+function MoneyOutFieldsProvider({ ...props }) {
+ const { accountId } = useMoneyOutDialogContext();
+
+ // Fetches the specific account details.
+ const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
+ enabled: !!accountId,
+ });
+ // Provider data.
+ const provider = {
+ account,
+ };
+ const isLoading = isAccountLoading;
+
+ return (
+
+
+
+ );
+}
+
+const useMoneyOutFieldsContext = () => React.useContext(MoneyOutFieldsContext);
+
+export { MoneyOutFieldsProvider, useMoneyOutFieldsContext };
diff --git a/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFloatingActions.tsx b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFloatingActions.tsx
index a370d328d..a39c34409 100644
--- a/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFloatingActions.tsx
+++ b/packages/webapp/src/containers/CashFlow/MoneyOutDialog/MoneyOutFloatingActions.tsx
@@ -24,18 +24,16 @@ function MoneyOutFloatingActions({
useMoneyOutDialogContext();
// handle submit as draft button click.
- const handleSubmitDraftBtnClick = (event) => {
+ const handleSubmitDraftBtnClick = () => {
setSubmitPayload({ publish: false });
submitForm();
};
-
// Handle submit button click.
- const handleSubmittBtnClick = (event) => {
+ const handleSubmittBtnClick = () => {
setSubmitPayload({ publish: true });
};
-
// Handle close button click.
- const handleCloseBtnClick = (event) => {
+ const handleCloseBtnClick = () => {
closeDialog(dialogName);
};
@@ -49,7 +47,7 @@ function MoneyOutFloatingActions({
>
-
+