mirror of
https://github.com/usememos/memos.git
synced 2025-10-19 02:37:19 +08:00
fix: add validation for user information update (#633)
This commit is contained in:
parent
00fe6d3862
commit
eba23c4f6e
1 changed files with 14 additions and 0 deletions
|
@ -6,6 +6,14 @@ import { userService } from "../services";
|
|||
import Icon from "./Icon";
|
||||
import { generateDialog } from "./Dialog";
|
||||
import toastHelper from "./Toast";
|
||||
import { validate, ValidatorConfig } from "../helpers/validator";
|
||||
|
||||
const validateConfig: ValidatorConfig = {
|
||||
minLength: 4,
|
||||
maxLength: 320,
|
||||
noSpace: true,
|
||||
noChinese: true,
|
||||
};
|
||||
|
||||
type Props = DialogProps;
|
||||
|
||||
|
@ -63,6 +71,12 @@ const UpdateAccountDialog: React.FC<Props> = ({ destroy }: Props) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const usernameValidResult = validate(state.username, validateConfig);
|
||||
if (!usernameValidResult.result) {
|
||||
toastHelper.error(t("common.username") + ": " + usernameValidResult.reason);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const user = userService.getState().user as User;
|
||||
const userPatch: UserPatch = {
|
||||
|
|
Loading…
Add table
Reference in a new issue