UserProfile.vue
4.84 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<script setup>
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
const router = useRouter()
const ability = useAbility()
// TODO: Get type from backend
const userData = useCookie('userData')
const logout = async () => {
// Remove "accessToken" from cookie
useCookie('accessToken').value = null
// Remove "userData" from cookie
userData.value = null
// Redirect to login page
await router.push('/login')
// ℹ️ We had to remove abilities in then block because if we don't nav menu items mutation is visible while redirecting user to login page
// Remove "userAbilities" from cookie
useCookie('userAbilityRules').value = null
// Reset ability to initial ability
ability.update([])
}
const userProfileList = [
{ type: 'divider' },
{
type: 'navItem',
icon: 'ri-user-line',
title: 'Profile',
to: {
name: 'apps-user-view-id',
params: { id: 21 },
},
},
{
type: 'navItem',
icon: 'ri-settings-4-line',
title: 'Settings',
to: {
name: 'pages-account-settings-tab',
params: { tab: 'account' },
},
},
{
type: 'navItem',
icon: 'ri-file-text-line',
title: 'Billing Plan',
to: {
name: 'pages-account-settings-tab',
params: { tab: 'billing-plans' },
},
badgeProps: {
color: 'error',
content: '4',
},
},
{ type: 'divider' },
{
type: 'navItem',
icon: 'ri-money-dollar-circle-line',
title: 'Pricing',
to: { name: 'pages-pricing' },
},
{
type: 'navItem',
icon: 'ri-question-line',
title: 'FAQ',
to: { name: 'pages-faq' },
},
{ type: 'divider' },
]
</script>
<template>
<VBadge
v-if="userData"
dot
bordered
location="bottom right"
offset-x="3"
offset-y="3"
color="success"
>
<VAvatar
class="cursor-pointer"
size="38"
:color="!(userData && userData.avatar) ? 'primary' : undefined"
:variant="!(userData && userData.avatar) ? 'tonal' : undefined"
>
<VImg
v-if="userData && userData.avatar"
:src="userData.avatar"
/>
<VIcon
v-else
icon="ri-user-line"
/>
<!-- SECTION Menu -->
<VMenu
activator="parent"
width="230"
location="bottom end"
offset="15px"
>
<VList>
<VListItem>
<div class="d-flex gap-2 align-center">
<VListItemAction>
<VBadge
dot
location="bottom right"
offset-x="3"
offset-y="3"
color="success"
>
<VAvatar
:color="!(userData && userData.avatar) ? 'primary' : undefined"
:variant="!(userData && userData.avatar) ? 'tonal' : undefined"
>
<VImg
v-if="userData && userData.avatar"
:src="userData.avatar"
/>
<VIcon
v-else
icon="ri-user-line"
/>
</VAvatar>
</VBadge>
</VListItemAction>
<div>
<h6 class="text-h6 font-weight-medium">
{{ userData.fullName || userData.username }}
</h6>
<VListItemSubtitle class="text-capitalize text-disabled">
{{ userData.role }}
</VListItemSubtitle>
</div>
</div>
</VListItem>
<PerfectScrollbar :options="{ wheelPropagation: false }">
<template
v-for="item in userProfileList"
:key="item.title"
>
<VListItem
v-if="item.type === 'navItem'"
:to="item.to"
>
<template #prepend>
<VIcon
:icon="item.icon"
size="22"
/>
</template>
<VListItemTitle>{{ item.title }}</VListItemTitle>
<template
v-if="item.badgeProps"
#append
>
<VBadge
inline
v-bind="item.badgeProps"
/>
</template>
</VListItem>
<VDivider
v-else
class="my-1"
/>
</template>
<VListItem>
<VBtn
block
color="error"
size="small"
append-icon="ri-logout-box-r-line"
@click="logout"
>
Logout
</VBtn>
</VListItem>
</PerfectScrollbar>
</VList>
</VMenu>
<!-- !SECTION -->
</VAvatar>
</VBadge>
</template>