/
index.vue
130 lines (117 loc) · 3.73 KB
/
index.vue
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
<template>
<div>
<div class="space-y-4">
<HoppButtonSecondary
:label="`${t('team.create_new')}`"
outline
:icon="IconPlus"
@click="displayModalAdd(true)"
/>
<div v-if="loading" class="flex flex-col items-center justify-center">
<HoppSmartSpinner class="mb-4" />
<span class="text-secondaryLight">{{ t("state.loading") }}</span>
</div>
<HoppSmartPlaceholder
v-if="!loading && myTeams.length === 0"
:src="`/images/states/${colorMode.value}/add_group.svg`"
:alt="`${t('empty.teams')}`"
:text="`${t('empty.teams')}`"
>
</HoppSmartPlaceholder>
<div
v-else-if="!loading"
class="grid gap-4"
:class="
modal ? 'grid-cols-1' : 'sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'
"
>
<TeamsTeam
v-for="(team, index) in myTeams"
:key="`team-${String(index)}`"
:team-i-d="team.id"
:team="team"
:compact="modal"
@edit-team="editTeam(team, team.id)"
@invite-team="inviteTeam(team, team.id)"
@refetch-teams="refetchTeams"
/>
</div>
<div v-if="!loading && adapterError" class="flex flex-col items-center">
<icon-lucide-help-circle class="svg-icons mb-4" />
{{ t("error.something_went_wrong") }}
</div>
</div>
<TeamsAdd :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
<!-- ¯\_(ツ)_/¯ -->
<TeamsEdit
v-if="!loading && myTeams.length > 0"
:team="myTeams[0]"
:show="showModalEdit"
:editing-team="editingTeam"
:editing-team-i-d="editingTeamID"
@hide-modal="displayModalEdit(false)"
@invite-team="inviteTeam(editingTeam, editingTeamID)"
@refetch-teams="refetchTeams"
/>
<TeamsInvite
v-if="!loading && myTeams.length > 0"
:team="myTeams[0]"
:show="showModalInvite"
:editing-team="editingTeam"
:editing-team-i-d="editingTeamID"
@hide-modal="displayModalInvite(false)"
/>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from "vue"
import { useI18n } from "@composables/i18n"
import { useReadonlyStream } from "@composables/stream"
import { useColorMode } from "@composables/theming"
import { WorkspaceService } from "~/services/workspace.service"
import { useService } from "dioc/vue"
import IconPlus from "~icons/lucide/plus"
const t = useI18n()
const colorMode = useColorMode()
defineProps<{
modal: boolean
}>()
const showModalAdd = ref(false)
const showModalEdit = ref(false)
const showModalInvite = ref(false)
const editingTeam = ref<any>({}) // TODO: Check this out
const editingTeamID = ref<any>("")
const workspaceService = useService(WorkspaceService)
const adapter = workspaceService.acquireTeamListAdapter(10000)
const adapterLoading = useReadonlyStream(adapter.loading$, false)
const adapterError = useReadonlyStream(adapter.error$, null)
const myTeams = useReadonlyStream(adapter.teamList$, [])
const loading = computed(
() => adapterLoading.value && myTeams.value.length === 0
)
const displayModalAdd = (shouldDisplay: boolean) => {
showModalAdd.value = shouldDisplay
adapter.fetchList()
}
const displayModalEdit = (shouldDisplay: boolean) => {
showModalEdit.value = shouldDisplay
adapter.fetchList()
}
const displayModalInvite = (shouldDisplay: boolean) => {
showModalInvite.value = shouldDisplay
adapter.fetchList()
}
const editTeam = (team: any, teamID: any) => {
editingTeam.value = team
editingTeamID.value = teamID
displayModalEdit(true)
}
const inviteTeam = (team: any, teamID: any) => {
editingTeam.value = team
editingTeamID.value = teamID
displayModalInvite(true)
}
const refetchTeams = () => {
adapter.fetchList()
}
</script>