Initial commit: FL-Akademie LMS mit Docker, Admin, Portal und Dokumentation.
Made-with: Cursor
This commit is contained in:
34
components/restart-course-button.tsx
Normal file
34
components/restart-course-button.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export function RestartCourseButton({ courseId }: { courseId: string }) {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onClick() {
|
||||
if (
|
||||
!confirm(
|
||||
"Fortschritt und Zertifikat für diesen Kurs zurücksetzen? Du kannst danach von vorn beginnen.",
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
const res = await fetch("/api/portal/restart", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ courseId }),
|
||||
});
|
||||
setLoading(false);
|
||||
if (!res.ok) return;
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
return (
|
||||
<button type="button" className="btn btn-danger" disabled={loading} onClick={onClick}>
|
||||
{loading ? "…" : "Fortschritt zurücksetzen"}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user