'use client' import Link from 'next/link' import { useMemo, useState } from 'react' import { useApiFetch } from '@saaslib/nextjs' import { Badge } from '../../../components/ui/badge' import { Button } from '../../../components/ui/button' import { Input } from '../../../components/ui/input' import { Label } from '../../../components/ui/label' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../../../components/ui/table' type AdminUser = { id: string email: string name?: string subscriptions?: Record } type AdminUserListResponse = { items: AdminUser[] total: number page: number pages: number limit: number } export default function SubscriptionsPage() { const [search, setSearch] = useState('') const [page, setPage] = useState(1) const query = useMemo(() => { const params = new URLSearchParams() params.set('page', page.toString()) params.set('limit', '20') if (search) params.set('search', search) return params.toString() }, [page, search]) const { data, loading, error } = useApiFetch(`/admin/users/subscriptions?${query}`) const subscribedUsers = useMemo(() => { const items = data?.items ?? [] return items.filter((user) => user.subscriptions && Object.keys(user.subscriptions).length > 0) }, [data]) return (

Subscriptions

Find customers with active plans and manage upgrades.

{ setSearch(event.target.value) setPage(1) }} placeholder="Email or name" />
{error && (
{error.message}
)} User Plans Status {loading && ( Loading subscriptions… )} {!loading && subscribedUsers.length === 0 && ( No active subscriptions found. )} {subscribedUsers.map((user) => { const userId = (user as any).id ?? (user as any)._id ?? '' const planKeys = Object.keys(user.subscriptions ?? {}) const isCancelled = planKeys.some((key) => user.subscriptions?.[key]?.cancelled) return (
{user.name || user.email}
{user.email}
{planKeys.join(', ')} {isCancelled ? Cancel pending : Active} {userId ? ( ) : ( Missing id )}
) })}
Page {data?.page ?? page} of {data?.pages ?? 1} · {data?.total ?? 0} total
) }