From 46e8fd466b4faba3fdad9318074dfe34042223ec Mon Sep 17 00:00:00 2001 From: Yashwin Date: Tue, 3 Feb 2026 19:40:34 +0530 Subject: [PATCH] Refactor Modules component to navigate to a redirect page with the launch URL as a query parameter instead of opening it in a new tab. Add new route for ModuleLaunchRedirect in tenant admin routes for improved URL handling. --- src/pages/ModuleLaunchRedirect.tsx | 36 ++++++++++++++++++++++++++++++ src/pages/tenant/Modules.tsx | 20 +++++------------ src/routes/tenant-admin-routes.tsx | 5 +++++ 3 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 src/pages/ModuleLaunchRedirect.tsx diff --git a/src/pages/ModuleLaunchRedirect.tsx b/src/pages/ModuleLaunchRedirect.tsx new file mode 100644 index 0000000..8f87e7d --- /dev/null +++ b/src/pages/ModuleLaunchRedirect.tsx @@ -0,0 +1,36 @@ +import { useEffect } from 'react'; +import type { ReactElement } from 'react'; +import { useSearchParams } from 'react-router-dom'; + +const ModuleLaunchRedirect = (): ReactElement => { + const [searchParams] = useSearchParams(); + const launchUrl = searchParams.get('url'); + + useEffect(() => { + if (launchUrl) { + // Make a fetch request with custom headers + fetch(launchUrl, { + method: 'GET', + headers: { + 'bypass-tunnel-reminder': 'true', + }, + credentials: 'include', + }) + .catch(() => { + // Ignore fetch errors, we'll still open the URL + }) + .finally(() => { + // Open the external URL in a new tab + window.open(launchUrl, '_blank', 'noopener,noreferrer'); + }); + } + }, [launchUrl]); + + return ( +
+
Redirecting...
+
+ ); +}; + +export default ModuleLaunchRedirect; diff --git a/src/pages/tenant/Modules.tsx b/src/pages/tenant/Modules.tsx index fb97db1..8c68a98 100644 --- a/src/pages/tenant/Modules.tsx +++ b/src/pages/tenant/Modules.tsx @@ -1,5 +1,6 @@ import { useState, useEffect } from 'react'; import type { ReactElement } from 'react'; +import { useNavigate } from 'react-router-dom'; import { Layout } from '@/components/layout/Layout'; import { StatusBadge, @@ -27,6 +28,7 @@ const getStatusVariant = (status: string | null): 'success' | 'failure' | 'proce }; const Modules = (): ReactElement => { + const navigate = useNavigate(); const { roles, tenantId } = useAppSelector((state) => state.auth); // const tenantId = useAppSelector((state) => state.auth.tenantId); const [modules, setModules] = useState([]); @@ -80,21 +82,9 @@ const Modules = (): ReactElement => { const launchTenantId = isSuperAdmin ? tenantId : null; const response = await moduleService.launch(moduleId, launchTenantId); if (response.success && response.data.launch_url) { - // Make a fetch request with custom headers first - try { - await fetch(response.data.launch_url, { - method: 'GET', - headers: { - 'bypass-tunnel-reminder': 'true', - }, - credentials: 'include', - }); - } catch (fetchError) { - // Ignore fetch errors, we'll still open the URL - console.warn('Failed to send header request:', fetchError); - } - // Open the URL in a new tab - window.open(response.data.launch_url, '_blank', 'noopener,noreferrer'); + // Navigate to redirect page with launch URL as query param + const encodedUrl = encodeURIComponent(response.data.launch_url); + navigate(`/tenant/module-launch?url=${encodedUrl}`); } } catch (err: any) { setError(err?.response?.data?.error?.message || 'Failed to launch module'); diff --git a/src/routes/tenant-admin-routes.tsx b/src/routes/tenant-admin-routes.tsx index edcec6c..a217a3e 100644 --- a/src/routes/tenant-admin-routes.tsx +++ b/src/routes/tenant-admin-routes.tsx @@ -8,6 +8,7 @@ const Settings = lazy(() => import('@/pages/tenant/Settings')); const Users = lazy(() => import('@/pages/tenant/Users')); const AuditLogs = lazy(() => import('@/pages/tenant/AuditLogs')); const Modules = lazy(() => import('@/pages/tenant/Modules')); +const ModuleLaunchRedirect = lazy(() => import('@/pages/ModuleLaunchRedirect')); // Loading fallback component const RouteLoader = (): ReactElement => ( @@ -54,4 +55,8 @@ export const tenantAdminRoutes: RouteConfig[] = [ path: '/tenant/settings', element: , }, + { + path: '/tenant/module-launch', + element: , + }, ];