"use client"; import { useQuery } from "@tanstack/react-query"; import { useRouter } from "next/navigation"; import { RefreshCw, Wifi, AlertCircle } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card"; import { Table, TableHead, TableBody, TableRow, Th, Td } from "@/components/ui/Table"; import { Badge } from "@/components/ui/Badge"; import { Button } from "@/components/ui/Button"; import { formatDate, formatCurrency } from "@/lib/utils"; import api from "@/lib/api"; import type { PaginatedResponse } from "@/types"; interface Subscription { id: string; clientId: string; status: string; startDate: string; endDate?: string; client?: { firstName: string; lastName: string; accountNumber: string }; plan?: { name: string; type: string; monthlyPrice: number }; planId?: string; monthlyRate?: number; mrc?: number; type?: string; } const statusVariant: Record = { ACTIVE: "success", active: "success", SUSPENDED: "warning", suspended: "warning", CANCELLED: "danger", cancelled: "danger", DISCONNECTED: "danger", disconnected: "danger", PENDING: "muted", pending: "muted", }; export default function SubscriptionsPage() { const router = useRouter(); const { data, isLoading, isError, error, refetch, isFetching } = useQuery>({ queryKey: ["subscriptions"], queryFn: async () => { const res = await api.get>("/api/v1/subscriptions?page=1&limit=50"); return res.data; }, retry: false, }); const subscriptions = data?.data ?? []; const meta = data?.meta; const isNotFound = isError && (error as { response?: { status?: number } })?.response?.status === 404; return (

Subscriptions

{meta?.total ?? 0} total subscriptions

All Subscriptions {isLoading ? (
{Array.from({ length: 4 }).map((_, i) => (
))}
) : isNotFound || (isError && !data) ? (

Subscriptions Module Not Yet Available

Subscription data will appear here once the module is deployed.

API endpoint not yet available
) : subscriptions.length === 0 ? (

No subscriptions yet.

) : ( {subscriptions.map((sub) => ( sub.clientId && router.push(`/clients/${sub.clientId}`)} > ))}
Client Plan Type Status Start Date MRC {sub.client ? (

{sub.client.firstName} {sub.client.lastName}

{sub.client.accountNumber}

) : ( )}
{sub.plan?.name ?? sub.planId ?? "—"} {sub.plan?.type ?? sub.type ?? "—"} {sub.status} {formatDate(sub.startDate)} {formatCurrency(sub.plan?.monthlyPrice ?? sub.monthlyRate ?? sub.mrc ?? 0)}
)}
); }