import { ShellPage } from "@/components/page-templates"; import { SectionCard } from "@/components/ui"; import { headers } from "next/headers"; import { getSession } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; import { redirect } from "next/navigation"; export default async function IntegrationsSettingsPage() { const session = await getSession(); if (!session) { redirect("/login"); } if (session.role === "agent") { redirect("/unauthorized"); } const tenantFilter = session.role === "super_admin" ? {} : { tenantId: session.tenantId }; const [channels, recentWebhook] = await Promise.all([ prisma.channel.findMany({ where: tenantFilter, orderBy: { createdAt: "desc" } }), prisma.webhookEvent.findMany({ where: tenantFilter, orderBy: { createdAt: "desc" }, take: 4 }) ]); const host = (await headers()).get("host"); const webhookBase = host ? `${process.env.NODE_ENV === "production" ? "https" : "http"}://${host}` : ""; const connectedCount = channels.filter((channel) => channel.status === "CONNECTED").length; const failedCount = channels.filter((channel) => channel.status === "ERROR").length; return (

Webhook URL: {webhookBase ? `${webhookBase}/api/webhooks/whatsapp` : "/api/webhooks/whatsapp"}

Connected: {connectedCount} • Error: {failedCount} • Total channels: {channels.length}

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

    Status: {channel.status}

    Provider: {channel.provider}

    WABA ID: {channel.wabaId ?? "N/A"} • Phone ID: {channel.phoneNumberId ?? "N/A"}

  • ))} {channels.length === 0 ?

    Tidak ada channel terhubung.

    : null}
    {recentWebhook.map((event) => (
  • {event.eventType} • {event.processStatus}

    {event.createdAt.toLocaleString("id-ID", { dateStyle: "medium", timeStyle: "short" })}

  • ))} {recentWebhook.length === 0 ?

    Belum ada event webhook terbaru.

    : null}
); }