diff --git a/src/components/Users/UserModal.css b/src/components/Users/UserModal.css
new file mode 100644
index 0000000..3224ee4
--- /dev/null
+++ b/src/components/Users/UserModal.css
@@ -0,0 +1,3 @@
+
+.normal {
+}
diff --git a/src/components/Users/UserModal.js b/src/components/Users/UserModal.js
new file mode 100644
index 0000000..bff8062
--- /dev/null
+++ b/src/components/Users/UserModal.js
@@ -0,0 +1,97 @@
+import React, { Component } from 'react';
+import { Modal, Form, Input } from 'antd';
+import styles from './UserModal.css';
+
+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 (
+
+
+ { children }
+
+
+
+
+
+ );
+ }
+}
+
+export default Form.create()(UserEditModal);
diff --git a/src/components/Users/Users.js b/src/components/Users/Users.js
index eb3ea53..344a1a3 100644
--- a/src/components/Users/Users.js
+++ b/src/components/Users/Users.js
@@ -4,6 +4,7 @@ import { Table, Pagination, Popconfirm } from 'antd';
import { routerRedux } from 'dva/router';
import styles from './Users.css';
import { PAGE_SIZE } from '../../constants';
+import UserModal from './UserModal';
function Users({ dispatch, list: dataSource, loading, total, page: current }) {
function deleteHandler(id) {
@@ -20,6 +21,13 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
}));
}
+ function editHandler(id, values) {
+ dispatch({
+ type: 'users/patch',
+ payload: { id, values },
+ });
+ }
+
const columns = [
{
title: 'Name',
@@ -40,10 +48,12 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
{
title: 'Operation',
key: 'operation',
- render: (text, { id }) => (
+ render: (text, record) => (
- Edit
-
+
+ Edit
+
+
Delete
diff --git a/src/models/users.js b/src/models/users.js
index c13d529..6c0fd17 100644
--- a/src/models/users.js
+++ b/src/models/users.js
@@ -29,6 +29,11 @@ export default {
const page = yield select(state => state.users.page);
yield put({ type: 'fetch', payload: { page } });
},
+ *patch({ payload: { id, values } }, { call, put, select }) {
+ yield call(usersService.patch, id, values);
+ const page = yield select(state => state.users.page);
+ yield put({ type: 'fetch', payload: { page } });
+ },
},
subscriptions: {
setup({ dispatch, history }) {
diff --git a/src/services/users.js b/src/services/users.js
index c4dd1bd..aa8b25a 100644
--- a/src/services/users.js
+++ b/src/services/users.js
@@ -10,3 +10,10 @@ export function remove(id) {
method: 'DELETE',
});
}
+
+export function patch(id, values) {
+ return request(`/api/users/${id}`, {
+ method: 'PATCH',
+ body: JSON.stringify(values),
+ });
+}