fix: make theme logic safe and add better e2e tests (#16959)

* fix: improve theme logic

* remove null from ThemeLabelProps value

* add better e2e tests
This commit is contained in:
Benny Joo authored and GitHub committed 2024-10-07 11:23:30 +01:00
1 parent b0bfec7247
commit 21dd44733f
6 files changed
+127 -23

No files matched your search

@@ -192,15 +192,21 @@ const AppearanceView = ({
</div>
<Form
form={userAppThemeFormMethods}
handleSubmit={(values) => {
handleSubmit={({ appTheme }) => {
if (appTheme === "light" || appTheme === "dark") {
mutation.mutate({
appTheme,
});
return;
}
mutation.mutate({
appTheme: values.appTheme === "" ? null : values.appTheme,
appTheme: null,
});
}}>
<div className="border-subtle flex flex-col justify-between border-x px-6 py-8 sm:flex-row">
<ThemeLabel
variant="system"
value={undefined}
value="system"
label={t("theme_system")}
defaultChecked={user.appTheme === null}
register={userAppThemeFormMethods.register}
@@ -244,17 +250,21 @@ const AppearanceView = ({
</div>
<Form
form={userThemeFormMethods}
handleSubmit={(values) => {
handleSubmit={({ theme }) => {
if (theme === "light" || theme === "dark") {
mutation.mutate({
theme,
});
return;
}
mutation.mutate({
// Radio values don't support null as values, therefore we convert an empty string
// back to null here.
theme: values.theme === "" ? null : values.theme,
theme: null,
});
}}>
<div className="border-subtle flex flex-col justify-between border-x px-6 py-8 sm:flex-row">
<ThemeLabel
variant="system"
value={undefined}
value="system"
label={t("theme_system")}
defaultChecked={user.theme === null}
register={userThemeFormMethods.register}