import React from 'react'; import { FormGroup, InputGroup, Position, ControlGroup, } from '@blueprintjs/core'; import { DateInput } from '@blueprintjs/datetime'; import { FormattedMessage as T } from 'components'; import { FastField, Field, ErrorMessage } from 'formik'; import styled from 'styled-components'; import { momentFormatter, compose, tansformDateValue, inputIntent, handleDateChange, } from 'utils'; import { customersFieldShouldUpdate } from './utils'; import classNames from 'classnames'; import { CLASSES } from 'common/classes'; import { CustomerSelectField, FieldRequiredHint, Icon, InputPrependButton, CustomerDrawerLink, } from 'components'; import withDialogActions from 'containers/Dialog/withDialogActions'; import withSettings from 'containers/Settings/withSettings'; import { useObserveEstimateNoSettings } from './utils'; import { EstimateExchangeRateInputField } from './components'; import { useEstimateFormContext } from './EstimateFormProvider'; /** * Estimate form header. */ function EstimateFormHeader({ // #withDialogActions openDialog, // #withSettings estimateAutoIncrement, estimateNumberPrefix, estimateNextNumber, }) { const { customers } = useEstimateFormContext(); const handleEstimateNumberBtnClick = () => { openDialog('estimate-number-form', {}); }; const handleEstimateNoBlur = (form, field) => (event) => { const newValue = event.target.value; if (field.value !== newValue && estimateAutoIncrement) { openDialog('estimate-number-form', { initialFormValues: { manualTransactionNo: newValue, incrementMode: 'manual-transaction', }, }); } }; // Syncs estimate number settings with the form. useObserveEstimateNoSettings(estimateNumberPrefix, estimateNextNumber); return (
{/* ----------- Customer name ----------- */} {({ form, field: { value }, meta: { error, touched } }) => ( } inline={true} className={classNames(CLASSES.FILL, 'form-group--customer')} labelInfo={} intent={inputIntent({ error, touched })} helperText={} > } onContactSelected={(customer) => { form.setFieldValue('customer_id', customer.id); form.setFieldValue('currency_code', customer?.currency_code); }} popoverFill={true} intent={inputIntent({ error, touched })} allowCreate={true} /> {value && ( View Customer Details )} )} {/* ----------- Exchange rate ----------- */} {/* ----------- Estimate date ----------- */} {({ form, field: { value }, meta: { error, touched } }) => ( } inline={true} labelInfo={} className={classNames(CLASSES.FILL, 'form-group--estimate-date')} intent={inputIntent({ error, touched })} helperText={} > { form.setFieldValue('estimate_date', formattedDate); })} popoverProps={{ position: Position.BOTTOM, minimal: true }} inputProps={{ leftIcon: , }} /> )} {/* ----------- Expiration date ----------- */} {({ form, field: { value }, meta: { error, touched } }) => ( } labelInfo={} inline={true} className={classNames( CLASSES.FORM_GROUP_LIST_SELECT, CLASSES.FILL, 'form-group--expiration-date', )} intent={inputIntent({ error, touched })} helperText={} > { form.setFieldValue('expiration_date', formattedDate); })} popoverProps={{ position: Position.BOTTOM, minimal: true }} inputProps={{ leftIcon: , }} /> )} {/* ----------- Estimate number ----------- */} {({ form, field, meta: { error, touched } }) => ( } inline={true} className={('form-group--estimate-number', CLASSES.FILL)} labelInfo={} intent={inputIntent({ error, touched })} helperText={} > , }} tooltip={true} tooltipProps={{ content: ( ), position: Position.BOTTOM_LEFT, }} /> )} {/* ----------- Reference ----------- */} {({ form, field, meta: { error, touched } }) => ( } inline={true} className={classNames('form-group--reference', CLASSES.FILL)} intent={inputIntent({ error, touched })} helperText={} > )}
); } export default compose( withDialogActions, withSettings(({ estimatesSettings }) => ({ estimateNextNumber: estimatesSettings?.nextNumber, estimateNumberPrefix: estimatesSettings?.numberPrefix, estimateAutoIncrement: estimatesSettings?.autoIncrement, })), )(EstimateFormHeader); const ControlCustomerGroup = styled(ControlGroup)` display: flex; align-items: center; transform: none; `; const CustomerButtonLink = styled(CustomerDrawerLink)` font-size: 11px; margin-top: 6px; `;