Skip to content

Commit 32d9025

Browse files
committed
Improve delete dialog
1 parent e3b7c9d commit 32d9025

File tree

1 file changed

+79
-10
lines changed

1 file changed

+79
-10
lines changed

site/src/pages/WorkspacesPage/WorkspacesPage.tsx

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { useFilter } from "components/Filter/filter"
1313
import { useUserFilterMenu } from "components/Filter/UserFilter"
1414
import { getWorkspaces } from "api/api"
1515
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"
1619

1720
const WorkspacesPage: FC = () => {
1821
const [lockedWorkspaces, setLockedWorkspaces] = useState<Workspace[]>([])
@@ -92,17 +95,9 @@ const WorkspacesPage: FC = () => {
9295
}}
9396
/>
9497

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}
101100
open={isDeletingAll}
102-
confirmLoading={false}
103-
onConfirm={() => {
104-
alert("DO IT!")
105-
}}
106101
onClose={() => {
107102
setIsDeletingAll(false)
108103
}}
@@ -159,3 +154,77 @@ const useWorkspacesFilter = ({
159154
},
160155
}
161156
}
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

Comments
 (0)