From 062f10a25d43b875d187cf582b2ecf96d075ec26 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Thu, 25 Mar 2021 23:09:49 +0300
Subject: refactor: move services to separate folder

---
 src/services/transfers/TransfersUpload.tsx | 44 ++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 src/services/transfers/TransfersUpload.tsx

(limited to 'src/services/transfers/TransfersUpload.tsx')

diff --git a/src/services/transfers/TransfersUpload.tsx b/src/services/transfers/TransfersUpload.tsx
new file mode 100644
index 0000000..1c81b08
--- /dev/null
+++ b/src/services/transfers/TransfersUpload.tsx
@@ -0,0 +1,44 @@
+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 '../../containers/Page';
+import { post } from '../../requests';
+
+const TransfersUpload: React.FC = () => {
+  const history = useHistory();
+
+  const handleSubmitFile = () => {
+    const reader = new FileReader();
+    const element = document.getElementById('file') as HTMLInputElement;
+    const file = element?.files?.[0];
+    if (file) {
+      reader.readAsDataURL(file);
+      reader.onload = (e: any) => {
+        const uri = e.target.result;
+        post('/uploads', { uri }).then(history.goBack);
+      };
+    }
+  };
+
+  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

