import { ShellPage } from "@/components/page-templates"; import { SectionCard } from "@/components/ui"; import { getSession } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; import { redirect } from "next/navigation"; function formatDate(value: Date | null | undefined) { if (!value) { return "-"; } return new Intl.DateTimeFormat("id-ID", { day: "2-digit", month: "short", year: "numeric" }).format(value); } export default async function ImportContactsPage() { const session = await getSession(); if (!session) { redirect("/login"); } if (session.role === "agent") { redirect("/unauthorized"); } const [channels, tags, sampleContacts] = await Promise.all([ prisma.channel.findMany({ where: { tenantId: session.tenantId }, select: { id: true, channelName: true, provider: true } }), prisma.tag.findMany({ where: { tenantId: session.tenantId }, orderBy: { name: "asc" } }), prisma.contact.findMany({ where: { tenantId: session.tenantId }, orderBy: { createdAt: "desc" }, take: 5, select: { id: true, fullName: true, phoneNumber: true, createdAt: true } }) ]); return (

Pilih file CSV dari browser dan pastikan header minimal: nama, no_telepon, email.

Gunakan channel yang aktif:

{channels.length === 0 ? (

Tenant belum memiliki channel. Tambahkan channel dulu.

) : (
    {channels.map((channel) => (
  • {channel.channelName} • {channel.provider}
  • ))}
)}

Baris terakhir di tenant: {sampleContacts.length} contoh terbaru.

{sampleContacts.length === 0 ? (

Belum ada contact sebelumnya.

) : (
    {sampleContacts.map((contact) => (
  • {contact.fullName}

    {contact.phoneNumber}

    Created: {formatDate(contact.createdAt)}

  • ))}
)}

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

); }