-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Expand file tree
/
Copy pathdelete-project-dialog.tsx
More file actions
92 lines (88 loc) · 2.41 KB
/
Copy pathdelete-project-dialog.tsx
File metadata and controls
92 lines (88 loc) · 2.41 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
83
84
85
86
87
88
89
90
91
92
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogBody,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { useState } from "react";
const REQUIRED_CONFIRMATION_TEXT = "DELETE";
export function DeleteProjectDialog({
isOpen,
onOpenChange,
onConfirm,
projectNames,
}: {
isOpen: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: () => void;
projectNames: string[];
}) {
const count = projectNames.length;
const isSingle = count === 1;
const singleName = isSingle ? projectNames[0] : null;
const [confirmationInput, setConfirmationInput] = useState<string>("");
return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
<DialogContent
onOpenAutoFocus={(event) => {
event.preventDefault();
event.stopPropagation();
}}
>
<DialogHeader>
<DialogTitle>
{singleName ? (
<>
{"Delete '"}
<span className="inline-block max-w-[300px] truncate align-bottom">
{singleName}
</span>
{"'?"}
</>
) : (
`Delete ${count} projects?`
)}
</DialogTitle>
</DialogHeader>
<DialogBody>
<Alert variant="destructive">
<AlertTitle>Warning</AlertTitle>
<AlertDescription>
This will permanently delete{" "}
{singleName ? `"${singleName}"` : `${count} projects`} and all
associated files.
</AlertDescription>
</Alert>
<div className="flex flex-col gap-3">
<Label htmlFor="confirmation-input" className="text-xs font-semibold text-slate-500">
{`Type "${REQUIRED_CONFIRMATION_TEXT}" to confirm`}
</Label>
<Input
id={"confirmation-input"}
onChange={(e) => {setConfirmationInput(e.target.value)}}
value={confirmationInput}
type="text"
placeholder={REQUIRED_CONFIRMATION_TEXT}
size="lg"
variant="destructive"
/>
</div>
</DialogBody>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button variant="destructive" onClick={onConfirm} disabled={confirmationInput !== REQUIRED_CONFIRMATION_TEXT}>
Delete project
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}