-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathTeamSelection.vue
More file actions
184 lines (172 loc) · 5.29 KB
/
TeamSelection.vue
File metadata and controls
184 lines (172 loc) · 5.29 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<template>
<ff-listbox v-if="hasAvailableTeams" :options="teamOptions" v-model="selection" class="ff-team-selection">
<template #button>
<div v-if="team" class="flex grow items-center">
<div class="ff-team-selection-name">
<label>TEAM:</label>
<h5>{{ team.name }}</h5>
</div>
</div>
<div v-else class="flex grow items-center">
<div class="ff-team-selection-name">
<h5>Select a team</h5>
</div>
</div>
</template>
<template #options="{options}">
<ListboxOption
v-for="option in options"
v-slot="{ active, selected }"
:key="option.label"
:value="option"
as="template"
class="ff-option ff-team-selection-option"
:class="{'create-new': option.value === 'create-new-team'}"
:data-option="option.label"
:title="option.label"
>
<li>
<div class="ff-option-content truncate" :class="{selected, active}">
<component v-if="option.icon" :is="option.icon" class="ff-icon transition-fade" />
<span class="truncate">{{ option.label }}</span>
</div>
</li>
</ListboxOption>
</template>
</ff-listbox>
</template>
<script>
import {
ListboxButton,
ListboxOption
} from '@headlessui/vue'
import { PlusIcon, UserAddIcon } from '@heroicons/vue/solid'
import { mapState } from 'pinia'
import { mapGetters, mapState as mapVuexState } from 'vuex'
import usePermissions from '../composables/Permissions.js'
import NavItem from './NavItem.vue'
import { useAccountStore } from '@/stores/account.js'
import { useContextStore } from '@/stores/context.js'
export default {
name: 'FFTeamSelection',
emits: ['option-selected'],
components: {
NavItem,
ListboxOption,
ListboxButton
},
setup () {
const { hasPermission } = usePermissions()
return { PlusIcon, UserAddIcon, hasPermission }
},
computed: {
...mapState(useContextStore, ['team']),
...mapState(useAccountStore, ['teams', 'hasAvailableTeams']),
...mapVuexState('account', ['settings']),
...mapGetters('account', ['canCreateTeam']),
teamOptions () {
return [
...this.teams.map(team => {
return { label: team.name, value: team.slug }
}),
(
this.team && this.hasPermission('team:user:invite')
? { label: 'Invite Members', value: 'invite-members', icon: UserAddIcon }
: undefined
),
(
this.canCreateTeam
? { label: 'Create New Team', value: 'create-new-team', icon: PlusIcon }
: undefined
)
].filter(v => v)
}
},
data () {
return {
selection: this.$route.params.team_slug ?? null,
loaded: false
}
},
watch: {
selection (value) {
if (value === 'create-new-team') {
return this.createTeam()
} else if (value === 'invite-members') {
return this.inviteMembers()
} else {
return this.selectTeam({ slug: value })
}
}
},
methods: {
selectTeam (team) {
if (team) {
useAccountStore().setTeam(team.slug)
.then(() => this.$router.push({
name: 'Team',
params: {
team_slug: team.slug
}
}))
.catch(e => console.warn(e))
}
},
createTeam () {
return this.$router.push({
name: 'CreateTeam'
})
},
inviteMembers () {
return this.$router.push({
name: 'team-members',
params: { team_slug: this.team.slug },
query: { action: 'invite' }
})
}
}
}
</script>
<style lang="scss">
@use "../stylesheets/components/team-list.scss" as *;
.ff-team-selection {
&.ff-listbox {
button {
border-radius: 0;
border: none;
background: none;
button {
padding: 0;
}
.icon {
svg {
color: $ff-grey-800;
width: 80%;
padding-left: 10px;
}
}
}
}
}
.ff-options .ff-team-selection-option {
border-color: $ff-color--border;
color: $ff-grey-800;
border-bottom: 1px solid $ff-color--border;
display: flex;
align-items: center;
.ff-option-content {
padding: 12px 12px 12px 18px;
display: flex;
align-items: center;
gap: 15px;
width: 100%;
&.selected {
background: $ff-grey-200;
}
.ff-icon {
width: 1.25rem;
height: 1.25rem;
}
}
}
</style>