import React, { useCallback } from 'react'; import { FormGroup, InputGroup, Position, ControlGroup, } from '@blueprintjs/core'; import { DateInput } from '@blueprintjs/datetime'; import { FormattedMessage as T } from 'react-intl'; import classNames from 'classnames'; import { FastField, ErrorMessage } from 'formik'; import { CLASSES } from 'common/classes'; import { AccountsSelectList, ContactSelecetList, FieldRequiredHint, Icon, InputPrependButton, } from 'components'; import withCustomers from 'containers/Customers/withCustomers'; import withAccounts from 'containers/Accounts/withAccounts'; import withDialogActions from 'containers/Dialog/withDialogActions'; import { momentFormatter, compose, tansformDateValue, saveInvoke, handleDateChange, inputIntent, } from 'utils'; function ReceiptFormHeader({ //#withCustomers customers, //#withAccouts accountsList, //#withDialogActions openDialog, // #ownProps onReceiptNumberChanged, }) { const handleReceiptNumberChange = useCallback(() => { openDialog('receipt-number-form', {}); }, [openDialog]); const handleReceiptNumberChanged = (event) => { saveInvoke(onReceiptNumberChanged, event.currentTarget.value); }; return (
{/* ----------- Customer name ----------- */} {({ form, field: { value }, meta: { error, touched } }) => ( } inline={true} className={classNames(CLASSES.FILL, 'form-group--customer')} labelInfo={} intent={inputIntent({ error, touched })} helperText={} > } onContactSelected={(contact) => { form.setFieldValue('customer_id', contact.id); }} popoverFill={true} /> )} {/* ----------- Deposit account ----------- */} {({ form, field: { value }, meta: { error, touched } }) => ( } className={classNames('form-group--deposit-account', CLASSES.FILL)} inline={true} labelInfo={} intent={inputIntent({ error, touched })} helperText={} > { form.setFieldValue('deposit_account_id', account.id); }} defaultSelectText={} selectedAccountId={value} filterByTypes={['current_asset']} popoverFill={true} /> )} {/* ----------- Receipt date ----------- */} {({ form, field: { value }, meta: { error, touched } }) => ( } inline={true} className={classNames(CLASSES.FILL)} intent={inputIntent({ error, touched })} helperText={} > { form.setFieldValue('receipt_date', formattedDate); })} popoverProps={{ position: Position.BOTTOM, minimal: true }} inputProps={{ leftIcon: , }} /> )} {/* ----------- Receipt number ----------- */} {({ field, meta: { error, touched } }) => ( } inline={true} className={('form-group--receipt_number', CLASSES.FILL)} labelInfo={} intent={inputIntent({ error, touched })} helperText={} > , }} tooltip={true} tooltipProps={{ content: 'Setting your auto-generated receipt number', position: Position.BOTTOM_LEFT, }} inputProps={{ leftIcon: , }} /> )} {/* ----------- Reference ----------- */} {({ field, meta: { error, touched } }) => ( } inline={true} className={classNames('form-group--reference', CLASSES.FILL)} intent={inputIntent({ error, touched })} helperText={} > )}
); } export default compose( withCustomers(({ customers }) => ({ customers, })), withAccounts(({ accountsList }) => ({ accountsList, })), withDialogActions, )(ReceiptFormHeader);