Skip to content

Commit

Permalink
Merge pull request dvajs#191 from jerexyz/master
Browse files Browse the repository at this point in the history
fix user-dashboard  example bug
  • Loading branch information
sorrycc authored Oct 25, 2016
2 parents 5088b1f + 8db4624 commit 585fd8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 15 additions & 3 deletions examples/user-dashboard/src/models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default {

state: {
list: [],
field: '',
keyword: '',
loading: false,
total: null,
current: 1,
Expand All @@ -31,6 +33,7 @@ export default {
effects: {
*query({ payload }, { call, put }) {
yield put({ type: 'showLoading' });
yield put({ type: 'updateQueryKey', payload });
const { data } = yield call(query, parse(payload));
if (data) {
yield put({
Expand Down Expand Up @@ -60,7 +63,13 @@ export default {
if (data && data.success) {
yield put({
type: 'createSuccess',
payload,
payload: {
list: data.data,
total: data.page.total,
current: data.page.current,
field: '',
keyword: '',
},
});
}
},
Expand All @@ -84,8 +93,8 @@ export default {
return { ...state, loading: true };
},
createSuccess(state, action) {
const newUser = action.payload;
return { ...state, list: [newUser, ...state.list], loading: false };
// const newUser = action.payload;
return { ...state, ...action.payload, loading: false };
},
deleteSuccess(state, action) {
const id = action.payload;
Expand All @@ -111,6 +120,9 @@ export default {
hideModal(state) {
return { ...state, modalVisible: false };
},
updateQueryKey(state, action) {
return { ...state, ...action.payload };
},
},

};
6 changes: 2 additions & 4 deletions examples/user-dashboard/src/routes/Users.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import UserModal from '../components/Users/UserModal';

function Users({ location, dispatch, users }) {
const {
loading, list, total, current,
loading, list, total, current, field, keyword,
currentItem, modalVisible, modalType,
} = users;

const { field, keyword } = location.query;

const userModalProps = {
item: modalType === 'create' ? {} : currentItem,
type: modalType,
Expand All @@ -40,7 +38,7 @@ function Users({ location, dispatch, users }) {
onPageChange(page) {
dispatch(routerRedux.push({
pathname: '/users',
query: { page },
query: { field, keyword, page },
}));
},
onDeleteItem(id) {
Expand Down

0 comments on commit 585fd8c

Please sign in to comment.