Skip to content

Commit

Permalink
#575 fix user save
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Sep 9, 2022
1 parent 8005177 commit 73fca00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_users(query: str) -> typing.List[User]:


def map_user(kc_user) -> User:
user = User.from_dict(kc_user._raw_dict)
user = kc_user if isinstance(kc_user, dict) else User.from_dict(kc_user._raw_dict)
if 'attributes' not in kc_user or not kc_user['attributes']:
kc_user['attributes'] = {}

Expand All @@ -73,7 +73,7 @@ def map_user(kc_user) -> User:
return user


def update_user(userid, user: User):
def update_user(userid, user: User):
client = AuthClient()

try:
Expand All @@ -85,15 +85,15 @@ def update_user(userid, user: User):
'firstName': user.first_name or current_user['firstName'],
'lastName': user.last_name or current_user['lastName'],
'attributes': {
**current_user.get('attributes', {}),
**(current_user.get('attributes') or {}),
**({('profile--' + k): user.profiles[k] for k in user.profiles} if user.profiles else {}),
'avatar': user.avatar,
'website': user.website
}
}

admin_client.update_user(userid, updated_user)
return map_user({**current_user, **updated_user})
return get_user(userid)
except KeycloakError as e:
if e.response_code == 404:
raise UserNotFound(userid)
Expand Down
16 changes: 4 additions & 12 deletions applications/osb-portal/src/pages/UserPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,12 @@ export const UserPage = (props: any) => {
const handleUpdateUser = (u: User) => {
setLoading(true);
setProfileEditDialogOpen(false);
setUser(u);
updateUser(userProfileForm).then((updatedUser) => {
console.log('user should be updated');
updateUser(userProfileForm).then((updatedUser) => {
setUser(updatedUser);
setLoading(false);
window.location.reload();
}).catch((err) => {
setLoading(false);
console.log('error updating user', err);
console.error('error updating user', err);
setError({ ...error, general: `An error occurred updating the user. Please try again later.` })
});

Expand Down Expand Up @@ -370,13 +368,7 @@ export const UserPage = (props: any) => {
{loading &&
<CircularProgress
size={24}
style={{
position: 'absolute',
top: '50%',
left: '50%',
marginTop: -12,
marginLeft: -12,
}}

/>
}
</Box >
Expand Down

0 comments on commit 73fca00

Please sign in to comment.