Skip to content

Commit

Permalink
Fixed: state not updating in case of no record for fetching users (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridwan6947 committed Jul 9, 2024
1 parent 4b5c6d6 commit 410042e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,17 @@ const actions: ActionTree<UserState, RootState> = {
"viewSize": payload.viewSize
}

let users = JSON.parse(JSON.stringify(state.users.list)), total = 0;
const users = JSON.parse(JSON.stringify(state.users.list));
let total = 0 , usersList = [] as any;

try {
const resp = await UserService.fetchUsers(params);

if (!hasError(resp) && resp.data.count) {
if (payload.viewIndex && payload.viewIndex > 0) {
users = users.concat(resp.data.docs);
usersList = users.concat(resp.data.docs);
} else {
users = resp.data.docs;
usersList = resp.data.docs;
}
total = resp.data.count;
} else {
Expand All @@ -366,7 +367,7 @@ const actions: ActionTree<UserState, RootState> = {
}

emitter.emit("dismissLoader");
commit(types.USER_LIST_UPDATED, { users, total });
commit(types.USER_LIST_UPDATED, { users: usersList, total });
},

updateQuery({ commit }, query) {
Expand Down

0 comments on commit 410042e

Please sign in to comment.