fixed moodle logic
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"use client";
|
||||
import { useEffect } from "react";
|
||||
import { use, useEffect } from "react";
|
||||
import { CheckCircledIcon, CalendarIcon, EnterIcon } from "@radix-ui/react-icons";
|
||||
import { Event, EventAppointment, Participant, User } from "@repo/db";
|
||||
import { cn } from "../../../../helper/cn";
|
||||
@@ -87,6 +87,10 @@ const ModalBtn = ({
|
||||
? (selectedDate as any)?.Participants?.length + 1
|
||||
: ownIndexInParticipantList + 1;
|
||||
|
||||
const missingRequirements =
|
||||
event.requiredBadges?.length > 0 &&
|
||||
!event.requiredBadges.some((badge) => user.badges.includes(badge));
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
@@ -96,14 +100,20 @@ const ModalBtn = ({
|
||||
eventCompleted(event, participant) && "btn-success",
|
||||
)}
|
||||
onClick={openModal}
|
||||
disabled={eventCompleted(event, participant)}
|
||||
disabled={eventCompleted(event, participant) || missingRequirements}
|
||||
>
|
||||
{participant && !eventCompleted(event, participant) && (
|
||||
{missingRequirements && (
|
||||
<>
|
||||
<TriangleAlert className="h-6 w-6 shrink-0 stroke-current" fill="none" />
|
||||
fehlende Anforderungen
|
||||
</>
|
||||
)}
|
||||
{participant && !eventCompleted(event, participant) && !missingRequirements && (
|
||||
<>
|
||||
<EyeIcon /> Anzeigen
|
||||
</>
|
||||
)}
|
||||
{!participant && (
|
||||
{!participant && !missingRequirements && (
|
||||
<>
|
||||
<EnterIcon /> Anmelden
|
||||
</>
|
||||
@@ -287,16 +297,20 @@ const MoodleCourseIndicator = ({
|
||||
<button
|
||||
className="btn btn-xs btn-info ml-2"
|
||||
onClick={async () => {
|
||||
await upsertParticipant({
|
||||
eventId: event.id,
|
||||
userId: user.id,
|
||||
finisherMoodleCurseCompleted: false,
|
||||
});
|
||||
try {
|
||||
await upsertParticipant({
|
||||
eventId: event.id,
|
||||
userId: user.id,
|
||||
finisherMoodleCurseCompleted: false,
|
||||
});
|
||||
|
||||
if (user.moodleId) {
|
||||
await inscribeToMoodleCourse(moodleCourseId, user.moodleId);
|
||||
if (user.moodleId) {
|
||||
await inscribeToMoodleCourse(moodleCourseId, user.moodleId);
|
||||
}
|
||||
window.open(courseUrl, "_blank");
|
||||
} catch (error) {
|
||||
console.log("Fehler beim öffnen des Moodle-Kurses", error);
|
||||
}
|
||||
window.open(courseUrl, "_blank");
|
||||
}}
|
||||
>
|
||||
Zum Moodle Kurs
|
||||
|
||||
Reference in New Issue
Block a user