summaryrefslogtreecommitdiff
path: root/src/services/transfers/TransfersUpload.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/transfers/TransfersUpload.tsx')
-rw-r--r--src/services/transfers/TransfersUpload.tsx17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/services/transfers/TransfersUpload.tsx b/src/services/transfers/TransfersUpload.tsx
index 56bcd7e..3a867aa 100644
--- a/src/services/transfers/TransfersUpload.tsx
+++ b/src/services/transfers/TransfersUpload.tsx
@@ -1,4 +1,4 @@
-import React, { useRef } from 'react';
+import React, { useState } from 'react';
import { useHistory } from 'react-router-dom';
import { Form, Formik } from 'formik';
import Input from '../../components/Input';
@@ -8,11 +8,14 @@ import { post } from '../../requests';
const TransfersUpload: React.FC = () => {
const history = useHistory();
- const inputRef = useRef<HTMLInputElement>(null);
+ const [file, setFile] = useState<File>();
+
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
+ setFile(event.target?.files?.[0]);
+ };
const handleSubmitFile = () => {
const reader = new FileReader();
- const file = inputRef?.current?.files?.[0];
if (file) {
reader.readAsDataURL(file);
reader.onload = (event: ProgressEvent<FileReader>) => {
@@ -34,7 +37,13 @@ const TransfersUpload: React.FC = () => {
>
<Formik onSubmit={handleSubmitFile} initialValues={{}}>
<Form id="form">
- <Input name="file" type="file" accept=".pdf" label="Прикрепите файл" ref={inputRef} />
+ <Input
+ name="file"
+ type="file"
+ accept=".pdf"
+ label="Прикрепите файл"
+ onChange={handleChange}
+ />
</Form>
</Formik>
</Page>