Skip to content

Commit 3245e91

Browse files
fix(site): set default color and display error on appearance form (#9004)
1 parent bc862fa commit 3245e91

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

site/src/pages/DeploySettingsPage/AppearanceSettingsPage/AppearanceSettingsPageView.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Stack } from "components/Stack/Stack"
2121
import { useFormik } from "formik"
2222
import { useTheme } from "@mui/styles"
2323
import Link from "@mui/material/Link"
24+
import { colors } from "theme/colors"
2425

2526
export type AppearanceSettingsPageViewProps = {
2627
appearance: UpdateAppearanceConfig
@@ -53,7 +54,8 @@ export const AppearanceSettingsPageView = ({
5354
initialValues: {
5455
message: appearance.service_banner.message,
5556
enabled: appearance.service_banner.enabled,
56-
background_color: appearance.service_banner.background_color,
57+
background_color:
58+
appearance.service_banner.background_color ?? colors.blue[7],
5759
},
5860
onSubmit: (values) =>
5961
updateAppearance(

site/src/xServices/appearance/appearanceXService.ts

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { displaySuccess } from "components/GlobalSnackbar/utils"
1+
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils"
22
import { assign, createMachine } from "xstate"
33
import * as API from "../../api/api"
44
import { AppearanceConfig } from "../../api/typesGenerated"
5+
import { getErrorMessage } from "api/errors"
56

67
export type AppearanceContext = {
78
appearance?: AppearanceConfig
89
getAppearanceError?: unknown
9-
setAppearanceError?: unknown
1010
preview: boolean
1111
}
1212

@@ -39,11 +39,7 @@ export const appearanceMachine = createMachine(
3939
idle: {
4040
on: {
4141
SET_PREVIEW_APPEARANCE: {
42-
actions: [
43-
"clearGetAppearanceError",
44-
"clearSetAppearanceError",
45-
"assignPreviewAppearance",
46-
],
42+
actions: ["clearGetAppearanceError", "assignPreviewAppearance"],
4743
},
4844
SAVE_APPEARANCE: "savingAppearance",
4945
},
@@ -64,7 +60,6 @@ export const appearanceMachine = createMachine(
6460
},
6561
},
6662
savingAppearance: {
67-
entry: "clearSetAppearanceError",
6863
invoke: {
6964
id: "setAppearance",
7065
src: "setAppearance",
@@ -74,7 +69,11 @@ export const appearanceMachine = createMachine(
7469
},
7570
onError: {
7671
target: "idle",
77-
actions: ["assignSetAppearanceError"],
72+
actions: (_, error) => {
73+
displayError(
74+
getErrorMessage(error, "Failed to update appearance settings."),
75+
)
76+
},
7877
},
7978
},
8079
},
@@ -99,12 +98,6 @@ export const appearanceMachine = createMachine(
9998
clearGetAppearanceError: assign({
10099
getAppearanceError: (_) => undefined,
101100
}),
102-
assignSetAppearanceError: assign({
103-
setAppearanceError: (_, event) => event.data,
104-
}),
105-
clearSetAppearanceError: assign({
106-
setAppearanceError: (_) => undefined,
107-
}),
108101
},
109102
services: {
110103
getAppearance: async () => {

0 commit comments

Comments
 (0)