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 (
); } return (
{loading &&
Loading pending reservations...
} {!loading && pending.length === 0 && (
No pending reservations at the moment.
)} {!loading && pending.length > 0 && (
{pending.map((item) => (
#{item.reservationId}

{item.requesterName}

{item.reservationDate} ยท {item.startTime} - {item.endTime}

Room {item.roomCode || "No room"}
Building {item.buildingName || "No building"}
Equipment {item.requestedEquipment || "No equipment"}
))}
)}
); } function Hero({ eyebrow, title, subtitle }) { return (
{eyebrow}

{title}

{subtitle}

); } function Badge({ value }) { return {value}; }