mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-20 14:01:24 +00:00
fix: update user fields
This commit is contained in:
parent
b1051418c6
commit
6920313b77
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -16,7 +16,7 @@ interface UserState {
|
||||
getCurrentUser: () => User;
|
||||
setCurrentUserId: (id: number) => void;
|
||||
createUser: (create: Partial<User>) => Promise<User>;
|
||||
patchUser: (userPatch: Partial<User>) => Promise<void>;
|
||||
patchUser: (userPatch: Partial<User>, updateMask: string[]) => Promise<void>;
|
||||
deleteUser: (id: number) => Promise<void>;
|
||||
|
||||
// User setting related actions.
|
||||
@ -75,10 +75,10 @@ const useUserStore = create<UserState>()((set, get) => ({
|
||||
set(userMap);
|
||||
return user;
|
||||
},
|
||||
patchUser: async (userPatch: Partial<User>) => {
|
||||
patchUser: async (userPatch: Partial<User>, updateMask: string[]) => {
|
||||
const { user } = await userServiceClient.updateUser({
|
||||
user: userPatch,
|
||||
updateMask: ["email", "nickname"],
|
||||
updateMask: updateMask,
|
||||
});
|
||||
if (!user) {
|
||||
throw new Error("User not found");
|
||||
|
Loading…
x
Reference in New Issue
Block a user