summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/user_lists/store/show/mutations.js
blob: 3cf3b2d8371410408fe0e3181a3287cd70fd01c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { states } from '../../constants/show';
import * as types from './mutation_types';
import { parseUserIds } from '../utils';

export default {
  [types.REQUEST_USER_LIST](state) {
    state.state = states.LOADING;
  },
  [types.RECEIVE_USER_LIST_SUCCESS](state, userList) {
    state.state = states.SUCCESS;
    state.userIds = userList.user_xids?.length > 0 ? parseUserIds(userList.user_xids) : [];
    state.userList = userList;
  },
  [types.RECEIVE_USER_LIST_ERROR](state) {
    state.state = states.ERROR;
  },
  [types.DISMISS_ERROR_ALERT](state) {
    state.state = states.ERROR_DISMISSED;
  },
  [types.ADD_USER_IDS](state, ids) {
    state.userIds = [
      ...state.userIds,
      ...parseUserIds(ids).filter((id) => id && !state.userIds.includes(id)),
    ];
  },
  [types.REMOVE_USER_ID](state, id) {
    state.userIds = state.userIds.filter((uid) => uid !== id);
  },
};