@@ -13,6 +13,9 @@ import { useFilter } from "components/Filter/filter"
13
13
import { useUserFilterMenu } from "components/Filter/UserFilter"
14
14
import { getWorkspaces } from "api/api"
15
15
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
16
+ import Box from "@mui/material/Box"
17
+ import { MONOSPACE_FONT_FAMILY } from "theme/constants"
18
+ import TextField from "@mui/material/TextField"
16
19
17
20
const WorkspacesPage : FC = ( ) => {
18
21
const [ lockedWorkspaces , setLockedWorkspaces ] = useState < Workspace [ ] > ( [ ] )
@@ -92,17 +95,9 @@ const WorkspacesPage: FC = () => {
92
95
} }
93
96
/>
94
97
95
- < ConfirmDialog
96
- type = "delete"
97
- title = { `Delete ${ checkedWorkspaces ?. length } ${
98
- checkedWorkspaces . length === 1 ? "workspace" : "workspaces"
99
- } `}
100
- description = "Deleting these workspaces is irreversible! Are you sure you want to proceed?"
98
+ < BatchDeleteConfirmation
99
+ checkedWorkspaces = { checkedWorkspaces }
101
100
open = { isDeletingAll }
102
- confirmLoading = { false }
103
- onConfirm = { ( ) => {
104
- alert ( "DO IT!" )
105
- } }
106
101
onClose = { ( ) => {
107
102
setIsDeletingAll ( false )
108
103
} }
@@ -159,3 +154,77 @@ const useWorkspacesFilter = ({
159
154
} ,
160
155
}
161
156
}
157
+
158
+ const BatchDeleteConfirmation = ( {
159
+ checkedWorkspaces,
160
+ open,
161
+ onClose,
162
+ } : {
163
+ checkedWorkspaces : Workspace [ ]
164
+ open : boolean
165
+ onClose : ( ) => void
166
+ } ) => {
167
+ const [ confirmValue , setConfirmValue ] = useState ( "" )
168
+ const [ confirmError , setConfirmError ] = useState ( false )
169
+
170
+ const confirmDeletion = ( ) => {
171
+ if ( confirmValue . toLowerCase ( ) !== "delete" ) {
172
+ setConfirmError ( true )
173
+ return
174
+ }
175
+ }
176
+
177
+ return (
178
+ < ConfirmDialog
179
+ open = { open }
180
+ onClose = { ( ) => {
181
+ onClose ( )
182
+ setConfirmValue ( "" )
183
+ setConfirmError ( false )
184
+ } }
185
+ type = "delete"
186
+ title = { `Delete ${ checkedWorkspaces ?. length } ${
187
+ checkedWorkspaces . length === 1 ? "workspace" : "workspaces"
188
+ } `}
189
+ description = {
190
+ < form
191
+ onSubmit = { ( e ) => {
192
+ e . preventDefault ( )
193
+ confirmDeletion ( )
194
+ } }
195
+ >
196
+ < Box >
197
+ Deleting these workspaces is irreversible! Are you sure you want to
198
+ proceed? Type{ " " }
199
+ < Box
200
+ component = "code"
201
+ sx = { {
202
+ fontFamily : MONOSPACE_FONT_FAMILY ,
203
+ color : ( theme ) => theme . palette . text . primary ,
204
+ fontWeight : 600 ,
205
+ } }
206
+ >
207
+ `DELETE`
208
+ </ Box > { " " }
209
+ to confirm.
210
+ </ Box >
211
+ < TextField
212
+ value = { confirmValue }
213
+ required
214
+ autoFocus
215
+ fullWidth
216
+ placeholder = "Type DELETE to confirm"
217
+ sx = { { mt : 2 } }
218
+ onChange = { ( e ) => {
219
+ setConfirmValue ( e . currentTarget . value )
220
+ } }
221
+ error = { confirmError }
222
+ helperText = { confirmError && "Please type DELETE to confirm" }
223
+ />
224
+ </ form >
225
+ }
226
+ confirmLoading = { false }
227
+ onConfirm = { confirmDeletion }
228
+ />
229
+ )
230
+ }
0 commit comments