1
1
import { useMachine } from "@xstate/react"
2
2
import { AlertBanner } from "components/AlertBanner/AlertBanner"
3
+ import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
3
4
import { scheduleToAutoStart } from "pages/WorkspaceSchedulePage/schedule"
4
5
import { ttlMsToAutoStop } from "pages/WorkspaceSchedulePage/ttl"
5
6
import React , { useEffect , useState } from "react"
@@ -20,6 +21,11 @@ const Language = {
20
21
"You don't have permissions to update the schedule for this workspace." ,
21
22
getWorkspaceError : "Failed to fetch workspace." ,
22
23
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" ,
23
29
}
24
30
25
31
export const WorkspaceSchedulePage : React . FC = ( ) => {
@@ -35,6 +41,7 @@ export const WorkspaceSchedulePage: React.FC = () => {
35
41
getWorkspaceError,
36
42
permissions,
37
43
workspace,
44
+ shouldRestartWorkspace,
38
45
} = scheduleState . context
39
46
40
47
// Get workspace on mount and whenever the args for getting a workspace change.
@@ -119,8 +126,32 @@ export const WorkspaceSchedulePage: React.FC = () => {
119
126
)
120
127
}
121
128
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
+ )
124
155
}
125
156
126
157
// Theoretically impossible - log and bail
0 commit comments