fix: update user fields

This commit is contained in:
Steven
2024-07-23 22:18:49 +08:00
parent b1051418c6
commit 6920313b77
4 changed files with 23 additions and 13 deletions

View File

@ -46,10 +46,13 @@ const ChangePasswordDialog: React.FC<Props> = (props: Props) => {
requestState.setLoading();
try {
userStore.patchUser({
id: userStore.getCurrentUser().id,
password: newPassword,
});
userStore.patchUser(
{
id: userStore.getCurrentUser().id,
password: newPassword,
},
["password"],
);
onClose();
toast("Password changed");
} catch (error: any) {

View File

@ -97,16 +97,20 @@ const CreateUserDialog: React.FC<Props> = (props: Props) => {
const userPatch: Partial<User> = {
id: user.id,
};
const updateMask: string[] = [];
if (user.email !== state.userCreate.email) {
userPatch.email = state.userCreate.email;
updateMask.push("email");
}
if (user.nickname !== state.userCreate.nickname) {
userPatch.nickname = state.userCreate.nickname;
updateMask.push("nickname");
}
if (user.role !== state.userCreate.role) {
userPatch.role = state.userCreate.role;
updateMask.push("role");
}
await userStore.patchUser(userPatch);
await userStore.patchUser(userPatch, updateMask);
} else {
await userStore.createUser(state.userCreate);
}

View File

@ -41,11 +41,14 @@ const EditUserinfoDialog: React.FC<Props> = (props: Props) => {
requestState.setLoading();
try {
await userStore.patchUser({
id: currentUser.id,
email,
nickname,
});
await userStore.patchUser(
{
id: currentUser.id,
email,
nickname,
},
["email", "nickname"],
);
onClose();
toast("User information updated");
} catch (error: any) {