-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathuploadFileModal.tsx
74 lines (68 loc) · 2.21 KB
/
uploadFileModal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { useContext, useState } from 'react';
import { Download } from '@osrd-project/ui-icons';
import { isNil } from 'lodash';
import { useTranslation } from 'react-i18next';
import ModalBodySNCF from 'common/BootstrapSNCF/ModalSNCF/ModalBodySNCF';
import ModalFooterSNCF from 'common/BootstrapSNCF/ModalSNCF/ModalFooterSNCF';
import { ModalContext } from 'common/BootstrapSNCF/ModalSNCF/ModalProvider';
interface UploadFileModalProps {
handleSubmit: (file: File) => void;
}
const UploadFileModal = ({ handleSubmit }: UploadFileModalProps) => {
const { t } = useTranslation(['operationalStudies/importTrainSchedule']);
const { closeModal } = useContext(ModalContext);
const [selectedFile, setSelectedFile] = useState<File | undefined>(undefined);
return (
<>
<ModalBodySNCF>
<>
<div className="h1 modal-title text-center mb-4">
<span className="text-primary">
<Download />
</span>
</div>
<input
type="file"
name="file"
accept=".json,.txt,.xml,.railml"
onChange={async (e) => {
if (e.target.files && e.target.files.length > 0) {
setSelectedFile(e.target.files[0]);
} else {
setSelectedFile(undefined);
}
}}
/>
</>
</ModalBodySNCF>
<ModalFooterSNCF>
<div className="w-100">
<div className="row">
<div className="col-6">
<button
type="button"
className="btn btn-block btn-sm btn-secondary"
onClick={closeModal}
>
{t('cancel')}
</button>
</div>
<div className="col-6">
<button
type="button"
disabled={isNil(selectedFile)}
className="btn btn-block btn-sm btn-primary"
onClick={() => {
if (selectedFile) handleSubmit(selectedFile);
}}
>
{t('download')}
</button>
</div>
</div>
</div>
</ModalFooterSNCF>
</>
);
};
export default UploadFileModal;