import React from 'react';
import { FastField, Field, ErrorMessage } from 'formik';
import { FormGroup, Classes, Checkbox, ControlGroup } from '@blueprintjs/core';
import {
AccountsSelectList,
MoneyInputGroup,
Col,
Row,
Hint,
InputPrependText,
} from 'components';
import { FormattedMessage as T } from 'react-intl';
import classNames from 'classnames';
import withAccounts from 'containers/Accounts/withAccounts';
import withSettings from 'containers/Settings/withSettings';
import { compose, inputIntent } from 'utils';
/**
* Item form body.
*/
function ItemFormBody({ accountsList, baseCurrency }) {
return (
{/*------------- Purchasable checbox ------------- */}
{({ form, field }) => (
}
name={'sellable'}
{...field}
/>
)}
{/*------------- Selling price ------------- */}
{({ form, field: { value }, meta: { error, touched } }) => (
}
className={'form-group--sell_price'}
intent={inputIntent({ error, touched })}
helperText={}
inline={true}
>
{
form.setFieldValue('sell_price', unformattedValue);
}}
/>
)}
{/*------------- Selling account ------------- */}
{({ form, field: { value }, meta: { error, touched } }) => (
}
labelInfo={}
inline={true}
intent={inputIntent({ error, touched })}
helperText={}
className={classNames(
'form-group--sell-account',
'form-group--select-list',
Classes.FILL,
)}
>
{
form.setFieldValue('sell_account_id', account.id);
}}
defaultSelectText={}
selectedAccountId={value}
disabled={!form.values.sellable}
filterByTypes={['income']}
popoverFill={true}
/>
)}
{/*------------- Sellable checkbox ------------- */}
{({ field }) => (
}
{...field}
/>
)}
{/*------------- Cost price ------------- */}
{({ field, form, field: { value }, meta: { error, touched } }) => (
}
className={'form-group--item-cost-price'}
intent={inputIntent({ error, touched })}
helperText={}
inline={true}
>
{
form.setFieldValue('cost_price', unformattedValue);
}}
/>
)}
{/*------------- Cost account ------------- */}
{({ form, field: { value }, meta: { error, touched } }) => (
}
labelInfo={}
inline={true}
intent={inputIntent({ error, touched })}
helperText={}
className={classNames(
'form-group--cost-account',
'form-group--select-list',
Classes.FILL,
)}
>
{
form.setFieldValue('cost_account_id', account.id);
}}
defaultSelectText={}
selectedAccountId={value}
disabled={!form.values.purchasable}
filterByTypes={['cost_of_goods_sold']}
popoverFill={true}
/>
)}
);
}
export default compose(
withAccounts(({ accountsList }) => ({
accountsList,
})),
withSettings(({ organizationSettings }) => ({
baseCurrency: organizationSettings?.baseCurrency,
})),
)(ItemFormBody);