Skip to content

fix: search for invitation in members table#1457

Open
rsbh wants to merge 2 commits intomainfrom
fix_sdk_member_search
Open

fix: search for invitation in members table#1457
rsbh wants to merge 2 commits intomainfrom
fix_sdk_member_search

Conversation

@rsbh
Copy link
Member

@rsbh rsbh commented Mar 17, 2026

This PR fixes the search issue of invitations in the Members table.

When we show the members list, we merge it with invitations. so table can render both. But both the member and invitation have different fields, thus the search was not working.

The organization invitations api returns the user email in the userId field; thus, the search was not working.
This PR adds a field called email in invitations and maps it to the invitation userId.

@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Mar 17, 2026 0:02am

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Fixed email display for invited organization members to show correct email addresses consistently.
  • Refactor

    • Consolidated organization member data handling by streamlining state management logic.
    • Updated member data type definitions to support partial field requirements, providing greater flexibility.

Walkthrough

The changes refactor member invitations handling across the hook and UI layer. The MemberWithInvite type is relaxed to use Partial<User> and Partial<Invitation>, invitations state is consolidated into a single useMemo computation, and email resolution in member columns is simplified to always use the email property.

Changes

Cohort / File(s) Summary
Member Invitations Refactoring
web/sdk/react/hooks/useOrganizationMembers.ts, web/sdk/react/views/members/member-columns.tsx
Updated MemberWithInvite type to use Partial<User> & Partial<Invitation>. Consolidated invitations state and effect into single useMemo. Simplified email resolution in member columns to consistently use the email property.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls
Copy link

coveralls commented Mar 17, 2026

Pull Request Test Coverage Report for Build 23193189067

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 40.775%

Totals Coverage Status
Change from base Build 23189815517: 0.0%
Covered Lines: 14321
Relevant Lines: 35122

💛 - Coveralls

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
web/sdk/react/hooks/useOrganizationMembers.ts (2)

9-9: Type relaxation may break downstream type safety.

Changing MemberWithInvite to Partial<User> & Partial<Invitation> makes all fields optional, including id which is required for actual users. Downstream consumers (e.g., MembersActions accessing member.id for policy queries) lose compile-time guarantees that id exists for non-invitation members.

Consider a discriminated union to preserve type safety:

♻️ Suggested type definition
-export type MemberWithInvite = Partial<User> & Partial<Invitation> & { invited?: boolean };
+export type MemberWithInvite =
+  | (User & { invited?: false })
+  | (Invitation & { email: string; invited: true });

77-86: The email mapping is correct; consider removing the unsafe cast.

The logic to map userId to email for invitations correctly addresses the search issue. However, the as unknown as MemberWithInvite[] cast bypasses type checking entirely.

If the type definition is adjusted to a discriminated union (as suggested above), this cast becomes unnecessary and the code gains full type safety:

♻️ Suggested refactor
  const updatedUsers = useMemo(() => {
-   const invitations = (invitationsData?.invitations || []).map(user => {
-     return {
-       ...user,
-       email: user.userId,
-       invited: true
-     };
-   });
-   return [...users, ...invitations] as unknown as MemberWithInvite[];
+   const invitations: MemberWithInvite[] = (invitationsData?.invitations || []).map(inv => ({
+     ...inv,
+     email: inv.userId,
+     invited: true as const
+   }));
+   const userMembers: MemberWithInvite[] = users.map(u => ({ ...u, invited: false as const }));
+   return [...userMembers, ...invitations];
  }, [users, invitationsData?.invitations]);
web/sdk/react/views/members/member-columns.tsx (1)

67-67: Email access may be undefined with the relaxed type.

Since MemberWithInvite now uses Partial<User>, email is typed as optional. While the hook ensures both users and invitations have an email value at runtime, TypeScript won't catch cases where email might be undefined.

Consider adding a fallback for defensive rendering:

🛡️ Suggested defensive fallback
-     const email = row.original.email;
+     const email = row.original.email ?? row.original.userId ?? '';

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ef980a3d-3185-4fbc-8ae0-16a0a005ff1f

📥 Commits

Reviewing files that changed from the base of the PR and between 44a30fc and ea3f474.

📒 Files selected for processing (2)
  • web/sdk/react/hooks/useOrganizationMembers.ts
  • web/sdk/react/views/members/member-columns.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants