Skip to content

Commit

Permalink
fix: user patch with empty email (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack authored Nov 25, 2022
1 parent 88c3b1a commit b511a7b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch user request").SetInternal(err)
}

if userPatch.Email != nil && !common.ValidateEmail(*userPatch.Email) {
if userPatch.Email != nil && *userPatch.Email != "" && !common.ValidateEmail(*userPatch.Email) {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid email format")
}

Expand Down
18 changes: 13 additions & 5 deletions web/src/components/UpdateAccountDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isEqual } from "lodash";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useAppSelector } from "../store";
Expand Down Expand Up @@ -64,12 +65,19 @@ const UpdateAccountDialog: React.FC<Props> = ({ destroy }: Props) => {

try {
const user = userService.getState().user as User;
await userService.patchUser({
const userPatch: UserPatch = {
id: user.id,
username: state.username,
nickname: state.nickname,
email: state.email,
});
};
if (!isEqual(user.nickname, state.nickname)) {
userPatch.nickname = state.nickname;
}
if (!isEqual(user.username, state.username)) {
userPatch.username = state.username;
}
if (!isEqual(user.email, state.email)) {
userPatch.email = state.email;
}
await userService.patchUser(userPatch);
toastHelper.info("Update succeed");
handleCloseBtnClick();
} catch (error: any) {
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/UserBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const UserBanner = () => {
</div>
<Dropdown
trigger={<Icon.MoreHorizontal className="ml-2 w-5 h-auto cursor-pointer" />}
actionsClassName="!w-36"
actionsClassName="min-w-36"
actions={
<>
{!userService.isVisitorMode() && (
Expand Down

0 comments on commit b511a7b

Please sign in to comment.