11import { MemberList } from "./member-list" ;
22import { AddMemberButton } from "./add-member-button" ;
33import { User } from "@/types/user" ;
4+ import { Role } from "@/types/general" ;
45import { CoachingRelationshipWithUserNames } from "@/types/coaching_relationship_with_user_names" ;
56import { UserSession } from "@/types/user-session" ;
67
@@ -22,26 +23,27 @@ export function MemberContainer({
2223 /// Force the AddMemberDialog to open
2324 openAddMemberDialog,
2425} : MemberContainerProps ) {
25- // Check if current user is a coach in any relationship
26- const isCoachInAnyRelationship = relationships . some (
27- ( rel ) => rel . coach_id === userSession . id
28- ) ;
29-
30- // Find relationships where current user is either coach or coachee
31- const userRelationships = relationships . filter (
32- ( rel ) =>
33- rel . coach_id === userSession . id || rel . coachee_id === userSession . id
34- ) ;
26+ // Check if current user is a coach in any relationship
27+ const isCoachInAnyRelationship = relationships . some (
28+ ( rel ) => rel . coach_id === userSession . id
29+ ) ;
30+
31+ // Find relationships where current user is either coach or coachee
32+ const userRelationships = relationships . filter (
33+ ( rel ) =>
34+ rel . coach_id === userSession . id || rel . coachee_id === userSession . id
35+ ) ;
3536
3637 // Get IDs of users in these relationships
3738 const associatedUserIds = new Set (
3839 userRelationships . flatMap ( ( rel ) => [ rel . coach_id , rel . coachee_id ] )
3940 ) ;
4041
41- // Filter users to only include those in the relationships
42- const associatedUsers = users . filter ( ( user ) =>
43- associatedUserIds . has ( user . id )
44- ) ;
42+ // If the current user is an admin, show all users. Otherwise, only show users
43+ // that are associated with the current user in a coaching relationship.
44+ const displayUsers = ( userSession . role === Role . Admin ) ? users : users . filter ( ( user ) =>
45+ associatedUserIds . has ( user . id )
46+ ) ;
4547
4648 if ( isLoading ) {
4749 return (
@@ -54,17 +56,17 @@ export function MemberContainer({
5456 < div className = "flex justify-between items-center" >
5557 < h3 className = "text-2xl font-semibold" > Members</ h3 >
5658 { /* Only show the button if user is a coach to _some_ user within the
57- scope of the organization. We may come back and add this directly to user
59+ scope of the organization or if user is an admin . We may come back and add this directly to user
5860 data. */ }
59- { isCoachInAnyRelationship && (
61+ { ( isCoachInAnyRelationship || userSession . role === Role . Admin ) && (
6062 < AddMemberButton
6163 onMemberAdded = { onRefresh }
6264 openAddMemberDialog = { openAddMemberDialog }
6365 />
6466 ) }
6567 </ div >
6668 < MemberList
67- users = { associatedUsers }
69+ users = { displayUsers }
6870 relationships = { userRelationships }
6971 onRefresh = { onRefresh }
7072 />
0 commit comments