Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Display error
  • Loading branch information
BrunoQuaresma committed Aug 9, 2023
commit 8f17bdf92d18de8615d4f53c87c74e786c9c185b
23 changes: 8 additions & 15 deletions site/src/xServices/appearance/appearanceXService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { displaySuccess } from "components/GlobalSnackbar/utils"
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils"
import { assign, createMachine } from "xstate"
import * as API from "../../api/api"
import { AppearanceConfig } from "../../api/typesGenerated"
import { getErrorMessage } from "api/errors"

export type AppearanceContext = {
appearance?: AppearanceConfig
getAppearanceError?: unknown
setAppearanceError?: unknown
preview: boolean
}

Expand Down Expand Up @@ -39,11 +39,7 @@ export const appearanceMachine = createMachine(
idle: {
on: {
SET_PREVIEW_APPEARANCE: {
actions: [
"clearGetAppearanceError",
"clearSetAppearanceError",
"assignPreviewAppearance",
],
actions: ["clearGetAppearanceError", "assignPreviewAppearance"],
},
SAVE_APPEARANCE: "savingAppearance",
},
Expand All @@ -64,7 +60,6 @@ export const appearanceMachine = createMachine(
},
},
savingAppearance: {
entry: "clearSetAppearanceError",
invoke: {
id: "setAppearance",
src: "setAppearance",
Expand All @@ -74,7 +69,11 @@ export const appearanceMachine = createMachine(
},
onError: {
target: "idle",
actions: ["assignSetAppearanceError"],
actions: (_, error) => {
displayError(
getErrorMessage(error, "Failed to update appearance settings."),
)
},
},
},
},
Expand All @@ -99,12 +98,6 @@ export const appearanceMachine = createMachine(
clearGetAppearanceError: assign({
getAppearanceError: (_) => undefined,
}),
assignSetAppearanceError: assign({
setAppearanceError: (_, event) => event.data,
}),
clearSetAppearanceError: assign({
setAppearanceError: (_) => undefined,
}),
},
services: {
getAppearance: async () => {
Expand Down