feat: adjustments.

This commit is contained in:
elforjani3
2021-01-13 07:14:38 +02:00
parent c2af716225
commit 244a32e5fd
18 changed files with 582 additions and 272 deletions

View File

@@ -1,21 +1,23 @@
import React from 'react';
import { FastField, ErrorMessage } from 'formik';
import { FastField, ErrorMessage, useFormikContext } from 'formik';
import { add, sumBy, subtract } from 'lodash';
import { FormGroup, InputGroup, Intent } from '@blueprintjs/core';
import { Row, Col, FieldRequiredHint } from 'components';
import { inputIntent } from 'utils';
import { FormattedMessage as T } from 'react-intl';
import { calculate } from './utils';
function IncrementAdjustmentFields() {
return (
<Row>
{/*------------ Quantity on hand -----------*/}
<Col sm={3}>
<FastField name={'quantity'}>
<FastField name={'quantity_on_hand'}>
{({ field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'qty_on_hand'} />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="quantity" />}
helperText={<ErrorMessage name="quantity_on_hand" />}
>
<InputGroup disabled={true} medium={'true'} {...field} />
</FormGroup>
@@ -24,15 +26,28 @@ function IncrementAdjustmentFields() {
</Col>
{/*------------ Increment -----------*/}
<Col sm={2}>
<FastField name={'increment'}>
{({ field, meta: { error, touched } }) => (
<FastField name={'quantity'}>
{({
form: { values, setFieldValue },
field,
meta: { error, touched },
}) => (
<FormGroup
label={<T id={'increment'} />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="increment" />}
helperText={<ErrorMessage name="quantity" />}
fill={true}
>
<InputGroup medium={'true'} {...field} />
<InputGroup
medium={'true'}
{...field}
onBlur={(event) => {
setFieldValue(
'new_quantity',
calculate(values, event.currentTarget.value),
);
}}
/>
</FormGroup>
)}
</FastField>
@@ -54,13 +69,26 @@ function IncrementAdjustmentFields() {
{/*------------ New quantity -----------*/}
<Col sm={4}>
<FastField name={'new_quantity'}>
{({ field, meta: { error, touched } }) => (
{({
form: { values, setFieldValue },
field,
meta: { error, touched },
}) => (
<FormGroup
label={<T id={'new_quantity'} />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="new_quantity" />}
>
<InputGroup medium={'true'} {...field} />
<InputGroup
medium={'true'}
{...field}
onBlur={(event) => {
setFieldValue(
'quantity',
subtract(field.value, values.quantity_on_hand),
);
}}
/>
</FormGroup>
)}
</FastField>