From 8e011b65f346386abe26afcce737dd59c5865988 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Mar 2021 12:08:32 +0300 Subject: feat: add Waybills --- src/containers/ContractorForm.tsx | 1 - src/containers/Service/ServiceContext.tsx | 1 + src/containers/Service/ServiceForm.tsx | 3 ++- src/containers/WaybillForm.tsx | 33 +++++++++++++++++++++++++++++++ src/index.tsx | 8 ++++++++ src/services.js | 30 ++++++++++++++++++++++++---- 6 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 src/containers/WaybillForm.tsx diff --git a/src/containers/ContractorForm.tsx b/src/containers/ContractorForm.tsx index 4e83fae..c78ed9b 100644 --- a/src/containers/ContractorForm.tsx +++ b/src/containers/ContractorForm.tsx @@ -8,7 +8,6 @@ const ContractorForm: React.FC = () => {
-
); diff --git a/src/containers/Service/ServiceContext.tsx b/src/containers/Service/ServiceContext.tsx index 2602936..8f23d9d 100644 --- a/src/containers/Service/ServiceContext.tsx +++ b/src/containers/Service/ServiceContext.tsx @@ -6,6 +6,7 @@ export interface ServiceParams { nameSingular: string; tableFields: any[]; Form: React.FC; + default: Record; } const ServiceContext = React.createContext({ diff --git a/src/containers/Service/ServiceForm.tsx b/src/containers/Service/ServiceForm.tsx index 273f5bd..62e4521 100644 --- a/src/containers/Service/ServiceForm.tsx +++ b/src/containers/Service/ServiceForm.tsx @@ -1,6 +1,7 @@ import React, { useContext } from 'react'; import { useParams, useHistory } from 'react-router-dom'; import { Formik } from 'formik'; +import _ from 'lodash'; import Page, { Action } from '../Page'; import hooks from '../../hooks/useAPIClient'; import { post, patch } from '../../requests'; @@ -32,7 +33,7 @@ const ServiceForm: React.FC = () => { {(!id || item) && ( diff --git a/src/containers/WaybillForm.tsx b/src/containers/WaybillForm.tsx new file mode 100644 index 0000000..e4d7d82 --- /dev/null +++ b/src/containers/WaybillForm.tsx @@ -0,0 +1,33 @@ +import React from 'react'; +import { Form, Field } from 'formik'; +import Input from '../components/Input'; +import hooks from '../hooks/useAPIClient'; + +const WaybillForm: React.FC = () => { + const { data: contractors } = hooks.contractors.useList(); + const { data: products } = hooks.products.useList(); + + return ( +
+
+ + + + + + {contractors?.map(contractor => ( + + ))} + + + {products?.map(product => ( + + ))} + + +
+
+ ); +}; + +export default WaybillForm; diff --git a/src/index.tsx b/src/index.tsx index 1005a9d..e637e68 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -11,6 +11,14 @@ import Home from './containers/Home'; import Service from './containers/Service/Service'; import { ServiceProvider } from './containers/Service/ServiceContext'; import services from './services'; +import WaybillForm from './containers/WaybillForm'; +import ContractorForm from './containers/ContractorForm'; +import ProductForm from './containers/ProductForm'; + +services[0].Form = ProductForm; +services[1].Form = ContractorForm; +services[2].Form = WaybillForm; + const navigation = [ { name: 'Главная', route: '/' }, diff --git a/src/services.js b/src/services.js index 83fc425..dbfedd5 100644 --- a/src/services.js +++ b/src/services.js @@ -1,5 +1,3 @@ -import ContractorForm from './containers/ContractorForm'; -import ProductForm from './containers/ProductForm'; import { ServiceParams } from './containers/Service/ServiceContext'; const services: ServiceParams[] = [ @@ -10,8 +8,13 @@ const services: ServiceParams[] = [ tableFields: [ { key: 'name', label: 'Название' }, { key: 'price', label: 'Цена' }, + { key: 'quantity', label: 'На складе' }, ], - Form: ProductForm, + default: { + name: '', + price: '', + quantity: 0, + }, }, { route: 'contractors', @@ -22,7 +25,26 @@ const services: ServiceParams[] = [ { key: 'name', label: 'Название' }, { key: 'debt', label: 'Долг' }, ], - Form: ContractorForm, + default: { + name: '', + vatId: '', + debt: 0, + }, + }, + { + route: 'waybills', + name: 'Накладные', + nameSingular: 'Накладная', + tableFields: [ + { key: 'operation', label: 'Операция' }, + { key: 'productId', label: 'Товар' }, + { key: 'contractorId', label: 'Поставщик' }, + { key: 'status', label: 'Статус' }, + { key: 'quantity', label: 'Количество' }, + ], + default: { + quantity: 1, + }, }, ]; -- cgit v1.2.3