4
4
*/
5
5
import { assign , createMachine } from "xstate"
6
6
import * as API from "../../api/api"
7
- import { ApiError , FieldErrors , mapApiErrorToFieldErrors } from "../../api/errors"
8
7
import * as TypesGen from "../../api/typesGenerated"
9
- import { displayError , displaySuccess } from "../../components/GlobalSnackbar/utils"
8
+ import { displaySuccess } from "../../components/GlobalSnackbar/utils"
10
9
11
10
export const Language = {
12
- errorSubmissionFailed : "Failed to update schedule" ,
13
- errorWorkspaceFetch : "Failed to fetch workspace" ,
14
11
successMessage : "Successfully updated workspace schedule." ,
15
12
}
16
13
17
14
type Permissions = Record < keyof ReturnType < typeof permissionsToCheck > , boolean >
18
15
19
16
export interface WorkspaceScheduleContext {
20
- formErrors ?: FieldErrors
21
17
getWorkspaceError ?: Error | unknown
22
18
/**
23
19
* Each workspace has their own schedule (start and ttl). For this reason, we
@@ -29,6 +25,7 @@ export interface WorkspaceScheduleContext {
29
25
userId ?: string
30
26
permissions ?: Permissions
31
27
checkPermissionsError ?: Error | unknown
28
+ submitScheduleError ?: Error | unknown
32
29
}
33
30
34
31
export const checks = {
@@ -86,7 +83,7 @@ export const workspaceSchedule = createMachine(
86
83
} ,
87
84
onError : {
88
85
target : "error" ,
89
- actions : [ "assignGetWorkspaceError" , "displayWorkspaceError" ] ,
86
+ actions : [ "assignGetWorkspaceError" ] ,
90
87
} ,
91
88
} ,
92
89
tags : "loading" ,
@@ -125,7 +122,7 @@ export const workspaceSchedule = createMachine(
125
122
} ,
126
123
onError : {
127
124
target : "presentForm" ,
128
- actions : [ "assignSubmissionError" , "displaySubmissionError" ] ,
125
+ actions : [ "assignSubmissionError" ] ,
129
126
} ,
130
127
} ,
131
128
tags : "loading" ,
@@ -145,7 +142,7 @@ export const workspaceSchedule = createMachine(
145
142
{
146
143
actions : {
147
144
assignSubmissionError : assign ( {
148
- formErrors : ( _ , event ) => mapApiErrorToFieldErrors ( ( event . data as ApiError ) . response . data ) ,
145
+ submitScheduleError : ( _ , event ) => event . data ,
149
146
} ) ,
150
147
assignWorkspace : assign ( {
151
148
workspace : ( _ , event ) => event . data ,
@@ -170,12 +167,6 @@ export const workspaceSchedule = createMachine(
170
167
clearGetWorkspaceError : ( context ) => {
171
168
assign ( { ...context , getWorkspaceError : undefined } )
172
169
} ,
173
- displayWorkspaceError : ( ) => {
174
- displayError ( Language . errorWorkspaceFetch )
175
- } ,
176
- displaySubmissionError : ( ) => {
177
- displayError ( Language . errorSubmissionFailed )
178
- } ,
179
170
displaySuccess : ( ) => {
180
171
displaySuccess ( Language . successMessage )
181
172
} ,
@@ -197,7 +188,7 @@ export const workspaceSchedule = createMachine(
197
188
submitSchedule : async ( context , event ) => {
198
189
if ( ! context . workspace ?. id ) {
199
190
// This state is theoretically impossible, but helps TS
200
- throw new Error ( "failed to load workspace" )
191
+ throw new Error ( "Failed to load workspace. " )
201
192
}
202
193
203
194
// REMARK: These calls are purposefully synchronous because if one
0 commit comments