"use client"; import { zodResolver } from "@hookform/resolvers/zod"; import { Loader2, Lock, LogOut, RefreshCw, Save, Trash2, Unlock } from "lucide-react"; import { useForm } from "react-hook-form"; import { deleteRoom, roomRconAction, updateRoom } from "@/actions/rooms"; 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"; import { type UpdateRoomInput, updateRoomSchema } from "@/lib/validators/room"; interface RoomEditFormProps { room: { id: number; name: string; description: string; state: string; usersMax: number; users: number; ownerName: string; }; } export function RoomEditForm({ room }: RoomEditFormProps) { const { run, isPending } = useServerAction(); const { register, handleSubmit, setValue, formState: { errors }, } = useForm({ resolver: zodResolver(updateRoomSchema), defaultValues: { name: room.name, description: room.description, state: room.state as "open" | "locked" | "password" | "invisible", usersMax: room.usersMax, }, }); function onSubmit(data: UpdateRoomInput) { run(() => updateRoom({ id: room.id, ...data }), { successMessage: "Room updated successfully.", }); } function handleDelete() { if (!confirm("Are you sure you want to delete this room? This cannot be undone.")) return; run(() => deleteRoom({ id: room.id }), { redirectTo: "/admin/rooms" }); } function handleRconAction(action: "kick" | "lock" | "unlock" | "reload") { run(() => roomRconAction({ roomId: room.id, action }), { successMessage: `Action "${action}" executed successfully.`, errorMessage: `Action "${action}" failed. Is the emulator running?`, }); } return (
{/* Edit Form */} Room Details
{errors.name &&

{errors.name.message}

}