import React from 'react'; import { Classes, FormGroup, InputGroup } from '@blueprintjs/core'; import { FastField } from 'formik'; import { FormattedMessage as T } from 'react-intl'; import classNames from 'classnames'; import { CLASSES } from 'common/classes'; import { useCurrencyFormContext } from './CurrencyFormProvider'; import { ErrorMessage, FieldRequiredHint, ListSelect } from 'components'; import { useAutofocus } from 'hooks'; import { inputIntent, currenciesOptions } from 'utils'; /** * Currency form fields. */ export default function CurrencyFormFields() { const currencyNameFieldRef = useAutofocus(); const { isEditMode } = useCurrencyFormContext(); // Filter currency code const filterCurrencyCode = (query, currency, _index, exactMatch) => { const normalizedTitle = currency.name.toLowerCase(); const normalizedQuery = query.toLowerCase(); if (exactMatch) { return normalizedTitle === normalizedQuery; } else { return normalizedTitle.indexOf(normalizedQuery) >= 0; } }; return (
{({ form: { setFieldValue }, field: { value }, meta: { error, touched }, }) => ( } className={classNames(CLASSES.FILL, 'form-group--type')} > } onItemSelect={(currency) => { setFieldValue('currency_code', currency.currency_code); setFieldValue('currency_name', currency.name); setFieldValue('currency_sign', currency.symbol); }} itemPredicate={filterCurrencyCode} disabled={isEditMode} popoverProps={{ minimal: true }} /> )} {/* ----------- Currency name ----------- */} {({ field, field: { value }, meta: { error, touched } }) => ( } labelInfo={} className={'form-group--currency-name'} intent={inputIntent({ error, touched })} helperText={} // inline={true} > (currencyNameFieldRef.current = ref)} {...field} /> )} {/* ----------- Currency Code ----------- */} {({ field, field: { value }, meta: { error, touched } }) => ( } labelInfo={} className={'form-group--currency-sign'} intent={inputIntent({ error, touched })} helperText={} > )}
); }