Anzeige für lsitenplatz, sortierung nach Datum
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user