import React, { useMemo, useCallback, useState } from 'react'; import { InputGroup, FormGroup, Intent, Position, MenuItem, Classes, } from '@blueprintjs/core'; import { DateInput } from '@blueprintjs/datetime'; import { FormattedMessage as T } from 'react-intl'; import { Row, Col } from 'react-grid-system'; import moment from 'moment'; import { momentFormatter, compose, tansformDateValue } from 'utils'; import classNames from 'classnames'; import { CurrencySelectList, ContactSelecetList, ErrorMessage, AccountsSelectList, FieldRequiredHint, Hint, } from 'components'; import withCurrencies from 'containers/Currencies/withCurrencies'; import withAccounts from 'containers/Accounts/withAccounts'; import withCustomers from 'containers/Customers/withCustomers'; function ExpenseFormHeader({ formik: { errors, touched, setFieldValue, getFieldProps, values }, currenciesList, accountsList, accountsTypes, customers, }) { const [selectedItems, setSelectedItems] = useState({}); const handleDateChange = useCallback( (date) => { const formatted = moment(date).format('YYYY-MM-DD'); setFieldValue('payment_date', formatted); }, [setFieldValue], ); // Handles change account. const onChangeAccount = useCallback( (account) => { setFieldValue('payment_account_id', account.id); }, [setFieldValue], ); const onItemsSelect = useCallback( (filedName) => { return (filed) => { setSelectedItems({ ...selectedItems, [filedName]: filed, }); setFieldValue(filedName, filed.currency_code); }; }, [setFieldValue, selectedItems], ); // handle change customer const onChangeCustomer = useCallback( (filedName) => { return (customer) => { setFieldValue(filedName, customer.id); }; }, [setFieldValue], ); return (