revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s
Local Build and Deploy / deploy (push) Successful in 1m11s
revert style: clean up code with prettier and eslint
This commit is contained in:
1 parent
27de078f54
commit
e85e4d74ea
378 files changed
+20710
-22428
No files matched your search
@@ -1,56 +1,62 @@
|
||||
"use client";
|
||||
'use client'
|
||||
|
||||
import { Plus, Trash2 } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { addEventPrize, deleteEventPrize } from "@/actions/events";
|
||||
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 { useServerAction } from "@/hooks/use-server-action";
|
||||
import { Plus, Trash2 } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { addEventPrize, deleteEventPrize } from '@/actions/events'
|
||||
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 { useServerAction } from '@/hooks/use-server-action'
|
||||
|
||||
interface Prize {
|
||||
id: number;
|
||||
position: number;
|
||||
prizeType: string;
|
||||
badgeCode: string | null;
|
||||
credits: number;
|
||||
pixels: number;
|
||||
points: number;
|
||||
itemId: number | null;
|
||||
description: string;
|
||||
id: number
|
||||
position: number
|
||||
prizeType: string
|
||||
badgeCode: string | null
|
||||
credits: number
|
||||
pixels: number
|
||||
points: number
|
||||
itemId: number | null
|
||||
description: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
eventId: number;
|
||||
prizes: Prize[];
|
||||
eventId: number
|
||||
prizes: Prize[]
|
||||
}
|
||||
|
||||
export function EventPrizesManager({ eventId, prizes }: Props) {
|
||||
const { run, isPending } = useServerAction();
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const { run, isPending } = useServerAction()
|
||||
const [showForm, setShowForm] = useState(false)
|
||||
const [form, setForm] = useState({
|
||||
position: prizes.length + 1,
|
||||
prizeType: "badge" as string,
|
||||
badgeCode: "",
|
||||
prizeType: 'badge' as string,
|
||||
badgeCode: '',
|
||||
credits: 0,
|
||||
pixels: 0,
|
||||
points: 0,
|
||||
description: "",
|
||||
});
|
||||
description: '',
|
||||
})
|
||||
|
||||
function handleAdd(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
e.preventDefault()
|
||||
// biome-ignore lint/suspicious/noExplicitAny: explicitly chosen here, see surrounding code
|
||||
run(() => addEventPrize({ eventId, ...form } as any), {
|
||||
successMessage: "Prize added!",
|
||||
successMessage: 'Prize added!',
|
||||
onSuccess: () => {
|
||||
setShowForm(false);
|
||||
setForm({ ...form, position: form.position + 1, badgeCode: "", description: "" });
|
||||
setShowForm(false)
|
||||
setForm({ ...form, position: form.position + 1, badgeCode: '', description: '' })
|
||||
},
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -75,7 +81,10 @@ export function EventPrizesManager({ eventId, prizes }: Props) {
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<Label>Type</Label>
|
||||
<Select value={form.prizeType} onValueChange={(v) => setForm({ ...form, prizeType: v })}>
|
||||
<Select
|
||||
value={form.prizeType}
|
||||
onValueChange={(v) => setForm({ ...form, prizeType: v })}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
@@ -124,11 +133,16 @@ export function EventPrizesManager({ eventId, prizes }: Props) {
|
||||
)}
|
||||
|
||||
{prizes.length === 0 && !showForm && (
|
||||
<p className="text-sm text-muted-foreground text-center py-4">No prizes configured yet.</p>
|
||||
<p className="text-sm text-muted-foreground text-center py-4">
|
||||
No prizes configured yet.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{prizes.map((prize) => (
|
||||
<div key={prize.id} className="flex items-center justify-between border rounded-lg px-4 py-3">
|
||||
<div
|
||||
key={prize.id}
|
||||
className="flex items-center justify-between border rounded-lg px-4 py-3"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="flex h-8 w-8 items-center justify-center rounded-full bg-accent font-bold text-sm">
|
||||
#{prize.position}
|
||||
@@ -141,14 +155,16 @@ export function EventPrizesManager({ eventId, prizes }: Props) {
|
||||
{prize.pixels > 0 && <span className="text-sm">{prize.pixels} pixels</span>}
|
||||
{prize.points > 0 && <span className="text-sm">{prize.points} points</span>}
|
||||
</div>
|
||||
{prize.description && <p className="text-xs text-muted-foreground">{prize.description}</p>}
|
||||
{prize.description && (
|
||||
<p className="text-xs text-muted-foreground">{prize.description}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() =>
|
||||
run(() => deleteEventPrize({ id: prize.id }), { successMessage: "Prize removed" })
|
||||
run(() => deleteEventPrize({ id: prize.id }), { successMessage: 'Prize removed' })
|
||||
}
|
||||
>
|
||||
<Trash2 className="h-4 w-4 text-destructive" />
|
||||
@@ -157,5 +173,5 @@ export function EventPrizesManager({ eventId, prizes }: Props) {
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user