CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/compute/cloud-filesystem/delete-filesystem.tsx
Views: 687
1
import { Alert, Button, Input, Modal, Popconfirm, Spin } from "antd";
2
import { useState } from "react";
3
4
import ShowError from "@cocalc/frontend/components/error";
5
import { Icon } from "@cocalc/frontend/components/icon";
6
import { CancelText } from "@cocalc/frontend/i18n/components";
7
import type { CloudFilesystem } from "@cocalc/util/db-schema/cloud-filesystems";
8
import { deleteCloudFilesystem } from "./api";
9
import { editModalStyle } from "./util";
10
11
interface Props {
12
cloudFilesystem: CloudFilesystem;
13
open?: boolean;
14
setOpen;
15
refresh;
16
}
17
18
export default function DeleteCloudFilesystem({
19
cloudFilesystem,
20
open,
21
setOpen,
22
refresh,
23
}: Props) {
24
const lock = cloudFilesystem.lock ?? "DELETE";
25
const [unlock, setUnlock] = useState<string>("");
26
const [deleting, setDeleting] = useState<boolean>(false);
27
const [error, setError] = useState<string>("");
28
29
const doDelete = async () => {
30
try {
31
setDeleting(true);
32
await deleteCloudFilesystem({ id: cloudFilesystem.id, lock: unlock });
33
refresh();
34
setOpen(false);
35
} catch (err) {
36
setError(`${err}`);
37
} finally {
38
setDeleting(false);
39
}
40
};
41
42
return (
43
<Modal
44
styles={{ body: editModalStyle(cloudFilesystem) }}
45
centered
46
title={
47
<>
48
<Icon name="trash" /> Delete "{cloudFilesystem.title}"{" "}
49
</>
50
}
51
open={open}
52
onCancel={() => setOpen(false)}
53
footer={[
54
<Button key="cancel" onClick={() => setOpen(false)}>
55
<CancelText />
56
</Button>,
57
<Popconfirm
58
key="ok"
59
title={
60
<>
61
<b>Permanently delete</b> '{cloudFilesystem.title}' (Id:{" "}
62
{cloudFilesystem.project_specific_id})?
63
</>
64
}
65
onConfirm={doDelete}
66
okText="Delete"
67
cancelText="No"
68
>
69
<Button type="primary" danger disabled={unlock != lock || deleting}>
70
<Icon name="trash" /> Delete...{" "}
71
{deleting ? <Spin style={{ marginLeft: "15px" }} /> : undefined}
72
</Button>
73
</Popconfirm>,
74
]}
75
>
76
<Alert
77
type="warning"
78
showIcon
79
message={
80
<>
81
<p>
82
Are you sure you want to delete '{cloudFilesystem.title}' (Id:{" "}
83
{cloudFilesystem.project_specific_id}) with mountpoint{" "}
84
<code>~/{cloudFilesystem.mountpoint}</code>? This action will
85
permanently delete all data. <b>Data will not be recoverable.</b>
86
</p>
87
<p>Confirm deletion by typing "{lock}" below:</p>
88
<Input
89
status={unlock != lock ? "error" : "warning"}
90
value={unlock}
91
onChange={(e) => setUnlock(e.target.value)}
92
/>
93
</>
94
}
95
/>
96
<ShowError error={error} setError={setError} />
97
</Modal>
98
);
99
}
100
101