PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.3
Yatra – Travel Booking & Tour Operator Software v3.0.3
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / resources / js / components / ui / confirmation-dialog.tsx

confirmation-dialog.tsx in Yatra – Travel Booking & Tour Operator Software 3.0.3, at resources/js/components/ui/confirmation-dialog.tsx

129 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Confirmation Dialog Component
3 * Displays a modal confirmation dialog for destructive actions
4 */
5
6 import React from "react";
7 import { AlertTriangle, Loader2 } from "lucide-react";
8 import { __ } from "../../lib/i18n";
9 import { Button } from "./button";
10 import { Modal } from "./modal";
11
12 interface ConfirmationDialogProps {
13 isOpen: boolean;
14 onClose: () => void;
15 onConfirm: () => void;
16 title?: string;
17 message?: string;
18 description?: string;
19 confirmText?: string;
20 cancelText?: string;
21 variant?: "danger" | "warning" | "info";
22 isLoading?: boolean;
23 icon?: React.ReactNode;
24 secondaryAction?: {
25 label: string;
26 onClick: () => void;
27 variant?: "default" | "outline" | "ghost" | "destructive";
28 };
29 }
30
31 export const ConfirmationDialog: React.FC<ConfirmationDialogProps> = ({
32 isOpen,
33 onClose,
34 onConfirm,
35 title,
36 message,
37 description,
38 confirmText,
39 cancelText,
40 variant = "danger",
41 isLoading = false,
42 icon,
43 secondaryAction,
44 }) => {
45 // Use description if provided, otherwise fall back to message
46 const displayMessage = description || message || "";
47
48 const getVariantStyles = () => {
49 switch (variant) {
50 case "danger":
51 return "text-red-600 dark:text-red-400";
52 case "warning":
53 return "text-yellow-600 dark:text-yellow-400";
54 case "info":
55 return "text-blue-600 dark:text-blue-400";
56 default:
57 return "text-gray-600 dark:text-gray-400";
58 }
59 };
60
61 const getButtonVariant = () => {
62 switch (variant) {
63 case "danger":
64 return "destructive";
65 case "warning":
66 return "default";
67 case "info":
68 return "default";
69 default:
70 return "default";
71 }
72 };
73
74 return (
75 <Modal
76 isOpen={isOpen}
77 onClose={onClose}
78 title={
79 <div className="flex items-start gap-3">
80 <div className={`flex-shrink-0 mt-0.5 ${getVariantStyles()}`}>
81 {icon || <AlertTriangle className="w-6 h-6" />}
82 </div>
83 <div>{title || __("Confirm Action", "yatra")}</div>
84 </div>
85 }
86 hideHeader={false}
87 hideFooter={false}
88 size="sm"
89 panelClassName="yatra-confirmation-ui yatra-model-ui"
90 bodyClassName="px-6 py-5"
91 footer={
92 <div className="flex gap-2 justify-end pt-2 flex-wrap">
93 <Button variant="outline" onClick={onClose} disabled={isLoading}>
94 {cancelText || __("Cancel", "yatra")}
95 </Button>
96 {secondaryAction && (
97 <Button
98 variant={secondaryAction.variant || "outline"}
99 onClick={secondaryAction.onClick}
100 disabled={isLoading}
101 >
102 {secondaryAction.label}
103 </Button>
104 )}
105 <Button
106 variant={getButtonVariant()}
107 onClick={onConfirm}
108 disabled={isLoading}
109 className="min-w-[100px]"
110 >
111 {isLoading ? (
112 <>
113 <Loader2 className="w-4 h-4 mr-2 animate-spin" />
114 {__("Deleting...", "yatra")}
115 </>
116 ) : (
117 confirmText || __("Confirm", "yatra")
118 )}
119 </Button>
120 </div>
121 }
122 >
123 <p className="text-sm text-gray-600 dark:text-gray-400 leading-relaxed">
124 {displayMessage}
125 </p>
126 </Modal>
127 );
128 };
129