import React, { useMemo, useCallback, useState } from 'react'; import { FormGroup, InputGroup, 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 { AccountsSelectList, ListSelect, ErrorMessage, FieldRequiredHint, Hint, } from 'components'; import withCustomers from 'containers/Customers/withCustomers'; import withAccounts from 'containers/Accounts/withAccounts'; function BillFormHeader({ formik: { errors, touched, setFieldValue, getFieldProps, values }, //#withCustomers customers, //#withAccouts accountsList, }) { const handleDateChange = useCallback( (date_filed) => (date) => { const formatted = moment(date).format('YYYY-MM-DD'); setFieldValue(date_filed, formatted); }, [setFieldValue], ); const onChangeSelected = useCallback( (filedName) => { return (item) => { setFieldValue(filedName, item.id); }; }, [setFieldValue], ); const vendorNameRenderer = useCallback( (accept, { handleClick }) => ( ), [], ); // Filter vendor name const filterVendorAccount = (query, vendor, _index, exactMatch) => { const normalizedTitle = vendor.display_name.toLowerCase(); const normalizedQuery = query.toLowerCase(); if (exactMatch) { return normalizedTitle === normalizedQuery; } else { return ( `${vendor.display_name} ${normalizedTitle}`.indexOf(normalizedQuery) >= 0 ); } }; return (
{/* vendor account name */} } inline={true} className={classNames('form-group--select-list', Classes.FILL)} labelInfo={} intent={errors.vendor_id && touched.vendor_id && Intent.DANGER} helperText={ } > } itemRenderer={vendorNameRenderer} itemPredicate={filterVendorAccount} popoverProps={{ minimal: true }} onItemSelect={onChangeSelected('vendor_id')} selectedItem={values.vendor_id} selectedItemProp={'id'} defaultText={} labelProp={'display_name'} /> } inline={true} labelInfo={} className={classNames('form-group--select-list', Classes.FILL)} intent={errors.bill_date && touched.bill_date && Intent.DANGER} helperText={ } > } inline={true} className={classNames('form-group--select-list', Classes.FILL)} intent={errors.due_date && touched.due_date && Intent.DANGER} helperText={ } > {/* bill number */} } inline={true} className={('form-group--estimate', Classes.FILL)} labelInfo={} intent={errors.bill_number && touched.bill_number && Intent.DANGER} helperText={ } >
} inline={true} className={classNames('form-group--reference', Classes.FILL)} intent={errors.reference_no && touched.reference_no && Intent.DANGER} helperText={} >
); } export default compose( withCustomers(({ customers }) => ({ customers, })), withAccounts(({ accountsList }) => ({ accountsList, })), )(BillFormHeader);