| @@ -3,10 +3,11 @@ | ||
| 3 | 3 | * Modular table component for displaying trips |
| 4 | 4 | * Supports extensibility for Pro features |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -import React from "react"; | |
| 7 | +import React, { useState } from "react"; | |
| 8 | 8 | import { __ } from "../../lib/i18n"; |
| 9 | +import { formatYatraMoney } from "../../lib/currency-display"; | |
| 9 | 10 | import { ConditionalRender } from "../ui/conditional-render"; |
| 10 | 11 | import { |
| 11 | 12 | Table, |
| 12 | 13 | TableBody, |
| @@ -17,8 +18,9 @@ | ||
| 17 | 18 | } from "../ui/table"; |
| 18 | 19 | import { Button } from "../ui/button"; |
| 19 | 20 | import { Badge } from "../ui/badge"; |
| 20 | 21 | import { Edit, Trash2, Eye } from "lucide-react"; |
| 22 | +import { ConfirmationDialog } from "../ui/confirmation-dialog"; | |
| 21 | 23 | |
| 22 | 24 | interface Trip { |
| 23 | 25 | id: number; |
| 24 | 26 | title: string; |
| @@ -50,16 +52,29 @@ | ||
| 50 | 52 | onDelete, |
| 51 | 53 | onView, |
| 52 | 54 | showProFeatures = false, |
| 53 | 55 | }) => { |
| 56 | + // Uses the shared ConfirmationDialog like the rest of the admin, instead of | |
| 57 | + // the browser's native confirm() which ignores the admin theme. | |
| 58 | + const [tripToDelete, setTripToDelete] = useState<any | null>(null); | |
| 59 | + | |
| 54 | 60 | const formatDate = (dateString: string) => { |
| 55 | 61 | return new Date(dateString).toLocaleDateString(); |
| 56 | 62 | }; |
| 57 | 63 | |
| 58 | - const formatPrice = (price: number) => { | |
| 59 | - return `$${price.toFixed(2)}`; | |
| 60 | - }; | |
| 64 | + const defaultCurrency = | |
| 65 | + (typeof window !== "undefined" && | |
| 66 | + ((window as unknown as { yatraAdmin?: { currency?: string } }).yatraAdmin | |
| 67 | + ?.currency || | |
| 68 | + (window as unknown as { yatraBookingData?: { currency?: string } }) | |
| 69 | + .yatraBookingData?.currency)) || | |
| 70 | + "USD"; | |
| 61 | 71 | |
| 72 | + const formatPrice = (price: number) => | |
| 73 | + formatYatraMoney(Number(price) || 0, defaultCurrency, { | |
| 74 | + zeroAsUnknown: false, | |
| 75 | + }); | |
| 76 | + | |
| 62 | 77 | const getStatusBadge = (status: string) => { |
| 63 | 78 | const statusMap: Record< |
| 64 | 79 | string, |
| 65 | 80 | { |
| @@ -170,20 +185,9 @@ | ||
| 170 | 185 | {onDelete && ( |
| 171 | 186 | <Button |
| 172 | 187 | variant="ghost" |
| 173 | 188 | size="sm" |
| 174 | - onClick={() => { | |
| 175 | - if ( | |
| 176 | - confirm( | |
| 177 | - __( | |
| 178 | - "Are you sure you want to delete this trip?", | |
| 179 | - "yatra", | |
| 180 | - ), | |
| 181 | - ) | |
| 182 | - ) { | |
| 183 | - onDelete(trip); | |
| 184 | - } | |
| 185 | - }} | |
| 189 | + onClick={() => setTripToDelete(trip)} | |
| 186 | 190 | aria-label={__("Delete trip", "yatra")} |
| 187 | 191 | > |
| 188 | 192 | <Trash2 className="w-4 h-4 text-red-500" /> |
| 189 | 193 | </Button> |
| @@ -194,8 +198,27 @@ | ||
| 194 | 198 | </TableRow> |
| 195 | 199 | ))} |
| 196 | 200 | </TableBody> |
| 197 | 201 | </Table> |
| 202 | + | |
| 203 | + <ConfirmationDialog | |
| 204 | + isOpen={tripToDelete !== null} | |
| 205 | + onClose={() => setTripToDelete(null)} | |
| 206 | + onConfirm={() => { | |
| 207 | + if (tripToDelete && onDelete) { | |
| 208 | + onDelete(tripToDelete); | |
| 209 | + } | |
| 210 | + setTripToDelete(null); | |
| 211 | + }} | |
| 212 | + title={__("Delete Trip", "yatra")} | |
| 213 | + message={__( | |
| 214 | + "Are you sure you want to delete this trip? This action cannot be undone.", | |
| 215 | + "yatra", | |
| 216 | + )} | |
| 217 | + confirmText={__("Delete", "yatra")} | |
| 218 | + cancelText={__("Cancel", "yatra")} | |
| 219 | + variant="danger" | |
| 220 | + /> | |
| 198 | 221 | </div> |
| 199 | 222 | ); |
| 200 | 223 | }; |
| 201 | 224 | |