'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 { Card, CardContent, CardHeader, CardTitle } from '../../../components/ui/card' import { Input } from '../../../components/ui/input' import { Label } from '../../../components/ui/label' import { Select } from '../../../components/ui/select' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../../../components/ui/table' type AdminUser = { id: string email: string name?: string role?: string blocked?: boolean subscriptions?: Record } type AdminUserListResponse = { items: AdminUser[] subscriptionTypes?: string[] total: number page: number pages: number limit: number } export default function UsersPage() { const [search, setSearch] = useState('') const [role, setRole] = useState('') const [blocked, setBlocked] = useState('all') 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) if (role) params.set('role', role) if (blocked !== 'all') params.set('blocked', blocked) return params.toString() }, [search, role, blocked, page]) const { data, loading, error } = useApiFetch(`/admin/users?${query}`) return (

Users

Review accounts, roles, and subscription state.

Filters
{ setSearch(event.target.value) setPage(1) }} placeholder="Email or name" />
{error && (
{error.message}
)} User Role Subscriptions Status {loading && ( Loading users… )} {!loading && data?.items?.length === 0 && ( No users found. )} {data?.items?.map((user) => { const userId = (user as any).id ?? (user as any)._id ?? '' const subscriptionKeys = Object.keys(user.subscriptions ?? {}) return (
{user.name || user.email}
{user.email}
{user.role === 'admin' ? Admin : User} {subscriptionKeys.length > 0 ? ( {subscriptionKeys.join(', ')} ) : ( 'None' )} {user.blocked ? ( Blocked ) : ( Active )} {userId ? ( ) : ( Missing id )}
) })}
Page {data?.page ?? page} of {data?.pages ?? 1}
) }