From 582a48dc7d1234a8d3e8a435f5fae16bdfcf7599 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sat, 20 Mar 2021 17:53:52 +0300
Subject: feat: add Transfers upload

---
 src/containers/TransfersUpload.tsx | 42 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 src/containers/TransfersUpload.tsx

(limited to '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 (
+    <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;
-- 
cgit v1.2.3

