Commit bf8a51ab authored by Maksym Tishchenko's avatar Maksym Tishchenko Committed by Matija Obreza

Added decorator to InventoryForm to update related fields

parent 1c28587e
......@@ -13,6 +13,7 @@ import { PageSection } from '@gringlobal/client/ui/common/layout/Section';
import SiteField from 'common/SiteField';
import TaxonomySpeciesField from 'common/TaxonomySpeciesField';
import AccessionField from 'common/AccessionField';
import createDecorator from 'final-form-calculate';
const styles = (theme) => createStyles({
textField: {},
......@@ -22,6 +23,32 @@ const styles = (theme) => createStyles({
},
});
const relatedFieldsToPolicy = [
'distributionCriticalQuantity' ,
'distributionDefaultFormCode',
'distributionDefaultQuantity',
'distributionUnitCode',
'formTypeCode',
'isAutoDeducted',
'maintenanceName',
'note',
'quantityOnHandUnitCode',
'regenerationCriticalQuantity',
'regenerationMethodCode',
]
const calculator = createDecorator(
{
field: 'inventoryMaintPolicy', // when inventory maintenance policy changes...
updates: {
// ...update related fields
...relatedFieldsToPolicy.reduce((acc, el) => {
acc[el] = (policy: InventoryPolicyField) => policy[el];
return acc;
}, {}),
},
});
interface IInventoryForm extends React.ClassAttributes<any>, FormProps, WithTranslation, WithStyles {
error: string;
initialValues: Partial<Inventory>;
......@@ -38,6 +65,7 @@ class InventoryForm extends React.Component<IInventoryForm, any> {
<Form
initialValues={ initialValues }
onSubmit={ onSubmit }
decorators={ [ calculator ] }
>
{ (props: FormRenderProps & WithStyles) => (
<form onSubmit={ props.handleSubmit } className={ classes.container }>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment