File tree 6 files changed +39
-14
lines changed
pages/UserSettingsPage/AccountPage
6 files changed +39
-14
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ declare module "@storybook/react" {
16
16
interface Parameters {
17
17
features ?: FeatureName [ ] ;
18
18
experiments ?: Experiments ;
19
+ showOrganizations ?: boolean ;
19
20
queries ?: { key : QueryKey ; data : unknown } [ ] ;
20
21
webSocket ?: WebSocketEvent [ ] ;
21
22
user ?: User ;
Original file line number Diff line number Diff line change @@ -1603,8 +1603,15 @@ class ApiMethods {
1603
1603
return response . data ;
1604
1604
} ;
1605
1605
1606
- getGroups = async ( ) : Promise < TypesGen . Group [ ] > => {
1607
- const response = await this . axios . get ( "/api/v2/groups" ) ;
1606
+ getGroups = async (
1607
+ options : { userId ?: string } = { } ,
1608
+ ) : Promise < TypesGen . Group [ ] > => {
1609
+ const params : Record < string , string > = { } ;
1610
+ if ( options . userId !== undefined ) {
1611
+ params . has_member = options . userId ;
1612
+ }
1613
+
1614
+ const response = await this . axios . get ( "/api/v2/groups" , { params } ) ;
1608
1615
return response . data ;
1609
1616
} ;
1610
1617
Original file line number Diff line number Diff line change @@ -74,15 +74,9 @@ export function groupsByUserId() {
74
74
75
75
export function groupsForUser ( userId : string ) {
76
76
return {
77
- ...groups ( ) ,
78
- select : ( allGroups ) => {
79
- const groupsForUser = allGroups . filter ( ( group ) =>
80
- group . members . some ( ( member ) => member . id === userId ) ,
81
- ) ;
82
-
83
- return sortGroupsByName ( groupsForUser , "asc" ) ;
84
- } ,
85
- } as const satisfies UseQueryOptions < Group [ ] , unknown , readonly Group [ ] > ;
77
+ queryKey : groupsQueryKey ,
78
+ queryFn : ( ) => API . getGroups ( { userId } ) ,
79
+ } as const satisfies UseQueryOptions < Group [ ] > ;
86
80
}
87
81
88
82
export const groupPermissionsKey = ( groupId : string ) => [
Original file line number Diff line number Diff line change 4
4
MockUser ,
5
5
mockApiError ,
6
6
} from "testHelpers/entities" ;
7
+ import { withDashboardProvider } from "testHelpers/storybook" ;
7
8
import { AccountUserGroups } from "./AccountUserGroups" ;
8
9
9
10
const MockGroup2 = {
@@ -24,13 +25,20 @@ const meta: Meta<typeof AccountUserGroups> = {
24
25
groups : [ MockGroup1 , MockGroup2 ] ,
25
26
loading : false ,
26
27
} ,
28
+ decorators : [ withDashboardProvider ] ,
27
29
} ;
28
30
29
31
export default meta ;
30
32
type Story = StoryObj < typeof AccountUserGroups > ;
31
33
32
34
export const Example : Story = { } ;
33
35
36
+ export const ExampleWithOrganizations : Story = {
37
+ parameters : {
38
+ showOrganizations : true ,
39
+ } ,
40
+ } ;
41
+
34
42
export const NoGroups : Story = {
35
43
args : {
36
44
groups : [ ] ,
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import type { Group } from "api/typesGenerated";
5
5
import { ErrorAlert } from "components/Alert/ErrorAlert" ;
6
6
import { AvatarCard } from "components/AvatarCard/AvatarCard" ;
7
7
import { Loader } from "components/Loader/Loader" ;
8
+ import { useDashboard } from "modules/dashboard/useDashboard" ;
8
9
import type { FC } from "react" ;
9
10
import { Section } from "../Section" ;
10
11
@@ -20,6 +21,7 @@ export const AccountUserGroups: FC<AccountGroupsProps> = ({
20
21
loading,
21
22
} ) => {
22
23
const theme = useTheme ( ) ;
24
+ const { showOrganizations } = useDashboard ( ) ;
23
25
24
26
return (
25
27
< Section
@@ -55,7 +57,16 @@ export const AccountUserGroups: FC<AccountGroupsProps> = ({
55
57
imgUrl = { group . avatar_url }
56
58
altText = { group . display_name || group . name }
57
59
header = { group . display_name || group . name }
58
- subtitle = { group . organization_display_name }
60
+ subtitle = {
61
+ showOrganizations ? (
62
+ group . organization_display_name
63
+ ) : (
64
+ < >
65
+ { group . total_member_count } member
66
+ { group . total_member_count !== 1 && "s" }
67
+ </ >
68
+ )
69
+ }
59
70
/>
60
71
</ Grid >
61
72
) ) }
Original file line number Diff line number Diff line change @@ -20,7 +20,11 @@ export const withDashboardProvider = (
20
20
Story : FC ,
21
21
{ parameters } : StoryContext ,
22
22
) => {
23
- const { features = [ ] , experiments = [ ] } = parameters ;
23
+ const {
24
+ features = [ ] ,
25
+ experiments = [ ] ,
26
+ showOrganizations = false ,
27
+ } = parameters ;
24
28
25
29
const entitlements : Entitlements = {
26
30
...MockEntitlements ,
@@ -42,7 +46,7 @@ export const withDashboardProvider = (
42
46
experiments,
43
47
appearance : MockAppearanceConfig ,
44
48
organizations : [ MockDefaultOrganization ] ,
45
- showOrganizations : false ,
49
+ showOrganizations,
46
50
} }
47
51
>
48
52
< Story />
You can’t perform that action at this time.
0 commit comments