import React from 'react'; import { FastField, Field, ErrorMessage } 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, InputPrependButton, } from 'components'; import { DateInput } from '@blueprintjs/datetime'; import { useAutofocus } from 'hooks'; import { ACCOUNT_TYPE } from 'common/accountTypes'; import { inputIntent, momentFormatter, tansformDateValue, handleDateChange, compose, } from 'utils'; import { CLASSES } from 'common/classes'; import { useMoneyInDailogContext } from '../MoneyInDialogProvider'; import { useObserveTransactionNoSettings } from '../utils'; import withSettings from 'containers/Settings/withSettings'; import withDialogActions from 'containers/Dialog/withDialogActions'; /** * Other income form fields. */ function OtherIncomeFormFields({ // #withDialogActions openDialog, // #withSettings transactionAutoIncrement, transactionNumberPrefix, transactionNextNumber, }) { // Money in dialog context. const { accounts } = useMoneyInDailogContext(); 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, ); return ( {/*------------ 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={(ref) => (amountFieldRef.current = ref)} intent={inputIntent({ error, touched })} /> )} {/*------------ other income 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.INCOME, ACCOUNT_TYPE.OTHER_INCOME, ]} 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={} >