1
|
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
|
password: values.password,
|
35
|
};
|
36
|
if (userInfo.id) {
|
37
|
userController.userUserIdPut(userInfo.id, req).then((r) => {
|
38
|
ShowToast('Heslo úspěšně změněno', 'success', 3000, 'top-end');
|
39
|
onCancel();
|
40
|
});
|
41
|
}
|
42
|
};
|
43
|
|
44
|
const onFinishFailed = (errorInfo: any) => {
|
45
|
ShowToast('Zadané údaje nejsou validní', 'error', 3000, 'top-end');
|
46
|
};
|
47
|
|
48
|
return (
|
49
|
<Modal
|
50
|
title={'Změnit heslo uživatele ' + userInfo.username}
|
51
|
onOk={handleOk}
|
52
|
visible={true}
|
53
|
onCancel={handleCancel}
|
54
|
footer={null}
|
55
|
width={400}
|
56
|
centered
|
57
|
>
|
58
|
<Form
|
59
|
onFinish={onFinish}
|
60
|
onFinishFailed={onFinishFailed}
|
61
|
autoComplete="off"
|
62
|
labelCol={{ span: 4 }}
|
63
|
layout="horizontal"
|
64
|
>
|
65
|
<Form.Item
|
66
|
name="password"
|
67
|
rules={[{ required: true, message: 'Prosím zadejte heslo' }]}
|
68
|
>
|
69
|
<Input.Password placeholder="Heslo" />
|
70
|
</Form.Item>
|
71
|
<Form.Item>
|
72
|
<Button type="primary" htmlType="submit" className="w-100">
|
73
|
Změnit
|
74
|
</Button>
|
75
|
</Form.Item>
|
76
|
</Form>
|
77
|
</Modal>
|
78
|
);
|
79
|
};
|
80
|
|
81
|
export default EditUserModal;
|