Fix : Vendor Select List

This commit is contained in:
elforjani3
2020-11-03 08:09:45 +02:00
parent 083a2dfbc5
commit 64ca4d2a8a
4 changed files with 84 additions and 35 deletions

View File

@@ -0,0 +1,58 @@
import React, { useCallback } from 'react';
import { FormattedMessage as T } from 'react-intl';
import { ListSelect } from 'components';
import { MenuItem } from '@blueprintjs/core';
export default function VendorSelecetList({
vendorsList,
selectedVendorId,
defaultSelectText = <T id={'select_vender_account'} />,
onVenderSelected,
// disabled = false,
...restProps
}) {
// Filter Vendors List
const FilterVendors = (query, vender, index, exactMatch) => {
const normalizedTitle = vender.display_name.toLowerCase();
const normalizedQuery = query.toLowerCase();
if (exactMatch) {
return normalizedTitle === normalizedQuery;
} else {
return (
`${vender.display_name} ${normalizedTitle}`.indexOf(normalizedQuery) >=
0
);
}
};
const handleVendorSelected = useCallback(
(Vendor) => onVenderSelected && onVenderSelected(Vendor),
[],
);
const handleVenderRenderer = useCallback(
(vender, { handleClick }) => (
<MenuItem
key={vender.id}
text={vender.display_name}
onClick={handleClick}
/>
),
[],
);
return (
<ListSelect
items={vendorsList}
selectedItemProp={'id'}
selectedItem={selectedVendorId}
labelProp={'display_name'}
defaultText={defaultSelectText}
onItemSelect={handleVendorSelected}
itemPredicate={FilterVendors}
itemRenderer={handleVenderRenderer}
popoverProps={{ minimal: true }}
{...restProps}
/>
);
}

View File

@@ -30,6 +30,7 @@ import Row from './Grid/Row';
import Col from './Grid/Col'; import Col from './Grid/Col';
import CloudLoadingIndicator from './CloudLoadingIndicator'; import CloudLoadingIndicator from './CloudLoadingIndicator';
import MoneyExchangeRate from './MoneyExchangeRate'; import MoneyExchangeRate from './MoneyExchangeRate';
import VendorSelecetList from './VendorSelecetList';
const Hint = FieldHint; const Hint = FieldHint;
@@ -67,4 +68,5 @@ export {
Row, Row,
CloudLoadingIndicator, CloudLoadingIndicator,
MoneyExchangeRate, MoneyExchangeRate,
VendorSelecetList,
}; };

View File

@@ -13,7 +13,7 @@ import { momentFormatter, compose, tansformDateValue } from 'utils';
import classNames from 'classnames'; import classNames from 'classnames';
import { CLASSES } from 'common/classes'; import { CLASSES } from 'common/classes';
import { import {
ListSelect, VendorSelecetList,
ErrorMessage, ErrorMessage,
FieldRequiredHint, FieldRequiredHint,
Row, Row,
@@ -91,17 +91,10 @@ function BillFormHeader({
<ErrorMessage name={'vendor_id'} {...{ errors, touched }} /> <ErrorMessage name={'vendor_id'} {...{ errors, touched }} />
} }
> >
<ListSelect <VendorSelecetList
items={vendorItems} vendorsList={vendorItems}
noResults={<MenuItem disabled={true} text="No results." />} selectedVendorId={values.vendor_id}
itemRenderer={vendorNameRenderer}
itemPredicate={filterVendorAccount}
popoverProps={{ minimal: true }}
onItemSelect={onChangeSelected('vendor_id')} onItemSelect={onChangeSelected('vendor_id')}
selectedItem={values.vendor_id}
selectedItemProp={'id'}
defaultText={<T id={'select_vendor_account'} />}
labelProp={'display_name'}
/> />
</FormGroup> </FormGroup>
@@ -135,7 +128,7 @@ function BillFormHeader({
className={classNames( className={classNames(
'form-group--due-date', 'form-group--due-date',
'form-group--select-list', 'form-group--select-list',
CLASSES.FILL CLASSES.FILL,
)} )}
intent={errors.due_date && touched.due_date && Intent.DANGER} intent={errors.due_date && touched.due_date && Intent.DANGER}
helperText={ helperText={

View File

@@ -16,7 +16,7 @@ import { CLASSES } from 'common/classes';
import { momentFormatter, compose, tansformDateValue } from 'utils'; import { momentFormatter, compose, tansformDateValue } from 'utils';
import { import {
AccountsSelectList, AccountsSelectList,
ListSelect, VendorSelecetList,
ErrorMessage, ErrorMessage,
FieldRequiredHint, FieldRequiredHint,
Money, Money,
@@ -81,7 +81,7 @@ function PaymentMadeFormHeader({
const triggerFullAmountChanged = (value) => { const triggerFullAmountChanged = (value) => {
onFullAmountChanged && onFullAmountChanged(value); onFullAmountChanged && onFullAmountChanged(value);
} };
const handleFullAmountBlur = (event) => { const handleFullAmountBlur = (event) => {
triggerFullAmountChanged(event.currentTarget.value); triggerFullAmountChanged(event.currentTarget.value);
@@ -133,18 +133,11 @@ function PaymentMadeFormHeader({
<ErrorMessage name={'vendor_id'} {...{ errors, touched }} /> <ErrorMessage name={'vendor_id'} {...{ errors, touched }} />
} }
> >
<ListSelect <VendorSelecetList
items={vendorItems} vendorsList={vendorItems}
noResults={<MenuItem disabled={true} text="No results." />} selectedVendorId={values.vendor_id}
itemRenderer={handleVenderRenderer}
itemPredicate={handleFilterVender}
popoverProps={{ minimal: true }}
onItemSelect={onChangeSelect('vendor_id')} onItemSelect={onChangeSelect('vendor_id')}
selectedItem={values.vendor_id} // buttonProps={{ disabled: !isNewMode }}
selectedItemProp={'id'}
defaultText={<T id={'select_vender_account'} />}
labelProp={'display_name'}
buttonProps={{ disabled: !isNewMode }}
disabled={!isNewMode} disabled={!isNewMode}
/> />
</FormGroup> </FormGroup>
@@ -173,26 +166,27 @@ function PaymentMadeFormHeader({
label={<T id={'full_amount'} />} label={<T id={'full_amount'} />}
inline={true} inline={true}
className={('form-group--full-amount', Classes.FILL)} className={('form-group--full-amount', Classes.FILL)}
intent={ intent={errors.full_amount && touched.full_amount && Intent.DANGER}
errors.full_amount && touched.full_amount && Intent.DANGER
}
labelInfo={<Hint />} labelInfo={<Hint />}
helperText={ helperText={
<ErrorMessage name="full_amount" {...{ errors, touched }} /> <ErrorMessage name="full_amount" {...{ errors, touched }} />
} }
> >
<InputGroup <InputGroup
intent={ intent={errors.full_amount && touched.full_amount && Intent.DANGER}
errors.full_amount && touched.full_amount && Intent.DANGER
}
minimal={true} minimal={true}
value={values.full_amount} value={values.full_amount}
{...getFieldProps('full_amount')} {...getFieldProps('full_amount')}
onBlur={handleFullAmountBlur} onBlur={handleFullAmountBlur}
/> />
<a onClick={handleReceiveFullAmountClick} href="#" className={'receive-full-amount'}> <a
Receive full amount (<Money amount={payableFullAmount} currency={'USD'} />) onClick={handleReceiveFullAmountClick}
href="#"
className={'receive-full-amount'}
>
Receive full amount (
<Money amount={payableFullAmount} currency={'USD'} />)
</a> </a>
</FormGroup> </FormGroup>
@@ -255,7 +249,9 @@ function PaymentMadeFormHeader({
inline={true} inline={true}
className={classNames('form-group--reference', Classes.FILL)} className={classNames('form-group--reference', Classes.FILL)}
intent={errors.reference && touched.reference && Intent.DANGER} intent={errors.reference && touched.reference && Intent.DANGER}
helperText={<ErrorMessage name="reference" {...{ errors, touched }} />} helperText={
<ErrorMessage name="reference" {...{ errors, touched }} />
}
> >
<InputGroup <InputGroup
intent={errors.reference && touched.reference && Intent.DANGER} intent={errors.reference && touched.reference && Intent.DANGER}