"use client"; import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { communicationApi } from "@/modules/communication/services/communication-api"; import { useTenantId } from "@/hooks/useTenantId"; import { CommunicationPageLoader, CommunicationPageError, exportToCsv } from "@/modules/communication/pages/shared"; import { CommunicationTablePage, CommunicationStatusChip } from "@/modules/communication/design-system"; import { CommunicationBreadcrumbs } from "@/modules/communication/components/CommunicationBreadcrumbs"; import { Button, Drawer, Badge } from "@/components/ds"; import { Timeline } from "@/src/shared/ui"; import { Download, RefreshCw } from "lucide-react"; import { useCommunicationPermissions } from "@/modules/communication/hooks/useCommunicationPermissions"; import { PermissionDeniedState } from "@/src/shared/ui"; export function MessagesPage() { const { tenantId } = useTenantId(); const perms = useCommunicationPermissions(); const [status, setStatus] = useState(""); const [detailId, setDetailId] = useState(null); const listQ = useQuery({ queryKey: ["communication", tenantId, "messages", status], queryFn: () => communicationApi.messages.list(tenantId!, status ? { status } : undefined), enabled: !!tenantId, }); const timelineQ = useQuery({ queryKey: ["communication", tenantId, "timeline", detailId], queryFn: () => communicationApi.messages.timeline(tenantId!, detailId!), enabled: !!tenantId && !!detailId, }); if (!tenantId || listQ.isLoading) return ; if (listQ.error) return listQ.refetch()} />; if (!perms.can("communication.messages.view")) return ; const rows = listQ.data ?? []; return ( <> }, { key: "channel", header: "کانال" }, { key: "sent_at", header: "ارسال", render: (r) => (r.sent_at ? new Date(String(r.sent_at)).toLocaleString("fa-IR") : "—") }, { key: "id", header: "جزئیات", render: (r) => ( ), }, ]} rows={rows} toolbar={ } actions={
} /> setDetailId(null)} title="Timeline تحویل"> {timelineQ.isLoading ? : null} {timelineQ.data ? ( ({ id: String(e.id), title: String(e.status), subtitle: e.detail ? String(e.detail) : undefined, timestamp: String(e.created_at ?? new Date().toISOString()), }))} /> ) : null} ); } export default MessagesPage;