import { ShellPage } from "@/components/page-templates"; import { Button, SectionCard } from "@/components/ui"; import { getSession } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; import { redirect } from "next/navigation"; export default async function ExportContactsPage() { const session = await getSession(); if (!session) { redirect("/login"); } if (session.role === "agent") { redirect("/unauthorized"); } const [segments, tags, count, lastUpdated] = await Promise.all([ prisma.contactSegment.findMany({ where: { tenantId: session.tenantId }, orderBy: { name: "asc" }, select: { id: true, name: true, _count: { select: { members: true } } } }), prisma.tag.findMany({ where: { tenantId: session.tenantId }, select: { name: true }, orderBy: { name: "asc" } }), prisma.contact.count({ where: { tenantId: session.tenantId } }), prisma.contact.findFirst({ where: { tenantId: session.tenantId }, orderBy: { updatedAt: "desc" }, select: { updatedAt: true } }) ]); const fields = ["fullName", "phoneNumber", "email", "countryCode", "optInStatus", "createdAt", "updatedAt"]; return (

Total kontak: {count} • Last updated: {lastUpdated?.updatedAt ? new Intl.DateTimeFormat("id-ID").format(lastUpdated.updatedAt) : "-"}

Available tags: {tags.length ? tags.map((tag) => tag.name).join(", ") : "-"}

{segments.length === 0 ? (

Tambahkan segment untuk filtering export yang lebih presisi.

) : null}
); }