Skip to content

Commit ba8c39c

Browse files
authored
fix(settings): show correct theme name on updateCustomTheme modal (@fehmer) (#7879)
fixes #7878
1 parent 542fc72 commit ba8c39c

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

frontend/src/ts/modals/simple-modals.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131

3232
import { GenerateDataRequest } from "@monkeytype/contracts/dev";
3333
import {
34+
CustomThemeNameSchema,
3435
PasswordSchema,
3536
UserEmailSchema,
3637
UserNameSchema,
@@ -40,6 +41,8 @@ import { z } from "zod";
4041
import { remoteValidation } from "../utils/remote-validation";
4142
import { list, PopupKey, showPopup } from "./simple-modals-base";
4243
import { getTheme } from "../states/theme";
44+
import { normalizeName } from "../utils/strings";
45+
import { IsValidResponse } from "../types/validation";
4346

4447
export { list, showPopup };
4548
export type { PopupKey };
@@ -972,6 +975,14 @@ list.unlinkDiscord = new SimpleModal({
972975
},
973976
});
974977

978+
const customThemeValidation = async (
979+
name: string,
980+
): Promise<IsValidResponse> => {
981+
const validationResult = CustomThemeNameSchema.safeParse(normalizeName(name));
982+
if (validationResult.success) return true;
983+
return validationResult.error.errors.map((err) => err.message).join(", ");
984+
};
985+
975986
list.updateCustomTheme = new SimpleModal({
976987
id: "updateCustomTheme",
977988
title: "Update custom theme",
@@ -980,6 +991,7 @@ list.updateCustomTheme = new SimpleModal({
980991
type: "text",
981992
placeholder: "name",
982993
initVal: "",
994+
validation: { isValid: customThemeValidation, debounceDelay: 0 },
983995
},
984996
{
985997
type: "checkbox",
@@ -1014,7 +1026,7 @@ list.updateCustomTheme = new SimpleModal({
10141026
: customTheme.colors;
10151027

10161028
const newTheme = {
1017-
name: name.replaceAll(" ", "_"),
1029+
name: normalizeName(name),
10181030
colors: newColors,
10191031
};
10201032
const validation = await DB.editCustomTheme(customTheme._id, newTheme);
@@ -1040,7 +1052,10 @@ list.updateCustomTheme = new SimpleModal({
10401052
(t) => t._id === _thisPopup.parameters[0],
10411053
);
10421054
if (!customTheme) return;
1043-
(_thisPopup.inputs[0] as TextInput).initVal = customTheme.name;
1055+
(_thisPopup.inputs[0] as TextInput).initVal = customTheme.name.replace(
1056+
/_/g,
1057+
" ",
1058+
);
10441059
},
10451060
});
10461061

0 commit comments

Comments
 (0)