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 { ListSelect, 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], ); const currencyCodeRenderer = useCallback((item, { handleClick }) => { return ( ); }, []); // Filters Currency code. const filterCurrencyCode = (query, currency, _index, exactMatch) => { const normalizedTitle = currency.currency_code.toLowerCase(); const normalizedQuery = query.toLowerCase(); if (exactMatch) { return normalizedTitle === normalizedQuery; } else { return ( `${currency.currency_code} ${normalizedTitle}`.indexOf( normalizedQuery, ) >= 0 ); } }; // 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], ); // Filter payment accounts. const paymentAccounts = useMemo( () => accountsList.filter((a) => a?.type?.key === 'current_asset'), [accountsList], ); const CustomerRenderer = useCallback( (cutomer, { handleClick }) => ( ), [], ); // handle change customer const onChangeCustomer = useCallback( (filedName) => { return (customer) => { setFieldValue(filedName, customer.id); }; }, [setFieldValue], ); return (