Skip to content

Commit

Permalink
9. Handle user delete
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Feb 22, 2018
1 parent 156220c commit f12e32b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/pages/users/components/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { PAGE_SIZE } from '../constants';

function Users({ dispatch, list: dataSource, loading, total, page: current }) {
function deleteHandler(id) {
console.warn(`TODO: ${id}`);
dispatch({
type: 'users/remove',
payload: id,
});
}

function pageChangeHandler(page) {
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 @@ -24,6 +24,11 @@ export default {
},
});
},
*remove({ payload: id }, { call, put, select }) {
yield call(usersService.remove, id);
const page = yield select(state => state.users.page);
yield put({ type: 'fetch', payload: { page } });
},
},
subscriptions: {
setup({ dispatch, history }) {
Expand Down
6 changes: 6 additions & 0 deletions src/pages/users/services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ import request from '../../../utils/request';
export function fetch({ page = 1 }) {
return request(`/api/users?_page=${page}&_limit=${PAGE_SIZE}`);
}

export function remove(id) {
return request(`/api/users/${id}`, {
method: 'DELETE',
});
}

0 comments on commit f12e32b

Please sign in to comment.