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 (
} className={classNames('form-group--select-list', Classes.FILL)} labelInfo={} intent={errors.beneficiary && touched.beneficiary && Intent.DANGER} helperText={ } > } onContactSelected={onChangeCustomer('customer_id')} /> } className={classNames( 'form-group--payment_account', 'form-group--select-list', Classes.FILL, )} labelInfo={} intent={ errors.payment_account_id && touched.payment_account_id && Intent.DANGER } helperText={ } > } selectedAccountId={values.payment_account_id} filterByTypes={['current_asset']} /> } labelInfo={} className={classNames('form-group--select-list', Classes.FILL)} intent={ errors.payment_date && touched.payment_date && Intent.DANGER } helperText={ } > } className={classNames( 'form-group--select-list', 'form-group--currency', Classes.FILL, )} intent={ errors.currency_code && touched.currency_code && Intent.DANGER } helperText={ } > } className={classNames('form-group--ref_no', Classes.FILL)} intent={ errors.reference_no && touched.reference_no && Intent.DANGER } helperText={ } >
); } export default compose( withAccounts(({ accountsList, accountsTypes }) => ({ accountsList, accountsTypes, })), withCurrencies(({ currenciesList }) => ({ currenciesList, })), withCustomers(({ customers }) => ({ customers, })), )(ExpenseFormHeader);