'use client'; import AdminShell from '@/components/AdminShell'; import { api } from '@/lib/api'; import { statusColor, formatDateTime } from '@/lib/utils'; import { useEffect, useState } from 'react'; import { useParams, useRouter } from 'next/navigation'; import { ArrowLeft, Shield, Ban, CheckCircle, XCircle, Star, RotateCcw } from 'lucide-react'; import Link from 'next/link'; export default function UserDetailPage() { const params = useParams(); const router = useRouter(); const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); const [actionLoading, setActionLoading] = useState(false); const [showModal, setShowModal] = useState(null); const [reason, setReason] = useState(''); const fetchUser = () => { setLoading(true); api.getUser(params.id as string) .then(setUser) .catch(() => router.push('/users')) .finally(() => setLoading(false)); }; useEffect(() => { fetchUser(); }, [params.id]); const handleStatusChange = async (status: string) => { if (!reason.trim()) return; setActionLoading(true); try { await api.updateUserStatus(params.id as string, status, reason); setShowModal(null); setReason(''); fetchUser(); } catch (e: any) { alert(`Status change failed: ${e.message}`); } setActionLoading(false); }; const handleRoleChange = async (role: string) => { setActionLoading(true); try { await api.updateUserRole(params.id as string, role); fetchUser(); } catch (e: any) { alert(`Role change failed: ${e.message}`); } setActionLoading(false); }; const handleVerification = async (isOfficial: boolean, isVerified: boolean) => { setActionLoading(true); try { await api.updateUserVerification(params.id as string, isOfficial, isVerified); fetchUser(); } catch (e: any) { alert(`Verification update failed: ${e.message}`); } setActionLoading(false); }; const handleResetStrikes = async () => { setActionLoading(true); try { await api.resetUserStrikes(params.id as string); fetchUser(); } catch (e: any) { alert(`Reset strikes failed: ${e.message}`); } setActionLoading(false); }; return ( Back to Users {loading ? (
) : user ? (
{/* Header */}
{(user.handle || user.email || '?')[0].toUpperCase()}

{user.display_name || user.handle || '—'}

@{user.handle || '—'} · {user.email}

{user.status} {user.role || 'user'} {user.is_official && Official} {user.is_verified && Verified} {user.is_private && Private}
{/* Stats Grid */}
{[ { label: 'Followers', value: user.follower_count }, { label: 'Following', value: user.following_count }, { label: 'Posts', value: user.post_count }, { label: 'Strikes', value: user.strikes }, { label: 'Violations', value: user.violation_count }, { label: 'Reports', value: user.report_count }, ].map((s) => (

{s.value ?? 0}

{s.label}

))}
{/* Details */}

Profile Details

{[ ['Bio', user.bio], ['Location', user.location], ['Website', user.website], ['Country', user.origin_country], ['Beacon Enabled', user.beacon_enabled ? 'Yes' : 'No'], ['Onboarding Complete', user.has_completed_onboarding ? 'Yes' : 'No'], ['Joined', user.created_at ? formatDateTime(user.created_at) : '—'], ['Last Login', user.last_login ? formatDateTime(user.last_login) : 'Never'], ].map(([label, value]) => (
{label}
{value || '—'}
))}
{/* Actions */}

Admin Actions

{/* Status changes */}

Account Status

{user.status !== 'active' && ( )} {user.status !== 'suspended' && ( )} {user.status !== 'banned' && ( )}
{/* Role */}

Role

{/* Verification */}

Verification

{/* Reset Strikes */} {(user.strikes ?? 0) > 0 && (

Strikes

)} {/* View Posts */}
View User's Posts →
) : (
User not found
)} {/* Status Change Modal */} {showModal && (
setShowModal(null)}>
e.stopPropagation()}>

{showModal === 'active' ? 'Activate' : showModal === 'suspended' ? 'Suspend' : 'Ban'} User

Please provide a reason for this action.