1
- import { displaySuccess } from "components/GlobalSnackbar/utils"
1
+ import { displayError , displaySuccess } from "components/GlobalSnackbar/utils"
2
2
import { assign , createMachine } from "xstate"
3
3
import * as API from "../../api/api"
4
4
import { AppearanceConfig } from "../../api/typesGenerated"
5
+ import { getErrorMessage } from "api/errors"
5
6
6
7
export type AppearanceContext = {
7
8
appearance ?: AppearanceConfig
8
9
getAppearanceError ?: unknown
9
- setAppearanceError ?: unknown
10
10
preview : boolean
11
11
}
12
12
@@ -39,11 +39,7 @@ export const appearanceMachine = createMachine(
39
39
idle : {
40
40
on : {
41
41
SET_PREVIEW_APPEARANCE : {
42
- actions : [
43
- "clearGetAppearanceError" ,
44
- "clearSetAppearanceError" ,
45
- "assignPreviewAppearance" ,
46
- ] ,
42
+ actions : [ "clearGetAppearanceError" , "assignPreviewAppearance" ] ,
47
43
} ,
48
44
SAVE_APPEARANCE : "savingAppearance" ,
49
45
} ,
@@ -64,7 +60,6 @@ export const appearanceMachine = createMachine(
64
60
} ,
65
61
} ,
66
62
savingAppearance : {
67
- entry : "clearSetAppearanceError" ,
68
63
invoke : {
69
64
id : "setAppearance" ,
70
65
src : "setAppearance" ,
@@ -74,7 +69,11 @@ export const appearanceMachine = createMachine(
74
69
} ,
75
70
onError : {
76
71
target : "idle" ,
77
- actions : [ "assignSetAppearanceError" ] ,
72
+ actions : ( _ , error ) => {
73
+ displayError (
74
+ getErrorMessage ( error , "Failed to update appearance settings." ) ,
75
+ )
76
+ } ,
78
77
} ,
79
78
} ,
80
79
} ,
@@ -99,12 +98,6 @@ export const appearanceMachine = createMachine(
99
98
clearGetAppearanceError : assign ( {
100
99
getAppearanceError : ( _ ) => undefined ,
101
100
} ) ,
102
- assignSetAppearanceError : assign ( {
103
- setAppearanceError : ( _ , event ) => event . data ,
104
- } ) ,
105
- clearSetAppearanceError : assign ( {
106
- setAppearanceError : ( _ ) => undefined ,
107
- } ) ,
108
101
} ,
109
102
services : {
110
103
getAppearance : async ( ) => {
0 commit comments