Files
myeasycms-v2/apps/web/app/[locale]/home/[account]/courses/[courseId]/delete-course-button.tsx
T. Zehetbauer c6b2824da8
Some checks failed
Workflow / ʦ TypeScript (push) Failing after 4m53s
Workflow / ⚫️ Test (push) Has been skipped
feat: add update and delete functionality for courses, events, and species; enhance attendance tracking and category creation
2026-04-01 16:03:50 +02:00

62 lines
1.8 KiB
TypeScript

'use client';
import { useRouter } from 'next/navigation';
import { Trash2 } from 'lucide-react';
import { deleteCourse } from '@kit/course-management/actions/course-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 {
courseId: string;
accountSlug: string;
}
export function DeleteCourseButton({ courseId, accountSlug }: Props) {
const router = useRouter();
const { execute, isPending } = useActionWithToast(deleteCourse, {
successMessage: 'Kurs wurde abgesagt',
errorMessage: 'Fehler beim Absagen',
onSuccess: () => router.push(`/home/${accountSlug}/courses`),
});
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="destructive" size="sm" disabled={isPending}>
<Trash2 className="mr-2 h-4 w-4" />
Kurs absagen
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Kurs absagen?</AlertDialogTitle>
<AlertDialogDescription>
Der Kurs wird auf den Status &quot;Abgesagt&quot; gesetzt. Diese
Aktion kann rückgängig gemacht werden.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Abbrechen</AlertDialogCancel>
<AlertDialogAction onClick={() => execute({ courseId })}>
Absagen
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}