// app/workspaces/page.tsx import { redirect } from "next/navigation" import { getServerSession } from "next-auth" import { authOptions } from "@/lib/auth/config" import { prisma } from "@/lib/prisma" import Link from "next/link" export default async function WorkspacesPage() { const session = await getServerSession(authOptions) if (!session) { redirect("/login") } const user = await prisma.user.findUnique({ where: { id: session.user.id }, include: { workspacesAsEmployee: { where: { status: { in: ["ACTIVE", "PENDING_INVITE"] } }, include: { manager: { select: { name: true, avatar: true, email: true } } } }, workspacesAsManager: { where: { status: { in: ["ACTIVE", "PENDING_INVITE"] } }, include: { employee: { select: { name: true, avatar: true, email: true } } } } } }) // Se for admin, mostrar link para painel admin const isAdmin = user?.role === "HR_ADMIN" const totalAsManager = user?.workspacesAsManager.length || 0 const totalAsEmployee = user?.workspacesAsEmployee.length || 0 const totalWorkspaces = totalAsManager + totalAsEmployee return (
{totalAsManager > 0 ? `Gerencie ${totalAsManager} ${totalAsManager === 1 ? 'colaborador' : 'colaboradores'} da sua equipe` : "Selecione um workspace para acessar" }
{totalWorkspaces > 0 && (Crie um novo workspace para começar a gerenciar sua equipe
+ Criar Primeiro Workspace