"use client"; import { Ban, ShieldOff } from "lucide-react"; import { useState } from "react"; import { banUser, unbanUser } from "@/actions/users"; 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, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Textarea } from "@/components/ui/textarea"; import { useServerAction } from "@/hooks/use-server-action"; interface BanInfo { id: number; reason: string; type: string; staffName: string; timestamp: number; banExpire: number; } interface UserBanSectionProps { userId: number; username: string; bans: BanInfo[]; } export function UserBanSection({ userId, username, bans, }: UserBanSectionProps) { const { isPending, run } = useServerAction(); const [showBanForm, setShowBanForm] = useState(false); const [reason, setReason] = useState(""); const [duration, setDuration] = useState("24"); const [banType, setBanType] = useState("account"); const activeBan = bans.find((b) => { const now = Math.floor(Date.now() / 1000); return b.banExpire === 0 || b.banExpire > now; }); function handleBan() { run( () => banUser({ userId, reason, duration: parseInt(duration, 10), type: banType as "account" | "ip" | "machine", }), { successMessage: `${username} has been banned.`, onSuccess: () => { setShowBanForm(false); setReason(""); }, }, ); } function handleUnban() { run(() => unbanUser({ userId }), { successMessage: `${username} has been unbanned.`, }); } return ( Bans
{activeBan ? ( ) : ( )}
{activeBan && (

Active Ban

{activeBan.reason}

By {activeBan.staffName} ·{" "} {activeBan.banExpire === 0 ? "Permanent" : `Expires ${new Date(activeBan.banExpire * 1000).toLocaleString()}`}

)} {showBanForm && !activeBan && (