import Link from 'next/link';
import { notFound, redirect } from 'next/navigation';
import {
ArrowLeft,
Plus,
Settings,
FolderOpen,
Clock,
Users,
Globe,
Lock,
UserPlus,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { auth } from '@/lib/auth';
import { db } from '@/lib/db';
function VisibilityIcon({ visibility }: { visibility: string }) {
switch (visibility) {
case 'PUBLIC':
return ;
case 'INVITE':
return ;
default:
return ;
}
}
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();
}
interface WorkspacePageProps {
params: Promise<{ workspaceId: string }>;
}
export default async function WorkspacePage({ params }: WorkspacePageProps) {
const session = await auth();
const { workspaceId } = await params;
if (!session?.user?.id) {
redirect('/login');
}
const workspace = await db.workspace.findUnique({
where: { id: workspaceId },
include: {
owner: { select: { id: true, name: true } },
members: {
where: { userId: session.user.id },
select: { role: true },
},
projects: {
orderBy: { updatedAt: 'desc' },
include: {
_count: { select: { videos: true, members: true } },
},
},
_count: { select: { projects: true, members: true } },
},
});
if (!workspace) {
notFound();
}
const isOwner = session.user.id === workspace.ownerId;
const membership = workspace.members[0];
const isMember = !!membership;
const isAdmin = isOwner || membership?.role === 'ADMIN';
if (!isOwner && !isMember) {
redirect('/workspaces');
}
return (
{/* Back & Header */}
{workspace.name}
{workspace.description && (
{workspace.description}
)}
{workspace._count.projects} projects
{workspace._count.members + 1} members
{isAdmin && (
<>
>
)}
{/* Projects Grid */}
{workspace.projects.length > 0 ? (
{workspace.projects.map((project) => (
{project.name}
{project.visibility.toLowerCase()}
{project.description || 'No description'}
{formatRelativeTime(project.updatedAt)}
{project._count.members + 1}
{project._count.videos} videos
))}
) : (
No projects yet
Create a project in this workspace to get started
{isAdmin && (
)}
)}
);
}