diff --git a/gridwalk-ui/src/app/project/[workspaceId]/[projectName]/components/navBars/mainMapNavigation.tsx b/gridwalk-ui/src/app/project/[workspaceId]/[projectName]/components/navBars/mainMapNavigation.tsx index bcc3586..a4a9ea5 100644 --- a/gridwalk-ui/src/app/project/[workspaceId]/[projectName]/components/navBars/mainMapNavigation.tsx +++ b/gridwalk-ui/src/app/project/[workspaceId]/[projectName]/components/navBars/mainMapNavigation.tsx @@ -44,7 +44,7 @@ const LayersTable: React.FC = ({ diff --git a/gridwalk-ui/src/app/workspace/page.tsx b/gridwalk-ui/src/app/workspace/page.tsx index 52428a4..be52dd5 100644 --- a/gridwalk-ui/src/app/workspace/page.tsx +++ b/gridwalk-ui/src/app/workspace/page.tsx @@ -1,16 +1,20 @@ "use client"; -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { FolderKanban, + FolderCheck, + MapIcon, Plus, HelpCircle, Users, - Database, LucideIcon, + Clock, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { CreateWorkspaceModal } from "./modal"; import { createWorkspace } from "./actions"; +import { getProjects } from "@/app/workspace/[workspaceId]/actions/projects/get"; +import { getWorkspaceMembers } from "@/app/workspace/[workspaceId]/actions/workspace/get_members"; import { HelpSupportModal } from "./supportModal"; import { useWorkspaces } from "./workspaceContext"; @@ -21,10 +25,17 @@ interface StatCardProps { description?: string; } +interface WorkspaceWithDetails { + id: string; + name: string; + projectCount: number; + memberCount: number; + adminCount: number; + readOnlyCount: number; +} + const StatCard = ({ title, value, icon: Icon, description }: StatCardProps) => (
- {" "} - {/* Changed border color */}
@@ -44,17 +55,89 @@ export default function WorkspacePage() { const { workspaces } = useWorkspaces(); const [isModalOpen, setIsModalOpen] = useState(false); const [isHelpSupportModalOpen, setIsHelpSupportModalOpen] = useState(false); + const [workspacesWithDetails, setWorkspacesWithDetails] = useState< + WorkspaceWithDetails[] + >([]); + const [totalProjects, setTotalProjects] = useState(0); + const [totalMembers, setTotalMembers] = useState(0); + const [loading, setLoading] = useState(true); + + useEffect(() => { + const fetchWorkspaceDetails = async () => { + setLoading(true); + try { + const detailsPromises = workspaces.map(async (workspace) => { + try { + const [projects, members] = await Promise.all([ + getProjects(workspace.id), + getWorkspaceMembers(workspace.id), + ]); + + const adminCount = members.filter((m) => m.role === "Admin").length; + const readOnlyCount = members.filter( + (m) => m.role === "Read" + ).length; + + return { + id: workspace.id, + name: workspace.name, + projectCount: projects.length, + memberCount: members.length, + adminCount, + readOnlyCount, + }; + } catch (error) { + console.error( + `Failed to fetch details for workspace ${workspace.id}:`, + error + ); + return { + id: workspace.id, + name: workspace.name, + projectCount: 0, + memberCount: 0, + adminCount: 0, + readOnlyCount: 0, + }; + } + }); + + const results = await Promise.all(detailsPromises); + setWorkspacesWithDetails(results); + + const projectsTotal = results.reduce( + (sum, workspace) => sum + workspace.projectCount, + 0 + ); + const membersTotal = results.reduce( + (sum, workspace) => sum + workspace.memberCount, + 0 + ); + + setTotalProjects(projectsTotal); + setTotalMembers(membersTotal); + } catch (error) { + console.error("Failed to fetch workspace details:", error); + } finally { + setLoading(false); + } + }; + + if (workspaces.length > 0) { + fetchWorkspaceDetails(); + } else { + setWorkspacesWithDetails([]); + setTotalProjects(0); + setTotalMembers(0); + setLoading(false); + } + }, [workspaces]); - // Mock data for now - // TODO add in real data const currentPlan = "MVP"; - const totalProjects = 0; // Example count - const totalConnections = 0; // Example count return (
- {/* Header Section with Plan Info */}

@@ -68,8 +151,7 @@ export default function WorkspacePage() {

- {/* Stats Grid */} -
+
- {/* Workspaces List */}
-
-

+
+

Your Workspaces

-
- {workspaces.length > 0 ? ( -
- {workspaces.map((workspace) => ( +
+ {loading ? ( +
+ +

Loading workspace details...

+
+ ) : workspacesWithDetails.length > 0 ? ( +
+ {workspacesWithDetails.map((workspace) => (
-
- -
-

{workspace.name}

-

- 0 projects • 0 members +

+ +
+

+ {workspace.name} +

+

+ {workspace.projectCount} projects •{" "} + {workspace.memberCount} members •{" "} + {workspace.adminCount} admins •{" "} + {workspace.readOnlyCount} viewers

@@ -119,7 +210,7 @@ export default function WorkspacePage() {
) : (
- +

No workspaces yet

@@ -136,7 +227,6 @@ export default function WorkspacePage() {
- {/* Help Button */}
- {/* Modals */} setIsModalOpen(false)}