import { useActionQuery } from "@agent-native/core/client/hooks"; import { useT } from "@agent-native/core/client/i18n"; import { isInAgentEmbed, postNavigate, } from "@agent-native/core/client/navigation"; import type { CalendarEvent } from "@shared/api"; import { IconClock, IconMapPin, IconUsers, IconAlignLeft, IconArrowUpRight, IconCalendar, } from "@tabler/icons-react"; import { format, parseISO, differenceInMinutes } from "date-fns"; import { useSearchParams } from "react-router"; import { Button } from "@/components/ui/button"; import { Spinner } from "@/components/ui/spinner"; import { messagesByLocale } from "@/i18n-data"; type EventPreviewResult = CalendarEvent | { error: string }; export function meta() { return [{ title: messagesByLocale["en-US"].routeTitles.eventPreview }]; } function formatDuration(start: string, end: string): string { const totalMinutes = differenceInMinutes(parseISO(end), parseISO(start)); const hours = Math.floor(totalMinutes / 60); const minutes = totalMinutes % 60; if (hours === 0) return `${minutes}m`; if (minutes === 0) return `${hours}h`; return `${hours}h ${minutes}m`; } function EventCard({ event }: { event: CalendarEvent }) { const t = useT(); const inEmbed = isInAgentEmbed(); return (
{/* Color bar */}
{/* Title */}

{event.title}

{event.status === "cancelled" && ( Cancelled )}
{/* Time */}
{event.allDay ? ( All day ·{" "} {format(parseISO(event.start), "MMMM d, yyyy")} ) : ( <> {format(parseISO(event.start), "h:mm a")} {" – "} {format(parseISO(event.end), "h:mm a")} {formatDuration(event.start, event.end)}
{format(parseISO(event.start), "EEEE, MMMM d")}
)}
{/* Location */} {event.location && (
{event.location}
)} {/* Description snippet */} {event.description && (

{event.description}

)} {/* Attendees */} {event.attendees && event.attendees.length > 0 && (
{event.attendees.slice(0, 5).map((a) => ( {a.displayName ? ( <> {a.displayName} {a.email} ) : ( a.email )} ))} {event.attendees.length > 5 && ( +{event.attendees.length - 5} more )}
)} {/* Open in app */} {inEmbed && (
)}
); } function ErrorCard({ message }: { message: string }) { const t = useT(); return (

{t("eventPreview.couldNotLoadEvent")}

{message}

); } export default function EventPreviewRoute() { const t = useT(); const [searchParams] = useSearchParams(); const id = searchParams.get("id") ?? ""; const calendarId = searchParams.get("calendarId") ?? "primary"; const { data, isLoading, error } = useActionQuery( "get-event", id ? { id, calendarId } : undefined, { enabled: !!id, retry: false }, ); if (!id) { return ; } if (isLoading) { return (
); } const result = data as EventPreviewResult | undefined; if (error || !result || "error" in result) { return ( ); } return ; }