Skip to content
Open
Changes from all commits
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
19 changes: 17 additions & 2 deletions frontend/src/ts/modals/simple-modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {

import { GenerateDataRequest } from "@monkeytype/contracts/dev";
import {
CustomThemeNameSchema,
PasswordSchema,
UserEmailSchema,
UserNameSchema,
Expand All @@ -40,6 +41,8 @@ import { z } from "zod";
import { remoteValidation } from "../utils/remote-validation";
import { list, PopupKey, showPopup } from "./simple-modals-base";
import { getTheme } from "../states/theme";
import { normalizeName } from "../utils/strings";
import { IsValidResponse } from "../types/validation";

export { list, showPopup };
export type { PopupKey };
Expand Down Expand Up @@ -972,6 +975,14 @@ list.unlinkDiscord = new SimpleModal({
},
});

const customThemeValidation = async (
name: string,
): Promise<IsValidResponse> => {
const validationResult = CustomThemeNameSchema.safeParse(normalizeName(name));
if (validationResult.success) return true;
return validationResult.error.errors.map((err) => err.message).join(", ");
};

list.updateCustomTheme = new SimpleModal({
id: "updateCustomTheme",
title: "Update custom theme",
Expand All @@ -980,6 +991,7 @@ list.updateCustomTheme = new SimpleModal({
type: "text",
placeholder: "name",
initVal: "",
validation: { isValid: customThemeValidation, debounceDelay: 0 },
},
{
type: "checkbox",
Expand Down Expand Up @@ -1014,7 +1026,7 @@ list.updateCustomTheme = new SimpleModal({
: customTheme.colors;

const newTheme = {
name: name.replaceAll(" ", "_"),
name: normalizeName(name),
colors: newColors,
};
const validation = await DB.editCustomTheme(customTheme._id, newTheme);
Expand All @@ -1040,7 +1052,10 @@ list.updateCustomTheme = new SimpleModal({
(t) => t._id === _thisPopup.parameters[0],
);
if (!customTheme) return;
(_thisPopup.inputs[0] as TextInput).initVal = customTheme.name;
(_thisPopup.inputs[0] as TextInput).initVal = customTheme.name.replace(
/_/g,
" ",
);
},
});

Expand Down
Loading