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.tsx12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/services/transfers/TransfersUpload.tsx b/src/services/transfers/TransfersUpload.tsx
index c14a5c1..56bcd7e 100644
--- a/src/services/transfers/TransfersUpload.tsx
+++ b/src/services/transfers/TransfersUpload.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useRef } from 'react';
import { useHistory } from 'react-router-dom';
import { Form, Formik } from 'formik';
import Input from '../../components/Input';
@@ -8,15 +8,15 @@ import { post } from '../../requests';
const TransfersUpload: React.FC = () => {
const history = useHistory();
+ const inputRef = useRef<HTMLInputElement>(null);
const handleSubmitFile = () => {
const reader = new FileReader();
- const element = document.getElementById('file') as HTMLInputElement;
- const file = element?.files?.[0];
+ const file = inputRef?.current?.files?.[0];
if (file) {
reader.readAsDataURL(file);
- reader.onload = (e: any) => {
- const uri = e.target.result;
+ reader.onload = (event: ProgressEvent<FileReader>) => {
+ const uri = event.target?.result;
post('/uploads', { uri }).then(history.goBack);
};
}
@@ -34,7 +34,7 @@ const TransfersUpload: React.FC = () => {
>
<Formik onSubmit={handleSubmitFile} initialValues={{}}>
<Form id="form">
- <Input name="file" type="file" accept=".pdf" label="Прикрепите файл" id="file" />
+ <Input name="file" type="file" accept=".pdf" label="Прикрепите файл" ref={inputRef} />
</Form>
</Formik>
</Page>