NotificationsSlideover.vue
2.15 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
<script setup lang="ts">
import { formatTimeAgo } from '@vueuse/core'
const { isNotificationsSlideoverOpen } = useDashboard()
const { t } = useAppI18n()
const dashboardDataApi = useDashboardDataApi()
const { data: notifications } = await dashboardDataApi.getNotifications()
const notificationBodyMap: Record<string, string> = {
'sent you a message': 'notifications.messageMap.sentMessage',
'subscribed to your email list': 'notifications.messageMap.subscribedEmailList',
'added you to a project': 'notifications.messageMap.addedProject',
'abandonned cart': 'notifications.messageMap.abandonedCart',
'abandoned cart': 'notifications.messageMap.abandonedCart',
'purchased your product': 'notifications.messageMap.purchasedProduct',
'requested a refund': 'notifications.messageMap.requestedRefund'
}
function translateNotificationBody(body: string): string {
const key = notificationBodyMap[body]
return key ? t(key) : body
}
</script>
<template>
<USlideover
v-model:open="isNotificationsSlideoverOpen"
:title="t('notifications.title')"
>
<template #body>
<NuxtLink
v-for="notification in notifications"
:key="notification.id"
:to="`/inbox?id=${notification.id}`"
class="px-3 py-2.5 rounded-md hover:bg-elevated/50 flex items-center gap-3 relative -mx-3 first:-mt-3 last:-mb-3"
>
<UChip
color="error"
:show="!!notification.unread"
inset
>
<UAvatar
v-bind="notification.sender.avatar"
:alt="notification.sender.name"
size="md"
/>
</UChip>
<div class="text-sm flex-1">
<p class="flex items-center justify-between">
<span class="text-highlighted font-medium">{{ notification.sender.name }}</span>
<time
:datetime="notification.date"
class="text-muted text-xs"
v-text="formatTimeAgo(new Date(notification.date))"
/>
</p>
<p class="text-dimmed">
{{ translateNotificationBody(notification.body) }}
</p>
</div>
</NuxtLink>
</template>
</USlideover>
</template>