3
3
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
4
4
*/
5
5
6
- import { Alert , Button , Space } from "antd" ;
7
- import { useState } from "react" ;
6
+ import { Alert , Button , Popconfirm , Switch } from "antd" ;
8
7
9
- import { Col , Row , Well } from "@cocalc/frontend/antd-bootstrap" ;
10
- import { Icon , SettingBox } from "@cocalc/frontend/components" ;
8
+ import { Col , Row } from "@cocalc/frontend/antd-bootstrap" ;
9
+ import {
10
+ Icon ,
11
+ Paragraph ,
12
+ SettingBox ,
13
+ Title ,
14
+ } from "@cocalc/frontend/components" ;
11
15
import { HelpEmailLink } from "@cocalc/frontend/customize" ;
12
16
import { ProjectsActions } from "@cocalc/frontend/todo-types" ;
13
17
import { webapp_client } from "@cocalc/frontend/webapp-client" ;
14
18
import { COLORS } from "@cocalc/util/theme" ;
19
+ import { useMemo } from "react" ;
15
20
import { DeletedProjectWarning } from "../warnings/deleted" ;
16
21
import { Project } from "./types" ;
17
22
@@ -24,12 +29,12 @@ interface Props {
24
29
export function HideDeleteBox ( props : Readonly < Props > ) {
25
30
const { project, actions, mode = "project" } = props ;
26
31
const isFlyout = mode === "flyout" ;
27
-
28
- const [ show_delete_conf , set_show_delete_conf ] = useState < boolean > ( false ) ;
32
+ const is_deleted = useMemo ( ( ) => {
33
+ return project . get ( "deleted" ) ;
34
+ } , [ project . get ( "deleted" ) ] ) ;
29
35
30
36
function toggle_delete_project ( ) : void {
31
37
actions . toggle_delete_project ( project . get ( "project_id" ) ) ;
32
- set_show_delete_conf ( false ) ;
33
38
}
34
39
35
40
function toggle_hide_project ( ) : void {
@@ -42,7 +47,7 @@ export function HideDeleteBox(props: Readonly<Props>) {
42
47
}
43
48
44
49
function delete_message ( ) : JSX . Element {
45
- if ( project . get ( "deleted" ) ) {
50
+ if ( is_deleted ) {
46
51
return < DeletedProjectWarning /> ;
47
52
} else {
48
53
return (
@@ -63,60 +68,65 @@ export function HideDeleteBox(props: Readonly<Props>) {
63
68
if ( user == undefined ) {
64
69
return < span > Does not make sense for admin.</ span > ;
65
70
}
66
- if ( user . get ( "hide" ) ) {
71
+
72
+ return (
73
+ < span >
74
+ Hide this project, so it does not show up in your default project
75
+ listing. This only impacts you, not your collaborators, and you can
76
+ easily unhide it.
77
+ </ span >
78
+ ) ;
79
+ }
80
+
81
+ function render_delete_undelete_button ( ) : JSX . Element {
82
+ if ( is_deleted ) {
67
83
return (
68
- < span >
69
- Unhide this project, so it shows up in your default project listing.
70
- Right now it only appears when hidden is checked.
71
- </ span >
84
+ < Button
85
+ danger
86
+ style = { { float : "right" } }
87
+ onClick = { toggle_delete_project }
88
+ icon = { < Icon name = "trash" /> }
89
+ >
90
+ Undelete Project
91
+ </ Button >
72
92
) ;
73
93
} else {
74
94
return (
75
- < span >
76
- Hide this project, so it does not show up in your default project
77
- listing. This only impacts you, not your collaborators, and you can
78
- easily unhide it.
79
- </ span >
95
+ < Popconfirm
96
+ placement = { "bottom" }
97
+ arrow = { { pointAtCenter : true } }
98
+ title = { render_expanded_delete_info ( ) }
99
+ onConfirm = { toggle_delete_project }
100
+ okText = { `Yes, please delete this project!` }
101
+ cancelText = "Cancel"
102
+ overlayStyle = { { maxWidth : "400px" } }
103
+ icon = { < Icon name = "trash" /> }
104
+ >
105
+ < Button
106
+ danger
107
+ style = { { float : "right" } }
108
+ icon = { < Icon name = "trash" /> }
109
+ >
110
+ Delete Project...
111
+ </ Button >
112
+ </ Popconfirm >
80
113
) ;
81
114
}
82
115
}
83
116
84
- function render_delete_undelete_button ( is_deleted , is_expanded ) : JSX . Element {
85
- let disabled , onClick , text ;
86
- if ( is_deleted ) {
87
- text = "Undelete Project" ;
88
- onClick = toggle_delete_project ;
89
- disabled = false ;
90
- } else {
91
- text = "Delete Project..." ;
92
- onClick = ( ) => set_show_delete_conf ( true ) ;
93
- disabled = is_expanded ;
94
- }
95
-
96
- return (
97
- < Button
98
- danger
99
- style = { { float : "right" } }
100
- onClick = { onClick }
101
- disabled = { disabled }
102
- cocalc-test = { is_deleted ? "undelete-project" : "delete-project" }
103
- >
104
- < Icon name = "trash" /> { text }
105
- </ Button >
106
- ) ;
107
- }
108
-
109
117
function render_expanded_delete_info ( ) : JSX . Element {
110
118
const has_upgrades =
111
119
webapp_client . account_id == null
112
120
? false
113
121
: user_has_applied_upgrades ( webapp_client . account_id , project ) ;
114
122
return (
115
- < Well style = { { textAlign : "center" } } >
123
+ < Paragraph >
124
+ < div style = { { marginBottom : "5px" } } >
125
+ Are you sure you want to delete this project?
126
+ </ div >
116
127
{ has_upgrades ? (
117
128
< Alert
118
129
showIcon
119
- style = { { margin : "15px" } }
120
130
type = "info"
121
131
description = {
122
132
< >
@@ -128,55 +138,41 @@ export function HideDeleteBox(props: Readonly<Props>) {
128
138
}
129
139
/>
130
140
) : undefined }
131
- { ! has_upgrades ? (
132
- < div style = { { marginBottom : "5px" } } >
133
- Are you sure you want to delete this project?
134
- </ div >
135
- ) : undefined }
136
- < Space >
137
- < Button onClick = { ( ) => set_show_delete_conf ( false ) } > Cancel</ Button >
138
- < Button
139
- danger
140
- onClick = { toggle_delete_project }
141
- cocalc-test = "please-delete-project"
142
- >
143
- Yes, please delete this project
144
- </ Button >
145
- </ Space >
146
- </ Well >
141
+ </ Paragraph >
147
142
) ;
148
143
}
149
144
150
145
function renderBody ( ) {
151
146
return (
152
147
< >
153
148
< Row >
154
- < Col sm = { 8 } > { hide_message ( ) } </ Col >
155
- < Col sm = { 4 } >
156
- < Button
157
- onClick = { toggle_hide_project }
158
- style = { { float : "right" } }
159
- cocalc-test = { hidden ? "unhide-project" : "hide-project" }
160
- >
161
- < Icon name = "eye-slash" /> { hidden ? "Unhide" : "Hide" } Project
162
- </ Button >
149
+ < Col sm = { 12 } >
150
+ < Title level = { 4 } >
151
+ < Icon name = { hidden ? "eye-slash" : "eye" } /> Project{ " " }
152
+ { hidden ? "hidden" : "visible" }
153
+ < Switch
154
+ checked = { hidden }
155
+ style = { { float : "right" } }
156
+ checkedChildren = { "Hidden" }
157
+ unCheckedChildren = { "Visible" }
158
+ onChange = { toggle_hide_project }
159
+ />
160
+ </ Title >
161
+ < Paragraph > { hide_message ( ) } </ Paragraph >
163
162
</ Col >
164
163
</ Row >
165
164
< hr />
166
165
< Row >
167
- < Col sm = { 8 } > { delete_message ( ) } </ Col >
168
- < Col sm = { 4 } >
169
- { render_delete_undelete_button (
170
- project . get ( "deleted" ) ,
171
- show_delete_conf ,
172
- ) }
166
+ < Col sm = { 12 } >
167
+ < Title level = { 4 } >
168
+ < Icon name = "trash" /> Delete project{ " " }
169
+ { render_delete_undelete_button ( ) }
170
+ </ Title >
171
+ </ Col >
172
+ < Col sm = { 12 } >
173
+ < Paragraph > { delete_message ( ) } </ Paragraph >
173
174
</ Col >
174
175
</ Row >
175
- { show_delete_conf && ! project . get ( "deleted" ) ? (
176
- < Row style = { { marginTop : "10px" } } >
177
- < Col sm = { 12 } > { render_expanded_delete_info ( ) } </ Col >
178
- </ Row >
179
- ) : undefined }
180
176
< hr />
181
177
< Row style = { { color : COLORS . GRAY_M } } >
182
178
< Col sm = { 12 } >
0 commit comments