Projekt

Obecné

Profil

Stáhnout (2.31 KB) Statistiky
| Větev: | Tag: | Revize:
1 428b6f89 Dominik Poch
import { message, Button, Modal, Upload } from 'antd';
2
import { InboxOutlined } from '@ant-design/icons';
3
import 'antd/dist/antd.css';
4
5
const { Dragger } = Upload;
6
7
/**
8
 * Creates a modal window that loads documents to the app.
9
 * @returns The modal window.
10
 */
11 c73aecde Dominik Poch
export function AddDocument(afterClose: () => {}) {
12 428b6f89 Dominik Poch
    /**
13
     * Settings of a file loader.
14
     */
15
    const props = {
16
        name: 'file',
17
        multiple: true,
18
        directory: true,
19
        /**
20
            @todo: Probably will be needed to change the uploading URL
21
        **/
22
        action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
23
        onChange(info: any) {
24
            const { status } = info.file;
25
26
            if (status !== 'uploading') {
27
                console.log(info.file, info.fileList);
28
            }
29
30
            if (status === 'done') {
31
                message.success(`${info.file.name} file uploaded successfully.`);
32
            } else if (status === 'error') {
33
                message.error(`${info.file.name} file upload failed.`);
34
            }
35
        },
36
        onDrop(e: any) {
37
            console.log('Dropped files', e.dataTransfer.files);
38
        },
39
    };
40
41
    /**
42 acb8a961 Dominik Poch
     * Handles successful closing of the modal window.
43 428b6f89 Dominik Poch
     */
44
    const handleOk = () => {
45
        /**
46
            @todo: Send documents to a server when all files are loaded
47
        **/
48
        console.log('Document is loaded');
49 c73aecde Dominik Poch
        afterClose();
50 428b6f89 Dominik Poch
    };
51
52
    /**
53
     * Handles cancelling of the model window.
54
     */
55
    const handleCancel = () => {
56
        console.log('Loading of documents is cancelled.');
57 c73aecde Dominik Poch
        afterClose();
58 428b6f89 Dominik Poch
    };
59
60
    return (
61
        <Modal
62
            title="Nový dokument"
63
            onOk={handleOk}
64
            onCancel={handleCancel}
65
            footer={[
66
                <Button key="back" onClick={handleCancel}>
67
                    Storno
68
                </Button>,
69
                <Button key="submit" type="primary" onClick={handleOk}>
70
                    Nahrát
71
                </Button>,
72
            ]}
73
        >
74
            <Dragger>
75
                <p className="ant-upload-drag-icon">
76
                    <InboxOutlined />
77
                </p>
78
                <p className="ant-upload-text">
79
                    Soubory lze nahrát stisknutím nebo přetažením...
80
                </p>
81
            </Dragger>
82
        </Modal>
83
    );
84
}