/** * Recent Bookings Widget * Displays recent bookings list */ import React from "react"; import { __ } from "../../lib/i18n"; import { toDateValue } from "../../lib/dateFormat"; import { Card, CardContent, CardHeader, CardTitle } from "../ui/card"; import { Badge } from "../ui/badge"; import { Calendar, User, ArrowRight } from "lucide-react"; import { formatYatraMoney } from "../../lib/currency-display"; interface Booking { id: number; booking_id: string; customer_name: string; trip_title: string; booking_date: string; total_amount: number; status: "confirmed" | "pending" | "cancelled" | "completed"; } interface RecentBookingsProps { bookings: Booking[]; loading?: boolean; onView?: (booking: Booking) => void; } /** * Recent Bookings Widget */ export const RecentBookings: React.FC = ({ bookings, loading = false, onView, }) => { const formatDate = (dateString: string) => { // toDateValue: a date-only booking_date must not roll back a day in behind-UTC zones. return toDateValue(dateString).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", }); }; const globalCurrency = (window as any)?.yatraAdmin?.currency || "USD"; const formatCurrency = (amount: number) => formatYatraMoney(Number(amount) || 0, globalCurrency, { zeroAsUnknown: false, }); const getStatusColor = (status: string) => { switch (status) { case "confirmed": return "bg-green-100 text-green-700 dark:bg-green-900/20 dark:text-green-400"; case "pending": return "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/20 dark:text-yellow-400"; case "cancelled": return "bg-red-100 text-red-700 dark:bg-red-900/20 dark:text-red-400"; case "completed": return "bg-blue-100 text-blue-700 dark:bg-blue-900/20 dark:text-blue-400"; default: return "bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-400"; } }; if (loading) { return ( {__("Recent Bookings", "yatra")}
{__("Loading...", "yatra")}
); } return ( {__("Recent Bookings", "yatra")} {bookings && bookings.length > 0 ? (
{bookings.slice(0, 5).map((booking) => (
onView && onView(booking)} >

{booking.trip_title}

{booking.status}
{booking.customer_name}
{formatDate(booking.booking_date)}

{formatCurrency(booking.total_amount)}

{booking.booking_id}

))}
) : (

{__("No recent bookings", "yatra")}

)}
); }; export default RecentBookings;