mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-20 22:07:15 +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();
|
requestState.setLoading();
|
||||||
try {
|
try {
|
||||||
userStore.patchUser({
|
userStore.patchUser(
|
||||||
id: userStore.getCurrentUser().id,
|
{
|
||||||
password: newPassword,
|
id: userStore.getCurrentUser().id,
|
||||||
});
|
password: newPassword,
|
||||||
|
},
|
||||||
|
["password"],
|
||||||
|
);
|
||||||
onClose();
|
onClose();
|
||||||
toast("Password changed");
|
toast("Password changed");
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -97,16 +97,20 @@ const CreateUserDialog: React.FC<Props> = (props: Props) => {
|
|||||||
const userPatch: Partial<User> = {
|
const userPatch: Partial<User> = {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
};
|
};
|
||||||
|
const updateMask: string[] = [];
|
||||||
if (user.email !== state.userCreate.email) {
|
if (user.email !== state.userCreate.email) {
|
||||||
userPatch.email = state.userCreate.email;
|
userPatch.email = state.userCreate.email;
|
||||||
|
updateMask.push("email");
|
||||||
}
|
}
|
||||||
if (user.nickname !== state.userCreate.nickname) {
|
if (user.nickname !== state.userCreate.nickname) {
|
||||||
userPatch.nickname = state.userCreate.nickname;
|
userPatch.nickname = state.userCreate.nickname;
|
||||||
|
updateMask.push("nickname");
|
||||||
}
|
}
|
||||||
if (user.role !== state.userCreate.role) {
|
if (user.role !== state.userCreate.role) {
|
||||||
userPatch.role = state.userCreate.role;
|
userPatch.role = state.userCreate.role;
|
||||||
|
updateMask.push("role");
|
||||||
}
|
}
|
||||||
await userStore.patchUser(userPatch);
|
await userStore.patchUser(userPatch, updateMask);
|
||||||
} else {
|
} else {
|
||||||
await userStore.createUser(state.userCreate);
|
await userStore.createUser(state.userCreate);
|
||||||
}
|
}
|
||||||
|
@ -41,11 +41,14 @@ const EditUserinfoDialog: React.FC<Props> = (props: Props) => {
|
|||||||
|
|
||||||
requestState.setLoading();
|
requestState.setLoading();
|
||||||
try {
|
try {
|
||||||
await userStore.patchUser({
|
await userStore.patchUser(
|
||||||
id: currentUser.id,
|
{
|
||||||
email,
|
id: currentUser.id,
|
||||||
nickname,
|
email,
|
||||||
});
|
nickname,
|
||||||
|
},
|
||||||
|
["email", "nickname"],
|
||||||
|
);
|
||||||
onClose();
|
onClose();
|
||||||
toast("User information updated");
|
toast("User information updated");
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -16,7 +16,7 @@ interface UserState {
|
|||||||
getCurrentUser: () => User;
|
getCurrentUser: () => User;
|
||||||
setCurrentUserId: (id: number) => void;
|
setCurrentUserId: (id: number) => void;
|
||||||
createUser: (create: Partial<User>) => Promise<User>;
|
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>;
|
deleteUser: (id: number) => Promise<void>;
|
||||||
|
|
||||||
// User setting related actions.
|
// User setting related actions.
|
||||||
@ -75,10 +75,10 @@ const useUserStore = create<UserState>()((set, get) => ({
|
|||||||
set(userMap);
|
set(userMap);
|
||||||
return user;
|
return user;
|
||||||
},
|
},
|
||||||
patchUser: async (userPatch: Partial<User>) => {
|
patchUser: async (userPatch: Partial<User>, updateMask: string[]) => {
|
||||||
const { user } = await userServiceClient.updateUser({
|
const { user } = await userServiceClient.updateUser({
|
||||||
user: userPatch,
|
user: userPatch,
|
||||||
updateMask: ["email", "nickname"],
|
updateMask: updateMask,
|
||||||
});
|
});
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error("User not found");
|
throw new Error("User not found");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user