import React, { useEffect, useRef } from 'react'; import { FormGroup, InputGroup, RadioGroup, Classes, Radio, Position, } from '@blueprintjs/core'; import { FormattedMessage as T } from 'react-intl'; import { ErrorMessage, FastField } from 'formik'; import { useIntl } from 'react-intl'; import { CategoriesSelectList, Hint, Col, Row, FieldRequiredHint, } from 'components'; import classNames from 'classnames'; import { CLASSES } from 'common/classes'; import withItemCategories from 'containers/Items/withItemCategories'; import withAccounts from 'containers/Accounts/withAccounts'; import withDashboardActions from 'containers/Dashboard/withDashboardActions'; import { compose, handleStringChange, inputIntent } from 'utils'; import { transitionItemTypeKeyToLabel } from './utils'; /** * Item form primary section. */ function ItemFormPrimarySection({ // #withItemCategories categoriesList, // #withDashboardActions changePageSubtitle, // #ownProps itemType, }) { const nameFieldRef = useRef(null); useEffect(() => { // Auto focus item name field once component mount. if (nameFieldRef.current) { nameFieldRef.current.focus(); } }, []); const itemTypeHintContent = ( <>
{'Service: '} {'Services that you provide to customers. '}
{'Inventory: '} {'Products you buy and/or sell and that you track quantities of.'}
{'Non-Inventory: '} { 'Products you buy and/or sell but don’t need to (or can’t) track quantities of, for example, nuts and bolts used in an installation.' }
); return (
{/*----------- Item type ----------*/} {({ form, field: { value }, meta: { touched, error } }) => ( } labelInfo={ } className={'form-group--item-type'} intent={inputIntent({ error, touched })} helperText={} inline={true} > { form.setFieldValue('type', _value); changePageSubtitle(transitionItemTypeKeyToLabel(_value)); })} selectedValue={value} disabled={itemType === 'inventory'} > } value="service" /> } value="non-inventory" /> } value="inventory" /> )} {/*----------- Item name ----------*/} {({ field, meta: { error, touched } }) => ( } labelInfo={} className={'form-group--item-name'} intent={inputIntent({ error, touched })} helperText={} inline={true} > (nameFieldRef.current = ref)} /> )} {/*----------- SKU ----------*/} {({ field, meta: { error, touched } }) => ( } className={'form-group--item_code'} intent={inputIntent({ error, touched })} helperText={} inline={true} > )} {/*----------- Item category ----------*/} {({ form, field: { value }, meta: { error, touched } }) => ( } inline={true} intent={inputIntent({ error, touched })} helperText={} className={classNames('form-group--category', Classes.FILL)} > { form.setFieldValue('category_id', category.id); }} /> )} {/* */}
); } export default compose( withAccounts(({ accountsList }) => ({ accountsList, })), withItemCategories(({ categoriesList }) => ({ categoriesList, })), withDashboardActions, )(ItemFormPrimarySection);