"use client";
import { useTransition } from "react";
import { format } from "date-fns";
import { de } from "date-fns/locale";
import { Check, X, Clock, CalendarIcon } from "lucide-react";
import { toast } from "sonner";
import { Termin, User } from "@prisma/client";
import { Card, CardContent } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { approveTermin, rejectTermin } from "../actions";
type PendingTermin = Termin & {
createdBy: { firstName: string; lastName: string } | null;
};
export function PendingAnfragen({ termine }: { termine: PendingTermin[] }) {
if (termine.length === 0) {
return (
Keine ausstehenden Anfragen
Es gibt aktuell keine Terminanfragen, die bestätigt werden müssen.
);
}
return (
{termine.map((termin) => (
))}
);
}
function PendingTerminCard({ termin }: { termin: PendingTermin }) {
const [isPending, startTransition] = useTransition();
const handleApprove = () => {
startTransition(async () => {
const res = await approveTermin(termin.id);
if (res.error) {
toast.error(res.error);
} else {
toast.success("Anfrage freigegeben.");
}
});
};
const handleReject = () => {
// In a real app, you might want to ask for a rejection reason in a prompt/modal.
startTransition(async () => {
const res = await rejectTermin(termin.id);
if (res.error) {
toast.error(res.error);
} else {
toast.success("Anfrage abgelehnt.");
}
});
};
return (
{termin.title}
{format(termin.startDate, "PP", { locale: de })}
{!termin.allDay && ` • ${format(termin.startDate, "p", { locale: de })}`}
Angefragt von: {termin.createdBy?.firstName} {termin.createdBy?.lastName}
);
}