forked from yeatmanlab/roar-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminProfile.vue
157 lines (148 loc) · 4.59 KB
/
AdminProfile.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
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
<template>
<div class="flex flex-row" style="max-height: 100vh">
<!-- Sidebar -->
<div :class="sidebarOpen ? 'sidebar-container-open' : 'sidebar-container-collapsed'">
<div class="flex flex-column">
<router-link v-if="!isLevante" to="/profile">
<div class="sidebar-button">
<i class="pi pi-user" /><span v-if="sidebarOpen">Your Info</span>
</div></router-link
>
<router-link v-if="isAdmin" to="/profile/password"
><div class="sidebar-button">
<i class="pi pi-key" /><span v-if="sidebarOpen">{{
hasPassword ? 'Change Password' : 'Add Password'
}}</span>
</div></router-link
>
<router-link v-if="isAdmin" to="/profile/accounts"
><div class="sidebar-button">
<i class="pi pi-users" /><span v-if="sidebarOpen">Link Accounts</span>
</div></router-link
>
<router-link v-if="isAdmin" to="/profile/offline"
><div class="sidebar-button">
<i class="pi pi-wifi" /><span v-if="sidebarOpen">Offline Settings</span>
</div></router-link
>
<router-link to="/profile/settings"
><div class="sidebar-button">
<i class="pi pi-cog" /><span v-if="sidebarOpen">{{ t('profile.settings.settings') }}</span>
</div></router-link
>
</div>
<button
class="w-full border-none cursor-pointer h-3rem flex align-items-center"
:class="sidebarOpen ? 'justify-content-end' : 'justify-content-center'"
style="background-color: var(--surface-b)"
@click="sidebarOpen = !sidebarOpen"
>
<i
v-if="!sidebarOpen"
class="pi text-2xl pi-angle-double-right text-grey-600"
style="color: var(--surface-400)"
></i>
<i v-else class="pi text-2xl pi-angle-double-left mr-2 text-grey-600" style="color: var(--surface-400)"></i>
</button>
</div>
<!-- Main Page Content-->
<div class="page-container">
<router-view />
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue';
import { useAuthStore } from '@/store/auth';
import { storeToRefs } from 'pinia';
import { useQuery } from '@tanstack/vue-query';
import { fetchDocById } from '@/helpers/query/utils';
import _isEmpty from 'lodash/isEmpty';
import _union from 'lodash/union';
import { isLevante } from '@/helpers';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const authStore = useAuthStore();
const { roarfirekit, uid } = storeToRefs(authStore);
const sidebarOpen = ref(true);
const providerIds = computed(() => {
const providerData = roarfirekit.value?.admin?.user?.providerData;
return providerData.map((provider) => {
return provider.providerId;
});
});
const hasPassword = computed(() => {
return providerIds.value.includes('password');
});
// +-------------------------+
// | Firekit Inititalization |
// +-------------------------+
const initialized = ref(false);
let unsubscribe;
const init = () => {
if (unsubscribe) unsubscribe();
initialized.value = true;
};
unsubscribe = authStore.$subscribe(async (mutation, state) => {
if (state.roarfirekit.restConfig) init();
});
onMounted(() => {
if (roarfirekit.value.restConfig) init();
});
const { data: userClaims } = useQuery({
queryKey: ['userClaims', uid],
queryFn: () => fetchDocById('userClaims', uid.value),
keepPreviousData: true,
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
});
// Keep track of the user's type
const isAdmin = computed(() => {
if (userClaims.value?.claims?.super_admin) return true;
if (_isEmpty(_union(...Object.values(userClaims.value?.claims?.minimalAdminOrgs ?? {})))) return false;
return true;
});
</script>
<style lang="scss" scoped>
.sidebar-container-open {
background-color: var(--surface-b);
flex-basis: 25%;
width: 100%;
height: calc(100vh - 119px);
border-right: 2px solid var(--surface-d);
a {
color: black;
text-decoration: none;
}
}
.sidebar-button {
width: 100%;
background-color: var(--surface-d);
padding: 1rem;
color: black;
span {
padding-left: 0.5rem;
color: black;
font-weight: 500;
}
}
.sidebar-button:hover {
background-color: var(--surface-400);
}
.page-container {
flex-basis: 75%;
flex-grow: 1;
max-height: calc(100vh - 119px);
overflow: scroll;
padding: 1rem;
scroll-behavior: smooth;
}
.sidebar-container-collapsed {
display: flex;
flex-direction: column;
background-color: var(--surface-b);
flex-basis: 2rem;
height: calc(100vh - 119px);
border-right: 2px solid var(--surface-d);
}
</style>