@pfm-platform/notifications-feature 0.2.0 → 0.2.1
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/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.cjs
CHANGED
|
@@ -24,6 +24,7 @@ function useNotificationGroups(userId) {
|
|
|
24
24
|
const now = /* @__PURE__ */ new Date();
|
|
25
25
|
const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1e3);
|
|
26
26
|
const recent = notifications.filter((notification) => {
|
|
27
|
+
if (!notification.created_at) return false;
|
|
27
28
|
const createdAt = new Date(notification.created_at);
|
|
28
29
|
return createdAt >= twentyFourHoursAgo;
|
|
29
30
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useNotificationGroups.ts","../src/hooks/useNotificationCount.ts"],"names":["useNotifications","useMemo"],"mappings":";;;;;;AAqBO,SAAS,sBAAsB,MAAA,EAAoC;AACxE,EAAA,MAAM,EAAE,IAAA,EAAM,aAAA,KAAkBA,wCAAA,CAAiB,EAAE,QAAQ,CAAA;AAE3D,EAAA,OAAOC,cAAQ,MAAM;AACnB,IAAA,IAAI,CAAC,aAAA,IAAiB,aAAA,CAAc,MAAA,KAAW,CAAA,EAAG;AAChD,MAAA,OAAO;AAAA,QACL,aAAa,EAAC;AAAA,QACd,QAAQ,EAAC;AAAA,QACT,KAAA,EAAO;AAAA,OACT;AAAA,IACF;AAGA,IAAA,MAAM,
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useNotificationGroups.ts","../src/hooks/useNotificationCount.ts"],"names":["useNotifications","useMemo"],"mappings":";;;;;;AAqBO,SAAS,sBAAsB,MAAA,EAAoC;AACxE,EAAA,MAAM,EAAE,IAA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MAAM,MAAA,GAA6B,sBAAsB,MAAM,CAAA;AAG/D,EAAA,OAAO,MAAA,CAAO,KAAA;AAChB","file":"index.cjs","sourcesContent":["import { useMemo } from 'react';\nimport { useNotifications } from '@pfm-platform/notifications-data-access';\nimport type { NotificationRow } from '@pfm-platform/shared';\n\nexport interface NotificationGroups {\n byAlertType: Record<string, NotificationRow[]>;\n recent: NotificationRow[];\n count: number;\n}\n\n/**\n * Group notifications by alert type and identify recent notifications\n *\n * Business logic:\n * - byAlertType: Group notifications by their alert_type (AccountThresholdAlert, GoalAlert, etc.)\n * - recent: Notifications from last 24 hours\n * - count: Total notification count\n *\n * @param userId - User ID to fetch notifications for\n * @returns Object with grouped notifications and counts\n */\nexport function useNotificationGroups(userId: string): NotificationGroups {\n const { data: notifications } = useNotifications({ userId });\n\n return useMemo(() => {\n if (!notifications || notifications.length === 0) {\n return {\n byAlertType: {},\n recent: [],\n count: 0,\n };\n }\n\n // Group by alert type\n const byAlertType: Record<string, NotificationRow[]> = {};\n notifications.forEach((notification) => {\n if (!byAlertType[notification.alert_type]) {\n byAlertType[notification.alert_type] = [];\n }\n byAlertType[notification.alert_type].push(notification);\n });\n\n // Filter recent notifications (last 24 hours)\n const now = new Date();\n const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);\n\n const recent = notifications.filter((notification) => {\n if (!notification.created_at) return false;\n const createdAt = new Date(notification.created_at);\n return createdAt >= twentyFourHoursAgo;\n });\n\n return {\n byAlertType,\n recent,\n count: notifications.length,\n };\n }, [notifications]);\n}\n","import { useNotificationGroups, type NotificationGroups } from './useNotificationGroups';\n\n/**\n * Returns the count of unread notifications for a user\n *\n * @param userId - User ID to get notification count for\n * @returns Number of unread notifications\n *\n * @example\n * ```tsx\n * function NotificationBadge({ userId }: { userId: string }) {\n * const count = useNotificationCount(userId);\n * return <Badge badgeContent={count}>...</Badge>;\n * }\n * ```\n */\nexport function useNotificationCount(userId: string): number {\n const groups: NotificationGroups = useNotificationGroups(userId);\n\n // Return the total count from the groups\n return groups.count;\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NotificationRow } from '@pfm-platform/shared';
|
|
2
2
|
|
|
3
3
|
interface NotificationGroups {
|
|
4
|
-
byAlertType: Record<string,
|
|
5
|
-
recent:
|
|
4
|
+
byAlertType: Record<string, NotificationRow[]>;
|
|
5
|
+
recent: NotificationRow[];
|
|
6
6
|
count: number;
|
|
7
7
|
}
|
|
8
8
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NotificationRow } from '@pfm-platform/shared';
|
|
2
2
|
|
|
3
3
|
interface NotificationGroups {
|
|
4
|
-
byAlertType: Record<string,
|
|
5
|
-
recent:
|
|
4
|
+
byAlertType: Record<string, NotificationRow[]>;
|
|
5
|
+
recent: NotificationRow[];
|
|
6
6
|
count: number;
|
|
7
7
|
}
|
|
8
8
|
/**
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ function useNotificationGroups(userId) {
|
|
|
22
22
|
const now = /* @__PURE__ */ new Date();
|
|
23
23
|
const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1e3);
|
|
24
24
|
const recent = notifications.filter((notification) => {
|
|
25
|
+
if (!notification.created_at) return false;
|
|
25
26
|
const createdAt = new Date(notification.created_at);
|
|
26
27
|
return createdAt >= twentyFourHoursAgo;
|
|
27
28
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useNotificationGroups.ts","../src/hooks/useNotificationCount.ts"],"names":[],"mappings":";;;;AAqBO,SAAS,sBAAsB,MAAA,EAAoC;AACxE,EAAA,MAAM,EAAE,IAAA,EAAM,aAAA,KAAkB,gBAAA,CAAiB,EAAE,QAAQ,CAAA;AAE3D,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,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AO,KAAA;AACrC,MAAA,MAAM,SAAA,GAAY,IAAI,IAAA,CAAK,YAAA,CAAa,UAAU,CAAA;AAClD,MAAA,OAAO,SAAA,IAAa,kBAAA;AAAA,IACtB,CAAC,CAAA;AAED,IAAA,OAAO;AAAA,MACL,WAAA;AAAA,MACA,MAAA;AAAA,MACA,OAAO,aAAA,CAAc;AAAA,KACvB;AAAA,EACF,CAAA,EAAG,CAAC,aAAa,CAAC,CAAA;AACpB;;;AC1CO,SAAS,qBAAqB,MAAA,EAAwB;AAC3D,EAAA,MAAM,MAAA,GAA6B,sBAAsB,MAAM,CAAA;AAG/D,EAAA,OAAO,MAAA,CAAO,KAAA;AAChB","file":"index.js","sourcesContent":["import { useMemo } from 'react';\nimport { useNotifications } from '@pfm-platform/notifications-data-access';\nimport type { NotificationRow } from '@pfm-platform/shared';\n\nexport interface NotificationGroups {\n byAlertType: Record<string, NotificationRow[]>;\n recent: NotificationRow[];\n count: number;\n}\n\n/**\n * Group notifications by alert type and identify recent notifications\n *\n * Business logic:\n * - byAlertType: Group notifications by their alert_type (AccountThresholdAlert, GoalAlert, etc.)\n * - recent: Notifications from last 24 hours\n * - count: Total notification count\n *\n * @param userId - User ID to fetch notifications for\n * @returns Object with grouped notifications and counts\n */\nexport function useNotificationGroups(userId: string): NotificationGroups {\n const { data: notifications } = useNotifications({ userId });\n\n return useMemo(() => {\n if (!notifications || notifications.length === 0) {\n return {\n byAlertType: {},\n recent: [],\n count: 0,\n };\n }\n\n // Group by alert type\n const byAlertType: Record<string, NotificationRow[]> = {};\n notifications.forEach((notification) => {\n if (!byAlertType[notification.alert_type]) {\n byAlertType[notification.alert_type] = [];\n }\n byAlertType[notification.alert_type].push(notification);\n });\n\n // Filter recent notifications (last 24 hours)\n const now = new Date();\n const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);\n\n const recent = notifications.filter((notification) => {\n if (!notification.created_at) return false;\n const createdAt = new Date(notification.created_at);\n return createdAt >= twentyFourHoursAgo;\n });\n\n return {\n byAlertType,\n recent,\n count: notifications.length,\n };\n }, [notifications]);\n}\n","import { useNotificationGroups, type NotificationGroups } from './useNotificationGroups';\n\n/**\n * Returns the count of unread notifications for a user\n *\n * @param userId - User ID to get notification count for\n * @returns Number of unread notifications\n *\n * @example\n * ```tsx\n * function NotificationBadge({ userId }: { userId: string }) {\n * const count = useNotificationCount(userId);\n * return <Badge badgeContent={count}>...</Badge>;\n * }\n * ```\n */\nexport function useNotificationCount(userId: string): number {\n const groups: NotificationGroups = useNotificationGroups(userId);\n\n // Return the total count from the groups\n return groups.count;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pfm-platform/notifications-feature",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"react": "19.2.
|
|
8
|
-
"@pfm-platform/notifications-data-access": "0.2.
|
|
9
|
-
"@pfm-platform/shared": "0.1
|
|
7
|
+
"react": "19.2.4",
|
|
8
|
+
"@pfm-platform/notifications-data-access": "0.2.1",
|
|
9
|
+
"@pfm-platform/shared": "0.2.1"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@tanstack/react-query": "5.90.
|
|
13
|
-
"@testing-library/react": "^16.3.
|
|
14
|
-
"@types/react": "^19.2.
|
|
15
|
-
"@vitejs/plugin-react": "^5.1.
|
|
16
|
-
"@vitest/coverage-v8": "^4.0.
|
|
12
|
+
"@tanstack/react-query": "5.90.21",
|
|
13
|
+
"@testing-library/react": "^16.3.2",
|
|
14
|
+
"@types/react": "^19.2.14",
|
|
15
|
+
"@vitejs/plugin-react": "^5.1.4",
|
|
16
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
17
17
|
"jsdom": "^27.2.0",
|
|
18
|
-
"react-dom": "19.2.
|
|
18
|
+
"react-dom": "19.2.4",
|
|
19
19
|
"typescript": "5.9.3",
|
|
20
|
-
"vitest": "4.0.
|
|
20
|
+
"vitest": "4.0.18"
|
|
21
21
|
},
|
|
22
22
|
"module": "./dist/index.js",
|
|
23
23
|
"types": "./dist/index.d.ts",
|