1
|
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
|
>
|
66
|
<Form
|
67
|
onFinish={onFinish}
|
68
|
onFinishFailed={onFinishFailed}
|
69
|
autoComplete="off"
|
70
|
labelCol={{ span: 4 }}
|
71
|
layout="horizontal"
|
72
|
>
|
73
|
<Form.Item
|
74
|
label=""
|
75
|
name="role"
|
76
|
rules={[
|
77
|
{
|
78
|
required: true,
|
79
|
message: 'Prosím vyberte roli',
|
80
|
},
|
81
|
]}
|
82
|
>
|
83
|
<Radio.Group>
|
84
|
<Radio.Button value={ERole.Annotator}>Anotátor</Radio.Button>
|
85
|
<Radio.Button value={ERole.Administrator}>Admin</Radio.Button>
|
86
|
</Radio.Group>
|
87
|
</Form.Item>
|
88
|
<Form.Item
|
89
|
name="username"
|
90
|
rules={[
|
91
|
{
|
92
|
required: true,
|
93
|
message: 'Prosím zadejte uživatelské jméno',
|
94
|
},
|
95
|
]}
|
96
|
>
|
97
|
<Input placeholder="Uživatelské jméno" />
|
98
|
</Form.Item>
|
99
|
<Form.Item
|
100
|
name="password"
|
101
|
rules={[{ required: true, message: 'Prosím zadejte heslo' }]}
|
102
|
>
|
103
|
<Input.Password placeholder="Heslo" />
|
104
|
</Form.Item>
|
105
|
|
106
|
<Form.Item
|
107
|
name="name"
|
108
|
rules={[
|
109
|
{
|
110
|
required: true,
|
111
|
message: 'Prosím zadejte jméno',
|
112
|
},
|
113
|
]}
|
114
|
>
|
115
|
<Input placeholder="Jméno" />
|
116
|
</Form.Item>
|
117
|
|
118
|
<Form.Item
|
119
|
name="surname"
|
120
|
rules={[
|
121
|
{
|
122
|
required: true,
|
123
|
message: 'Prosím zadejte příjmení',
|
124
|
},
|
125
|
]}
|
126
|
>
|
127
|
<Input placeholder="Příjmení" />
|
128
|
</Form.Item>
|
129
|
<Form.Item>
|
130
|
<Button type="primary" htmlType="submit" className="w-100">
|
131
|
Vytvořit
|
132
|
</Button>
|
133
|
</Form.Item>
|
134
|
</Form>
|
135
|
</Modal>
|
136
|
);
|
137
|
};
|
138
|
|
139
|
export default AddUserModal;
|