Anzeige für lsitenplatz, sortierung nach Datum

This commit is contained in:
PxlLoewe
2025-03-11 00:25:42 -07:00
parent 92dff8f3c9
commit 07310907f1
6 changed files with 129 additions and 27 deletions

View File

@@ -26,6 +26,7 @@ import { Select } from "../../../_components/ui/Select";
import toast from "react-hot-toast";
import { useRouter } from "next/navigation";
import { eventCompleted } from "@repo/ui";
import { se } from "date-fns/locale";
interface ModalBtnProps {
title: string;
@@ -93,6 +94,23 @@ const ModalBtn = ({
date.id === selectAppointmentForm.watch("eventAppointmentId") ||
selectedAppointment?.id,
);
const ownIndexInParticipantList =
(selectedDate as any)?.Participants?.findIndex(
(p: Participant) => p.userId === user.id,
) || (selectedDate as any)?.Participants?.length + 1;
const ownPlaceInParticipantList =
ownIndexInParticipantList === -1
? (selectedDate as any)?.Participants?.length + 1
: ownIndexInParticipantList + 1;
console.log(
selectedDate,
ownPlaceInParticipantList > event.maxParticipants!,
ownPlaceInParticipantList,
event.maxParticipants,
);
return (
<>
<button
@@ -156,10 +174,10 @@ const ModalBtn = ({
Du hast an dem Presenztermin teilgenommen
</p>
)}
{selectedDate &&
event.maxParticipants !== null &&
(selectedDate as any)._count.Participants >=
event.maxParticipants && (
{!!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"
@@ -169,7 +187,8 @@ const ModalBtn = ({
fill="none"
/>
Dieser Termin ist ausgebucht, wahrscheinlich wirst du nicht
teilnehmen können
teilnehmen können. (Listenplatz: {ownPlaceInParticipantList}{" "}
, max. {event.maxParticipants})
</p>
)}
{selectedAppointment && !participant?.appointmentCancelled && (
@@ -237,13 +256,12 @@ const ModalBtn = ({
event.type === "OBLIGATED_COURSE" && "btn-secondary",
)}
onClick={async () => {
console.log("submit", selectAppointmentForm.formState.errors);
const data = selectAppointmentForm.getValues();
if (!data.eventAppointmentId) return;
console.log("submit", data);
await upsertParticipant({
...data,
enscriptionDate: new Date(),
statusLog: data.statusLog?.filter((log) => log !== null),
appointmentCancelled: false,
});

View File

@@ -38,8 +38,13 @@ export default async () => {
},
include: {
Participants: {
where: {
userId: user.id,
select: {
enscriptionDate: true,
id: true,
userId: true,
},
orderBy: {
enscriptionDate: "asc",
},
},
_count: {