From 640739f3234dfe3392566e76fc950dde4b42af09 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 17 Mar 2021 03:25:28 +0300 Subject: feat: allow multiple products in a waybill --- src/containers/WaybillForm.tsx | 36 +++++++++++++++++++++++++++++------- src/containers/WaybillPanel.tsx | 20 +++++++------------- 2 files changed, 36 insertions(+), 20 deletions(-) (limited to 'src/containers') diff --git a/src/containers/WaybillForm.tsx b/src/containers/WaybillForm.tsx index fedc9c4..2167d17 100644 --- a/src/containers/WaybillForm.tsx +++ b/src/containers/WaybillForm.tsx @@ -1,10 +1,17 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Form, FormikProps } from 'formik'; +import _ from 'lodash'; import Input from '../components/Input'; +import Button from '../components/Button'; import Select from '../components/Select'; +import Paper from '../components/Paper'; import useOptions from '../hooks/useOptions'; const WaybillForm: React.FC = ({ setFieldValue, values }) => { + const [recordsNumber, setRecordsNumber] = useState(values.records.length); + + const handleAddRecord = () => setRecordsNumber(v => v + 1); + const contractorOptions = useOptions('contractors', 'contractorId', values, setFieldValue); const productOptions = useOptions('products', 'productId', values, setFieldValue); @@ -15,11 +22,6 @@ const WaybillForm: React.FC = ({ setFieldValue, values }) => { label="Контрагент" options={contractorOptions} /> - = ({ setFieldValue, values }) => { { key: 'out', label: 'Расход' }, ]} /> - + + {_.times(recordsNumber).map(index => ( + + + + {values.records[index]?.price * values.records[index]?.quantity || 0} + + ))} ); }; diff --git a/src/containers/WaybillPanel.tsx b/src/containers/WaybillPanel.tsx index ca40169..397b16b 100644 --- a/src/containers/WaybillPanel.tsx +++ b/src/containers/WaybillPanel.tsx @@ -3,35 +3,29 @@ import { useHistory } from 'react-router-dom'; import Input from '../components/Input'; import Button from '../components/Button'; import Paper from '../components/Paper'; -import { post } from '../requests'; +import { patch } from '../requests'; import { PanelProps } from './Service/ServiceContext'; const WaybillPanel: React.FC = ({ item }) => { const history = useHistory(); - const handleExecute = () => post(`/waybills/${item._id}/execute`) + const handleExecute = () => patch(`/waybills/${item._id}`, { status: 'executed' }) .then(() => history.push('/waybills')); - const handleCancel = () => post(`/waybills/${item._id}/cancel`) + const handleCancel = () => patch(`/waybills/${item._id}`, { status: 'cancelled' }) .then(() => history.push('/waybills')); const executed = item.status === 'executed'; - const total = item.product.price * item.quantity; return (

- Итоговая сумма: ${total} + Итоговая сумма: ${item.total}

-
- - -
+ { executed ? -- cgit v1.2.3