From dd71820ac99c6cd1a32d1d60a74df508d8aea230 Mon Sep 17 00:00:00 2001 From: Yashwin Date: Wed, 4 Feb 2026 14:54:37 +0530 Subject: [PATCH] Enhance Header component to display user roles alongside names. Update Sidebar menu item label for clarity. Refactor Modules component to utilize new MyModule type and fetch modules with updated service method. Comment out unused code in RolesTable and Dashboard components for cleaner codebase. Add MyModule and MyModulesResponse types for better type safety in module handling. --- src/components/layout/Header.tsx | 4 ++-- src/components/layout/Sidebar.tsx | 2 +- src/components/superadmin/RolesTable.tsx | 18 +++++++++--------- src/pages/tenant/Dashboard.tsx | 14 +++++++------- src/pages/tenant/Modules.tsx | 24 ++++++++---------------- src/pages/tenant/Roles.tsx | 18 +++++++++--------- src/pages/tenant/TenantLogin.tsx | 4 ++-- src/services/module-service.ts | 6 +++++- src/types/module.ts | 24 ++++++++++++++++++++++++ 9 files changed, 67 insertions(+), 47 deletions(-) diff --git a/src/components/layout/Header.tsx b/src/components/layout/Header.tsx index 104fbda..d538411 100644 --- a/src/components/layout/Header.tsx +++ b/src/components/layout/Header.tsx @@ -17,7 +17,7 @@ interface HeaderProps { export const Header = ({ breadcrumbs, currentPage, onMenuClick }: HeaderProps): ReactElement => { const navigate = useNavigate(); const dispatch = useAppDispatch(); - const { user, isLoading } = useAppSelector((state) => state.auth); + const { user, isLoading,roles } = useAppSelector((state) => state.auth); const [isDropdownOpen, setIsDropdownOpen] = useState(false); const dropdownRef = useRef(null); @@ -35,7 +35,7 @@ export const Header = ({ breadcrumbs, currentPage, onMenuClick }: HeaderProps): // Get user display name const getUserDisplayName = (): string => { if (user?.first_name && user?.last_name) { - return `${user.first_name} ${user.last_name}`; + return `${user.first_name} - ${roles[0] || 'N/A'}`; } return user?.email?.split('@')[0] || 'Admin'; }; diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx index 30f1334..06ae6e8 100644 --- a/src/components/layout/Sidebar.tsx +++ b/src/components/layout/Sidebar.tsx @@ -48,7 +48,7 @@ const tenantAdminPlatformMenu: MenuItem[] = [ { icon: LayoutDashboard, label: 'Dashboard', path: '/tenant' }, { icon: Shield, label: 'Roles', path: '/tenant/roles', requiredPermission: { resource: 'roles' } }, { icon: Users, label: 'Users', path: '/tenant/users', requiredPermission: { resource: 'users' } }, - { icon: Package, label: 'TenantModules', path: '/tenant/modules', requiredPermission: { resource: 'tenants' } }, + { icon: Package, label: 'Modules', path: '/tenant/modules' }, ]; const tenantAdminSystemMenu: MenuItem[] = [ diff --git a/src/components/superadmin/RolesTable.tsx b/src/components/superadmin/RolesTable.tsx index b3d0e9d..467bcba 100644 --- a/src/components/superadmin/RolesTable.tsx +++ b/src/components/superadmin/RolesTable.tsx @@ -215,15 +215,15 @@ export const RolesTable = ({ tenantId, showHeader = true, compact = false }: Rol ), }, - { - key: 'is_system', - label: 'System Role', - render: (role) => ( - - {role.is_system ? 'Yes' : 'No'} - - ), - }, + // { + // key: 'is_system', + // label: 'System Role', + // render: (role) => ( + // + // {role.is_system ? 'Yes' : 'No'} + // + // ), + // }, { key: 'created_at', label: 'Created Date', diff --git a/src/pages/tenant/Dashboard.tsx b/src/pages/tenant/Dashboard.tsx index 180d91b..5ea3a0b 100644 --- a/src/pages/tenant/Dashboard.tsx +++ b/src/pages/tenant/Dashboard.tsx @@ -65,13 +65,13 @@ const StatCard = ({ icon: Icon, value, label, status, statusLabel }: StatCardPro const Dashboard = (): ReactElement => { const statCards: StatCardProps[] = [ - { - icon: Info, - value: '18', - label: 'Open CAPAs', - status: 'success', - statusLabel: 'Success', - }, + // { + // icon: Info, + // value: '18', + // label: 'Open CAPAs', + // status: 'success', + // statusLabel: 'Success', + // }, { icon: FileCheck, value: '7', diff --git a/src/pages/tenant/Modules.tsx b/src/pages/tenant/Modules.tsx index ac850a2..77d8a6a 100644 --- a/src/pages/tenant/Modules.tsx +++ b/src/pages/tenant/Modules.tsx @@ -7,9 +7,8 @@ import { type Column, } from '@/components/shared'; import { useAppSelector } from '@/hooks/redux-hooks'; -import { tenantService } from '@/services/tenant-service'; -import type { AssignedModule } from '@/types/tenant'; import { moduleService } from '@/services/module-service'; +import type { MyModule } from '@/types/module'; // Helper function to get status badge variant const getStatusVariant = (status: string | null): 'success' | 'failure' | 'process' => { @@ -28,24 +27,17 @@ const getStatusVariant = (status: string | null): 'success' | 'failure' | 'proce const Modules = (): ReactElement => { const { roles, tenantId } = useAppSelector((state) => state.auth); - // const tenantId = useAppSelector((state) => state.auth.tenantId); - const [modules, setModules] = useState([]); + const [modules, setModules] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const fetchTenantModules = async (): Promise => { - if (!tenantId) { - setError('Tenant ID not found'); - setIsLoading(false); - return; - } - try { setIsLoading(true); setError(null); - const response = await tenantService.getById(tenantId); - if (response.success && response.data.assignedModules) { - setModules(response.data.assignedModules); + const response = await moduleService.getMyModules(); + if (response.success && response.data) { + setModules(response.data); } else { setError('Failed to load modules'); } @@ -58,7 +50,7 @@ const Modules = (): ReactElement => { useEffect(() => { fetchTenantModules(); - }, [tenantId]); + }, []); // Launch module handler const handleLaunchModule = async (moduleId: string): Promise => { @@ -88,7 +80,7 @@ const Modules = (): ReactElement => { }; // Define table columns - const columns: Column[] = [ + const columns: Column[] = [ { key: 'module_id', label: 'Module ID', @@ -149,7 +141,7 @@ const Modules = (): ReactElement => { ]; // Mobile card renderer - const mobileCardRenderer = (module: AssignedModule) => ( + const mobileCardRenderer = (module: MyModule) => (
diff --git a/src/pages/tenant/Roles.tsx b/src/pages/tenant/Roles.tsx index 99c8569..be192ae 100644 --- a/src/pages/tenant/Roles.tsx +++ b/src/pages/tenant/Roles.tsx @@ -218,15 +218,15 @@ const Roles = (): ReactElement => { ), }, - { - key: 'is_system', - label: 'System Role', - render: (role) => ( - - {role.is_system ? 'Yes' : 'No'} - - ), - }, + // { + // key: 'is_system', + // label: 'System Role', + // render: (role) => ( + // + // {role.is_system ? 'Yes' : 'No'} + // + // ), + // }, { key: 'created_at', label: 'Created Date', diff --git a/src/pages/tenant/TenantLogin.tsx b/src/pages/tenant/TenantLogin.tsx index 0f7f9da..57cd7a5 100644 --- a/src/pages/tenant/TenantLogin.tsx +++ b/src/pages/tenant/TenantLogin.tsx @@ -245,11 +245,11 @@ const TenantLogin = (): ReactElement => {
{/* Header */}
-
+ {/*
Tenant Admin Portal
-
+
*/}

Sign in to your tenant

Use your work email or configured SSO provider to access the admin portal. diff --git a/src/services/module-service.ts b/src/services/module-service.ts index fd267b4..c4cb76f 100644 --- a/src/services/module-service.ts +++ b/src/services/module-service.ts @@ -1,5 +1,5 @@ import apiClient from './api-client'; -import type { ModulesResponse, GetModuleResponse, CreateModuleRequest, CreateModuleResponse, LaunchModuleResponse } from '@/types/module'; +import type { ModulesResponse, GetModuleResponse, CreateModuleRequest, CreateModuleResponse, LaunchModuleResponse, MyModulesResponse } from '@/types/module'; export const moduleService = { getAll: async ( @@ -75,4 +75,8 @@ export const moduleService = { const response = await apiClient.post(url); return response.data; }, + getMyModules: async (): Promise => { + const response = await apiClient.get('/modules/my'); + return response.data; + }, }; diff --git a/src/types/module.ts b/src/types/module.ts index 5f574df..ca5a88f 100644 --- a/src/types/module.ts +++ b/src/types/module.ts @@ -101,3 +101,27 @@ export interface LaunchModuleResponse { }; }; } + +export interface MyModule { + id: string; + module_id: string; + name: string; + description: string | null; + version: string; + status: string; + base_url: string; + health_status: string | null; + assigned_at: string; + tenant_settings: Record | null; +} + +export interface MyModulesResponse { + success: boolean; + data: MyModule[]; + meta: { + tenant_id: string; + is_super_admin: boolean; + is_tenant_admin: boolean; + total: number; + }; +}