import { BanIcon, CheckIcon, ClockIcon, XIcon } from "@heroicons/react/outline"; import { BookingStatus } from "@prisma/client"; import dayjs from "dayjs"; import { useMutation } from "react-query"; import { HttpError } from "@lib/core/http/error"; import { inferQueryOutput, trpc } from "@lib/trpc"; import TableActions from "@components/ui/TableActions"; type BookingItem = inferQueryOutput<"viewer.bookings">[number]; function BookingListItem(booking: BookingItem) { const utils = trpc.useContext(); const mutation = useMutation( async (confirm: boolean) => { const res = await fetch("/api/book/confirm", { method: "PATCH", body: JSON.stringify({ id: booking.id, confirmed: confirm }), headers: { "Content-Type": "application/json", }, }); if (!res.ok) { throw new HttpError({ statusCode: res.status }); } }, { async onSettled() { await utils.invalidateQuery(["viewer.bookings"]); }, } ); const isUpcoming = new Date(booking.endTime) >= new Date(); const isCancelled = booking.status === BookingStatus.CANCELLED; const pendingActions = [ { id: "reject", label: "Reject", onClick: () => mutation.mutate(false), icon: BanIcon, disabled: mutation.isLoading, }, { id: "confirm", label: "Confirm", onClick: () => mutation.mutate(true), icon: CheckIcon, disabled: mutation.isLoading, color: "primary", }, ]; const bookedActions = [ { id: "cancel", label: "Cancel", href: `/cancel/${booking.uid}`, icon: XIcon, }, { id: "reschedule", label: "Reschedule", href: `/reschedule/${booking.uid}`, icon: ClockIcon, }, ]; const startTime = dayjs(booking.startTime).format(isUpcoming ? "ddd, D MMM" : "D MMMM YYYY"); return (