app: Add the group memberships

This commit is contained in:
Valentin Tolmer 2021-09-15 09:27:32 +02:00 committed by nitnelave
parent 718da71d0d
commit a54e73bded
2 changed files with 41 additions and 11 deletions

View File

@ -6,5 +6,8 @@ query GetUserDetails($id: String!) {
firstName firstName
lastName lastName
creationDate creationDate
groups {
id
}
} }
} }

View File

@ -134,19 +134,24 @@ impl UserDetails {
Ok(_) => { Ok(_) => {
ConsoleService::log("Successfully updated user"); ConsoleService::log("Successfully updated user");
self.update_successful = true; self.update_successful = true;
let user = self.user.as_ref().unwrap(); let User {
id,
display_name,
first_name,
last_name,
email,
creation_date,
groups,
} = self.user.take().unwrap();
let new_user = self.update_request.take().unwrap(); let new_user = self.update_request.take().unwrap();
self.user = Some(User { self.user = Some(User {
id: user.id.clone(), id,
email: new_user.email.unwrap_or_else(|| user.email.clone()), email: new_user.email.unwrap_or(email),
display_name: new_user display_name: new_user.displayName.unwrap_or(display_name),
.displayName first_name: new_user.firstName.unwrap_or(first_name),
.unwrap_or_else(|| user.display_name.clone()), last_name: new_user.lastName.unwrap_or(last_name),
first_name: new_user creation_date,
.firstName groups,
.unwrap_or_else(|| user.first_name.clone()),
last_name: new_user.lastName.unwrap_or_else(|| user.last_name.clone()),
creation_date: user.creation_date,
}); });
} }
}; };
@ -209,6 +214,15 @@ impl Component for UserDetails {
} }
fn view(&self) -> Html { fn view(&self) -> Html {
type Group = get_user_details::GetUserDetailsUserGroups;
let make_group_row = |group: &Group| {
html! {
<tr>
<td><button>{"-"}</button></td>
<td>{&group.id}</td>
</tr>
}
};
match (&self.user, &self.error) { match (&self.user, &self.error) {
(None, None) => html! {{"Loading..."}}, (None, None) => html! {{"Loading..."}},
(None, Some(e)) => html! {<div>{"Error: "}{e.to_string()}</div>}, (None, Some(e)) => html! {<div>{"Error: "}{e.to_string()}</div>},
@ -253,6 +267,19 @@ impl Component for UserDetails {
</div> </div>
} }
} else { html! {} }} } else { html! {} }}
<div>
<span>{"Group memberships"}</span>
<table>
<tr>
<th></th>
<th>{"Group"}</th>
</tr>
{u.groups.iter().map(make_group_row).collect::<Vec<_>>()}
<tr>
<td><button>{"+"}</button></td>
</tr>
</table>
</div>
<div> <div>
<NavButton route=AppRoute::ChangePassword(self.username.clone())>{"Change password"}</NavButton> <NavButton route=AppRoute::ChangePassword(self.username.clone())>{"Change password"}</NavButton>
</div> </div>