revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s

revert style: clean up code with prettier and eslint
This commit is contained in:
remco committed 2026-07-12 21:02:03 +02:00
1 parent 27de078f54
commit e85e4d74ea
378 files changed
+20710 -22428

No files matched your search

+62 -46
View File
@@ -1,60 +1,66 @@
"use client";
'use client'
import { useForm } from "react-hook-form";
import { createEvent, updateEvent } from "@/actions/events";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { DateTimePicker } from "@/components/ui/date-time-picker";
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 { CreateEventInput } from "@/lib/validators/event";
import { useForm } from 'react-hook-form'
import { createEvent, updateEvent } from '@/actions/events'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { DateTimePicker } from '@/components/ui/date-time-picker'
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 { CreateEventInput } from '@/lib/validators/event'
interface EventType {
id: number;
name: string;
slug: string;
color: string;
id: number
name: string
slug: string
color: string
}
interface EventFormProps {
eventTypes: EventType[];
defaultValues?: Partial<CreateEventInput> & { id?: number };
eventTypes: EventType[]
defaultValues?: Partial<CreateEventInput> & { id?: number }
}
export function EventForm({ eventTypes, defaultValues }: EventFormProps) {
const { run, isPending } = useServerAction();
const isEditing = !!defaultValues?.id;
const { run, isPending } = useServerAction()
const isEditing = !!defaultValues?.id
const form = useForm({
defaultValues: {
title: "",
description: "",
title: '',
description: '',
typeId: eventTypes[0]?.id,
status: "draft",
status: 'draft',
isRecurring: 0,
...defaultValues,
},
});
})
// biome-ignore lint/suspicious/noExplicitAny: form values typed by useForm defaults; createEvent does its own zod validation
function onSubmit(data: any) {
if (isEditing && defaultValues?.id) {
run(() => updateEvent({ id: defaultValues.id!, ...data }), {
successMessage: "Event updated!",
});
successMessage: 'Event updated!',
})
} else {
run(() => createEvent(data), {
successMessage: "Event created!",
successMessage: 'Event created!',
onSuccess: (result) => {
const data = result.data as Record<string, unknown> | undefined;
const data = result.data as Record<string, unknown> | undefined
if (data?.id) {
window.location.href = `/admin/events/${data.id}`;
window.location.href = `/admin/events/${data.id}`
}
},
});
})
}
}
@@ -62,13 +68,13 @@ export function EventForm({ eventTypes, defaultValues }: EventFormProps) {
<form onSubmit={form.handleSubmit(onSubmit)}>
<Card>
<CardHeader>
<CardTitle>{isEditing ? "Edit Event" : "Event Details"}</CardTitle>
<CardTitle>{isEditing ? 'Edit Event' : 'Event Details'}</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="title">Title</Label>
<Input id="title" {...form.register("title")} />
<Input id="title" {...form.register('title')} />
{form.formState.errors.title && (
<p className="text-sm text-destructive">{form.formState.errors.title.message}</p>
)}
@@ -77,8 +83,8 @@ export function EventForm({ eventTypes, defaultValues }: EventFormProps) {
<div className="space-y-2">
<Label htmlFor="typeId">Event Type</Label>
<Select
value={String(form.watch("typeId"))}
onValueChange={(v) => form.setValue("typeId", Number(v))}
value={String(form.watch('typeId'))}
onValueChange={(v) => form.setValue('typeId', Number(v))}
>
<SelectTrigger>
<SelectValue placeholder="Select type" />
@@ -96,44 +102,54 @@ export function EventForm({ eventTypes, defaultValues }: EventFormProps) {
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea id="description" rows={4} {...form.register("description")} />
<Textarea id="description" rows={4} {...form.register('description')} />
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div className="space-y-2">
<Label>Starts At</Label>
<DateTimePicker
value={form.watch("startsAt")}
value={form.watch('startsAt')}
// biome-ignore lint/suspicious/noExplicitAny: form value type inferred loose; runtime validated by zod on submit
onChange={(d) => form.setValue("startsAt", d as any, { shouldDirty: true })}
onChange={(d) => form.setValue('startsAt', d as any, { shouldDirty: true })}
placeholder="Select start date"
/>
</div>
<div className="space-y-2">
<Label>Ends At</Label>
<DateTimePicker
value={form.watch("endsAt")}
value={form.watch('endsAt')}
// biome-ignore lint/suspicious/noExplicitAny: form value type inferred loose; runtime validated by zod on submit
onChange={(d) => form.setValue("endsAt", d as any, { shouldDirty: true })}
onChange={(d) => form.setValue('endsAt', d as any, { shouldDirty: true })}
placeholder="Select end date"
/>
</div>
<div className="space-y-2">
<Label htmlFor="maxPlayers">Max Players</Label>
<Input id="maxPlayers" type="number" {...form.register("maxPlayers")} placeholder="Unlimited" />
<Input
id="maxPlayers"
type="number"
{...form.register('maxPlayers')}
placeholder="Unlimited"
/>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="roomId">Room ID</Label>
<Input id="roomId" type="number" {...form.register("roomId")} placeholder="Optional" />
<Input
id="roomId"
type="number"
{...form.register('roomId')}
placeholder="Optional"
/>
</div>
<div className="space-y-2">
<Label htmlFor="status">Status</Label>
<Select
value={form.watch("status")}
onValueChange={(v) => form.setValue("status", v as CreateEventInput["status"])}
value={form.watch('status')}
onValueChange={(v) => form.setValue('status', v as CreateEventInput['status'])}
>
<SelectTrigger>
<SelectValue />
@@ -150,16 +166,16 @@ export function EventForm({ eventTypes, defaultValues }: EventFormProps) {
<div className="space-y-2">
<Label htmlFor="image">Image URL</Label>
<Input id="image" {...form.register("image")} placeholder="https://..." />
<Input id="image" {...form.register('image')} placeholder="https://..." />
</div>
<div className="flex justify-end">
<Button type="submit" disabled={isPending}>
{isPending ? "Saving..." : isEditing ? "Update Event" : "Create Event"}
{isPending ? 'Saving...' : isEditing ? 'Update Event' : 'Create Event'}
</Button>
</div>
</CardContent>
</Card>
</form>
);
)
}