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/edit-lock.tsx
Views: 687
1
import { Button, Input, Modal, 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 { editCloudFilesystem } from "./api";
9
import { editModalStyle } from "./util";
10
11
interface Props {
12
cloudFilesystem: CloudFilesystem;
13
open?: boolean;
14
setOpen;
15
refresh;
16
}
17
18
// Edit the title and color of a cloud file system
19
export default function EditLock({
20
cloudFilesystem,
21
open,
22
setOpen,
23
refresh,
24
}: Props) {
25
const [changing, setChanging] = useState<boolean>(false);
26
const [error, setError] = useState<string>("");
27
const [lock, setLock] = useState<string>(cloudFilesystem.lock ?? "DELETE");
28
29
const doEdit = async () => {
30
if (cloudFilesystem.lock == lock) {
31
// no op
32
setOpen(false);
33
return;
34
}
35
try {
36
setChanging(true);
37
await editCloudFilesystem({
38
id: cloudFilesystem.id,
39
lock,
40
});
41
refresh();
42
setOpen(false);
43
} catch (err) {
44
setError(`${err}`);
45
} finally {
46
setChanging(false);
47
}
48
};
49
50
return (
51
<Modal
52
styles={{ body: editModalStyle(cloudFilesystem) }}
53
centered
54
title={
55
<>
56
<Icon name={"lock"} /> Edit Delete Confirmation for "
57
{cloudFilesystem.title}"
58
</>
59
}
60
open={open}
61
onCancel={() => setOpen(false)}
62
footer={[
63
<Button key="cancel" onClick={() => setOpen(false)}>
64
<CancelText />
65
</Button>,
66
<Button
67
key="ok"
68
type="primary"
69
disabled={changing || cloudFilesystem.lock == lock}
70
onClick={doEdit}
71
>
72
Change{" "}
73
{changing ? <Spin style={{ marginLeft: "15px" }} /> : undefined}
74
</Button>,
75
]}
76
>
77
If you delete this filesystem, you will first be asked to type this phrase
78
to avoid mistakes.
79
<Input
80
onPressEnter={doEdit}
81
style={{ width: "100%", margin: "10px 0", color: "red" }}
82
value={lock}
83
onChange={(e) => setLock(e.target.value)}
84
/>
85
<ShowError error={error} setError={setError} />
86
</Modal>
87
);
88
}
89
90