From ddbd2e55675ab8d12151ed66aa9282afc93dfc7c Mon Sep 17 00:00:00 2001 From: Yashwin Date: Thu, 25 Jun 2026 18:44:51 +0530 Subject: [PATCH] feat: add handleLaunchModule function and intercept module launch URLs in notifications --- src/pages/tenant/Notifications.tsx | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/pages/tenant/Notifications.tsx b/src/pages/tenant/Notifications.tsx index c88c78e..550aecb 100644 --- a/src/pages/tenant/Notifications.tsx +++ b/src/pages/tenant/Notifications.tsx @@ -34,6 +34,7 @@ import { Layout } from "@/components/layout/Layout"; import { Button } from "@/components/ui/button"; import { PrimaryButton } from "@/components/shared/PrimaryButton"; import { notificationService } from "@/services/notification-service"; +import { moduleService } from "@/services/module-service"; import { showToast } from "@/utils/toast"; const getNotificationIcon = ( @@ -90,6 +91,7 @@ export const Notifications = () => { const { notifications, unread_count, isLoading } = useAppSelector( (state) => state.notifications, ); + const { roles, tenantId } = useAppSelector((state) => state.auth); const [activeFilter, setActiveFilter] = useState("all"); const [searchQuery, setSearchQuery] = useState(""); @@ -158,6 +160,34 @@ export const Notifications = () => { } }; + const handleLaunchModule = async (moduleId: string): Promise => { + try { + let rolesArray: string[] = []; + if (Array.isArray(roles)) { + rolesArray = roles; + } else if (typeof roles === "string") { + try { + rolesArray = JSON.parse(roles); + } catch { + rolesArray = []; + } + } + const isSuperAdmin = rolesArray.includes("super_admin"); + const launchTenantId = isSuperAdmin ? tenantId : null; + + const response = await moduleService.launch(moduleId, launchTenantId); + if (response.success && response.data?.launch_url) { + window.open(response.data.launch_url, "_blank", "noopener,noreferrer"); + } else { + showToast.error("Failed to retrieve launch URL"); + } + } catch (err: any) { + showToast.error( + err?.response?.data?.error?.message || "Failed to launch module", + ); + } + }; + const handleAction = (notification: Notification) => { if (!notification.is_read) { handleMarkRead(notification.id); @@ -176,6 +206,15 @@ export const Notifications = () => { // } if (notification.action_url) { + const match = notification.action_url.match( + /^\/?modules\/([a-fA-F0-9-]+)\/launch\/?$/, + ); + if (match) { + const moduleId = match[1]; + handleLaunchModule(moduleId); + return; + } + const targetUrl = notification.action_url.startsWith("/tenant") ? notification.action_url : `/tenant${notification.action_url.startsWith("/") ? "" : "/"}${notification.action_url}`;