mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-08 08:25:05 +08:00
impr: parse username locally before querying the server
also fixes non user friendly error messages !nuf
This commit is contained in:
parent
313897d0d1
commit
7f4cf76141
1 changed files with 9 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ import * as Skeleton from "../utils/skeleton";
|
|||
import * as Misc from "../utils/misc";
|
||||
import TypoList from "../utils/typo-list";
|
||||
import { z } from "zod";
|
||||
import { UserNameSchema } from "@monkeytype/contracts/users";
|
||||
|
||||
export function enableSignUpButton(): void {
|
||||
$(".page.pageLogin .register.side button").prop("disabled", false);
|
||||
|
|
@ -59,6 +60,14 @@ const checkNameDebounced = debounce(1000, async () => {
|
|||
updateSignupButton();
|
||||
return;
|
||||
}
|
||||
|
||||
const parsed = UserNameSchema.safeParse(val);
|
||||
if (!parsed.success) {
|
||||
nameIndicator.show("unavailable", parsed.error.errors[0]?.message);
|
||||
updateSignupButton();
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await Ape.users.getNameAvailability({
|
||||
params: { name: val },
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue