@7365admin1/layer-common 4.19.0 → 4.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -4
- package/components/InventoryItemDetail.vue +1 -1
- package/components/InventoryItemDialog.vue +7 -2
- package/components/InventoryMyStockTab.vue +4 -4
- package/components/InventoryReportsTab.vue +2 -0
- package/components/InventoryStockTab.vue +1 -1
- package/components/InventoryTechniciansTab.vue +1 -1
- package/components/InventoryUsageDialog.vue +5 -0
- package/components/Layout/Header.vue +25 -0
- package/components/NotificationBell.vue +478 -0
- package/composables/useInventory.ts +2 -1
- package/composables/useNotification.ts +78 -0
- package/composables/useSecurityPermission.ts +8 -7
- package/package.json +1 -1
- package/types/inventory.d.ts +5 -0
- package/utils/notification-inbox.ts +47 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a26bc2e: Notification bell on by default in the shared top bar, for every signed-in web app: unread count, the latest notifications, mark one or all as read, an in-page pop-up for new ones (checked every 30 s and when the tab regains focus), optional desktop notifications, and a link to Notification settings. The list shows everything addressed to the person (it was site-scoped, which disagreed with the badge).
|
|
8
|
+
|
|
9
|
+
## 4.20.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- a12e294: Inventory: packing on items (form, stock list, item detail, movement report), "Fault reported by" on Record Usage and in the usage report, and each technician's stock shows left and used this month (My Stock, Technicians). Items used up this month stay listed at 0 left without the Record usage button.
|
|
14
|
+
|
|
3
15
|
## 4.19.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -1193,11 +1205,11 @@
|
|
|
1193
1205
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
1194
1206
|
own rule from two endpoints the console already calls, unprojected:
|
|
1195
1207
|
|
|
1196
|
-
|
|
1197
|
-
|
|
1208
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
1209
|
+
GET /api/roles/id/:role that membership's role document
|
|
1198
1210
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1211
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
1212
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
1201
1213
|
|
|
1202
1214
|
`role.default` is the marker because it is the only property of a platform
|
|
1203
1215
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<div class="flex-grow-1">
|
|
13
13
|
<div class="text-h5 mb-1" :class="item.lowStock ? 'text-error' : ''">{{ item.onHand }} {{ item.unit }} in store</div>
|
|
14
14
|
<div class="text-body-2 text-medium-emphasis">
|
|
15
|
-
{{ [item.code && `Code ${item.code}`, item.category, item.reorderLevel ? `Alert at ${item.reorderLevel}` : "", item.unitCost !== undefined ? `$${Number(item.unitCost).toFixed(2)} each` : ""].filter(Boolean).join(" · ") }}
|
|
15
|
+
{{ [item.code && `Code ${item.code}`, item.category, item.packing, item.reorderLevel ? `Alert at ${item.reorderLevel}` : "", item.unitCost !== undefined ? `$${Number(item.unitCost).toFixed(2)} each` : ""].filter(Boolean).join(" · ") }}
|
|
16
16
|
</div>
|
|
17
17
|
<div v-if="item.description" class="text-body-2 mt-2">{{ item.description }}</div>
|
|
18
18
|
</div>
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
<InputLabel title="Unit" required class="mb-1" />
|
|
16
16
|
<v-combobox v-model="f.unit" :items="units" :rules="[requiredRule]" density="comfortable" />
|
|
17
17
|
</v-col>
|
|
18
|
+
<v-col cols="12" sm="4">
|
|
19
|
+
<InputLabel title="Packing" class="mb-1" />
|
|
20
|
+
<v-text-field v-model="f.packing" density="comfortable" placeholder="e.g. 25 pcs / box" maxlength="60" />
|
|
21
|
+
</v-col>
|
|
18
22
|
<v-col cols="12" sm="4">
|
|
19
23
|
<InputLabel title="Item code" class="mb-1" />
|
|
20
24
|
<v-text-field v-model="f.code" density="comfortable" />
|
|
@@ -79,7 +83,7 @@ const moneyRule = (v: any) => v === "" || v === null || Number(v) >= 0 || "Enter
|
|
|
79
83
|
|
|
80
84
|
const form = ref();
|
|
81
85
|
const saving = ref(false);
|
|
82
|
-
const blank = () => ({ name: "", unit: "pcs", code: "", category: "", reorderLevel: 0, unitCost: 0, openingQty: 0, description: "" });
|
|
86
|
+
const blank = () => ({ name: "", unit: "pcs", packing: "", code: "", category: "", reorderLevel: 0, unitCost: 0, openingQty: 0, description: "" });
|
|
83
87
|
const f = reactive(blank());
|
|
84
88
|
const photo = ref<string[]>([]);
|
|
85
89
|
const inUse = ref(true);
|
|
@@ -87,7 +91,7 @@ const inUse = ref(true);
|
|
|
87
91
|
watch(show, (open) => {
|
|
88
92
|
if (!open) return;
|
|
89
93
|
const i = props.item;
|
|
90
|
-
Object.assign(f, blank(), i ? { name: i.name, unit: i.unit, code: i.code, category: i.category, reorderLevel: i.reorderLevel, unitCost: i.unitCost ?? 0, description: i.description } : {});
|
|
94
|
+
Object.assign(f, blank(), i ? { name: i.name, unit: i.unit, packing: i.packing ?? "", code: i.code, category: i.category, reorderLevel: i.reorderLevel, unitCost: i.unitCost ?? 0, description: i.description } : {});
|
|
91
95
|
photo.value = i?.photo ? [i.photo] : [];
|
|
92
96
|
inUse.value = i ? i.status === "active" : true;
|
|
93
97
|
});
|
|
@@ -99,6 +103,7 @@ async function save() {
|
|
|
99
103
|
const body = {
|
|
100
104
|
name: f.name,
|
|
101
105
|
unit: f.unit,
|
|
106
|
+
packing: f.packing,
|
|
102
107
|
code: f.code,
|
|
103
108
|
category: f.category,
|
|
104
109
|
reorderLevel: Number(f.reorderLevel || 0),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div>
|
|
3
3
|
<div class="d-flex flex-wrap ga-2 align-center mb-3">
|
|
4
|
-
<div class="text-body-2 text-medium-emphasis">Stock you have taken from the store and
|
|
4
|
+
<div class="text-body-2 text-medium-emphasis">Stock you have taken from the store: how many are left, and how many you used this month.</div>
|
|
5
5
|
<v-spacer />
|
|
6
6
|
<v-btn class="text-none screen-btn-primary" variant="flat" prepend-icon="mdi-cart-arrow-down" @click="showRequest = true">Request Stock</v-btn>
|
|
7
7
|
</div>
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
</v-avatar>
|
|
22
22
|
<div class="flex-grow-1">
|
|
23
23
|
<div class="font-weight-medium">{{ h.itemName }}</div>
|
|
24
|
-
<div class="text-body-2">{{ h.qty }} {{ h.unit }}
|
|
24
|
+
<div class="text-body-2">{{ h.qty }} {{ h.unit }} left · {{ h.usedThisMonth ?? 0 }} used this month</div>
|
|
25
25
|
</div>
|
|
26
|
-
<v-btn class="text-none screen-btn-primary" variant="flat" size="small" @click="use(h)">Record usage</v-btn>
|
|
26
|
+
<v-btn v-if="h.qty > 0" class="text-none screen-btn-primary" variant="flat" size="small" @click="use(h)">Record usage</v-btn>
|
|
27
27
|
</AppCard>
|
|
28
28
|
</v-col>
|
|
29
29
|
</v-row>
|
|
@@ -90,7 +90,7 @@ const usage = reactive({ show: false, holding: null as TInventoryHolding | null
|
|
|
90
90
|
async function load() {
|
|
91
91
|
loading.value = true;
|
|
92
92
|
try {
|
|
93
|
-
const [h, t] = await Promise.all([api.getHoldings(props.store._id, "me"), api.getTransactions(props.store._id, { page: 1, limit: 15, holder: currentUser.value?._id })]);
|
|
93
|
+
const [h, t] = await Promise.all([api.getHoldings(props.store._id, "me", true), api.getTransactions(props.store._id, { page: 1, limit: 15, holder: currentUser.value?._id })]);
|
|
94
94
|
holdings.value = h;
|
|
95
95
|
activity.value = t.items.filter((x) => x.holderChange !== undefined);
|
|
96
96
|
} catch {
|
|
@@ -168,6 +168,7 @@ const headers: Record<string, any[]> = {
|
|
|
168
168
|
movement: [
|
|
169
169
|
{ title: "Item", key: "name" },
|
|
170
170
|
{ title: "Unit", key: "unit" },
|
|
171
|
+
{ title: "Packing", key: "packing" },
|
|
171
172
|
{ title: "Start", key: "opening" },
|
|
172
173
|
{ title: "Received", key: "received" },
|
|
173
174
|
{ title: "Purchase cost", key: "receivedCost" },
|
|
@@ -190,6 +191,7 @@ const headers: Record<string, any[]> = {
|
|
|
190
191
|
{ title: "Total", key: "totalCost" },
|
|
191
192
|
{ title: "Technician", key: "technician" },
|
|
192
193
|
{ title: "Reference", key: "reference" },
|
|
194
|
+
{ title: "Reported by", key: "reportedBy" },
|
|
193
195
|
{ title: "Checked by", key: "checkedByName" },
|
|
194
196
|
],
|
|
195
197
|
technicians: [
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
</v-avatar>
|
|
62
62
|
<div>
|
|
63
63
|
<div class="font-weight-medium">{{ item.name }}</div>
|
|
64
|
-
<div class="text-caption text-medium-emphasis">{{ [item.code, item.category].filter(Boolean).join(" · ") }}</div>
|
|
64
|
+
<div class="text-caption text-medium-emphasis">{{ [item.code, item.category, item.packing].filter(Boolean).join(" · ") }}</div>
|
|
65
65
|
</div>
|
|
66
66
|
</div>
|
|
67
67
|
</template>
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<v-btn class="text-none screen-btn-ghost" variant="outlined" size="small" prepend-icon="mdi-keyboard-return" @click="openReturn(g)">Receive return</v-btn>
|
|
17
17
|
</div>
|
|
18
18
|
<div class="d-flex flex-wrap ga-2">
|
|
19
|
-
<v-chip v-for="h in g.items" :key="h._id" variant="tonal">{{ h.itemName }}: {{ h.qty }} {{ h.unit }}</v-chip>
|
|
19
|
+
<v-chip v-for="h in g.items" :key="h._id" variant="tonal">{{ h.itemName }}: {{ h.qty }} {{ h.unit }} left · {{ h.usedThisMonth ?? 0 }} used this month</v-chip>
|
|
20
20
|
</div>
|
|
21
21
|
</AppCard>
|
|
22
22
|
|
|
@@ -83,6 +83,8 @@
|
|
|
83
83
|
|
|
84
84
|
<InputLabel title="Date used" class="mb-1 mt-3" />
|
|
85
85
|
<v-text-field v-model="date" type="date" :max="today" density="comfortable" style="max-width: 200px" />
|
|
86
|
+
<InputLabel title="Fault reported by (optional)" class="mb-1" />
|
|
87
|
+
<v-text-field v-model="reportedBy" density="comfortable" placeholder="e.g. tenant, security guard" maxlength="120" />
|
|
86
88
|
<InputLabel title="Remarks (optional)" class="mb-1" />
|
|
87
89
|
<v-textarea v-model="remarks" rows="2" auto-grow density="comfortable" />
|
|
88
90
|
</v-form>
|
|
@@ -122,6 +124,7 @@ const unit = ref("");
|
|
|
122
124
|
const area = ref("");
|
|
123
125
|
const reference = ref("");
|
|
124
126
|
const remarks = ref("");
|
|
127
|
+
const reportedBy = ref("");
|
|
125
128
|
const date = ref(today);
|
|
126
129
|
const photosBefore = ref<string[]>([]);
|
|
127
130
|
const photosAfter = ref<string[]>([]);
|
|
@@ -169,6 +172,7 @@ async function save() {
|
|
|
169
172
|
photosBefore: photosBefore.value,
|
|
170
173
|
photosAfter: photosAfter.value,
|
|
171
174
|
remarks: remarks.value,
|
|
175
|
+
reportedBy: reportedBy.value,
|
|
172
176
|
});
|
|
173
177
|
notify("Usage saved.");
|
|
174
178
|
show.value = false;
|
|
@@ -195,6 +199,7 @@ watch(show, (open) => {
|
|
|
195
199
|
area.value = "";
|
|
196
200
|
reference.value = "";
|
|
197
201
|
remarks.value = "";
|
|
202
|
+
reportedBy.value = "";
|
|
198
203
|
date.value = today;
|
|
199
204
|
site.value = props.store.sites.includes(props.siteId) ? props.siteId : props.store.sites[0];
|
|
200
205
|
searchUnits("");
|
|
@@ -41,6 +41,11 @@
|
|
|
41
41
|
@click="toggleTheme"
|
|
42
42
|
/>
|
|
43
43
|
|
|
44
|
+
<NotificationBell
|
|
45
|
+
v-if="props.showNotifications"
|
|
46
|
+
:site-id="routeSiteId"
|
|
47
|
+
/>
|
|
48
|
+
|
|
44
49
|
<v-menu offset="10px" :close-on-content-click="false">
|
|
45
50
|
<template #activator="{ props }">
|
|
46
51
|
<v-btn fab variant="text" icon v-bind="props" class="ms-2 me-1">
|
|
@@ -96,6 +101,17 @@ const props = defineProps({
|
|
|
96
101
|
type: Boolean,
|
|
97
102
|
default: false,
|
|
98
103
|
},
|
|
104
|
+
/**
|
|
105
|
+
* Whether to show the notification bell.
|
|
106
|
+
*
|
|
107
|
+
* ON by default (owner requirement 2026-09-19: every type of account on the
|
|
108
|
+
* web is told about its notifications). An app can still pass `false` for a
|
|
109
|
+
* screen that should not have one.
|
|
110
|
+
*/
|
|
111
|
+
showNotifications: {
|
|
112
|
+
type: Boolean,
|
|
113
|
+
default: true,
|
|
114
|
+
},
|
|
99
115
|
});
|
|
100
116
|
|
|
101
117
|
const menu = defineModel("menu", { type: Boolean });
|
|
@@ -128,6 +144,15 @@ const { currentUser } = useLocalAuth();
|
|
|
128
144
|
*/
|
|
129
145
|
const { site } = useSite();
|
|
130
146
|
|
|
147
|
+
/**
|
|
148
|
+
* The site the user is currently inside, straight off the route. Empty outside
|
|
149
|
+
* a site, where the feed falls back to everything addressed to this user.
|
|
150
|
+
*/
|
|
151
|
+
const routeSiteId = computed(() => {
|
|
152
|
+
const param = useRoute().params.site;
|
|
153
|
+
return typeof param === "string" ? param : "";
|
|
154
|
+
});
|
|
155
|
+
|
|
131
156
|
/**
|
|
132
157
|
* The shared `site` state is only populated by the screens that load a site
|
|
133
158
|
* document, so on most screens - the dashboard included - the bar had no name
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="notif-bell">
|
|
3
|
+
<v-menu
|
|
4
|
+
v-model="open"
|
|
5
|
+
offset="10px"
|
|
6
|
+
:close-on-content-click="false"
|
|
7
|
+
location="bottom end"
|
|
8
|
+
>
|
|
9
|
+
<template #activator="{ props: activator }">
|
|
10
|
+
<v-btn
|
|
11
|
+
v-bind="activator"
|
|
12
|
+
variant="text"
|
|
13
|
+
size="36"
|
|
14
|
+
class="app-topbar-shell__icon-btn ms-2"
|
|
15
|
+
:aria-label="
|
|
16
|
+
unread > 0 ? `Notifications, ${unread} unread` : 'Notifications'
|
|
17
|
+
"
|
|
18
|
+
>
|
|
19
|
+
<v-badge
|
|
20
|
+
:model-value="unread > 0"
|
|
21
|
+
:content="badgeLabel"
|
|
22
|
+
color="error"
|
|
23
|
+
offset-x="-2"
|
|
24
|
+
offset-y="-2"
|
|
25
|
+
>
|
|
26
|
+
<v-icon icon="mdi-bell-outline" size="20" />
|
|
27
|
+
</v-badge>
|
|
28
|
+
</v-btn>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<v-card :width="440" elevation="0" class="notif-panel">
|
|
32
|
+
<div class="notif-panel__head">
|
|
33
|
+
<span>Notification</span>
|
|
34
|
+
<v-btn
|
|
35
|
+
v-if="unread > 0"
|
|
36
|
+
variant="text"
|
|
37
|
+
size="small"
|
|
38
|
+
class="text-none"
|
|
39
|
+
:loading="markingAll"
|
|
40
|
+
@click="readAll"
|
|
41
|
+
>
|
|
42
|
+
Mark all as read
|
|
43
|
+
</v-btn>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<div v-if="canAskDesktop" class="notif-panel__desktop">
|
|
47
|
+
<v-icon icon="mdi-monitor" size="18" />
|
|
48
|
+
<span>Get a pop-up on this computer when something new arrives.</span>
|
|
49
|
+
<v-btn variant="tonal" size="small" class="text-none" @click="askDesktop">
|
|
50
|
+
Turn on
|
|
51
|
+
</v-btn>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div class="notif-panel__body">
|
|
55
|
+
<div v-if="loading" class="notif-panel__state">
|
|
56
|
+
<v-progress-circular indeterminate size="22" />
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<p v-else-if="error" class="notif-panel__state text-error">
|
|
60
|
+
Notifications could not be loaded.
|
|
61
|
+
</p>
|
|
62
|
+
|
|
63
|
+
<p v-else-if="!items.length" class="notif-panel__state">
|
|
64
|
+
You have no notifications.
|
|
65
|
+
</p>
|
|
66
|
+
|
|
67
|
+
<template v-else>
|
|
68
|
+
<button
|
|
69
|
+
v-for="item in items"
|
|
70
|
+
:key="item._id"
|
|
71
|
+
type="button"
|
|
72
|
+
class="notif-card"
|
|
73
|
+
:class="{ 'notif-card--unread': !item.hasRead }"
|
|
74
|
+
@click="openNotification(item)"
|
|
75
|
+
>
|
|
76
|
+
<div class="notif-card__top">
|
|
77
|
+
<span class="notif-card__title" :class="titleClass(item)">
|
|
78
|
+
{{ item.title }}
|
|
79
|
+
</span>
|
|
80
|
+
<span class="notif-card__age">{{ timeAgo(item.createdAt) }}</span>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<div class="notif-card__bottom">
|
|
84
|
+
<v-icon size="18" class="notif-card__icon">
|
|
85
|
+
{{ iconFor(item) }}
|
|
86
|
+
</v-icon>
|
|
87
|
+
<span class="notif-card__body">{{ item.body }}</span>
|
|
88
|
+
<span
|
|
89
|
+
class="notif-card__dot"
|
|
90
|
+
:class="{ 'notif-card__dot--read': item.hasRead }"
|
|
91
|
+
/>
|
|
92
|
+
</div>
|
|
93
|
+
</button>
|
|
94
|
+
</template>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div class="notif-panel__foot">
|
|
98
|
+
<NuxtLink
|
|
99
|
+
:to="{ path: '/notification-settings' }"
|
|
100
|
+
class="notif-panel__settings"
|
|
101
|
+
@click="open = false"
|
|
102
|
+
>
|
|
103
|
+
<v-icon icon="mdi-cog-outline" size="16" /> Notification settings
|
|
104
|
+
</NuxtLink>
|
|
105
|
+
</div>
|
|
106
|
+
</v-card>
|
|
107
|
+
</v-menu>
|
|
108
|
+
|
|
109
|
+
<v-snackbar
|
|
110
|
+
v-model="toast.show"
|
|
111
|
+
location="top right"
|
|
112
|
+
:timeout="6000"
|
|
113
|
+
color="surface"
|
|
114
|
+
class="notif-toast"
|
|
115
|
+
>
|
|
116
|
+
<div class="d-flex align-center ga-3">
|
|
117
|
+
<v-icon icon="mdi-bell-ring-outline" color="primary" />
|
|
118
|
+
<div>
|
|
119
|
+
<div class="font-weight-bold">{{ toast.title }}</div>
|
|
120
|
+
<div v-if="toast.body" class="text-body-2">{{ toast.body }}</div>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
<template #actions>
|
|
124
|
+
<v-btn variant="text" class="text-none" @click="viewFromToast">View</v-btn>
|
|
125
|
+
</template>
|
|
126
|
+
</v-snackbar>
|
|
127
|
+
</div>
|
|
128
|
+
</template>
|
|
129
|
+
|
|
130
|
+
<script setup lang="ts">
|
|
131
|
+
import {
|
|
132
|
+
badgeText,
|
|
133
|
+
newArrivals,
|
|
134
|
+
timeAgo,
|
|
135
|
+
type TInboxItem,
|
|
136
|
+
} from "../utils/notification-inbox";
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The top-bar notification feed for the web, in every signed-in app.
|
|
140
|
+
*
|
|
141
|
+
* Owner requirement (2026-09-19): every type of account on the web gets the
|
|
142
|
+
* bell AND is told when something new arrives. So it is on by default in
|
|
143
|
+
* `Layout/Header.vue`, and it checks the unread count every 30 seconds and
|
|
144
|
+
* whenever the tab comes back into view — one small count query, not the list.
|
|
145
|
+
* When the count rises, the newest unread items are read and anything not seen
|
|
146
|
+
* before pops up in the page; if the person turned it on, as a desktop
|
|
147
|
+
* notification too (a browser only allows asking after a click, hence the
|
|
148
|
+
* "Turn on" button, never a prompt on load).
|
|
149
|
+
*
|
|
150
|
+
* The list shows everything addressed to the person, not only the current
|
|
151
|
+
* site: the unread count is never site-scoped, and most rows carry no site, so
|
|
152
|
+
* a site-scoped list disagreed with its own badge and was empty on site pages.
|
|
153
|
+
* `siteId` is still accepted so existing callers keep working.
|
|
154
|
+
*/
|
|
155
|
+
const PAGE_SIZE = 10;
|
|
156
|
+
const POLL_MS = 30_000;
|
|
157
|
+
|
|
158
|
+
defineProps({
|
|
159
|
+
/** Accepted for existing callers; the feed is not narrowed by it (see above). */
|
|
160
|
+
siteId: {
|
|
161
|
+
type: String,
|
|
162
|
+
default: "",
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const { getAll, getUnreadCount, markAsRead, markAllAsRead } = useNotification();
|
|
167
|
+
const { currentUser } = useLocalAuth();
|
|
168
|
+
|
|
169
|
+
const open = ref(false);
|
|
170
|
+
const loading = ref(false);
|
|
171
|
+
const error = ref(false);
|
|
172
|
+
const markingAll = ref(false);
|
|
173
|
+
const items = ref<Array<Record<string, any>>>([]);
|
|
174
|
+
const unread = ref(0);
|
|
175
|
+
const toast = reactive({ show: false, title: "", body: "" });
|
|
176
|
+
|
|
177
|
+
const userId = computed(() => String(currentUser.value?._id ?? ""));
|
|
178
|
+
const badgeLabel = computed(() => badgeText(unread.value));
|
|
179
|
+
|
|
180
|
+
const seen = new Set<string>();
|
|
181
|
+
let firstLook = true;
|
|
182
|
+
let timer: ReturnType<typeof setInterval> | null = null;
|
|
183
|
+
|
|
184
|
+
const desktopState = ref<NotificationPermission | "unsupported">("unsupported");
|
|
185
|
+
const canAskDesktop = computed(() => desktopState.value === "default");
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Red for a document that has already lapsed, amber for one approaching it;
|
|
189
|
+
* everything else is plain. Matched on the title because the stored feed row
|
|
190
|
+
* carries no structured stage (see `document-expiry-reminder.util.ts`).
|
|
191
|
+
*/
|
|
192
|
+
function titleClass(item: Record<string, any>) {
|
|
193
|
+
const title = String(item?.title ?? "");
|
|
194
|
+
if (/expired/i.test(title)) return "notif-card__title--urgent";
|
|
195
|
+
if (/expir/i.test(title)) return "notif-card__title--warn";
|
|
196
|
+
return "";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function iconFor(item: Record<string, any>) {
|
|
200
|
+
return /expir|document/i.test(`${item?.title ?? ""} ${item?.module ?? ""}`)
|
|
201
|
+
? "mdi-file-document-outline"
|
|
202
|
+
: "mdi-bell-outline";
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Tolerates the reply being paginated, wrapped once, or a bare array. */
|
|
206
|
+
function readRows(response: any): Array<Record<string, any>> {
|
|
207
|
+
const payload = response?.data ?? response;
|
|
208
|
+
const rows = payload?.items ?? payload?.data ?? payload;
|
|
209
|
+
return Array.isArray(rows) ? rows : [];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function readCount(response: any): number {
|
|
213
|
+
const payload = response?.data ?? response;
|
|
214
|
+
const value = payload?.unread ?? payload?.count ?? payload;
|
|
215
|
+
return Number.isFinite(Number(value)) ? Number(value) : 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function refreshList() {
|
|
219
|
+
if (!userId.value) return;
|
|
220
|
+
loading.value = true;
|
|
221
|
+
error.value = false;
|
|
222
|
+
try {
|
|
223
|
+
items.value = readRows(await getAll({ page: 1, limit: PAGE_SIZE, user: userId.value }));
|
|
224
|
+
} catch {
|
|
225
|
+
error.value = true;
|
|
226
|
+
items.value = [];
|
|
227
|
+
} finally {
|
|
228
|
+
loading.value = false;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** One check: the count, and — only if it rose — the newest unread, to announce what is new. */
|
|
233
|
+
async function check() {
|
|
234
|
+
if (!userId.value) return;
|
|
235
|
+
try {
|
|
236
|
+
const count = readCount(await getUnreadCount(userId.value));
|
|
237
|
+
const rose = count > unread.value;
|
|
238
|
+
unread.value = count;
|
|
239
|
+
if (!firstLook && !rose) return;
|
|
240
|
+
const latest = readRows(
|
|
241
|
+
await getAll({ page: 1, limit: PAGE_SIZE, hasRead: false, user: userId.value }),
|
|
242
|
+
) as TInboxItem[];
|
|
243
|
+
const fresh = newArrivals(latest, seen, firstLook);
|
|
244
|
+
latest.forEach((i) => i?._id && seen.add(i._id));
|
|
245
|
+
firstLook = false;
|
|
246
|
+
if (fresh.length) announce(fresh);
|
|
247
|
+
if (open.value) await refreshList();
|
|
248
|
+
} catch {
|
|
249
|
+
// A failed check is retried on the next tick; the top bar never shows an error for it.
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function announce(fresh: TInboxItem[]) {
|
|
254
|
+
const first = fresh[0];
|
|
255
|
+
toast.title = fresh.length > 1 ? `${fresh.length} new notifications` : first.title || "New notification";
|
|
256
|
+
toast.body = fresh.length > 1 ? first.title || "" : first.body || "";
|
|
257
|
+
toast.show = true;
|
|
258
|
+
if (desktopState.value === "granted" && document.visibilityState !== "visible") {
|
|
259
|
+
try {
|
|
260
|
+
const note = new Notification(toast.title, { body: toast.body, tag: `iservice365-${first._id}` });
|
|
261
|
+
note.onclick = () => {
|
|
262
|
+
window.focus();
|
|
263
|
+
open.value = true;
|
|
264
|
+
note.close();
|
|
265
|
+
};
|
|
266
|
+
} catch {
|
|
267
|
+
// Some browsers only allow notifications from a service worker; the in-page pop-up still shows.
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function openNotification(item: Record<string, any>) {
|
|
273
|
+
if (item.hasRead) return;
|
|
274
|
+
// Marked locally first: waiting on a round trip to move the dot reads as a dead control.
|
|
275
|
+
item.hasRead = true;
|
|
276
|
+
unread.value = Math.max(0, unread.value - 1);
|
|
277
|
+
try {
|
|
278
|
+
await markAsRead(String(item._id), userId.value);
|
|
279
|
+
} catch {
|
|
280
|
+
item.hasRead = false;
|
|
281
|
+
unread.value += 1;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function readAll() {
|
|
286
|
+
markingAll.value = true;
|
|
287
|
+
try {
|
|
288
|
+
await markAllAsRead(userId.value);
|
|
289
|
+
items.value.forEach((i) => (i.hasRead = true));
|
|
290
|
+
unread.value = 0;
|
|
291
|
+
} catch {
|
|
292
|
+
// Left as it was; the next check shows the real state.
|
|
293
|
+
} finally {
|
|
294
|
+
markingAll.value = false;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async function askDesktop() {
|
|
299
|
+
try {
|
|
300
|
+
desktopState.value = await Notification.requestPermission();
|
|
301
|
+
} catch {
|
|
302
|
+
desktopState.value = "denied";
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function viewFromToast() {
|
|
307
|
+
toast.show = false;
|
|
308
|
+
open.value = true;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function onVisible() {
|
|
312
|
+
if (document.visibilityState === "visible") check();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
watch(open, (isOpen) => {
|
|
316
|
+
if (isOpen) refreshList();
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
watch(userId, (id) => {
|
|
320
|
+
if (id) check();
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
onMounted(() => {
|
|
324
|
+
if (typeof window !== "undefined" && "Notification" in window) {
|
|
325
|
+
desktopState.value = Notification.permission;
|
|
326
|
+
}
|
|
327
|
+
check();
|
|
328
|
+
timer = setInterval(check, POLL_MS);
|
|
329
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
onBeforeUnmount(() => {
|
|
333
|
+
if (timer) clearInterval(timer);
|
|
334
|
+
document.removeEventListener("visibilitychange", onVisible);
|
|
335
|
+
});
|
|
336
|
+
</script>
|
|
337
|
+
|
|
338
|
+
<style scoped>
|
|
339
|
+
.notif-bell {
|
|
340
|
+
display: inline-flex;
|
|
341
|
+
align-items: center;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/* The header's 36px bordered icon button; its rule is scoped to Header.vue. */
|
|
345
|
+
.app-topbar-shell__icon-btn {
|
|
346
|
+
border: 1px solid var(--border);
|
|
347
|
+
border-radius: var(--r-inner);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
.notif-panel {
|
|
351
|
+
border-radius: var(--r-menu);
|
|
352
|
+
background: var(--card);
|
|
353
|
+
overflow: hidden;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
.notif-panel__head {
|
|
357
|
+
display: flex;
|
|
358
|
+
align-items: center;
|
|
359
|
+
justify-content: space-between;
|
|
360
|
+
padding: 14px 16px;
|
|
361
|
+
font-weight: 600;
|
|
362
|
+
border-bottom: 1px solid var(--border);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
.notif-panel__desktop {
|
|
366
|
+
display: flex;
|
|
367
|
+
align-items: center;
|
|
368
|
+
gap: 8px;
|
|
369
|
+
padding: 10px 16px;
|
|
370
|
+
font-size: 12.5px;
|
|
371
|
+
background: var(--hover);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.notif-panel__body {
|
|
375
|
+
max-height: 420px;
|
|
376
|
+
overflow-y: auto;
|
|
377
|
+
padding: 12px;
|
|
378
|
+
display: flex;
|
|
379
|
+
flex-direction: column;
|
|
380
|
+
gap: 10px;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.notif-panel__state {
|
|
384
|
+
padding: 24px 8px;
|
|
385
|
+
text-align: center;
|
|
386
|
+
color: var(--muted);
|
|
387
|
+
margin: 0;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.notif-panel__foot {
|
|
391
|
+
padding: 10px 16px;
|
|
392
|
+
border-top: 1px solid var(--border);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
.notif-panel__settings {
|
|
396
|
+
display: inline-flex;
|
|
397
|
+
align-items: center;
|
|
398
|
+
gap: 6px;
|
|
399
|
+
font-size: 12.5px;
|
|
400
|
+
color: var(--text2);
|
|
401
|
+
text-decoration: none;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.notif-card {
|
|
405
|
+
width: 100%;
|
|
406
|
+
text-align: left;
|
|
407
|
+
padding: 12px 14px;
|
|
408
|
+
border: 1px solid var(--border);
|
|
409
|
+
border-radius: var(--r-inner);
|
|
410
|
+
background: transparent;
|
|
411
|
+
cursor: pointer;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
.notif-card:hover {
|
|
415
|
+
background: var(--hover);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
.notif-card__top {
|
|
419
|
+
display: flex;
|
|
420
|
+
align-items: baseline;
|
|
421
|
+
justify-content: space-between;
|
|
422
|
+
gap: 12px;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
.notif-card__title {
|
|
426
|
+
font-size: var(--fs-cell);
|
|
427
|
+
font-weight: 500;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
.notif-card--unread .notif-card__title {
|
|
431
|
+
font-weight: 700;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.notif-card__title--warn {
|
|
435
|
+
color: var(--warn);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.notif-card__title--urgent {
|
|
439
|
+
color: var(--err);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
.notif-card__age {
|
|
443
|
+
flex: 0 0 auto;
|
|
444
|
+
font-size: 12px;
|
|
445
|
+
color: var(--muted);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
.notif-card__bottom {
|
|
449
|
+
display: flex;
|
|
450
|
+
align-items: center;
|
|
451
|
+
gap: 8px;
|
|
452
|
+
margin-top: 6px;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.notif-card__icon {
|
|
456
|
+
flex: 0 0 auto;
|
|
457
|
+
color: var(--text);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
.notif-card__body {
|
|
461
|
+
flex: 1 1 auto;
|
|
462
|
+
font-size: var(--fs-cell);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/* Filled while unread, hollow grey once read - the design's two states. */
|
|
466
|
+
.notif-card__dot {
|
|
467
|
+
flex: 0 0 auto;
|
|
468
|
+
width: 10px;
|
|
469
|
+
height: 10px;
|
|
470
|
+
border-radius: 50%;
|
|
471
|
+
background: var(--info);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
.notif-card__dot--read {
|
|
475
|
+
background: var(--muted);
|
|
476
|
+
opacity: 0.45;
|
|
477
|
+
}
|
|
478
|
+
</style>
|
|
@@ -45,7 +45,8 @@ export default function useInventory() {
|
|
|
45
45
|
rejectRequest: (id: string, remarks: string) => api(`/requests/${id}/reject`, { method: "POST", body: { remarks } }),
|
|
46
46
|
cancelRequest: (id: string) => api(`/requests/${id}/cancel`, { method: "POST" }),
|
|
47
47
|
|
|
48
|
-
getHoldings: (store: string, holder: string = "me"
|
|
48
|
+
getHoldings: (store: string, holder: string = "me", includeUsedUp = false) =>
|
|
49
|
+
api<TInventoryHolding[]>(`/stores/${store}/holdings`, { query: { holder, ...(includeUsedUp ? { includeUsedUp: true } : {}) } }),
|
|
49
50
|
getTransactions: (store: string, query: Record<string, any>) =>
|
|
50
51
|
api<{ items: TInventoryTransaction[]; total: number; page: number; pages: number }>(`/stores/${store}/transactions`, { query }),
|
|
51
52
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The web client for the in-app notification feed.
|
|
3
|
+
*
|
|
4
|
+
* The feed itself is not new - it has been written to for a while and read by
|
|
5
|
+
* the MA mobile app. Nothing on the web ever read it, which is why this is the
|
|
6
|
+
* first composable for it.
|
|
7
|
+
*
|
|
8
|
+
* `appSlug` is deliberately never sent. The inbox query applies that filter only
|
|
9
|
+
* when it is given one, so omitting it returns the rows written for the web
|
|
10
|
+
* (which carry no slug) alongside anything else addressed to this user, while a
|
|
11
|
+
* mobile client asking for its own slug still sees only its own.
|
|
12
|
+
*/
|
|
13
|
+
export default function useNotification() {
|
|
14
|
+
function getAll({
|
|
15
|
+
page = 1,
|
|
16
|
+
limit = 10,
|
|
17
|
+
siteId = "",
|
|
18
|
+
hasRead,
|
|
19
|
+
search = "",
|
|
20
|
+
user = "",
|
|
21
|
+
}: {
|
|
22
|
+
page?: number;
|
|
23
|
+
limit?: number;
|
|
24
|
+
siteId?: string;
|
|
25
|
+
hasRead?: boolean;
|
|
26
|
+
search?: string;
|
|
27
|
+
user?: string;
|
|
28
|
+
} = {}) {
|
|
29
|
+
const query: Record<string, any> = { page, limit, search };
|
|
30
|
+
|
|
31
|
+
// Sent only when set. The list schema rejects a malformed id rather than
|
|
32
|
+
// ignoring it, and `hasRead` false is a real filter that `||` would drop.
|
|
33
|
+
if (siteId) query.siteId = siteId;
|
|
34
|
+
if (user) query.user = user;
|
|
35
|
+
if (hasRead !== undefined) query.hasRead = hasRead;
|
|
36
|
+
|
|
37
|
+
return useNuxtApp().$api<Record<string, any>>("/api/notifications", {
|
|
38
|
+
method: "GET",
|
|
39
|
+
query,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getUnreadCount(user: string) {
|
|
44
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
45
|
+
"/api/notifications/unread-count",
|
|
46
|
+
{
|
|
47
|
+
method: "GET",
|
|
48
|
+
query: { user },
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function markAsRead(id: string, user: string) {
|
|
54
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
55
|
+
`/api/notifications/${id}/${user}/read`,
|
|
56
|
+
{
|
|
57
|
+
method: "PATCH",
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function markAllAsRead(user: string) {
|
|
63
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
64
|
+
"/api/notifications/read-all",
|
|
65
|
+
{
|
|
66
|
+
method: "PATCH",
|
|
67
|
+
query: { user },
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
getAll,
|
|
74
|
+
getUnreadCount,
|
|
75
|
+
markAsRead,
|
|
76
|
+
markAllAsRead,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -42,13 +42,14 @@ export default function useSecurityPermission() {
|
|
|
42
42
|
check: true,
|
|
43
43
|
description: "Allows the user to add a new feedback to the system.",
|
|
44
44
|
},
|
|
45
|
-
"see
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
45
|
+
// ONE row for "see all feedbacks" (2026-09-17). The editor showed two -
|
|
46
|
+
// `see-all-feedbacks` and `see-all-feedback` - for the same right.
|
|
47
|
+
// Kept: `see-all-feedback`, the canonical spelling ~95 live roles hold and
|
|
48
|
+
// the iSecure365 app checks. Removed: the plural row. Roles that hold
|
|
49
|
+
// `feedbacks:see-all-feedbacks` (~8) are NOT un-granted: it stays in
|
|
50
|
+
// `LEGACY_PERMISSION_ALIASES`, so `hasPermission` still honours it and the
|
|
51
|
+
// edit dialog shows it ticked on this row (and unticking removes it).
|
|
52
|
+
// API-core and the mobile app accept both spellings too.
|
|
52
53
|
"see-all-feedback": {
|
|
53
54
|
check: true,
|
|
54
55
|
description: "Allows the user to view the list of all feedbacks.",
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.
|
|
5
|
+
"version": "4.21.0",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
package/types/inventory.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare type TInventoryItem = {
|
|
|
24
24
|
code: string;
|
|
25
25
|
category: string;
|
|
26
26
|
unit: string;
|
|
27
|
+
packing?: string;
|
|
27
28
|
description: string;
|
|
28
29
|
photo: string;
|
|
29
30
|
reorderLevel: number;
|
|
@@ -60,6 +61,9 @@ declare type TInventoryHolding = {
|
|
|
60
61
|
holder: string;
|
|
61
62
|
holderName: string;
|
|
62
63
|
qty: number;
|
|
64
|
+
packing?: string;
|
|
65
|
+
/** Used by this holder since the start of the month (Singapore time). */
|
|
66
|
+
usedThisMonth?: number;
|
|
63
67
|
};
|
|
64
68
|
|
|
65
69
|
declare type TInventoryTransaction = {
|
|
@@ -82,6 +86,7 @@ declare type TInventoryTransaction = {
|
|
|
82
86
|
totalCost: number;
|
|
83
87
|
photos?: { before: string[]; after: string[]; other: string[] };
|
|
84
88
|
remarks?: string;
|
|
89
|
+
reportedBy?: string;
|
|
85
90
|
date: string;
|
|
86
91
|
createdByName: string;
|
|
87
92
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The web notification bell's decisions, kept free of Vue and Nuxt so they are
|
|
3
|
+
* unit-tested directly (`utils/notification-inbox.test.ts`).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type TInboxItem = {
|
|
7
|
+
_id: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
body?: string;
|
|
10
|
+
hasRead?: boolean;
|
|
11
|
+
createdAt?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Which of the newest unread items have not been announced yet.
|
|
16
|
+
*
|
|
17
|
+
* The first look after sign-in announces nothing: a pop-up for every message
|
|
18
|
+
* that was already waiting is noise, and the badge already says how many there
|
|
19
|
+
* are. After that, anything unread whose id was not seen before is new.
|
|
20
|
+
*/
|
|
21
|
+
export function newArrivals(items: TInboxItem[], seen: Set<string>, firstLook: boolean): TInboxItem[] {
|
|
22
|
+
const unread = items.filter((i) => i && i._id && !i.hasRead);
|
|
23
|
+
if (firstLook) return [];
|
|
24
|
+
return unread.filter((i) => !seen.has(i._id));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** "just now", "5 min ago", "3 h ago", "2 days ago", then the date. */
|
|
28
|
+
export function timeAgo(value: string | undefined, now: Date = new Date()): string {
|
|
29
|
+
if (!value) return "";
|
|
30
|
+
const at = new Date(value);
|
|
31
|
+
if (Number.isNaN(at.getTime())) return "";
|
|
32
|
+
const seconds = Math.round((now.getTime() - at.getTime()) / 1000);
|
|
33
|
+
if (seconds < 60) return "just now";
|
|
34
|
+
const minutes = Math.round(seconds / 60);
|
|
35
|
+
if (minutes < 60) return `${minutes} min ago`;
|
|
36
|
+
const hours = Math.round(minutes / 60);
|
|
37
|
+
if (hours < 24) return `${hours} h ago`;
|
|
38
|
+
const days = Math.round(hours / 24);
|
|
39
|
+
if (days < 7) return `${days} day${days === 1 ? "" : "s"} ago`;
|
|
40
|
+
return at.toLocaleDateString("en-SG", { day: "2-digit", month: "short", year: "numeric" });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The badge text: nothing at 0, the number up to 99, then "99+". */
|
|
44
|
+
export function badgeText(unread: number): string {
|
|
45
|
+
if (!unread || unread < 0) return "";
|
|
46
|
+
return unread > 99 ? "99+" : String(unread);
|
|
47
|
+
}
|