Anzeige für lsitenplatz, sortierung nach Datum
This commit is contained in:
@@ -46,7 +46,7 @@ export const AppointmentModal = ({
|
||||
|
||||
return (
|
||||
<dialog ref={ref} className="modal ">
|
||||
<div className="modal-box">
|
||||
<div className="modal-box min-w-[900px]">
|
||||
<form method="dialog">
|
||||
{/* if there is a button in form, it will close the modal */}
|
||||
<button
|
||||
@@ -99,10 +99,40 @@ export const AppointmentModal = ({
|
||||
header: "Nachname",
|
||||
},
|
||||
{
|
||||
header: "Aktion",
|
||||
accessorKey: "enscriptionDate",
|
||||
header: "Einschreibedatum",
|
||||
cell: ({ row }: CellContext<Participant, any>) => {
|
||||
return (
|
||||
<>
|
||||
<span>
|
||||
{new Date(
|
||||
row.original.enscriptionDate,
|
||||
).toLocaleString()}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Anwesend",
|
||||
cell: ({ row }: CellContext<Participant, any>) => {
|
||||
if (row.original.attended) {
|
||||
return <span className="text-green-500">Ja</span>;
|
||||
} else if (row.original.appointmentCancelled) {
|
||||
return (
|
||||
<span className="text-red-500">
|
||||
Nein (Termin abgesagt)
|
||||
</span>
|
||||
);
|
||||
} else {
|
||||
return <span>Abwarten</span>;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Aktion",
|
||||
|
||||
cell: ({ row }: CellContext<Participant, any>) => {
|
||||
return (
|
||||
<div className="space-x-2">
|
||||
<button
|
||||
onClick={() => {
|
||||
participantForm.reset(row.original);
|
||||
@@ -121,6 +151,7 @@ export const AppointmentModal = ({
|
||||
eventId: event!.id,
|
||||
userId: participantForm.watch("userId"),
|
||||
attended: true,
|
||||
appointmentCancelled: false,
|
||||
});
|
||||
participantTableRef.current?.refresh();
|
||||
}}
|
||||
@@ -129,7 +160,33 @@ export const AppointmentModal = ({
|
||||
Anwesend
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
{!row.original.attended && event?.hasPresenceEvents && (
|
||||
<button
|
||||
type="button"
|
||||
onSubmit={() => {}}
|
||||
onClick={async () => {
|
||||
await upsertParticipant({
|
||||
eventId: event!.id,
|
||||
userId: participantForm.watch("userId"),
|
||||
attended: false,
|
||||
appointmentCancelled: true,
|
||||
statusLog: [
|
||||
...(row.original.statusLog as any),
|
||||
{
|
||||
event: "Gefehlt",
|
||||
timestamp: new Date().toISOString(),
|
||||
user: `${session?.user?.firstname} (${session?.user?.lastname} - ${session?.user?.publicId})`,
|
||||
},
|
||||
],
|
||||
});
|
||||
participantTableRef.current?.refresh();
|
||||
}}
|
||||
className="btn btn-outline btn-error btn-sm"
|
||||
>
|
||||
nicht da
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
@@ -35,6 +35,11 @@ export const ParticipantModal = ({
|
||||
})}
|
||||
className="space-y-1"
|
||||
>
|
||||
<Switch
|
||||
form={participantForm}
|
||||
name="attended"
|
||||
label="Termin Teilgenommen"
|
||||
/>
|
||||
<Switch
|
||||
form={participantForm}
|
||||
name="appointmentCancelled"
|
||||
@@ -50,6 +55,18 @@ export const ParticipantModal = ({
|
||||
name="completetionWorkflowFinished"
|
||||
label="Abgeschlossen (E-Mail-Benachrichtigung senden)"
|
||||
/>
|
||||
<div className="w-full">
|
||||
<h3 className="text-xl">Termine</h3>
|
||||
|
||||
<p className="w-full flex justify-between">
|
||||
<span>Termin ausgewählt</span>
|
||||
<span>
|
||||
{new Date(
|
||||
participantForm.watch("enscriptionDate"),
|
||||
).toLocaleString()}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<h3 className="text-xl">Verlauf</h3>
|
||||
{participantForm.watch("statusLog")?.map((s) => (
|
||||
@@ -59,9 +76,12 @@ export const ParticipantModal = ({
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Button type="submit">Speichern</Button>
|
||||
<Button type="submit" className="btn btn-primary">
|
||||
Speichern
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
className="btn btn-error btn-outline"
|
||||
onSubmit={() => false}
|
||||
onClick={() => {
|
||||
deleteParticipant(participantForm.watch("id"));
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -38,8 +38,13 @@ export default async () => {
|
||||
},
|
||||
include: {
|
||||
Participants: {
|
||||
where: {
|
||||
userId: user.id,
|
||||
select: {
|
||||
enscriptionDate: true,
|
||||
id: true,
|
||||
userId: true,
|
||||
},
|
||||
orderBy: {
|
||||
enscriptionDate: "asc",
|
||||
},
|
||||
},
|
||||
_count: {
|
||||
|
||||
@@ -24,6 +24,8 @@ model Participant {
|
||||
appointmentCancelled Boolean @default(false)
|
||||
completetionWorkflowFinished Boolean @default(false)
|
||||
eventAppointmentId Int?
|
||||
enscriptionDate DateTime @default(now())
|
||||
|
||||
statusLog Json[] @default([])
|
||||
eventId Int
|
||||
// relations:
|
||||
|
||||
@@ -27,7 +27,7 @@ model User {
|
||||
moodleId Int? @map(name: "moodle_id")
|
||||
emailVerified DateTime? @map(name: "email_verified")
|
||||
image String?
|
||||
badges BADGES[] @unique @default([])
|
||||
badges BADGES[] @default([])
|
||||
permissions PERMISSION[] @default([])
|
||||
createdAt DateTime @default(now()) @map(name: "created_at")
|
||||
updatedAt DateTime @default(now()) @map(name: "updated_at")
|
||||
|
||||
Reference in New Issue
Block a user