Skip to content

Commit a64731e

Browse files
refactor: Add group badge to diff groups from users (#4478)
1 parent 934777d commit a64731e

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Story } from "@storybook/react"
2+
import { GroupAvatar, GroupAvatarProps } from "./GroupAvatar"
3+
4+
export default {
5+
title: "components/GroupAvatar",
6+
component: GroupAvatar,
7+
}
8+
9+
const Template: Story<GroupAvatarProps> = (args) => <GroupAvatar {...args} />
10+
11+
export const Example = Template.bind({})
12+
Example.args = {
13+
name: "My Group",
14+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import Avatar from "@material-ui/core/Avatar"
2+
import Badge from "@material-ui/core/Badge"
3+
import { withStyles } from "@material-ui/core/styles"
4+
import Group from "@material-ui/icons/Group"
5+
import { FC } from "react"
6+
import { firstLetter } from "util/firstLetter"
7+
8+
const StyledBadge = withStyles((theme) => ({
9+
badge: {
10+
backgroundColor: theme.palette.background.paper,
11+
border: `1px solid ${theme.palette.divider}`,
12+
borderRadius: "100%",
13+
width: 24,
14+
height: 24,
15+
display: "flex",
16+
alignItems: "center",
17+
justifyContent: "center",
18+
19+
"& svg": {
20+
width: 14,
21+
height: 14,
22+
},
23+
},
24+
}))(Badge)
25+
26+
export type GroupAvatarProps = {
27+
name: string
28+
}
29+
30+
export const GroupAvatar: FC<GroupAvatarProps> = ({ name }) => {
31+
return (
32+
<StyledBadge
33+
overlap="circular"
34+
anchorOrigin={{
35+
vertical: "bottom",
36+
horizontal: "right",
37+
}}
38+
badgeContent={<Group />}
39+
>
40+
<Avatar>{firstLetter(name)}</Avatar>
41+
</StyledBadge>
42+
)
43+
}

site/src/pages/GroupsPage/GroupsPageView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import React from "react"
2121
import { Link as RouterLink, useNavigate } from "react-router-dom"
2222
import { Paywall } from "components/Paywall/Paywall"
2323
import { Group } from "api/typesGenerated"
24+
import { GroupAvatar } from "components/GroupAvatar/GroupAvatar"
2425

2526
export type GroupsPageViewProps = {
2627
groups: Group[] | undefined
@@ -135,6 +136,7 @@ export const GroupsPageView: React.FC<GroupsPageViewProps> = ({
135136
>
136137
<TableCell>
137138
<AvatarData
139+
avatar={<GroupAvatar name={group.name} />}
138140
title={group.name}
139141
subtitle={`${group.members.length} members`}
140142
highlightTitle

site/src/pages/TemplatePage/TemplatePermissionsPage/TemplatePermissionsPageView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from "components/UserOrGroupAutocomplete/UserOrGroupAutocomplete"
2929
import { FC, useState } from "react"
3030
import { Maybe } from "components/Conditionals/Maybe"
31+
import { GroupAvatar } from "components/GroupAvatar/GroupAvatar"
3132

3233
type AddTemplateUserOrGroupProps = {
3334
organizationId: string
@@ -208,6 +209,7 @@ export const TemplatePermissionsPageView: FC<
208209
<TableRow key={group.id}>
209210
<TableCell>
210211
<AvatarData
212+
avatar={<GroupAvatar name={group.name} />}
211213
title={group.name}
212214
subtitle={`${group.members.length} members`}
213215
highlightTitle

site/src/testHelpers/entities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const MockUser: TypesGen.User = {
7373
status: "active",
7474
organization_ids: ["fc0774ce-cc9e-48d4-80ae-88f7a4d4a8b0"],
7575
roles: [MockOwnerRole],
76-
avatar_url: "https://github.com/coder.png",
76+
avatar_url: "https://avatars.githubusercontent.com/u/95932066?s=200&v=4",
7777
last_seen_at: "",
7878
}
7979

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy