import { useEffect, useState } from "react";
import { motion } from "framer-motion";
import toast from "react-hot-toast";
import { CheckCircle2, ClipboardCheck, XCircle } from "lucide-react";
import { approveReservation, getPendingReservations } from "../api.js";
export default function ApprovalsPage({ activeUser }) {
const [pending, setPending] = useState([]);
const [loading, setLoading] = useState(true);
function loadData() {
setLoading(true);
getPendingReservations()
.then(setPending)
.catch((err) => toast.error(err.message))
.finally(() => setLoading(false));
}
useEffect(() => {
if (canApprove) {
loadData();
}
}, [canApprove]);
const canApprove = activeUser.role === "approver" || activeUser.role === "admin";
async function saveDecision(reservationId, decision) {
try {
await approveReservation({
reservationId,
approverId: activeUser.userId,
decision,
note: `${decision} through React UI.`,
});
toast.success(`Reservation ${decision}`);
loadData();
} catch (err) {
toast.error(err.message);
}
}
if (!canApprove) {
return (
{item.reservationDate} ยท {item.startTime} - {item.endTime}{item.requesterName}
{subtitle}