diff options
author | eug-vs <eug-vs@keemail.me> | 2021-03-20 17:53:52 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2021-03-20 17:54:35 +0300 |
commit | 582a48dc7d1234a8d3e8a435f5fae16bdfcf7599 (patch) | |
tree | 363e549ddf17ce1e30ba2571e92b0930113b78df | |
parent | 5f1bf64ed38fdda9143b75f0ab847eebe55eaaaa (diff) | |
download | commercel-ui-582a48dc7d1234a8d3e8a435f5fae16bdfcf7599.tar.gz |
feat: add Transfers upload
-rw-r--r-- | src/containers/TransfersUpload.tsx | 42 | ||||
-rw-r--r-- | src/containers/WaybillForm.tsx | 2 | ||||
-rw-r--r-- | src/index.tsx | 2 | ||||
-rw-r--r-- | src/services.js | 5 |
4 files changed, 50 insertions, 1 deletions
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 ( + <Page + title="Загрузить выписку" + actions={actions} + > + <Formik onSubmit={handleSubmitFile} initialValues={{}}> + <Form id="form"> + <Input name="file" type="file" accept=".pdf" label="Прикрепите файл" id="file" /> + </Form> + </Formik> + </Page> + ); +}; + +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<FormikProps> = ({ 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: [], |