Skip to content

feat: add list of user's groups to Accounts page #10522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Nov 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
00d819f
chore: add query for a user's groups
Parkreiner Nov 1, 2023
1d646eb
chore: integrate user groups into UI
Parkreiner Nov 1, 2023
024879d
refactor: split UI card into separate component
Parkreiner Nov 2, 2023
102b1e0
chore: enforce alt text for AvatarCard
Parkreiner Nov 2, 2023
e8c713c
chore: add proper alt text support for Avatar
Parkreiner Nov 2, 2023
22e9573
fix: update props for Avatar call sites
Parkreiner Nov 2, 2023
acf2500
finish AccountPage changes
Parkreiner Nov 2, 2023
f4b9a63
wip: commit progress on AvatarCard
Parkreiner Nov 2, 2023
426260d
fix: add better UI error handling
Parkreiner Nov 3, 2023
fecf41e
fix: update theme setup for AvatarCard
Parkreiner Nov 3, 2023
831d110
fix: update styling for AccountPage
Parkreiner Nov 3, 2023
69fab82
fix: make error message conditional
Parkreiner Nov 3, 2023
f7cffd1
chore: update styling for AvatarCard
Parkreiner Nov 3, 2023
2e43d5f
chore: finish AvatarCard
Parkreiner Nov 3, 2023
7c322fa
fix: add maxWidth support to AvatarCard
Parkreiner Nov 3, 2023
b92c5f7
chore: update how no max width is defined
Parkreiner Nov 3, 2023
d5b5323
chore: add AvatarCard stories
Parkreiner Nov 3, 2023
43ae56b
fix: remove incorrect semantics for AvatarCard
Parkreiner Nov 6, 2023
ba57fff
docs: add comment about flexbox behavior
Parkreiner Nov 6, 2023
387c033
docs: add clarifying text about prop
Parkreiner Nov 6, 2023
7dcddbf
fix: fix grammar for singular groups
Parkreiner Nov 6, 2023
68ae492
refactor: split off AccountUserGroups and add story
Parkreiner Nov 6, 2023
d56a9cc
fix: differentiate mock groups more
Parkreiner Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: integrate user groups into UI
  • Loading branch information
Parkreiner committed Nov 1, 2023
commit 1d646eba2b37fe09932e194c9c4c4feb07610e3c
86 changes: 71 additions & 15 deletions site/src/pages/UserSettingsPage/AccountPage/AccountPage.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,86 @@
import { FC } from "react";
import { type FC } from "react";
import { Section } from "components/SettingsLayout/Section";
import { AccountForm } from "./AccountForm";
import { useAuth } from "components/AuthProvider/AuthProvider";
import { useMe } from "hooks/useMe";
import { usePermissions } from "hooks/usePermissions";
import { Stack } from "@mui/system";
import { useQuery } from "react-query";
import { groupsForUser } from "api/queries/groups";
import { useOrganizationId } from "hooks";
import { useTheme } from "@emotion/react";
import { Loader } from "components/Loader/Loader";
import { Group } from "api/typesGenerated";

export const AccountPage: FC = () => {
const theme = useTheme();
const { updateProfile, updateProfileError, isUpdatingProfile } = useAuth();
const me = useMe();
const permissions = usePermissions();
const canEditUsers = permissions && permissions.updateUsers;

const me = useMe();
const organizationId = useOrganizationId();
const groupsQuery = useQuery(groupsForUser(organizationId, me.id));

return (
<Section title="Account" description="Update your account info">
<AccountForm
editable={Boolean(canEditUsers)}
email={me.email}
updateProfileError={updateProfileError}
isLoading={isUpdatingProfile}
initialValues={{
username: me.username,
}}
onSubmit={updateProfile}
/>
</Section>
<Stack spacing={6}>
<Section title="Account" description="Update your account info">
<AccountForm
editable={permissions?.updateUsers ?? false}
email={me.email}
updateProfileError={updateProfileError}
isLoading={isUpdatingProfile}
initialValues={{ username: me.username }}
onSubmit={updateProfile}
/>
</Section>

<Section
title="Your groups"
layout="fluid"
description={
groupsQuery.isSuccess && (
<span>
You are in{" "}
<em
css={{
fontStyle: "normal",
color: theme.palette.text.primary,
fontWeight: 600,
}}
>
{groupsQuery.data.length} groups
</em>
</span>
)
}
>
{groupsQuery.isSuccess ? (
<GroupList groups={groupsQuery.data} />
) : (
<Loader />
)}
</Section>
</Stack>
);
};

type GroupListProps = {
groups: readonly Group[];
};

function GroupList({ groups }: GroupListProps) {
const theme = useTheme();

return (
<>
{groups.map((group) => (
<div key={group.id} css={{ backgroundColor: "blue" }}>
<span>{group.display_name || group.name}</span>
<span>{group.members.length} members</span>
</div>
))}
</>
);
}

export default AccountPage;