import React, { useMemo, useCallback, useState } from 'react'; import { FormGroup, InputGroup, Intent, Position, ControlGroup, } from '@blueprintjs/core'; import { DateInput } from '@blueprintjs/datetime'; import { FormattedMessage as T } from 'react-intl'; import moment from 'moment'; import { momentFormatter, compose, tansformDateValue, saveInvoke } from 'utils'; import classNames from 'classnames'; import { CLASSES } from 'common/classes'; import { ContactSelecetList, ErrorMessage, FieldRequiredHint, Icon, InputPrependButton, Row, Col, } from 'components'; import withCustomers from 'containers/Customers/withCustomers'; import withDialogActions from 'containers/Dialog/withDialogActions'; function InvoiceFormHeader({ formik: { errors, touched, setFieldValue, getFieldProps, values }, //#withCustomers customers, //#withDialogActions openDialog, // #ownProps onInvoiceNumberChanged, }) { const handleDateChange = useCallback( (date_filed) => (date) => { const formatted = moment(date).format('YYYY-MM-DD'); setFieldValue(date_filed, formatted); }, [setFieldValue], ); // handle change customer const onChangeCustomer = useCallback( (filedName) => { return (customer) => { setFieldValue(filedName, customer.id); }; }, [setFieldValue], ); const handleInvoiceNumberChange = useCallback(() => { openDialog('invoice-number-form', {}); }, [openDialog]); const handleInvoiceNumberChanged = (event) => { saveInvoke(onInvoiceNumberChanged, event.currentTarget.value); }; return (
{/* ----------- Customer name ----------- */} } inline={true} className={classNames( 'form-group--select-list', 'form-group--customer-name', CLASSES.FILL, )} labelInfo={} intent={errors.customer_id && touched.customer_id && Intent.DANGER} helperText={ } > } onContactSelected={onChangeCustomer('customer_id')} /> {/* ----------- Invoice date ----------- */} } inline={true} labelInfo={} className={classNames( 'form-group--select-list', 'form-group--invoice-date', CLASSES.FILL, )} intent={ errors.invoice_date && touched.invoice_date && Intent.DANGER } helperText={ } > {/* ----------- Due date ----------- */} } inline={true} className={classNames( 'form-group--select-list', 'form-group--due-date', CLASSES.FILL, )} intent={errors.due_date && touched.due_date && Intent.DANGER} helperText={ } > {/* ----------- Invoice number ----------- */} } inline={true} className={classNames('form-group--invoice-no', CLASSES.FILL)} intent={errors.invoice_no && touched.invoice_no && Intent.DANGER} helperText={ } > , }} tooltip={true} tooltipProps={{ content: 'Setting your auto-generated invoice number', position: Position.BOTTOM_LEFT, }} /> {/* ----------- Reference ----------- */} } 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, })), withDialogActions, )(InvoiceFormHeader);