{"size": 2012, "ext": "js", "max_stars_repo_path": "packages/admin/store/organization.js", "max_stars_repo_name": "mrtonyhuynh/pubnow-frontend", "max_stars_repo_stars_event_min_datetime": "2020-02-26T09:31:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-25T02:14:34.000Z", "max_issues_repo_path": "packages/admin/store/organization.js", "max_issues_repo_name": "mrtonyhuynh/pubnow-frontend", "max_issues_repo_issues_event_min_datetime": "2020-02-22T06:34:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T00:05:40.000Z", "max_forks_repo_path": "packages/admin/store/organization.js", "max_forks_repo_name": "pubnow/pubnow-frontend", "max_forks_repo_forks_event_min_datetime": "2020-07-06T10:00:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-25T01:22:24.000Z"}
{"max_stars_count": 4, "max_issues_count": 11, "max_forks_count": 3, "avg_line_length": 26.1298701299, "max_line_length": 70, "alphanum_fraction": 0.5999005964}
export const state = () => ({
  organizations: [],
  perPage: 10,
  currentPage: 1,
  total: -1,
})

export const getters = {
  organizations: s => s.organizations,
  total: state => state.total,
  perPage: state => state.perPage,
  currentPage: state => state.currentPage,
}

export const mutations = {
  setOrganizations(state, organizations) {
    state.organizations = organizations
  },
  setPerPage(state, perPage) {
    state.perPage = perPage
  },
  setTotal(state, total) {
    state.total = total
  },
  setCurrentPage(state, currentPage) {
    state.currentPage = currentPage
  },
}

export const actions = {
  async list({ commit, dispatch, state }) {
    try {
      dispatch('wait/start', 'org.list', { root: true })
      const result = await this.$http.$get(
        `organizations?page=${state.currentPage}`,
      )
      const {
        data,
        meta: { current_page: currentPage, per_page: perPage, total },
      } = result
      commit('setOrganizations', data)
      commit('setCurrentPage', currentPage)
      commit('setPerPage', perPage)
      commit('setTotal', total)
      dispatch('wait/end', 'org.list', { root: true })
      return true
    } catch (e) {
      dispatch('wait/end', 'org.list', { root: true })
      return false
    }
  },
  async changePage({ dispatch, commit }, payload) {
    commit('setCurrentPage', payload)
    dispatch('list')
  },
  async create({ dispatch }, data) {
    try {
      dispatch('wait/start', 'org.create', { root: true })
      const result = await this.$http.$post('organizations', data)
      dispatch('wait/end', 'org.create', { root: true })
      return result
    } catch (e) {
      dispatch('wait/end', 'org.create', { root: true })
      return false
    }
  },
  async update(_, { id, ...updateData }) {
    this.$http.setHeader('Accept', 'application/json')
    await this.$http.$put(`organizations/${id}`, {
      ...updateData,
    })
  },
  async remove(_, id) {
    await this.$http.delete(`organizations/${id}`)
  },
}
