From 292ea1b8ed73e8ed2facd384edcba371601fc603 Mon Sep 17 00:00:00 2001 From: digpalsinghpanwar Date: Tue, 14 Jul 2026 17:18:51 +0530 Subject: [PATCH] updated Notification events --- .../components/notifications-popover.tsx | 40 ++++++++++++++++--- src/hooks/store/chat/index.ts | 11 +++-- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/components/screens-component/chat-screen/components/notifications-popover.tsx b/src/components/screens-component/chat-screen/components/notifications-popover.tsx index 1f1c6eb..a568106 100644 --- a/src/components/screens-component/chat-screen/components/notifications-popover.tsx +++ b/src/components/screens-component/chat-screen/components/notifications-popover.tsx @@ -32,6 +32,40 @@ function getSeenIds(): Set { } catch { return new Set(); } } +function getStoredLocationCoordinates(): { latitude?: number; longitude?: number } { + try { + const rawLocation = localStorage.getItem("user_location"); + if (!rawLocation) return {}; + + const location = JSON.parse(rawLocation); + const latitude = Number(location?.latitude); + const longitude = Number(location?.longitude); + + return { + ...(Number.isFinite(latitude) ? { latitude } : {}), + ...(Number.isFinite(longitude) ? { longitude } : {}) + }; + } catch { + return {}; + } +} + +function buildNegativeFeedbackMetadata( + notification: ApiNotification, + reason: NotificationFeedbackReason, + message: string +) { + return { + notification_id: notification.notification_id, + notification_description: notification.content?.body, + message_type: notification.message_type ?? notification.metadata?.message_type, + category_type: notification.category_type, + ...getStoredLocationCoordinates(), + reason, + feedback: message + }; +} + export function NotificationsPopover() { const notifications = useChatStore((s) => s.notifications); const markNotificationRead = useChatStore((s) => s.markNotificationRead); @@ -445,11 +479,7 @@ export function NotificationsPopover() { apiService.trackUiTelemetryEvent({ event_name: "notification_feedback_dislike_submitted", category: "notification_feedback", - metadata: { - notification_id: feedbackTarget.notification_id, - reason, - feedback: message - } + metadata: buildNegativeFeedbackMetadata(feedbackTarget, reason, message) }); setFeedbackMap((previous) => ({ ...previous, [feedbackTarget.notification_id]: "disliked" })); setFeedbackModalOpen(false); diff --git a/src/hooks/store/chat/index.ts b/src/hooks/store/chat/index.ts index 5aba65b..93315c5 100644 --- a/src/hooks/store/chat/index.ts +++ b/src/hooks/store/chat/index.ts @@ -19,6 +19,8 @@ import { environment } from "@/lib/config/environment"; export type ApiNotification = { notification_id: string; type: string; + message_type?: string; + category_type?: string; priority: "HIGH" | "MEDIUM" | "LOW"; valid_from: string; valid_to: string; @@ -31,10 +33,11 @@ export type ApiNotification = { distance_km?: number; } | null; metadata: { - source: string; - template: string; - unique_id_iitm: string; - unique_id_pm_kisan: number; + source?: string; + template?: string; + unique_id_iitm?: string; + unique_id_pm_kisan?: number; + message_type?: string; }; };