fix(desktop): show the server's invalid handle error under the Handle field

The server now refuses a handle with spaces or invisible characters with
HANDLE_INVALID_CHARACTERS, a code added after the profile form mapped the
others, so it would have toasted English text. It now shows the translated
handle message under the field, like the form's own check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DIYgod
2026-10-12 23:53:45 +08:00
parent 48d55c9fba
commit add03e12f9
2 changed files with 15 additions and 6 deletions
@@ -36,6 +36,12 @@ describe("profileFormSchema", () => {
"Use at most 256 characters.",
)
})
test("refuses a handle with spaces or invisible characters, as the server does", () => {
for (const handle of ["Ta ken", "Taken\u200B", "\u202ETaken"]) {
expect(errorOf({ handle }), handle).toBe("Use only letters, numbers and underscores.")
}
})
})
describe("getProfileFieldError", () => {
@@ -52,6 +58,10 @@ describe("getProfileFieldError", () => {
field: "website",
message: "Use at most 256 characters.",
})
expect(getProfileFieldError("HANDLE_INVALID_CHARACTERS")).toEqual({
field: "handle",
message: "Use only letters, numbers and underscores.",
})
})
test("leaves other errors to the generic message", () => {
@@ -30,13 +30,10 @@ const withMaxLength = (schema: z.ZodString, field: ProfileTextField) =>
error: () => tooLongMessage(field),
})
const invalidHandleMessage = () => i18next.t("profile.handle.invalid", { ns: "settings" })
export const profileFormSchema = z.object({
handle: withMaxLength(
z
.string()
.regex(/^\w+$/, { error: () => i18next.t("profile.handle.invalid", { ns: "settings" }) }),
"handle",
)
handle: withMaxLength(z.string().regex(/^\w+$/, { error: invalidHandleMessage }), "handle")
.optional()
.or(z.literal("")),
name: withMaxLength(z.string().trim().min(1), "name"),
@@ -52,6 +49,8 @@ const SERVER_FIELD_ERRORS: Record<string, { field: ProfileTextField; message: ()
field: "handle",
message: () => i18next.t("profile.handle.taken", { ns: "settings" }),
},
// Spaces or invisible characters in a handle; the form's own check refuses them first
HANDLE_INVALID_CHARACTERS: { field: "handle", message: invalidHandleMessage },
NAME_CANNOT_BE_EMPTY: {
field: "name",
message: () => i18next.t("validation.required", { ns: "common" }),