Finalized Event modal

This commit is contained in:
PxlLoewe
2025-07-02 22:32:30 -07:00
parent 363aad803d
commit fc8d81d2d1
9 changed files with 172 additions and 153 deletions

View File

@@ -81,6 +81,7 @@ router.put("/", async (req, res) => {
router.patch("/:id", async (req, res) => { router.patch("/:id", async (req, res) => {
const { id } = req.params; const { id } = req.params;
try { try {
console.log("Updating mission with ID:", id, req.body);
const updatedMission = await prisma.mission.update({ const updatedMission = await prisma.mission.update({
where: { id: Number(id) }, where: { id: Number(id) },
data: req.body, data: req.body,

View File

@@ -1,6 +1,6 @@
import { getServerSession } from "../../api/auth/[...nextauth]/auth"; import { getServerSession } from "../../api/auth/[...nextauth]/auth";
import { prisma } from "@repo/db"; import { prisma } from "@repo/db";
import { EventCard } from "../events/_components/item"; import { EventCard } from "../events/_components/EventCard";
import { RocketIcon } from "lucide-react"; import { RocketIcon } from "lucide-react";
import { eventCompleted } from "@repo/shared-components"; import { eventCompleted } from "@repo/shared-components";

View File

@@ -6,7 +6,7 @@ import { useSession } from "next-auth/react";
import { useRef, useEffect, useState } from "react"; import { useRef, useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { getEvents } from "../../../helper/events"; import { getEvents } from "../../../helper/events";
import { EventCard } from "(app)/events/_components/item"; import { EventCard } from "(app)/events/_components/EventCard";
const PathsOptions = ({ const PathsOptions = ({
selected, selected,

View File

@@ -9,7 +9,7 @@ export const StatsToggle = () => {
const session = useSession(); const session = useSession();
const router = useRouter(); const router = useRouter();
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const user = session.data?.user;
useEffect(() => { useEffect(() => {
const statsPage = searchParams.get("stats") || "pilot"; const statsPage = searchParams.get("stats") || "pilot";
if (statsPage === "dispo") { if (statsPage === "dispo") {
@@ -30,11 +30,7 @@ export const StatsToggle = () => {
return ( return (
<header className="flex justify-between items-center pb-4"> <header className="flex justify-between items-center pb-4">
<h1 className="text-2xl font-bold"> <h1 className="text-2xl font-bold">
Hallo,{" "} Hallo, {user?.firstname} <span className="text-gray-500">{" #" + user?.publicId}</span>!
{session.status === "authenticated"
? session.data?.user.firstname + " <" + session.data?.user.publicId + ">"
: "<username>"}
{"!"}
</h1> </h1>
<div> <div>
<div className="tooltip tooltip-left" data-tip="Disponent / Pilot"> <div className="tooltip tooltip-left" data-tip="Disponent / Pilot">

View File

@@ -35,7 +35,7 @@ export const AppointmentModal = ({
return ( return (
<dialog ref={ref} className="modal "> <dialog ref={ref} className="modal ">
<div className="modal-box min-w-[900px]"> <div className="modal-box min-w-[900px] min-h-[500px]">
<form method="dialog"> <form method="dialog">
{/* if there is a button in form, it will close the modal */} {/* if there is a button in form, it will close the modal */}
<button <button

View File

@@ -155,27 +155,6 @@ export const Form = ({ event }: { event?: Event }) => {
{form.watch("hasPresenceEvents") ? ( {form.watch("hasPresenceEvents") ? (
<div className="card bg-base-200 shadow-xl col-span-6"> <div className="card bg-base-200 shadow-xl col-span-6">
<div className="card-body"> <div className="card-body">
<div className="flex justify-between">
<h2 className="card-title">
<Calendar className="w-5 h-5" /> Termine
</h2>
{event && (
<button
className="btn btn-primary btn-outline"
onClick={() => {
appointmentModal.current?.showModal();
appointmentForm.reset({
id: undefined,
eventId: event.id,
presenterId: session?.user?.id,
});
}}
>
Hinzufügen
</button>
)}
</div>
<PaginatedTable <PaginatedTable
ref={appointmentsTableRef} ref={appointmentsTableRef}
prismaModel={"eventAppointment"} prismaModel={"eventAppointment"}
@@ -186,6 +165,28 @@ export const Form = ({ event }: { event?: Event }) => {
Presenter: true, Presenter: true,
Participants: true, Participants: true,
}} }}
leftOfSearch={
<h2 className="card-title">
<Calendar className="w-5 h-5" /> Termine
</h2>
}
rightOfSearch={
event && (
<button
className="btn btn-primary btn-outline"
onClick={() => {
appointmentModal.current?.showModal();
appointmentForm.reset({
id: undefined,
eventId: event.id,
presenterId: session?.user?.id,
});
}}
>
Hinzufügen
</button>
)
}
columns={ columns={
[ [
{ {

View File

@@ -1,7 +1,7 @@
"use client"; "use client";
import { DrawingPinFilledIcon } from "@radix-ui/react-icons"; import { DrawingPinFilledIcon } from "@radix-ui/react-icons";
import { Event, Participant, EventAppointment, User } from "@repo/db"; import { Event, Participant, EventAppointment, User } from "@repo/db";
import ModalBtn from "./modalBtn"; import ModalBtn from "./Modal";
import MDEditor from "@uiw/react-md-editor"; import MDEditor from "@uiw/react-md-editor";
import { Badge } from "@repo/shared-components"; import { Badge } from "@repo/shared-components";

View File

@@ -4,7 +4,17 @@ import { CheckCircledIcon, EnterIcon, DrawingPinFilledIcon } from "@radix-ui/rea
import { Event, EventAppointment, Participant, User } from "@repo/db"; import { Event, EventAppointment, Participant, User } from "@repo/db";
import { cn } from "@repo/shared-components"; import { cn } from "@repo/shared-components";
import { inscribeToMoodleCourse, upsertParticipant } from "../actions"; import { inscribeToMoodleCourse, upsertParticipant } from "../actions";
import { Check, Clock10Icon, ExternalLink, EyeIcon, TriangleAlert } from "lucide-react"; import {
BookCheck,
Calendar,
Check,
CirclePlay,
Clock10Icon,
ExternalLink,
EyeIcon,
Info,
TriangleAlert,
} from "lucide-react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { ParticipantOptionalDefaults, ParticipantOptionalDefaultsSchema } from "@repo/db/zod"; import { ParticipantOptionalDefaults, ParticipantOptionalDefaultsSchema } from "@repo/db/zod";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
@@ -15,6 +25,7 @@ import { eventCompleted } from "@repo/shared-components";
import MDEditor from "@uiw/react-md-editor"; import MDEditor from "@uiw/react-md-editor";
import { DayPicker } from "react-day-picker"; import { DayPicker } from "react-day-picker";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import { se } from "date-fns/locale";
interface ModalBtnProps { interface ModalBtnProps {
title: string; title: string;
@@ -131,8 +142,11 @@ const ModalBtn = ({
<button className="btn btn-sm btn-circle btn-ghost absolute right-3 top-3"></button> <button className="btn btn-sm btn-circle btn-ghost absolute right-3 top-3"></button>
</form> </form>
<h3 className="font-bold text-lg text-left">{title}</h3> <h3 className="font-bold text-lg text-left">{title}</h3>
<div className="grid grid-cols-6 gap-4 mt-4"> <div className="flex flex-wrap gap-4 mt-4">
<div className="col-span-4"> <div className="flex flex-col gap-2 flex-1 p-3 bg-base-300 min-w-[300px] shadow rounded-lg">
<h2 className="flex gap-2 text-lg font-bold">
<Info /> Details
</h2>
<div className="text-left text-balance"> <div className="text-left text-balance">
<MDEditor.Markdown <MDEditor.Markdown
source={event.description} source={event.description}
@@ -144,102 +158,98 @@ const ModalBtn = ({
</div> </div>
</div> </div>
{event.hasPresenceEvents && ( {event.hasPresenceEvents && (
<div className="flex col-span-2 justify-end"> <div className="flex flex-col gap-2 flex-1 p-3 bg-base-300 min-w-[300px] shadow rounded-lg">
{canSelectDate && ( <h2 className="flex gap-2 text-lg font-bold">
<div className="flex flex-col items-center justify-center gap-2"> <Calendar /> Termine
{!!dates.length && ( </h2>
<> <div className="flex flex-1 flex-col justify-center items-center">
<p className="text-center text-info">Melde dich zu einem Termin an</p> {!!dates.length && !selectedDate && (
<Select <>
form={selectAppointmentForm} <p className="text-center text-info">Melde dich zu einem Termin an</p>
options={dates.map((date) => ({ <Select
label: `${new Date(date.appointmentDate).toLocaleString("de-DE", { form={selectAppointmentForm}
year: "numeric", options={dates.map((date) => ({
month: "2-digit", label: `${new Date(date.appointmentDate).toLocaleString("de-DE", {
day: "2-digit", year: "numeric",
hour: "2-digit", month: "2-digit",
minute: "2-digit", day: "2-digit",
})} - (${(date as any).Participants.length}/${event.maxParticipants})`, hour: "2-digit",
value: date.id, minute: "2-digit",
}))} })} - (${(date as any).Participants.length}/${event.maxParticipants})`,
name="eventAppointmentId" value: date.id,
label={""} }))}
placeholder="Wähle einen Termin" name="eventAppointmentId"
className="min-w-[250px]" label={""}
/> placeholder="Wähle einen Termin"
</> className="min-w-[250px]"
)} />
{!dates.length && ( </>
<p className="text-center text-error">Aktuell sind keine Termine verfügbar</p>
)}
</div>
)}
{!canSelectDate && participant?.attended && (
<p className="py-4 flex items-center gap-2 justify-center">
<CheckCircledIcon className="text-success" />
Du hast an dem Presenztermin teilgenommen
</p>
)}
{!!selectedDate &&
!!event.maxParticipants &&
!!ownPlaceInParticipantList &&
!!(ownPlaceInParticipantList > event.maxParticipants) && (
<p
role="alert"
className="py-4 my-5 flex items-center gap-2 justify-center border alert alert-error alert-outline"
>
<TriangleAlert className="h-6 w-6 shrink-0 stroke-current" fill="none" />
Dieser Termin ist ausgebucht, wahrscheinlich wirst du nicht teilnehmen können.
(Listenplatz: {ownPlaceInParticipantList} , max. {event.maxParticipants})
</p>
)} )}
{selectedAppointment && !participant?.appointmentCancelled && ( {selectedAppointment && !participant?.appointmentCancelled && (
<div className="flex flex-col items-center justify-center gap-2"> <div className="flex flex-col items-center justify-center gap-2">
<span>Dein ausgewählter Termin (Deutsche Zeit)</span> <span>Dein ausgewählter Termin (Deutsche Zeit)</span>
<div> <div>
<button <button
popoverTarget="rdp-popover" className="input input-border min-w-[250px] pointer-events-none"
className="input input-border min-w-[250px]" style={{ anchorName: "--rdp" } as React.CSSProperties}
style={{ anchorName: "--rdp" } as React.CSSProperties} >
> {new Date(selectedAppointment.appointmentDate).toLocaleString("de-DE", {
{selectedAppointment.appointmentDate year: "numeric",
? new Date(selectedAppointment.appointmentDate).toLocaleString("de-DE", { month: "2-digit",
year: "numeric", day: "2-digit",
month: "2-digit", hour: "2-digit",
day: "2-digit", minute: "2-digit",
hour: "2-digit", })}
minute: "2-digit", </button>
})
: "Keinen Termin ausgewählt"}
</button>
<div
popover="auto"
id="rdp-popover"
className="dropdown"
style={{ positionAnchor: "--rdp" } as React.CSSProperties}
>
<DayPicker
className="react-day-picker"
mode="single"
selected={selectedAppointment.appointmentDate}
disabled
/>
</div> </div>
{participant?.attended ? (
<p className="py-4 flex items-center gap-2 justify-center">
<CheckCircledIcon className="text-success" />
Du hast an dem Presenztermin teilgenommen
</p>
) : (
<p className="py-4 flex items-center gap-2 justify-center">
Bitte erscheine ~5 minuten vor dem Termin im Discord
</p>
)}
</div> </div>
<span>Bitte erscheine pünktlich im Discord.</span> )}
</div>
)} {!dates.length && (
<p className="text-center text-error">Aktuell sind keine Termine verfügbar</p>
)}
{!!selectedDate &&
!!event.maxParticipants &&
!!ownPlaceInParticipantList &&
!!(ownPlaceInParticipantList > event.maxParticipants) && (
<p
role="alert"
className="py-4 my-5 flex items-center gap-2 justify-center border alert alert-error alert-outline"
>
<TriangleAlert className="h-6 w-6 shrink-0 stroke-current" fill="none" />
Dieser Termin ist ausgebucht, wahrscheinlich wirst du nicht teilnehmen
können. (Listenplatz: {ownPlaceInParticipantList} , max.{" "}
{event.maxParticipants})
</p>
)}
</div>
</div> </div>
)} )}
{event.finisherMoodleCourseId && ( {event.finisherMoodleCourseId && (
<div className="flex col-span-2 justify-end"> <div className="flex flex-col gap-2 flex-1 p-3 bg-base-300 min-w-[300px] shadow rounded-lg">
<MoodleCourseIndicator <h2 className="flex gap-2 text-lg font-bold">
participant={participant} <BookCheck /> Moodle-Kurs
user={user} </h2>
moodleCourseId={event.finisherMoodleCourseId} <div className="flex flex-col items-center justify-center h-full">
completed={participant?.finisherMoodleCurseCompleted || false} <MoodleCourseIndicator
event={event} participant={participant}
/> user={user}
moodleCourseId={event.finisherMoodleCourseId}
completed={participant?.finisherMoodleCurseCompleted || false}
event={event}
/>
</div>
</div> </div>
)} )}
</div> </div>
@@ -278,34 +288,36 @@ const ModalBtn = ({
<EnterIcon /> Anmelden <EnterIcon /> Anmelden
</button> </button>
)} )}
{selectedAppointment && !participant?.appointmentCancelled && ( {selectedAppointment &&
<button !participant?.appointmentCancelled &&
onClick={async () => { !participant?.attended && (
await upsertParticipant({ <button
eventId: event.id, onClick={async () => {
userId: participant!.userId, await upsertParticipant({
appointmentCancelled: true, eventId: event.id,
statusLog: [ userId: participant!.userId,
...(participant?.statusLog as any), appointmentCancelled: true,
{ statusLog: [
data: { ...(participant?.statusLog as any),
appointmentId: selectedAppointment.id, {
appointmentDate: selectedAppointment.appointmentDate, data: {
appointmentId: selectedAppointment.id,
appointmentDate: selectedAppointment.appointmentDate,
},
user: `${user?.firstname} ${user?.lastname} - ${user?.publicId}`,
event: "Termin abgesagt",
timestamp: new Date(),
}, },
user: `${user?.firstname} ${user?.lastname} - ${user?.publicId}`, ],
event: "Termin abgesagt", });
timestamp: new Date(), toast.success("Termin abgesagt");
}, router.refresh();
], }}
}); className="btn btn-error btn-outline btn-wide"
toast.success("Termin abgesagt"); >
router.refresh(); Termin Absagen
}} </button>
className="btn btn-error btn-outline btn-wide" )}
>
Termin Absagen
</button>
)}
</div> </div>
</div> </div>
</div> </div>
@@ -349,7 +361,9 @@ const MoodleCourseIndicator = ({
); );
return ( return (
<div className="flex flex-col items-center justify-center gap-2"> <div className="flex flex-col items-center justify-center gap-2">
<p>Moodle-Kurs Benötigt</p> <p className="text-sm flex items-center gap-2">
<CirclePlay className="text-warning" /> Moodle-Kurs bereit
</p>
<button <button
className="btn btn-sm btn-outline btn-info ml-2" className="btn btn-sm btn-outline btn-info ml-2"
onClick={async () => { onClick={async () => {
@@ -372,6 +386,10 @@ const MoodleCourseIndicator = ({
<ExternalLink size={16} /> <ExternalLink size={16} />
Zum Moodle Kurs Zum Moodle Kurs
</button> </button>
<p className="text-xs text-gray-400">
Wenn du nach dem Anmelden den moodle Kurs nicht siehst, warte ein paar Sekunden und lade die
Seite neu.
</p>
</div> </div>
); );
}; };

View File

@@ -1,6 +1,6 @@
import { prisma } from "@repo/db"; import { prisma } from "@repo/db";
import { getServerSession } from "../../api/auth/[...nextauth]/auth"; import { getServerSession } from "../../api/auth/[...nextauth]/auth";
import { EventCard } from "./_components/item"; import { EventCard } from "./_components/EventCard";
import { RocketIcon } from "@radix-ui/react-icons"; import { RocketIcon } from "@radix-ui/react-icons";
const page = async () => { const page = async () => {
@@ -38,6 +38,9 @@ const page = async () => {
id: true, id: true,
userId: true, userId: true,
}, },
where: {
appointmentCancelled: false,
},
orderBy: { orderBy: {
enscriptionDate: "asc", enscriptionDate: "asc",
}, },