// @ts-nocheck import React from 'react'; import { FastField, Field, ErrorMessage, useFormikContext } from 'formik'; import { Classes, FormGroup, InputGroup, TextArea, Position, ControlGroup, } from '@blueprintjs/core'; import classNames from 'classnames'; import { FormattedMessage as T, AccountsSuggestField, InputPrependText, MoneyInputGroup, FieldRequiredHint, Icon, Col, Row, If, InputPrependButton, FeatureCan, BranchSelect, BranchSelectButton, ExchangeRateMutedField, } from '@/components'; import { DateInput } from '@blueprintjs/datetime'; import { useAutofocus } from '@/hooks'; import { ACCOUNT_TYPE } from '@/constants/accountTypes'; import { inputIntent, momentFormatter, tansformDateValue, handleDateChange, compose, } from '@/utils'; import { Features } from '@/constants'; 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'; /** * Transfer to account form fields. */ function TransferToAccountFormFields({ // #withDialogActions openDialog, // #withSettings transactionAutoIncrement, transactionNumberPrefix, transactionNextNumber, }) { // Money in dialog context. const { accounts, account, branches } = useMoneyOutDialogContext(); const { values } = useFormikContext(); const isForeigAccount = useForeignAccount(); 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(); return ( } className={classNames('form-group--select-list', Classes.FILL)} > {/*------------ Date -----------*/} {({ form, field: { value }, meta: { error, touched } }) => ( } labelInfo={} intent={inputIntent({ error, touched })} helperText={} minimal={true} className={classNames(CLASSES.FILL, 'form-group--date')} > { form.setFieldValue('date', formattedDate); })} value={tansformDateValue(value)} popoverProps={{ position: Position.BOTTOM, minimal: true, }} intent={inputIntent({ error, touched })} /> )} {/*------------ 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 -----------*/} {({ form: { values, setFieldValue }, field: { value }, meta: { error, touched }, }) => ( } labelInfo={} intent={inputIntent({ error, touched })} helperText={} className={'form-group--amount'} > { setFieldValue('amount', amount); }} inputRef={accountRef} intent={inputIntent({ error, touched })} /> )} {/*------------ exchange rate -----------*/} {/*------------ transfer from account -----------*/} {({ form, field, meta: { error, touched } }) => ( } labelInfo={} intent={inputIntent({ error, touched })} helperText={} className={'form-group--credit_account_id'} > form.setFieldValue('credit_account_id', id) } filterByTypes={[ ACCOUNT_TYPE.CASH, ACCOUNT_TYPE.BANK, ACCOUNT_TYPE.CREDIT_CARD, ]} inputProps={{ intent: inputIntent({ 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={} >