'use client'; import { useRouter } from 'next/navigation'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { FileText, Layout, Upload, BookOpen, Fuel } from 'lucide-react'; import Image from 'next/image'; import { useKindeBrowserClient } from "@kinde-oss/kinde-auth-nextjs"; interface AppTile { id: string; title: string; description: string; icon: React.ReactNode; href: string; color: string; } export default function DashboardPage() { const router = useRouter(); const { isAuthenticated, accessToken } = useKindeBrowserClient(); const roles = accessToken?.roles || []; const permissions = accessToken?.permissions || []; // Extract role keys for easier checking const roleKeys = roles.map(role => role.key); // Check if user has admin role const hasAdminRole = isAuthenticated && roleKeys.includes('admin'); // Check if user has customer role and cintas_access permission const hasCustomerRole = isAuthenticated && roleKeys.includes('customer'); const hasCintasAccess = permissions.includes('cintas_access'); // Check if user can access Cintas summary const canAccessCintasSummary = hasAdminRole || (hasCustomerRole && hasCintasAccess); const allApps: AppTile[] = [ { id: 'files', title: 'Files', description: 'Manage and organize your uploaded files', icon: , href: '/files', color: 'bg-blue-500' }, { id: 'layout-configurations', title: 'Layout Configurations', description: 'Create and manage layout configurations', icon: , href: '/layout-configurations', color: 'bg-green-500' }, { id: 'imports', title: 'Imports', description: 'Import and manage data from external sources', icon: , href: '/imports', color: 'bg-purple-500' }, { id: 'api-docs', title: 'API Documentation', description: 'Explore API endpoints and documentation', icon: , href: '/api-docs', color: 'bg-orange-500' }, { id: 'cintas-calendar-summary', title: 'Cintas Install Calendar Summary', description: 'View installation calendar summary and statistics', icon: (
Cintas
), href: '/cintas-calendar-summary', color: 'bg-blue-600' }, { id: 'terratech-facility-summaries', title: 'TerraTech Facility Summaries', description: 'View Gas, Oil, and Water production summaries', icon: , href: '/terratech-facility-summaries', color: 'bg-amber-500' } ]; // Filter apps based on authentication and authorization const filteredApps = allApps.filter(app => { // Cintas summary has special access rules if (app.id === 'cintas-calendar-summary') { return canAccessCintasSummary; } // All other apps require admin role return hasAdminRole; }); const handleAppClick = (href: string) => { router.push(href); }; return (

Welcome to Vtorio Dashboard

Select an application to get started

{filteredApps.map((app) => ( handleAppClick(app.href)} >
{app.icon}
{app.title}
{app.description}
))}

Click on any application to access its features

); }