UserModal.js
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Component } from 'react';
import { Modal, Form, Input } from 'antd';
const FormItem = Form.Item;
class UserEditModal extends Component {
constructor(props) {
super(props);
this.state = {
visible: false,
};
}
showModelHandler = e => {
if (e) e.stopPropagation();
this.setState({
visible: true,
});
};
hideModelHandler = () => {
this.setState({
visible: false,
});
};
okHandler = () => {
const { onOk } = this.props;
this.props.form.validateFields((err, values) => {
if (!err) {
onOk(values);
this.hideModelHandler();
}
});
};
render() {
const { children } = this.props;
const { getFieldDecorator } = this.props.form;
const { name, email, website } = this.props.record;
const formItemLayout = {
labelCol: { span: 6 },
wrapperCol: { span: 14 },
};
return (
<span>
<span onClick={this.showModelHandler}>{children}</span>
<Modal
title="Edit User"
visible={this.state.visible}
onOk={this.okHandler}
onCancel={this.hideModelHandler}
>
<Form horizontal onSubmit={this.okHandler}>
<FormItem {...formItemLayout} label="Name">
{getFieldDecorator('name', {
initialValue: name,
})(<Input />)}
</FormItem>
<FormItem {...formItemLayout} label="Email">
{getFieldDecorator('email', {
initialValue: email,
})(<Input />)}
</FormItem>
<FormItem {...formItemLayout} label="Website">
{getFieldDecorator('website', {
initialValue: website,
})(<Input />)}
</FormItem>
</Form>
</Modal>
</span>
);
}
}
export default Form.create()(UserEditModal);