Unverified Commit eba23c4f authored by Zeng1998's avatar Zeng1998 Committed by GitHub

fix: add validation for user information update (#633)

parent 00fe6d38
...@@ -6,6 +6,14 @@ import { userService } from "../services"; ...@@ -6,6 +6,14 @@ import { userService } from "../services";
import Icon from "./Icon"; import Icon from "./Icon";
import { generateDialog } from "./Dialog"; import { generateDialog } from "./Dialog";
import toastHelper from "./Toast"; import toastHelper from "./Toast";
import { validate, ValidatorConfig } from "../helpers/validator";
const validateConfig: ValidatorConfig = {
minLength: 4,
maxLength: 320,
noSpace: true,
noChinese: true,
};
type Props = DialogProps; type Props = DialogProps;
...@@ -63,6 +71,12 @@ const UpdateAccountDialog: React.FC<Props> = ({ destroy }: Props) => { ...@@ -63,6 +71,12 @@ const UpdateAccountDialog: React.FC<Props> = ({ destroy }: Props) => {
return; return;
} }
const usernameValidResult = validate(state.username, validateConfig);
if (!usernameValidResult.result) {
toastHelper.error(t("common.username") + ": " + usernameValidResult.reason);
return;
}
try { try {
const user = userService.getState().user as User; const user = userService.getState().user as User;
const userPatch: UserPatch = { const userPatch: UserPatch = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment