From 582a48dc7d1234a8d3e8a435f5fae16bdfcf7599 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 20 Mar 2021 17:53:52 +0300 Subject: feat: add Transfers upload --- src/containers/TransfersUpload.tsx | 42 ++++++++++++++++++++++++++++++++++++++ src/containers/WaybillForm.tsx | 2 +- src/index.tsx | 2 ++ src/services.js | 5 +++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/containers/TransfersUpload.tsx diff --git a/src/containers/TransfersUpload.tsx b/src/containers/TransfersUpload.tsx new file mode 100644 index 0000000..8239ab9 --- /dev/null +++ b/src/containers/TransfersUpload.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import { Form, Formik } from 'formik'; +import Button from '../components/Button'; +import Input from '../components/Input'; +import Page, { Action } from './Page'; +import { post } from '../requests'; + +const TransfersUpload: React.FC = () => { + const history = useHistory(); + + const handleSubmitFile = () => { + const reader = new FileReader(); + const file = document.getElementById('file').files[0]; + reader.readAsDataURL(file); + reader.onload = (e: any) => { + const uri = e.target.result; + post('/uploads', { uri }) + .then(() => history.push('/transfers')); + }; + }; + + const actions: Action[] = [ + { name: 'Назад', variant: 'outlined', onClick: history.goBack }, + { name: 'Загрузить', type: 'submit', form: 'form' }, + ]; + + return ( + + +
+ +
+
+
+ ); +}; + +export default TransfersUpload; diff --git a/src/containers/WaybillForm.tsx b/src/containers/WaybillForm.tsx index a6a37e2..5fcdb7d 100644 --- a/src/containers/WaybillForm.tsx +++ b/src/containers/WaybillForm.tsx @@ -17,7 +17,7 @@ const WaybillForm: 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); + if (!values.contractorId && contractors?.length) setFieldValue('contractorId', contractors[0]._id); const handleAddRecord = () => setFieldValue('records', [...values.records, { productId: _.map(products, '_id').reduce((acc, id) => { diff --git a/src/index.tsx b/src/index.tsx index af5ca5a..71caf35 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -16,12 +16,14 @@ import WaybillPanel from './containers/WaybillPanel'; import ContractorForm from './containers/ContractorForm'; import ProductForm from './containers/ProductForm'; import TransferForm from './containers/TransferForm'; +import TransfersUpload from './containers/TransfersUpload'; services[0].Form = ProductForm; services[1].Form = ContractorForm; services[2].Form = WaybillForm; services[2].Panel = WaybillPanel; services[3].Form = TransferForm; +services[3].routes = { upload: TransfersUpload }; const navigation = [ diff --git a/src/services.js b/src/services.js index a21c5b9..7187519 100644 --- a/src/services.js +++ b/src/services.js @@ -68,6 +68,11 @@ const services: ServiceParams[] = [ { key: 'operation', label: 'Операция', transform: op => operationNames[op] }, { key: 'amount', label: 'Сумма' }, ], + actions: [{ + name: 'Загрузить выписку', + route: 'upload', + variant: 'outlined', + }], default: { operation: 'in', records: [], -- cgit v1.2.3