fixed event completed Workflow
This commit is contained in:
@@ -19,6 +19,7 @@ router.post("/set-standard-name", async (req, res) => {
|
||||
id: userId,
|
||||
},
|
||||
});
|
||||
console.log(`Setting standard name for user ${userId} (${user?.publicId}) to member ${memberId}`);
|
||||
if (!user) {
|
||||
res.status(404).json({ error: "User not found" });
|
||||
return;
|
||||
|
||||
@@ -47,7 +47,6 @@ export const handleParticipantFinished = async (
|
||||
id: participant.id,
|
||||
},
|
||||
data: {
|
||||
completetionWorkflowFinished: true,
|
||||
statusLog: {
|
||||
push: {
|
||||
event: "Berechtigungen und Badges vergeben",
|
||||
|
||||
@@ -24,6 +24,7 @@ router.post("/handle-participant-finished", async (req, res) => {
|
||||
},
|
||||
},
|
||||
});
|
||||
console.log("Handeling Participant-completed", participant?.User.publicId);
|
||||
if (!participant) {
|
||||
res.status(404).json({ error: "Participant not found" });
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Event, Participant } from "@repo/db";
|
||||
import { EventAppointmentOptionalDefaults } from "@repo/db/zod";
|
||||
import { CellContext } from "@tanstack/react-table";
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { RefObject, useRef } from "react";
|
||||
import { UseFormReturn } from "react-hook-form";
|
||||
@@ -10,6 +10,7 @@ import { DateInput } from "../../../../_components/ui/DateInput";
|
||||
import { upsertParticipant } from "../../../events/actions";
|
||||
import { deleteAppoinement, upsertAppointment } from "../action";
|
||||
import { handleParticipantFinished } from "../../../../../helper/events";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
interface AppointmentModalProps {
|
||||
event?: Event;
|
||||
@@ -74,101 +75,111 @@ export const AppointmentModal = ({
|
||||
<PaginatedTable
|
||||
hide={appointmentForm.watch("id") === undefined}
|
||||
ref={participantTableRef}
|
||||
columns={[
|
||||
{
|
||||
accessorKey: "User.firstname",
|
||||
header: "Vorname",
|
||||
},
|
||||
{
|
||||
accessorKey: "User.lastname",
|
||||
header: "Nachname",
|
||||
},
|
||||
{
|
||||
accessorKey: "enscriptionDate",
|
||||
header: "Einschreibedatum",
|
||||
cell: ({ row }: CellContext<Participant, any>) => {
|
||||
return <span>{new Date(row.original.enscriptionDate).toLocaleString()}</span>;
|
||||
columns={
|
||||
[
|
||||
{
|
||||
accessorKey: "User.firstname",
|
||||
header: "Vorname",
|
||||
},
|
||||
},
|
||||
{
|
||||
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>?</span>;
|
||||
}
|
||||
{
|
||||
accessorKey: "User.lastname",
|
||||
header: "Nachname",
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Aktion",
|
||||
{
|
||||
accessorKey: "enscriptionDate",
|
||||
header: "Einschreibedatum",
|
||||
cell: ({ row }) => {
|
||||
return <span>{new Date(row.original.enscriptionDate).toLocaleString()}</span>;
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Anwesend",
|
||||
cell: ({ row }) => {
|
||||
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>?</span>;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
header: "Aktion",
|
||||
|
||||
cell: ({ row }: CellContext<Participant, any>) => {
|
||||
return (
|
||||
<div className="space-x-2">
|
||||
<button
|
||||
onClick={() => {
|
||||
participantForm.reset(row.original);
|
||||
participantModal.current?.showModal();
|
||||
}}
|
||||
className="btn btn-outline btn-sm"
|
||||
>
|
||||
anzeigen
|
||||
</button>
|
||||
{!row.original.attended && event?.hasPresenceEvents && (
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="space-x-2">
|
||||
<button
|
||||
type="button"
|
||||
onSubmit={() => {}}
|
||||
onClick={async () => {
|
||||
await upsertParticipant({
|
||||
eventId: event!.id,
|
||||
userId: row.original.userId,
|
||||
attended: true,
|
||||
appointmentCancelled: false,
|
||||
});
|
||||
if (!event.finisherMoodleCourseId) {
|
||||
await handleParticipantFinished(row.original.id.toString());
|
||||
}
|
||||
participantTableRef.current?.refresh();
|
||||
onClick={() => {
|
||||
participantForm.reset(row.original);
|
||||
participantModal.current?.showModal();
|
||||
}}
|
||||
className="btn btn-outline btn-info btn-sm"
|
||||
className="btn btn-outline btn-sm"
|
||||
>
|
||||
Anwesend
|
||||
anzeigen
|
||||
</button>
|
||||
)}
|
||||
{!row.original.appointmentCancelled && event?.hasPresenceEvents && (
|
||||
<button
|
||||
type="button"
|
||||
onSubmit={() => {}}
|
||||
onClick={async () => {
|
||||
await upsertParticipant({
|
||||
eventId: event!.id,
|
||||
userId: row.original.userId,
|
||||
attended: false,
|
||||
appointmentCancelled: true,
|
||||
statusLog: [
|
||||
...(row.original.statusLog as any),
|
||||
{
|
||||
event: "Gefehlt an Event",
|
||||
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"
|
||||
>
|
||||
abwesend
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
{!row.original.attended && event?.hasPresenceEvents && (
|
||||
<button
|
||||
type="button"
|
||||
onSubmit={() => {}}
|
||||
onClick={async () => {
|
||||
await upsertParticipant({
|
||||
eventId: event!.id,
|
||||
userId: row.original.userId,
|
||||
attended: true,
|
||||
appointmentCancelled: false,
|
||||
});
|
||||
console.log(
|
||||
"Participant attended",
|
||||
event.finisherMoodleCourseId,
|
||||
!event.finisherMoodleCourseId?.length,
|
||||
);
|
||||
if (!event.finisherMoodleCourseId?.length) {
|
||||
toast(
|
||||
"Teilnehmer hat das event abgeschlossen, workflow ausgeführt",
|
||||
);
|
||||
await handleParticipantFinished(row.original.id.toString());
|
||||
}
|
||||
participantTableRef.current?.refresh();
|
||||
}}
|
||||
className="btn btn-outline btn-info btn-sm"
|
||||
>
|
||||
Anwesend
|
||||
</button>
|
||||
)}
|
||||
{!row.original.appointmentCancelled && event?.hasPresenceEvents && (
|
||||
<button
|
||||
type="button"
|
||||
onSubmit={() => {}}
|
||||
onClick={async () => {
|
||||
await upsertParticipant({
|
||||
eventId: event!.id,
|
||||
userId: row.original.userId,
|
||||
attended: false,
|
||||
appointmentCancelled: true,
|
||||
statusLog: [
|
||||
...(row.original.statusLog as any),
|
||||
{
|
||||
event: "Gefehlt an Event",
|
||||
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"
|
||||
>
|
||||
abwesend
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
},
|
||||
]}
|
||||
] as ColumnDef<Participant, any>[]
|
||||
}
|
||||
prismaModel={"participant"}
|
||||
filter={{
|
||||
eventAppointmentId: appointmentForm.watch("id"),
|
||||
|
||||
@@ -61,16 +61,6 @@ export const ParticipantModal = ({ participantForm, ref }: ParticipantModalProps
|
||||
name="finisherMoodleCurseCompleted"
|
||||
label="Abschluss-Moodle-Kurs abgeschlossen"
|
||||
/>
|
||||
<Switch
|
||||
form={participantForm}
|
||||
name="inscriptionWorkflowCompleted"
|
||||
label="Anmeldeprozess abgeschlossen (Discord-rollen vergeben)"
|
||||
/>
|
||||
<Switch
|
||||
form={participantForm}
|
||||
name="completetionWorkflowFinished"
|
||||
label="Abgeschlossen (E-Mail-Benachrichtigung senden)"
|
||||
/>
|
||||
<div className="w-full">
|
||||
<h3 className="text-xl">Termine</h3>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user