forked from abdlelahalwali8-a11y/dr-appointments-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfirmDialog.tsx
More file actions
72 lines (67 loc) · 1.75 KB
/
Copy pathConfirmDialog.tsx
File metadata and controls
72 lines (67 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React from 'react';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog';
interface ConfirmDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
title: string;
description: string;
onConfirm: () => void | Promise<void>;
onCancel?: () => void;
confirmText?: string;
cancelText?: string;
isLoading?: boolean;
isDangerous?: boolean;
}
const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
open,
onOpenChange,
title,
description,
onConfirm,
onCancel,
confirmText = 'تأكيد',
cancelText = 'إلغاء',
isLoading = false,
isDangerous = false,
}) => {
const handleConfirm = async () => {
await onConfirm();
onOpenChange(false);
};
const handleCancel = () => {
onCancel?.();
onOpenChange(false);
};
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{title}</AlertDialogTitle>
<AlertDialogDescription>{description}</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel onClick={handleCancel} disabled={isLoading}>
{cancelText}
</AlertDialogCancel>
<AlertDialogAction
onClick={handleConfirm}
disabled={isLoading}
className={isDangerous ? 'bg-destructive hover:bg-destructive/90' : ''}
>
{isLoading ? 'جاري المعالجة...' : confirmText}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
};
export default ConfirmDialog;