aboutsummaryrefslogtreecommitdiff
path: root/src/components/staff_panel/staff_panel.js
blob: 46a92ac78b14e93ff19073d3936289f494cbfbf7 (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
30
31
32
33
import map from 'lodash/map'
import groupBy from 'lodash/groupBy'
import { mapGetters, mapState } from 'vuex'
import BasicUserCard from '../basic_user_card/basic_user_card.vue'

const StaffPanel = {
  created () {
    const nicknames = this.$store.state.instance.staffAccounts
    nicknames.forEach(nickname => this.$store.dispatch('fetchUserIfMissing', nickname))
  },
  components: {
    BasicUserCard
  },
  computed: {
    groupedStaffAccounts () {
      const staffAccounts = map(this.staffAccounts, this.findUserByName).filter(_ => _)
      const groupedStaffAccounts = groupBy(staffAccounts, 'role')

      return [
        { role: 'admin', users: groupedStaffAccounts.admin },
        { role: 'moderator', users: groupedStaffAccounts.moderator }
      ].filter(group => group.users)
    },
    ...mapGetters([
      'findUserByName'
    ]),
    ...mapState({
      staffAccounts: state => state.instance.staffAccounts
    })
  }
}

export default StaffPanel