Skip to content

Commit

Permalink
11. Handle user create
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Feb 22, 2018
1 parent 6044e2f commit 91708ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/pages/users/components/Users.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
.operation a {
margin: 0 .5em;
}

.create {
margin: 1.5em 0;
}
14 changes: 13 additions & 1 deletion src/pages/users/components/Users.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connect } from 'dva';
import { Table, Pagination, Popconfirm } from 'antd';
import { Table, Pagination, Popconfirm, Button } from 'antd';
import { routerRedux } from 'dva/router';
import styles from './Users.css';
import { PAGE_SIZE } from '../constants';
Expand Down Expand Up @@ -27,6 +27,13 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
});
}

function createHandler(values) {
dispatch({
type: 'users/create',
payload: values,
});
}

const columns = [
{
title: 'Name',
Expand Down Expand Up @@ -63,6 +70,11 @@ function Users({ dispatch, list: dataSource, loading, total, page: current }) {
return (
<div className={styles.normal}>
<div>
<div className={styles.create}>
<UserModal record={{}} onOk={createHandler}>
<Button type="primary">Create User</Button>
</UserModal>
</div>
<Table
loading={loading}
columns={columns}
Expand Down
5 changes: 5 additions & 0 deletions src/pages/users/models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default {
const page = yield select(state => state.users.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: {
setup({ dispatch, history }) {
Expand Down
7 changes: 7 additions & 0 deletions src/pages/users/services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ export function patch(id, values) {
body: JSON.stringify(values),
});
}

export function create(values) {
return request('/api/users', {
method: 'POST',
body: JSON.stringify(values),
});
}

0 comments on commit 91708ca

Please sign in to comment.