1
- import { useActor } from "@xstate/react" ;
2
1
import { useDashboard } from "components/Dashboard/DashboardProvider" ;
3
2
import dayjs from "dayjs" ;
4
3
import { useFeatureVisibility } from "hooks/useFeatureVisibility" ;
@@ -34,6 +33,9 @@ import { templateVersion, templateVersions } from "api/queries/templates";
34
33
import { Alert } from "components/Alert/Alert" ;
35
34
import { Stack } from "components/Stack/Stack" ;
36
35
import { useWorkspaceBuildLogs } from "hooks/useWorkspaceBuildLogs" ;
36
+ import { decreaseDeadline , increaseDeadline } from "api/queries/workspaces" ;
37
+ import { getErrorMessage } from "api/errors" ;
38
+ import { displaySuccess , displayError } from "components/GlobalSnackbar/utils" ;
37
39
38
40
interface WorkspaceReadyPageProps {
39
41
workspaceState : StateFrom < typeof workspaceMachine > ;
@@ -56,9 +58,6 @@ export const WorkspaceReadyPage = ({
56
58
isLoadingMoreBuilds,
57
59
hasMoreBuilds,
58
60
} : WorkspaceReadyPageProps ) : JSX . Element => {
59
- const [ _ , bannerSend ] = useActor (
60
- workspaceState . children [ "scheduleBannerMachine" ] ,
61
- ) ;
62
61
const { buildInfo } = useDashboard ( ) ;
63
62
const featureVisibility = useFeatureVisibility ( ) ;
64
63
const {
@@ -121,10 +120,25 @@ export const WorkspaceReadyPage = ({
121
120
} = useMutation ( {
122
121
mutationFn : restartWorkspace ,
123
122
} ) ;
124
- // keep banner machine in sync with workspace
125
- useEffect ( ( ) => {
126
- bannerSend ( { type : "REFRESH_WORKSPACE" , workspace } ) ;
127
- } , [ bannerSend , workspace ] ) ;
123
+
124
+ const onDeadlineChangeSuccess = ( ) => {
125
+ displaySuccess ( "Updated workspace shutdown time." ) ;
126
+ } ;
127
+ const onDeadlineChangeFails = ( error : unknown ) => {
128
+ displayError (
129
+ getErrorMessage ( error , "Failed to update workspace shutdown time." ) ,
130
+ ) ;
131
+ } ;
132
+ const decreaseMutation = useMutation ( {
133
+ ...decreaseDeadline ( workspace ) ,
134
+ onSuccess : onDeadlineChangeSuccess ,
135
+ onError : onDeadlineChangeFails ,
136
+ } ) ;
137
+ const increaseMutation = useMutation ( {
138
+ ...increaseDeadline ( workspace ) ,
139
+ onSuccess : onDeadlineChangeSuccess ,
140
+ onError : onDeadlineChangeFails ,
141
+ } ) ;
128
142
129
143
return (
130
144
< >
@@ -144,18 +158,8 @@ export const WorkspaceReadyPage = ({
144
158
145
159
< Workspace
146
160
scheduleProps = { {
147
- onDeadlineMinus : ( hours : number ) => {
148
- bannerSend ( {
149
- type : "DECREASE_DEADLINE" ,
150
- hours,
151
- } ) ;
152
- } ,
153
- onDeadlinePlus : ( hours : number ) => {
154
- bannerSend ( {
155
- type : "INCREASE_DEADLINE" ,
156
- hours,
157
- } ) ;
158
- } ,
161
+ onDeadlineMinus : decreaseMutation . mutate ,
162
+ onDeadlinePlus : increaseMutation . mutate ,
159
163
maxDeadlineDecrease : getMaxDeadlineChange ( deadline , getMinDeadline ( ) ) ,
160
164
maxDeadlineIncrease : getMaxDeadlineChange (
161
165
getMaxDeadline ( workspace ) ,
0 commit comments