import Link from 'next/link'; import { Plus, Building2, Clock, FolderOpen, Users } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { auth } from '@/lib/auth'; import { redirect } from 'next/navigation'; import { db } from '@/lib/db'; function formatRelativeTime(date: Date): string { const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffMins = Math.floor(diffMs / 60000); const diffHours = Math.floor(diffMs / 3600000); const diffDays = Math.floor(diffMs / 86400000); if (diffMins < 1) return 'just now'; if (diffMins < 60) return `${diffMins}m ago`; if (diffHours < 24) return `${diffHours}h ago`; if (diffDays < 7) return `${diffDays}d ago`; return date.toLocaleDateString(); } export default async function WorkspacesPage() { const session = await auth(); if (!session?.user?.id) { redirect('/login'); } const workspaces = await db.workspace.findMany({ where: { OR: [ { ownerId: session.user.id }, { members: { some: { userId: session.user.id } } }, ], }, include: { owner: { select: { id: true, name: true } }, _count: { select: { projects: true, members: true, }, }, }, orderBy: { updatedAt: 'desc' }, }); return (
Manage your workspaces and their projects
Create a workspace to organize your projects and invite team members