style: clean up code with prettier and eslint

This commit is contained in:
openhands committed 2026-07-12 20:31:05 +02:00
1 parent 60278b9e71
commit fb8e77bb68
378 files changed
+22407 -20689

No files matched your search

+42 -61
View File
@@ -1,39 +1,33 @@
'use client'
"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'
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
}
id: number;
name: string;
description: string;
state: string;
usersMax: number;
users: number;
ownerName: string;
};
}
export function RoomEditForm({ room }: RoomEditFormProps) {
const { run, isPending } = useServerAction()
const { run, isPending } = useServerAction();
const {
register,
handleSubmit,
@@ -44,27 +38,27 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
defaultValues: {
name: room.name,
description: room.description,
state: room.state as 'open' | 'locked' | 'password' | 'invisible',
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.',
})
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' })
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') {
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 (
@@ -79,13 +73,13 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="name">Name</Label>
<Input id="name" {...register('name')} />
<Input id="name" {...register("name")} />
{errors.name && <p className="text-sm text-destructive">{errors.name.message}</p>}
</div>
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea id="description" rows={3} {...register('description')} />
<Textarea id="description" rows={3} {...register("description")} />
</div>
<div className="grid gap-4 sm:grid-cols-2">
@@ -94,7 +88,7 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
<Select
defaultValue={room.state}
onValueChange={(v) =>
setValue('state', v as 'open' | 'locked' | 'password' | 'invisible')
setValue("state", v as "open" | "locked" | "password" | "invisible")
}
>
<SelectTrigger>
@@ -110,11 +104,7 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
</div>
<div className="space-y-2">
<Label htmlFor="usersMax">Max Users</Label>
<Input
id="usersMax"
type="number"
{...register('usersMax', { valueAsNumber: true })}
/>
<Input id="usersMax" type="number" {...register("usersMax", { valueAsNumber: true })} />
</div>
</div>
@@ -127,12 +117,7 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
)}
Save Changes
</Button>
<Button
type="button"
variant="destructive"
onClick={handleDelete}
disabled={isPending}
>
<Button type="button" variant="destructive" onClick={handleDelete} disabled={isPending}>
<Trash2 className="mr-2 h-4 w-4" />
Delete Room
</Button>
@@ -161,11 +146,7 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
<span className="text-muted-foreground">State</span>
<Badge
variant={
room.state === 'open'
? 'default'
: room.state === 'locked'
? 'secondary'
: 'destructive'
room.state === "open" ? "default" : room.state === "locked" ? "secondary" : "destructive"
}
>
{room.state}
@@ -178,7 +159,7 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
<Button
variant="outline"
size="sm"
onClick={() => handleRconAction('kick')}
onClick={() => handleRconAction("kick")}
disabled={isPending}
>
<LogOut className="mr-2 h-4 w-4" />
@@ -187,7 +168,7 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
<Button
variant="outline"
size="sm"
onClick={() => handleRconAction('lock')}
onClick={() => handleRconAction("lock")}
disabled={isPending}
>
<Lock className="mr-2 h-4 w-4" />
@@ -196,7 +177,7 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
<Button
variant="outline"
size="sm"
onClick={() => handleRconAction('unlock')}
onClick={() => handleRconAction("unlock")}
disabled={isPending}
>
<Unlock className="mr-2 h-4 w-4" />
@@ -205,7 +186,7 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
<Button
variant="outline"
size="sm"
onClick={() => handleRconAction('reload')}
onClick={() => handleRconAction("reload")}
disabled={isPending}
>
<RefreshCw className="mr-2 h-4 w-4" />
@@ -217,5 +198,5 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
</Card>
</div>
</div>
)
);
}