summaryrefslogtreecommitdiff
path: root/src/containers
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-20 17:53:52 +0300
committereug-vs <eug-vs@keemail.me>2021-03-20 17:54:35 +0300
commit582a48dc7d1234a8d3e8a435f5fae16bdfcf7599 (patch)
tree363e549ddf17ce1e30ba2571e92b0930113b78df /src/containers
parent5f1bf64ed38fdda9143b75f0ab847eebe55eaaaa (diff)
downloadcommercel-ui-582a48dc7d1234a8d3e8a435f5fae16bdfcf7599.tar.gz
feat: add Transfers upload
Diffstat (limited to 'src/containers')
-rw-r--r--src/containers/TransfersUpload.tsx42
-rw-r--r--src/containers/WaybillForm.tsx2
2 files changed, 43 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) => {