Projekt

Obecné

Profil

Stáhnout (4.11 KB) Statistiky
| Větev: | Tag: | Revize:
1 82ba2ee5 Jaroslav Hrubý
import { Button, Form, Input, Modal, Radio, Upload } from 'antd';
2
import { InboxOutlined, LockOutlined, UserOutlined } from '@ant-design/icons';
3
import 'antd/dist/antd.css';
4
import React from 'react';
5
import {
6
    CreateUserRequest,
7
    DocumentAddInfo,
8
    EAddDocumentFormat,
9
    ERole,
10
    LoginResponse,
11
} from '../../api';
12
import { documentController, userController } from '../../controllers';
13
import { ShowToast } from '../../utils/alerts';
14
import { getTokenData } from '../../utils/login';
15
16
const { Dragger } = Upload;
17
18
interface ModalProps {
19
    onCancel: () => void;
20
}
21
22
/**
23
 * Creates a modal window that loads documents to the app.
24
 * @returns The modal window.
25
 */
26
const AddUserModal: React.FC<ModalProps> = ({ onCancel }) => {
27
    /**
28
     * Handles successful closing of the modal window.
29
     */
30
    const handleOk = () => {
31
        onCancel();
32
    };
33
34
    /**
35
     * Handles cancelling of the model window.
36
     */
37
    const handleCancel = () => {
38
        onCancel();
39
    };
40
41
    const onFinish = async (values: any) => {
42
        const req: CreateUserRequest = {
43
            username: values.username,
44
            password: values.password,
45
            name: values.name,
46
            surname: values.surname,
47
            role: values.role,
48
        };
49
50
        const loginRes = await userController.usersPost(req);
51
        onCancel();
52
    };
53
54
    const onFinishFailed = (errorInfo: any) => {
55
        ShowToast('Zadané údaje nejsou validní', 'error', 3000, 'top-end');
56
    };
57
58
    return (
59
        <Modal
60
            title="Nový uživatel"
61
            onOk={handleOk}
62
            visible={true}
63
            onCancel={handleCancel}
64
            footer={null}
65 669ffe38 Jaroslav Hrubý
            centered
66 82ba2ee5 Jaroslav Hrubý
        >
67
            <Form
68
                onFinish={onFinish}
69
                onFinishFailed={onFinishFailed}
70
                autoComplete="off"
71
                labelCol={{ span: 4 }}
72
                layout="horizontal"
73
            >
74
                <Form.Item
75
                    label=""
76
                    name="role"
77
                    rules={[
78
                        {
79
                            required: true,
80
                            message: 'Prosím vyberte roli',
81
                        },
82
                    ]}
83
                >
84
                    <Radio.Group>
85
                        <Radio.Button value={ERole.Annotator}>Anotátor</Radio.Button>
86
                        <Radio.Button value={ERole.Administrator}>Admin</Radio.Button>
87
                    </Radio.Group>
88
                </Form.Item>
89
                <Form.Item
90
                    name="username"
91
                    rules={[
92
                        {
93
                            required: true,
94
                            message: 'Prosím zadejte uživatelské jméno',
95
                        },
96
                    ]}
97
                >
98
                    <Input placeholder="Uživatelské jméno" />
99
                </Form.Item>
100
                <Form.Item
101
                    name="password"
102
                    rules={[{ required: true, message: 'Prosím zadejte heslo' }]}
103
                >
104 43d49a98 Jaroslav Hrubý
                    <Input.Password placeholder="Heslo" />
105 82ba2ee5 Jaroslav Hrubý
                </Form.Item>
106
107
                <Form.Item
108
                    name="name"
109
                    rules={[
110
                        {
111
                            required: true,
112
                            message: 'Prosím zadejte jméno',
113
                        },
114
                    ]}
115
                >
116
                    <Input placeholder="Jméno" />
117
                </Form.Item>
118
119
                <Form.Item
120
                    name="surname"
121
                    rules={[
122
                        {
123
                            required: true,
124
                            message: 'Prosím zadejte příjmení',
125
                        },
126
                    ]}
127
                >
128
                    <Input placeholder="Příjmení" />
129
                </Form.Item>
130
                <Form.Item>
131
                    <Button type="primary" htmlType="submit" className="w-100">
132
                        Vytvořit
133
                    </Button>
134
                </Form.Item>
135
            </Form>
136
        </Modal>
137
    );
138
};
139
140
export default AddUserModal;