import React from 'react';
import { useFormikContext, FastField, Field, ErrorMessage } from 'formik';
import {
FormGroup,
Classes,
TextArea,
Checkbox,
ControlGroup,
} from '@blueprintjs/core';
import {
AccountsSelectList,
MoneyInputGroup,
Col,
Row,
Hint,
InputPrependText,
} from 'components';
import { FormattedMessage as T } from 'components';
import classNames from 'classnames';
import { useItemFormContext } from './ItemFormProvider';
import withSettings from 'containers/Settings/withSettings';
import { ACCOUNT_PARENT_TYPE } from 'common/accountTypes';
import { compose, inputIntent } from 'utils';
import {
sellDescriptionFieldShouldUpdate,
sellAccountFieldShouldUpdate,
sellPriceFieldShouldUpdate,
costPriceFieldShouldUpdate,
costAccountFieldShouldUpdate,
purchaseDescFieldShouldUpdate,
} from './utils';
/**
* Item form body.
*/
function ItemFormBody({ baseCurrency }) {
const { accounts } = useItemFormContext();
const { values } = useFormikContext();
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}
filterByParentTypes={[ACCOUNT_PARENT_TYPE.INCOME]}
popoverFill={true}
/>
)}
{({ form: { values }, field, meta: { error, touched } }) => (
}
className={'form-group--sell-description'}
intent={inputIntent({ error, touched })}
helperText={}
inline={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}
filterByParentTypes={[ACCOUNT_PARENT_TYPE.EXPENSE]}
popoverFill={true}
/>
)}
{({ form: { values }, field, meta: { error, touched } }) => (
}
className={'form-group--purchase-description'}
intent={inputIntent({ error, touched })}
helperText={}
inline={true}
>
)}
);
}
export default compose(
withSettings(({ organizationSettings }) => ({
baseCurrency: organizationSettings?.baseCurrency,
})),
)(ItemFormBody);