import React from 'react';
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
import {
Classes,
FormGroup,
RadioGroup,
Radio,
InputGroup,
} from '@blueprintjs/core';
import classNames from 'classnames';
import { FormattedMessage as T, If } from 'components';
import intl from 'react-intl-universal';
import { inputIntent, handleStringChange } from 'utils';
import { FieldRequiredHint, ListSelect } from 'components';
import { CLASSES } from 'common/classes';
import allocateLandedCostType from 'common/allocateLandedCostType';
import { useLandedCostTransaction } from 'hooks/query';
import AllocateLandedCostFormBody from './AllocateLandedCostFormBody';
import { getEntriesByTransactionId } from './utils';
/**
* Allocate landed cost form fields.
*/
export default function AllocateLandedCostFormFields() {
const { values } = useFormikContext();
const {
data: { transactions },
} = useLandedCostTransaction(values.transaction_type);
// Retrieve entries of the given transaction id.
const transactionEntries = React.useMemo(() => getEntriesByTransactionId(
transactions,
values.transaction_id,
), [transactions, values.transaction_id]);
return (
{/*------------Transaction type -----------*/}
{({
form: { values, setFieldValue },
field: { value },
meta: { error, touched },
}) => (
}
labelInfo={}
helperText={}
intent={inputIntent({ error, touched })}
inline={true}
className={classNames(CLASSES.FILL, 'form-group--transaction_type')}
>
{
setFieldValue('transaction_type', type.value);
}}
filterable={false}
selectedItem={value}
selectedItemProp={'value'}
textProp={'name'}
popoverProps={{ minimal: true }}
/>
)}
{/*------------ Transaction -----------*/}
{({ form, field: { value }, meta: { error, touched } }) => (
}
labelInfo={}
intent={inputIntent({ error, touched })}
helperText={}
className={classNames(CLASSES.FILL, 'form-group--transaction_id')}
inline={true}
>
{
form.setFieldValue('transaction_id', id);
}}
filterable={false}
selectedItem={value}
selectedItemProp={'id'}
textProp={'name'}
labelProp={'id'}
defaultText={intl.get('select_transaction')}
popoverProps={{ minimal: true }}
/>
)}
{/*------------ Transaction line -----------*/}
0}>
{({ form, field: { value }, meta: { error, touched } }) => (
}
intent={inputIntent({ error, touched })}
helperText={}
className={classNames(
CLASSES.FILL,
'form-group--transaction_entry_id',
)}
inline={true}
>
{
form.setFieldValue('amount', amount)
form.setFieldValue('transaction_entry_id', id);
}}
filterable={false}
selectedItem={value}
selectedItemProp={'id'}
textProp={'name'}
labelProp={'id'}
defaultText={intl.get('select_transaction')}
popoverProps={{ minimal: true }}
/>
)}
{/*------------ Amount -----------*/}
{({ form, field, meta: { error, touched } }) => (
}
intent={inputIntent({ error, touched })}
helperText={}
className={'form-group--amount'}
inline={true}
>
)}
{/*------------ Allocation method -----------*/}
{({ form, field: { value }, meta: { touched, error } }) => (
}
labelInfo={}
className={'form-group--allocation_method'}
intent={inputIntent({ error, touched })}
helperText={}
inline={true}
>
{
form.setFieldValue('allocation_method', _value);
})}
selectedValue={value}
inline={true}
>
} value="quantity" />
} value="value" />
)}
{/*------------ Allocate Landed cost Table -----------*/}
);
}