From 3132b9262c136d56772aaa69c747a429f237930b Mon Sep 17 00:00:00 2001 From: Furqan-14 Date: Tue, 20 Jan 2026 17:38:12 +0530 Subject: [PATCH] feat: added the base for module integrations --- src/application/dashboard/Dashboard.tsx | 111 +++++++++++++++++++++--- src/application/module/ModuleApi.ts | 34 ++++++++ src/constant.ts | 3 +- 3 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 src/application/module/ModuleApi.ts diff --git a/src/application/dashboard/Dashboard.tsx b/src/application/dashboard/Dashboard.tsx index 00fc667..13667c3 100644 --- a/src/application/dashboard/Dashboard.tsx +++ b/src/application/dashboard/Dashboard.tsx @@ -1,25 +1,114 @@ -import { Construction } from 'lucide-react'; +import { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; +import { ExternalLink, Box } from 'lucide-react'; +import { moduleApi, type Module } from '../module/ModuleApi'; const Dashboard = () => { const { t } = useTranslation('dashboard'); + const [modules, setModules] = useState([]); + const [loading, setLoading] = useState(true); + + useEffect(() => { + const fetchModules = async () => { + try { + const fetchedModules = await moduleApi.getAvailableModules(); + setModules(fetchedModules); + } catch (error) { + console.error('Failed to fetch modules', error); + } finally { + setLoading(false); + } + }; + + fetchModules(); + }, []); + + const handleModuleClick = async (moduleId: string) => { + try { + const response = await moduleApi.launchModule(moduleId); + if (response.redirect_url) { + window.location.href = response.redirect_url; + } + } catch (error) { + console.error('Failed to launch module', error); + } + }; return ( -
-
-
- -
- -

+
+
+

{t('title')}

- -

+

{t('message')}

+
- + {/* Modules Section */} +
+

+ Available Modules +

+ + {loading ? ( +
+ {[1, 2, 3].map((i) => ( +
+
+
+
+
+ ))} +
+ ) : modules.length > 0 ? ( +
+ {modules.map((module) => ( + + ))} +
+ ) : ( +
+ +

+ No modules available +

+
+ )}
); diff --git a/src/application/module/ModuleApi.ts b/src/application/module/ModuleApi.ts new file mode 100644 index 0000000..7b1abc6 --- /dev/null +++ b/src/application/module/ModuleApi.ts @@ -0,0 +1,34 @@ +import axios from "axios"; +import { API_BASE_URL } from "../../constant"; + +export interface Module { + module_id: string; + module_name: string; + description: string | null; + icon_url: string | null; + display_order: number; + is_active: boolean; +} + +export interface LaunchResponse { + redirect_url: string; + grant_code: string; +} + +export const moduleApi = { + getAvailableModules: async (): Promise => { + const response = await axios.get(`${API_BASE_URL}/api/modules/available`, { + withCredentials: true, + }); + return response.data; + }, + + launchModule: async (moduleId: string): Promise => { + const response = await axios.post( + `${API_BASE_URL}/api/sso/initiate`, + { module_id: moduleId }, + { withCredentials: true } + ); + return response.data; + }, +}; diff --git a/src/constant.ts b/src/constant.ts index aae5ac8..a59fa9f 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,2 +1 @@ -// Use VITE_API_BASE_URL to match your backend host when working with cookies. -export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL; +export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL; \ No newline at end of file