From 839c9ccc0e12b7d15611df72baf9acaea19e8480 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 20 Mar 2021 00:20:42 +0300 Subject: feat: add Transers section --- src/containers/ProductForm.tsx | 1 - src/containers/TransferForm.tsx | 44 +++++++++++++++++++++++++++++++++++++++++ src/containers/WaybillPanel.tsx | 3 +-- src/index.tsx | 2 ++ src/services.js | 15 ++++++++++++++ 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/containers/TransferForm.tsx diff --git a/src/containers/ProductForm.tsx b/src/containers/ProductForm.tsx index f458372..060fbbb 100644 --- a/src/containers/ProductForm.tsx +++ b/src/containers/ProductForm.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { Form } from 'formik'; import Input from '../components/Input'; -import DatePicker from '../components/DatePicker'; const ProductForm: React.FC = () => { diff --git a/src/containers/TransferForm.tsx b/src/containers/TransferForm.tsx new file mode 100644 index 0000000..afb2dff --- /dev/null +++ b/src/containers/TransferForm.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import { Form, FormikProps } from 'formik'; +import moment from 'moment'; +import Input from '../components/Input'; +import Select from '../components/Select'; +import hooks from '../hooks/useAPIClient'; + + +const mapper = (item: any) => ({ key: item._id, label: item.name }); + + +const TransferForm: React.FC = ({ setFieldValue, values }) => { + const { data: contractors } = hooks.contractors.useList(); + + if (!values.date) setFieldValue('date', moment().format('YYYY-MM-DD')); + if (!values.contractorId && contractors) setFieldValue('contractorId', contractors[0]._id); + + return ( +
+
+ +
+
+ +
+
+ ); +}; + +export default TransferForm; diff --git a/src/containers/WaybillPanel.tsx b/src/containers/WaybillPanel.tsx index d74ef1e..b90447e 100644 --- a/src/containers/WaybillPanel.tsx +++ b/src/containers/WaybillPanel.tsx @@ -1,8 +1,7 @@ import React from 'react'; import { useHistory } from 'react-router-dom'; -import Input from '../components/Input'; import Button from '../components/Button'; -import { patch, get, baseURL } from '../requests'; +import { patch, baseURL } from '../requests'; import { PanelProps } from './Service/ServiceContext'; diff --git a/src/index.tsx b/src/index.tsx index 68f3222..af5ca5a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -15,11 +15,13 @@ import WaybillForm from './containers/WaybillForm'; import WaybillPanel from './containers/WaybillPanel'; import ContractorForm from './containers/ContractorForm'; import ProductForm from './containers/ProductForm'; +import TransferForm from './containers/TransferForm'; services[0].Form = ProductForm; services[1].Form = ContractorForm; services[2].Form = WaybillForm; services[2].Panel = WaybillPanel; +services[3].Form = TransferForm; const navigation = [ diff --git a/src/services.js b/src/services.js index 2e219ed..a21c5b9 100644 --- a/src/services.js +++ b/src/services.js @@ -58,6 +58,21 @@ const services: ServiceParams[] = [ records: [], }, }, + { + route: 'transfers', + name: 'Переводы', + nameSingular: 'Перевод', + tableFields: [ + { key: 'date', label: 'Дата', transform: date => new Date(date).toLocaleDateString() }, + { key: 'contractor.name', label: 'Контрагент' }, + { key: 'operation', label: 'Операция', transform: op => operationNames[op] }, + { key: 'amount', label: 'Сумма' }, + ], + default: { + operation: 'in', + records: [], + }, + }, ]; export default services; -- cgit v1.2.3