Skip to content

Commit 9408e24

Browse files
committed
Add dialog
1 parent 86b695d commit 9408e24

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useMachine } from "@xstate/react"
22
import { AlertBanner } from "components/AlertBanner/AlertBanner"
3+
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
34
import { scheduleToAutoStart } from "pages/WorkspaceSchedulePage/schedule"
45
import { ttlMsToAutoStop } from "pages/WorkspaceSchedulePage/ttl"
56
import React, { useEffect, useState } from "react"
@@ -20,6 +21,11 @@ const Language = {
2021
"You don't have permissions to update the schedule for this workspace.",
2122
getWorkspaceError: "Failed to fetch workspace.",
2223
checkPermissionsError: "Failed to fetch permissions.",
24+
dialogTitle: "Restart workspace?",
25+
dialogDescription: `Would you like to restart your workspace now to apply your new auto-stop setting,
26+
or let it apply after your next workspace start?`,
27+
restart: "Restart workspace now",
28+
applyLater: "Apply update later",
2329
}
2430

2531
export const WorkspaceSchedulePage: React.FC = () => {
@@ -35,6 +41,7 @@ export const WorkspaceSchedulePage: React.FC = () => {
3541
getWorkspaceError,
3642
permissions,
3743
workspace,
44+
shouldRestartWorkspace,
3845
} = scheduleState.context
3946

4047
// Get workspace on mount and whenever the args for getting a workspace change.
@@ -119,8 +126,32 @@ export const WorkspaceSchedulePage: React.FC = () => {
119126
)
120127
}
121128

122-
if (scheduleState.matches("submitSuccess")) {
123-
return <Navigate to={`/@${username}/${workspaceName}`} />
129+
if (scheduleState.matches("showingRestartDialog")) {
130+
return (
131+
<ConfirmDialog
132+
open
133+
title={Language.dialogTitle}
134+
description={Language.dialogDescription}
135+
confirmText={Language.restart}
136+
cancelText={Language.applyLater}
137+
hideCancel={false}
138+
onConfirm={() => {
139+
scheduleSend("RESTART_WORKSPACE")
140+
}}
141+
onClose={() => {
142+
scheduleSend("APPLY_LATER")
143+
}}
144+
/>
145+
)
146+
}
147+
148+
if (scheduleState.matches("done")) {
149+
return (
150+
<Navigate
151+
to={`/@${username}/${workspaceName}`}
152+
state={{ shouldRestartWorkspace }}
153+
/>
154+
)
124155
}
125156

126157
// Theoretically impossible - log and bail

0 commit comments

Comments
 (0)