/** * Trips Table Component * Modular table component for displaying trips * Supports extensibility for Pro features */ import React from "react"; import { __ } from "../../lib/i18n"; import { ConditionalRender } from "../ui/conditional-render"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../ui/table"; import { Button } from "../ui/button"; import { Badge } from "../ui/badge"; import { Edit, Trash2, Eye } from "lucide-react"; interface Trip { id: number; title: string; slug: string; price: number; status: string; created_at: string; bookings_count?: number; featured?: boolean; } interface TripsTableProps { trips: Trip[]; loading?: boolean; onEdit?: (trip: Trip) => void; onDelete?: (trip: Trip) => void; onView?: (trip: Trip) => void; showProFeatures?: boolean; } /** * Trips Table Component * Displays trips in a table format with actions */ export const TripsTable: React.FC = ({ trips, loading = false, onEdit, onDelete, onView, showProFeatures = false, }) => { const formatDate = (dateString: string) => { return new Date(dateString).toLocaleDateString(); }; const formatPrice = (price: number) => { return `$${price.toFixed(2)}`; }; const getStatusBadge = (status: string) => { const statusMap: Record< string, { variant: "default" | "success" | "warning" | "error" | "info"; label: string; } > = { active: { variant: "success", label: __("Active", "yatra") }, draft: { variant: "default", label: __("Draft", "yatra") }, inactive: { variant: "error", label: __("Inactive", "yatra") }, pending: { variant: "warning", label: __("Pending", "yatra") }, }; const statusInfo = statusMap[status] || { variant: "default" as const, label: status, }; return {statusInfo.label}; }; if (loading) { return (
{__("Loading trips...", "yatra")}
); } if (trips.length === 0) { return (
{__("No trips found", "yatra")}
); } return (
{__("Title", "yatra")} {__("Slug", "yatra")} {__("Price", "yatra")} {__("Status", "yatra")} {showProFeatures && ( {__("Bookings", "yatra")} )} {__("Created", "yatra")} {__("Actions", "yatra")} {trips.map((trip) => (
{trip.title} {trip.featured && showProFeatures && ( {__("Featured", "yatra")} )}
{trip.slug} {formatPrice(trip.price)} {getStatusBadge(trip.status)} {showProFeatures && ( {trip.bookings_count || 0} )} {formatDate(trip.created_at)}
{onView && ( )} {onEdit && ( )} {onDelete && ( )}
))}
); }; export default TripsTable;