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 moment from 'moment'; import { momentFormatter, compose, tansformDateValue } from 'utils'; import classNames from 'classnames'; import { CLASSES } from 'common/classes'; import { ListSelect, ErrorMessage, FieldRequiredHint, Icon, InputPrependButton, Row, Col, } from 'components'; import withCustomers from 'containers/Customers/withCustomers'; import withDialogActions from 'containers/Dialog/withDialogActions'; function EstimateFormHeader({ formik: { errors, touched, setFieldValue, getFieldProps, values }, //#withCustomers customers, // #withDialogActions openDialog, }) { const handleDateChange = useCallback( (date_filed) => (date) => { const formatted = moment(date).format('YYYY-MM-DD'); setFieldValue(date_filed, formatted); }, [setFieldValue], ); const CustomerRenderer = useCallback( (cutomer, { handleClick }) => ( ), [], ); // Filter Customer const filterCustomer = (query, customer, _index, exactMatch) => { const normalizedTitle = customer.display_name.toLowerCase(); const normalizedQuery = query.toLowerCase(); if (exactMatch) { return normalizedTitle === normalizedQuery; } else { return ( `${customer.display_name} ${normalizedTitle}`.indexOf( normalizedQuery, ) >= 0 ); } }; // handle change customer const onChangeCustomer = useCallback( (filedName) => { return (customer) => { setFieldValue(filedName, customer.id); }; }, [setFieldValue], ); const handleEstimateNumberChange = useCallback(() => { openDialog('estimate-number-form', {}); }, [openDialog]); return (
} inline={true} className={classNames( 'form-group--select-list', 'form-group--customer', Classes.FILL, )} labelInfo={} intent={errors.customer_id && touched.customer_id && Intent.DANGER} helperText={ } > } itemRenderer={CustomerRenderer} itemPredicate={filterCustomer} popoverProps={{ minimal: true }} onItemSelect={onChangeCustomer('customer_id')} selectedItem={values.customer_id} selectedItemProp={'id'} defaultText={} labelProp={'display_name'} /> } inline={true} labelInfo={} className={classNames( 'form-group--select-list', 'form-group--estimate-date', Classes.FILL, )} intent={ errors.estimate_date && touched.estimate_date && Intent.DANGER } helperText={ } > } inline={true} className={classNames( 'form-group--select-list', 'form-group--expiration-date', Classes.FILL, )} intent={ errors.expiration_date && touched.expiration_date && Intent.DANGER } helperText={ } > {/*- Estimate -*/} } inline={true} className={('form-group--estimate-number', Classes.FILL)} labelInfo={} intent={ errors.estimate_number && touched.estimate_number && Intent.DANGER } helperText={ } > , }} tooltip={true} tooltipProps={{ content: 'Setting your auto-generated estimate number', position: Position.BOTTOM_LEFT, }} /> } {...getFieldProps('estimate_number')} /> } inline={true} className={classNames('form-group--reference', Classes.FILL)} intent={errors.reference && touched.reference && Intent.DANGER} helperText={ } >
); } export default compose( withCustomers(({ customers }) => ({ customers, })), withDialogActions, )(EstimateFormHeader);