'use client' import { useState, useEffect } from 'react' import { useParams, useRouter } from 'next/navigation' import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Badge } from '@/components/ui/badge' import Link from 'next/link' import { ArrowLeft, RefreshCw, Copy, Check } from 'lucide-react' export default function ClientSettingsPage() { const params = useParams() const router = useRouter() const [client, setClient] = useState(null) const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) const [copied, setCopied] = useState(false) const [error, setError] = useState('') const [success, setSuccess] = useState('') const [form, setForm] = useState({ name: '', semaphoreKey: '', senderName: '', isActive: true }) useEffect(() => { fetch(`/api/clients/${params.id}`) .then(r => r.json()) .then(data => { setClient(data) setForm({ name: data.name, semaphoreKey: data.semaphoreKey || '', senderName: data.senderName || 'NFC-HUB', isActive: data.isActive, }) setLoading(false) }) }, [params.id]) async function handleSave(e: React.FormEvent) { e.preventDefault() setSaving(true) setError('') setSuccess('') const res = await fetch(`/api/clients/${params.id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(form), }) if (res.ok) { setSuccess('Settings saved successfully') const updated = await res.json() setClient((prev: any) => ({ ...prev, ...updated })) } else { const data = await res.json() setError(data.error || 'Save failed') } setSaving(false) } async function copyApiKey() { await navigator.clipboard.writeText(client.apiKey) setCopied(true) setTimeout(() => setCopied(false), 2000) } if (loading) return
Loading...
if (!client) return
Client not found
return (

{client.name}

Client settings and API configuration

{/* API Key Card */} API Key Use this key in the X-API-Key header for SMS submissions.
{client.apiKey}
{/* Credit Balance */} {client.semaphoreKey && ( Semaphore Credits
{client.balance !== null ? client.balance.toLocaleString() : 'N/A'}

Available SMS credits

)} {/* Settings Form */} Settings
{error &&
{error}
} {success &&
{success}
}
setForm(f => ({ ...f, name: e.target.value }))} required />
setForm(f => ({ ...f, semaphoreKey: e.target.value }))} placeholder="Enter Semaphore API key" type="password" />
setForm(f => ({ ...f, senderName: e.target.value }))} maxLength={11} />
setForm(f => ({ ...f, isActive: e.target.checked }))} className="h-4 w-4" />
) }