'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, Pencil, UserPlus, UserMinus, Users, Save, X, RefreshCcw } 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 [customReason, setCustomReason] = useState(false); const reasonPresets: Record = { banned: [ 'Hate speech or slurs', 'Harassment or bullying', 'Spam or scam activity', 'Posting illegal content', 'Impersonation', 'Repeated violations after warnings', 'Ban evasion (alt account)', ], suspended: [ 'Posting inappropriate content', 'Minor harassment', 'Spam behavior', 'Violating community guidelines', 'Cooling-off period after heated exchange', ], active: [ 'Appeal reviewed and approved', 'Ban was issued in error', 'Suspension period served', 'User agreed to follow guidelines', ], }; 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); }; const handleResetFeedImpressions = async () => { if (!confirm('Reset this user\'s feed impression history? They will see previously-seen posts again.')) return; setActionLoading(true); try { const result = await api.resetFeedImpressions(params.id as string); alert(`Feed impressions reset. ${result.deleted ?? 0} records cleared.`); } catch (e: any) { alert(`Reset 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

)} {/* Feed Impressions */}

Feed History

{/* View Posts */}
View User's Posts →
{/* Editable Profile */} {/* Follower/Following Management */}
) : (
User not found
)} {/* Status Change Modal */} {showModal && (
{ setShowModal(null); setReason(''); setCustomReason(false); }}>
e.stopPropagation()}>

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

Select a reason for this action.

{(reasonPresets[showModal] || []).map((preset) => ( ))}
{customReason && (