-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Expand file tree
/
Copy pathdelete-modal.tsx
More file actions
82 lines (74 loc) · 2.68 KB
/
Copy pathdelete-modal.tsx
File metadata and controls
82 lines (74 loc) · 2.68 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
73
74
75
76
77
78
79
80
81
82
import {Button, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle} from '@tryghost/shade/components';
import {useState} from 'react';
interface DeleteModalProps {
open: boolean;
memberCount: number;
onOpenChange: (open: boolean) => void;
onConfirm: () => void;
onExportBackup: () => void;
isLoading?: boolean;
}
export function DeleteModal({
open,
memberCount,
onOpenChange,
onConfirm,
onExportBackup,
isLoading = false
}: DeleteModalProps) {
const [isPreparingBackup, setIsPreparingBackup] = useState(false);
const handleOpenChange = (isOpen: boolean) => {
if (!isOpen) {
setIsPreparingBackup(false);
}
onOpenChange(isOpen);
};
const handleConfirm = async () => {
if (memberCount < 1 || isLoading || isPreparingBackup) {
return;
}
try {
setIsPreparingBackup(true);
await onExportBackup();
onConfirm();
} catch {
// Error handling/toasts are managed by the parent callbacks.
} finally {
setIsPreparingBackup(false);
}
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent className="gap-5">
<DialogHeader>
<DialogTitle>Delete selected members?</DialogTitle>
</DialogHeader>
{memberCount > 0 ? (
<>
<p>
You're about to delete <strong>{memberCount.toLocaleString()} {memberCount === 1 ? 'member' : 'members'}</strong>.
This is permanent! All Ghost data will be deleted, this will have no effect on subscriptions in Stripe.
</p>
<p>
A backup of your selection will be automatically downloaded to your device before deletion.
</p>
</>
) : (
<p>No members are selected.</p>
)}
<DialogFooter>
<Button variant="outline" onClick={() => handleOpenChange(false)}>
Cancel
</Button>
<Button
disabled={isLoading || isPreparingBackup || memberCount < 1}
variant="destructive"
onClick={handleConfirm}
>
{isLoading || isPreparingBackup ? 'Deleting...' : 'Download backup & delete members'}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}