'use client'; import { useQuery } from '@tanstack/react-query'; import Link from 'next/link'; import type { ReactNode } from 'react'; import api from '@/lib/api'; import { useAuthStore } from '@/lib/store'; import type { Application } from '@/types'; import { Rocket, Package, Circle, Hexagon } from 'lucide-react'; const statusColors: Record = { running: 'bg-emerald-100 text-emerald-700', pending: 'bg-amber-100 text-amber-700', building: 'bg-blue-100 text-blue-700', deploying: 'bg-blue-100 text-blue-700', failed: 'bg-red-100 text-red-700', build_failed: 'bg-red-100 text-red-700', stopped: 'bg-gray-100 text-gray-600', }; const statusIcons: Record = { running: , pending: , building: , deploying: , failed: , build_failed: , stopped: , }; export default function DashboardPage() { const user = useAuthStore((s) => s.user); const { data: apps = [], isLoading } = useQuery({ queryKey: ['applications'], queryFn: () => api.get('/applications').then((r) => r.data), }); const runningApps = apps.filter( (a) => a.deployments?.some((d) => d.status === 'running'), ); const failedApps = apps.filter( (a) => a.deployments?.some((d) => d.status === 'failed' || d.status === 'build_failed'), ); return (
{/* Welcome */}

Welcome back, {user?.firstName}!

Here's an overview of your applications.

{/* Stats */}
Total Apps
{isLoading ? '—' : apps.length}
Running
{isLoading ? '—' : runningApps.length}
Failed
{isLoading ? '—' : failedApps.length}
Total Deploys
{isLoading ? '—' : apps.reduce((sum, a) => sum + (a.deployments?.length || 0), 0)}
{/* Recent Applications */}

Recent Applications

New Application
{isLoading ? (
{[1, 2, 3].map((i) => (
))}
) : apps.length === 0 ? (

No applications yet

Deploy your first application to get started.

Deploy your first app
) : (
{apps.slice(0, 5).map((app) => { const latestDeploy = app.deployments?.[0]; const status = latestDeploy?.status || 'pending'; return (

{app.name}

{app.runtime} · {app.replicas} replica{app.replicas > 1 ? 's' : ''} {app.databaseType !== 'none' && ` · ${app.databaseType}`}

{statusIcons[status]} {status}
); })} {apps.length > 5 && ( View all {apps.length} applications → )}
)}
); }