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 { AccountsSelectList, ListSelect, ErrorMessage, FieldRequiredHint, Icon, InputPrependButton, } from 'components'; import withCustomers from 'containers/Customers/withCustomers'; import withAccounts from 'containers/Accounts/withAccounts'; import withDialogActions from 'containers/Dialog/withDialogActions'; function ReceiptFormHeader({ formik: { errors, touched, setFieldValue, getFieldProps, values }, //#withCustomers customers, //#withAccouts accountsList, //#withDialogActions openDialog, }) { const handleDateChange = useCallback( (date) => { const formatted = moment(date).format('YYYY-MM-DD'); setFieldValue('receipt_date', 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 const onChangeSelect = useCallback( (filedName) => { return (item) => { setFieldValue(filedName, item.id); }; }, [setFieldValue], ); // Filter deposit accounts. const depositAccounts = useMemo( () => accountsList.filter((a) => a?.type?.key === 'current_asset'), [accountsList], ); const handleReceiptNumberChange = useCallback(() => { openDialog('receipt-number-form', {}); }, [openDialog]); return (
{/*- Customer name -*/} } inline={true} className={classNames( 'form-group--select-list', Classes.FILL, 'form-group--customer', )} labelInfo={} intent={errors.customer_id && touched.customer_id && Intent.DANGER} helperText={ } > } itemRenderer={CustomerRenderer} itemPredicate={filterCustomer} popoverProps={{ minimal: true }} onItemSelect={onChangeSelect('customer_id')} selectedItem={values.customer_id} selectedItemProp={'id'} defaultText={} labelProp={'display_name'} /> {/*- Deposit account -*/} } className={classNames( 'form-group--deposit-account', 'form-group--select-list', Classes.FILL, )} inline={true} labelInfo={} intent={ errors.deposit_account_id && touched.deposit_account_id && Intent.DANGER } helperText={ } > } selectedAccountId={values.deposit_account_id} /> } inline={true} className={classNames('form-group--select-list', Classes.FILL)} intent={errors.receipt_date && touched.receipt_date && Intent.DANGER} helperText={ } >
{/* receipt_no */} } inline={true} className={('form-group--receipt_number', Classes.FILL)} labelInfo={} intent={ errors.receipt_number && touched.receipt_number && Intent.DANGER } helperText={ } > , }} tooltip={true} tooltipProps={{ content: 'Setting your auto-generated receipt number', position: Position.BOTTOM_LEFT, }} /> } {...getFieldProps('receipt_number')} /> {/*- Reference -*/} } inline={true} className={classNames('form-group--reference', Classes.FILL)} intent={errors.reference_no && touched.reference_no && Intent.DANGER} helperText={} > {/*- Send to email -*/} } inline={true} className={classNames('form-group--send_to_email', Classes.FILL)} intent={errors.send_to_email && touched.send_to_email && Intent.DANGER} helperText={} >
); } export default compose( withCustomers(({ customers }) => ({ customers, })), withAccounts(({ accountsList }) => ({ accountsList, })), withDialogActions, )(ReceiptFormHeader);