1 |
43d49a98
|
Jaroslav Hrubý
|
import { Button, Form, Input, Modal, Radio } from 'antd';
|
2 |
|
|
import 'antd/dist/antd.css';
|
3 |
|
|
import React from 'react';
|
4 |
|
|
import { ChangeUserInfoRequest, ERole, UserInfo } from '../../api';
|
5 |
|
|
import { userController } from '../../controllers';
|
6 |
|
|
import { ShowToast } from '../../utils/alerts';
|
7 |
|
|
|
8 |
|
|
interface ModalProps {
|
9 |
|
|
onCancel: () => void;
|
10 |
|
|
userInfo: UserInfo;
|
11 |
|
|
}
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Creates a modal window that loads documents to the app.
|
15 |
|
|
* @returns The modal window.
|
16 |
|
|
*/
|
17 |
|
|
const EditUserModal: React.FC<ModalProps> = ({ onCancel, userInfo }: ModalProps) => {
|
18 |
|
|
/**
|
19 |
|
|
* Handles successful closing of the modal window.
|
20 |
|
|
*/
|
21 |
|
|
const handleOk = () => {
|
22 |
|
|
onCancel();
|
23 |
|
|
};
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* Handles cancelling of the model window.
|
27 |
|
|
*/
|
28 |
|
|
const handleCancel = () => {
|
29 |
|
|
onCancel();
|
30 |
|
|
};
|
31 |
|
|
|
32 |
|
|
const onFinish = async (values: any) => {
|
33 |
|
|
const req: ChangeUserInfoRequest = {
|
34 |
|
|
username: values.username,
|
35 |
|
|
password: values.password,
|
36 |
|
|
name: values.name,
|
37 |
|
|
surname: values.surname,
|
38 |
|
|
role: values.role,
|
39 |
|
|
};
|
40 |
|
|
if (userInfo.id) {
|
41 |
669ffe38
|
Jaroslav Hrubý
|
userController.userUserIdPut(userInfo.id, req).then((r) => {
|
42 |
|
|
ShowToast(
|
43 |
|
|
'Úprava uživatele proběhla úspěšně',
|
44 |
|
|
'success',
|
45 |
|
|
3000,
|
46 |
|
|
'top-end'
|
47 |
|
|
);
|
48 |
|
|
onCancel();
|
49 |
|
|
});
|
50 |
43d49a98
|
Jaroslav Hrubý
|
}
|
51 |
|
|
};
|
52 |
|
|
|
53 |
|
|
const onFinishFailed = (errorInfo: any) => {
|
54 |
|
|
ShowToast('Zadané údaje nejsou validní', 'error', 3000, 'top-end');
|
55 |
|
|
};
|
56 |
|
|
|
57 |
|
|
return (
|
58 |
|
|
<Modal
|
59 |
|
|
title="Upravit uživatele"
|
60 |
|
|
onOk={handleOk}
|
61 |
|
|
visible={true}
|
62 |
|
|
onCancel={handleCancel}
|
63 |
|
|
footer={null}
|
64 |
669ffe38
|
Jaroslav Hrubý
|
centered
|
65 |
43d49a98
|
Jaroslav Hrubý
|
>
|
66 |
|
|
<Form
|
67 |
|
|
onFinish={onFinish}
|
68 |
|
|
onFinishFailed={onFinishFailed}
|
69 |
|
|
autoComplete="off"
|
70 |
|
|
labelCol={{ span: 4 }}
|
71 |
|
|
layout="horizontal"
|
72 |
|
|
>
|
73 |
669ffe38
|
Jaroslav Hrubý
|
<Form.Item label="" name="role">
|
74 |
|
|
<Radio.Group defaultValue={userInfo.role}>
|
75 |
43d49a98
|
Jaroslav Hrubý
|
<Radio.Button value={ERole.Annotator}>Anotátor</Radio.Button>
|
76 |
|
|
<Radio.Button value={ERole.Administrator}>Admin</Radio.Button>
|
77 |
|
|
</Radio.Group>
|
78 |
|
|
</Form.Item>
|
79 |
|
|
<Form.Item
|
80 |
|
|
name="username"
|
81 |
|
|
initialValue={userInfo.username}
|
82 |
|
|
rules={[
|
83 |
|
|
{
|
84 |
|
|
required: true,
|
85 |
|
|
message: 'Prosím zadejte uživatelské jméno',
|
86 |
|
|
},
|
87 |
|
|
]}
|
88 |
|
|
>
|
89 |
|
|
<Input placeholder="Uživatelské jméno" />
|
90 |
|
|
</Form.Item>
|
91 |
|
|
<Form.Item
|
92 |
|
|
name="name"
|
93 |
|
|
initialValue={userInfo.name}
|
94 |
|
|
rules={[
|
95 |
|
|
{
|
96 |
|
|
required: true,
|
97 |
|
|
message: 'Prosím zadejte jméno',
|
98 |
|
|
},
|
99 |
|
|
]}
|
100 |
|
|
>
|
101 |
|
|
<Input placeholder="Jméno" />
|
102 |
|
|
</Form.Item>
|
103 |
|
|
|
104 |
|
|
<Form.Item
|
105 |
|
|
name="surname"
|
106 |
|
|
initialValue={userInfo.surname}
|
107 |
|
|
rules={[
|
108 |
|
|
{
|
109 |
|
|
required: true,
|
110 |
|
|
message: 'Prosím zadejte příjmení',
|
111 |
|
|
},
|
112 |
|
|
]}
|
113 |
|
|
>
|
114 |
|
|
<Input placeholder="Příjmení" />
|
115 |
|
|
</Form.Item>
|
116 |
|
|
<Form.Item>
|
117 |
|
|
<Button type="primary" htmlType="submit" className="w-100">
|
118 |
|
|
Upravit
|
119 |
|
|
</Button>
|
120 |
|
|
</Form.Item>
|
121 |
|
|
</Form>
|
122 |
|
|
</Modal>
|
123 |
|
|
);
|
124 |
|
|
};
|
125 |
|
|
|
126 |
|
|
export default EditUserModal;
|