feat: integrate user team retrieval into session components, enhancing sharing functionality and user experience across motivators, sessions, weekly check-ins, and year reviews
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m35s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m35s
This commit is contained in:
37
src/lib/share-utils.ts
Normal file
37
src/lib/share-utils.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Shared utilities for share modals across workshop types.
|
||||
*/
|
||||
|
||||
export interface TeamMemberUser {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
}
|
||||
|
||||
export interface TeamWithMembers {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
userRole?: 'ADMIN' | 'MEMBER';
|
||||
members?: { user: TeamMemberUser }[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten team members from all teams, dedupe by userId, exclude current user.
|
||||
*/
|
||||
export function getTeamMembersForShare(
|
||||
userTeams: TeamWithMembers[],
|
||||
currentUserId: string
|
||||
): TeamMemberUser[] {
|
||||
const seen = new Set<string>();
|
||||
return (
|
||||
userTeams
|
||||
.flatMap((t) => t.members ?? [])
|
||||
.map((m) => m.user)
|
||||
.filter((u) => {
|
||||
if (u.id === currentUserId || seen.has(u.id)) return false;
|
||||
seen.add(u.id);
|
||||
return true;
|
||||
})
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user