import type { Attendee, Booking, User } from "@prisma/client"; import type { FC } from "react"; import { useMemo } from "react"; import { JsonLd } from "react-schemaorg"; import type { EventReservation, Person, ReservationStatusType } from "schema-dts"; type EventSchemaUser = Pick; type EventSchemaAttendee = Pick; interface EventReservationSchemaInterface { reservationId: Booking["uid"]; eventName: Booking["title"]; startTime: Booking["startTime"]; endTime: Booking["endTime"]; organizer: EventSchemaUser | null; attendees: EventSchemaAttendee[]; location: Booking["location"]; description: Booking["description"]; status: Booking["status"]; } const EventReservationSchema: FC = ({ reservationId, eventName, startTime, endTime, organizer, attendees, location, description, status, }) => { const reservationStatus = useMemo(() => { switch (status) { case "ACCEPTED": return "ReservationConfirmed"; case "REJECTED": case "CANCELLED": return "ReservationCancelled"; case "PENDING": return "ReservationPending"; default: return "ReservationHold"; } }, [status]); return ( item={{ "@context": "https://schema.org", "@type": "EventReservation", reservationId, reservationStatus, reservationFor: { "@type": "Event", name: eventName, startDate: startTime.toString(), endDate: endTime.toString(), organizer: organizer ? ({ "@type": "Person", name: organizer.name, email: organizer.email } as Person) : undefined, attendee: attendees?.map( (person) => ({ "@type": "Person", name: person.name, email: person.email } as Person) ), location: location || undefined, description: description || undefined, }, }} /> ); }; export default EventReservationSchema;