import Link from "next/link"; import { redirect } from "next/navigation"; import { ShellPage } from "@/components/page-templates"; import { SectionCard } from "@/components/ui"; import { getSession } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; function formatDate(date: Date | null) { if (!date) { return "Not synced"; } return new Intl.DateTimeFormat("id-ID", { day: "2-digit", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit" }).format(date); } export default async function SuperAdminChannelDetailPage({ params }: { params: Promise<{ channelId: string }>; }) { const session = await getSession(); if (!session || session.role !== "super_admin") { redirect("/unauthorized"); } const { channelId } = await params; const channel = await prisma.channel.findUnique({ where: { id: channelId }, include: { tenant: true, conversations: { where: {}, take: 5, orderBy: { lastMessageAt: "desc" } }, webhookEvents: { orderBy: { createdAt: "desc" }, take: 8 } } }); if (!channel) { redirect("/super-admin/channels?error=channel_not_found"); } const failedWebhookCount = channel.webhookEvents.filter((item) => item.processStatus === "failed").length; return (

Tenant: {channel.tenant.name}

Provider: {channel.provider}

Channel name: {channel.channelName}

WABA ID: {channel.wabaId ?? "-"}

Phone Number ID: {channel.phoneNumberId ?? "-"}

Display Number: {channel.displayPhoneNumber ?? "-"}

Status: {channel.status}

Webhook status: {channel.webhookStatus ?? "unknown"}

Last sync: {formatDate(channel.lastSyncAt)}

Open tenant Back to channels

Webhook failures: {failedWebhookCount}

Conversations tracked: {channel.conversations.length}

    {channel.webhookEvents.map((event) => (
  • {event.eventType}

    Status: {event.processStatus}

    Created: {formatDate(event.createdAt)}

  • ))} {channel.webhookEvents.length === 0 ?

    No webhook events.

    : null}
); }