feat: add update and delete functionality for courses, events, and species; enhance attendance tracking and category creation
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import { Trash2 } from 'lucide-react';
|
||||
|
||||
import { deleteEvent } from '@kit/event-management/actions/event-actions';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from '@kit/ui/alert-dialog';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { useActionWithToast } from '@kit/ui/use-action-with-toast';
|
||||
|
||||
interface Props {
|
||||
eventId: string;
|
||||
accountSlug: string;
|
||||
}
|
||||
|
||||
export function DeleteEventButton({ eventId, accountSlug }: Props) {
|
||||
const router = useRouter();
|
||||
|
||||
const { execute, isPending } = useActionWithToast(deleteEvent, {
|
||||
successMessage: 'Veranstaltung wurde abgesagt',
|
||||
errorMessage: 'Fehler beim Absagen',
|
||||
onSuccess: () => router.push(`/home/${accountSlug}/events`),
|
||||
});
|
||||
|
||||
return (
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="destructive" size="sm" disabled={isPending}>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
Absagen
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Veranstaltung absagen?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Die Veranstaltung wird auf den Status "Abgesagt" gesetzt.
|
||||
Diese Aktion kann rückgängig gemacht werden.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Abbrechen</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={() => execute({ eventId })}>
|
||||
Absagen
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { createEventManagementApi } from '@kit/event-management/api';
|
||||
import { CreateEventForm } from '@kit/event-management/components';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { AccountNotFound } from '~/components/account-not-found';
|
||||
import { CmsPageShell } from '~/components/cms-page-shell';
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{ account: string; eventId: string }>;
|
||||
}
|
||||
|
||||
export default async function EditEventPage({ params }: PageProps) {
|
||||
const { account, eventId } = await params;
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
const { data: acct } = await client
|
||||
.from('accounts')
|
||||
.select('id')
|
||||
.eq('slug', account)
|
||||
.single();
|
||||
|
||||
if (!acct) return <AccountNotFound />;
|
||||
|
||||
const api = createEventManagementApi(client);
|
||||
const event = await api.getEvent(eventId);
|
||||
if (!event) return <AccountNotFound />;
|
||||
|
||||
const e = event as Record<string, unknown>;
|
||||
|
||||
return (
|
||||
<CmsPageShell account={account} title={`${String(e.name)} — Bearbeiten`}>
|
||||
<CreateEventForm
|
||||
accountId={acct.id}
|
||||
account={account}
|
||||
eventId={eventId}
|
||||
initialData={{
|
||||
name: String(e.name ?? ''),
|
||||
description: String(e.description ?? ''),
|
||||
eventDate: String(e.event_date ?? ''),
|
||||
eventTime: String(e.event_time ?? ''),
|
||||
endDate: String(e.end_date ?? ''),
|
||||
location: String(e.location ?? ''),
|
||||
capacity: e.capacity != null ? Number(e.capacity) : undefined,
|
||||
minAge: e.min_age != null ? Number(e.min_age) : undefined,
|
||||
maxAge: e.max_age != null ? Number(e.max_age) : undefined,
|
||||
fee: Number(e.fee ?? 0),
|
||||
status: String(e.status ?? 'planned'),
|
||||
registrationDeadline: String(e.registration_deadline ?? ''),
|
||||
contactName: String(e.contact_name ?? ''),
|
||||
contactEmail: String(e.contact_email ?? ''),
|
||||
contactPhone: String(e.contact_phone ?? ''),
|
||||
}}
|
||||
/>
|
||||
</CmsPageShell>
|
||||
);
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
CalendarDays,
|
||||
MapPin,
|
||||
Users,
|
||||
Euro,
|
||||
Clock,
|
||||
Pencil,
|
||||
UserPlus,
|
||||
} from 'lucide-react';
|
||||
|
||||
@@ -17,7 +17,8 @@ import { Button } from '@kit/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card';
|
||||
|
||||
import { CmsPageShell } from '~/components/cms-page-shell';
|
||||
import { EmptyState } from '~/components/empty-state';
|
||||
|
||||
import { DeleteEventButton } from './delete-event-button';
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{ account: string; eventId: string }>;
|
||||
@@ -61,6 +62,17 @@ export default async function EventDetailPage({ params }: PageProps) {
|
||||
return (
|
||||
<CmsPageShell account={account} title={String(eventData.name)}>
|
||||
<div className="flex w-full flex-col gap-6">
|
||||
{/* Action Buttons */}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<Link href={`/home/${account}/events/${eventId}/edit`}>
|
||||
<Pencil className="mr-2 h-4 w-4" />
|
||||
Bearbeiten
|
||||
</Link>
|
||||
</Button>
|
||||
<DeleteEventButton eventId={eventId} accountSlug={account} />
|
||||
</div>
|
||||
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user