Commit 91708ca1 authored by chencheng's avatar chencheng

11. Handle user create

parent 6044e2fc
...@@ -5,3 +5,7 @@ ...@@ -5,3 +5,7 @@
.operation a { .operation a {
margin: 0 .5em; margin: 0 .5em;
} }
.create {
margin: 1.5em 0;
}
import { connect } from 'dva'; import { connect } from 'dva';
import { Table, Pagination, Popconfirm } from 'antd'; import { Table, Pagination, Popconfirm, Button } from 'antd';
import { routerRedux } from 'dva/router'; import { routerRedux } from 'dva/router';
import styles from './Users.css'; import styles from './Users.css';
import { PAGE_SIZE } from '../constants'; import { PAGE_SIZE } from '../constants';
...@@ -27,6 +27,13 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) { ...@@ -27,6 +27,13 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
}); });
} }
function createHandler(values) {
dispatch({
type: 'users/create',
payload: values,
});
}
const columns = [ const columns = [
{ {
title: 'Name', title: 'Name',
...@@ -63,6 +70,11 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) { ...@@ -63,6 +70,11 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
return ( return (
<div className={styles.normal}> <div className={styles.normal}>
<div> <div>
<div className={styles.create}>
<UserModal record={{}} onOk={createHandler}>
<Button type="primary">Create User</Button>
</UserModal>
</div>
<Table <Table
loading={loading} loading={loading}
columns={columns} columns={columns}
......
...@@ -34,6 +34,11 @@ export default { ...@@ -34,6 +34,11 @@ export default {
const page = yield select(state => state.users.page); const page = yield select(state => state.users.page);
yield put({ type: 'fetch', payload: { page } }); yield put({ type: 'fetch', payload: { page } });
}, },
*create({ payload: values }, { call, put, select }) {
yield call(usersService.create, values);
const page = yield select(state => state.users.page);
yield put({ type: 'fetch', payload: { page } });
},
}, },
subscriptions: { subscriptions: {
setup({ dispatch, history }) { setup({ dispatch, history }) {
......
...@@ -17,3 +17,10 @@ export function patch(id, values) { ...@@ -17,3 +17,10 @@ export function patch(id, values) {
body: JSON.stringify(values), body: JSON.stringify(values),
}); });
} }
export function create(values) {
return request('/api/users', {
method: 'POST',
body: JSON.stringify(values),
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment