// @ts-nocheck
import React from 'react';
import { useFormikContext, FastField, ErrorMessage } from 'formik';
import {
FormGroup,
Classes,
TextArea,
Checkbox,
ControlGroup,
} from '@blueprintjs/core';
import {
AccountsSelect,
MoneyInputGroup,
Col,
Row,
Hint,
InputPrependText,
FFormGroup,
} from '@/components';
import { FormattedMessage as T } from '@/components';
import { useItemFormContext } from './ItemFormProvider';
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
import { ACCOUNT_PARENT_TYPE } from '@/constants/accountTypes';
import {
sellDescriptionFieldShouldUpdate,
sellAccountFieldShouldUpdate,
sellPriceFieldShouldUpdate,
costPriceFieldShouldUpdate,
costAccountFieldShouldUpdate,
purchaseDescFieldShouldUpdate,
} from './utils';
import { compose, inputIntent } from '@/utils';
/**
* Item form body.
*/
function ItemFormBody({ organization: { base_currency } }) {
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 ------------- */}
}
name={'sell_account_id'}
labelInfo={
} />
}
inline={true}
items={accounts}
sellable={values.sellable}
shouldUpdate={sellAccountFieldShouldUpdate}
fastField={true}
>
}
disabled={!values.sellable}
filterByParentTypes={[ACCOUNT_PARENT_TYPE.INCOME]}
fill={true}
allowCreate={true}
fastField={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 ------------- */}
}
labelInfo={
} />
}
inline={true}
fastField={true}
>
}
filterByParentTypes={[ACCOUNT_PARENT_TYPE.EXPENSE]}
popoverFill={true}
allowCreate={true}
fastField={true}
disabled={!values.purchasable}
purchasable={values.purchasable}
shouldUpdate={costAccountFieldShouldUpdate}
/>
{({ form: { values }, field, meta: { error, touched } }) => (
}
className={'form-group--purchase-description'}
intent={inputIntent({ error, touched })}
helperText={}
inline={true}
>
)}
);
}
export default compose(withCurrentOrganization())(ItemFormBody);