diff --git a/src/lib/team-api.ts b/src/lib/team-api.ts index 5877d2b..85187fa 100644 --- a/src/lib/team-api.ts +++ b/src/lib/team-api.ts @@ -72,7 +72,7 @@ const initialsOf = (name: string) => /* ---- be-crm DTO types (subset used here) -------------------------------- */ interface RoleRef { id: string; slug: string; name: string; color: string | null; isSystem: boolean; isOwnerRole: boolean } -interface MemberDTO { id: string; principalId: string; jobTitle: string | null; joinedAt: string; status: "active" | "deactivated"; roles: RoleRef[]; openDeals: number } +interface MemberDTO { id: string; principalId: string; jobTitle: string | null; joinedAt: string; status: "active" | "deactivated"; roles: RoleRef[]; openDeals: number; email?: string | null; firstName?: string | null; lastName?: string | null; displayName?: string | null } interface RoleDTO { id: string; slug: string; name: string; description: string | null; color: string | null; isSystem: boolean; isOwnerRole: boolean; permissions: string[]; memberCount: number } interface InvitationDTO { id: string; email: string; roles: RoleRef[]; invitedBy: string; createdAt: string; token?: string } @@ -158,12 +158,16 @@ function useLiveTeam(): TeamData { const members: UiMember[] = useMemo(() => (membersQ.data?.items ?? []).map((m) => { const isYou = !!meId && m.principalId === meId; - const name = isYou && user?.displayName - ? user.displayName - : (m.jobTitle?.trim() || `Member ${m.principalId.replace(/^pp_/, "").slice(0, 6)}`); + // Prefer the member's real name/email from their CRM registration; fall back to the + // ACE (for the current user), then job title, then a short principal id. + const name = m.displayName?.trim() + || (isYou && user?.displayName) + || m.jobTitle?.trim() + || `Member ${m.principalId.replace(/^pp_/, "").slice(0, 6)}`; + const email = m.email || (isYou ? user?.email : undefined) || ""; return { id: m.id, principalId: m.principalId, name, initials: initialsOf(name), - email: isYou && user?.email ? user.email : m.principalId, + email, title: m.jobTitle ?? "", roleIds: m.roles.map((r) => r.id), gradient: gradientFor(m.id), status: (m.status === "active" ? "active" : "offline") as UiStatus, lastActive: m.status === "active" ? "Active" : "—",