{"size": 1203, "ext": "js", "max_stars_repo_path": "src/store/modules/students.js", "max_stars_repo_name": "syntialai/TA-admin", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/store/modules/students.js", "max_issues_repo_name": "syntialai/TA-admin", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/store/modules/students.js", "max_forks_repo_name": "syntialai/TA-admin", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.1346153846, "max_line_length": 71, "alphanum_fraction": 0.672485453}
/* eslint-disable no-shadow */
import { getStudentsData, updateUser } from '@/api/data/user/user.api';
import * as Types from '@/store/types';
// import * as Messages from '@/config/message-constants';

const namespaced = true;

const state = {
  studentInfo: [],
};

const actions = {
  resetState({ commit }) {
    commit(Types.RESET_STUDENTS_STATE);
  },

  async getStudentsDataFromApi({ commit }) {
    const studentInfo = await getStudentsData();
    commit(Types.SET_STUDENT_INFO, studentInfo);
  },

  async updateStudent({ dispatch }, { user, deactivated }) {
    const newUserData = { ...user };
    newUserData.deactivated = deactivated;
    dispatch('app/setIsLoading', null, { root: true });
    await updateUser(newUserData.id, newUserData);
    await dispatch('getStudentsDataFromApi');
    dispatch('app/setIsNotLoading', null, { root: true });
  },
};

const getters = {
  studentInfo: (state) => state.studentInfo,
};

const mutations = {
  [Types.RESET_STUDENTS_STATE](state) {
    state.studentInfo = [];
  },
  [Types.SET_STUDENT_INFO](state, studentInfo) {
    state.studentInfo = studentInfo;
  },
};

export default {
  namespaced,
  state,
  actions,
  getters,
  mutations,
};
