Skip to content

feat(react. examples): add invitation hook, container, and example app#161

Open
rax7389 wants to merge 2 commits intofeat/mm-invitations-componentsfrom
feat/mm-invitations-hook-container
Open

feat(react. examples): add invitation hook, container, and example app#161
rax7389 wants to merge 2 commits intofeat/mm-invitations-componentsfrom
feat/mm-invitations-hook-container

Conversation

@rax7389
Copy link
Contributor

@rax7389 rax7389 commented Mar 14, 2026

Changes

Summary: Adds the central useOrganizationMemberManagement hook for state management, the OrganizationMemberManagement container component connecting the hook to the view layer, and example app integration with sidebar navigation.

Why: The presentational components from PR 3 are purely prop-driven. This PR provides the orchestration layer — a single hook that manages all invitation state (fetching, mutations, pagination, sorting, filtering, modals) and a container component that wires everything together. Separating the hook from the UI components keeps business logic testable and the view layer thin.

What:

*useOrganizationMemberManagement Hook *

Central hook managing all invitation lifecycle state via TanStack Query:

  • Data fetching — Queries for invitations (with checkpoint pagination tokens), roles, and identity providers via coreClient.getMyOrganizationApiClient().
  • Mutations — Create, revoke, and revoke-and-resend flows with ComponentAction hooks (onBefore/onAfter) and automatic query invalidation.
  • Checkpoint pagination — Token stack (previousTokens) for navigating back through cursor-based pages.
  • Server-side sorting — Maps table column keys to API sort fields (e.g., created_atcreated-at).
  • Race condition handlinguseRef request ID tracking for details fetch to discard stale responses.
  • Toast notifications — Success/error feedback for all mutation outcomes.
const { state, handlers } = useOrganizationMemberManagement({
  defaultTab: 'invitations',
  createInvitationAction: {
    onBefore: (data) => { console.log('Creating:', data); return true; },
    onAfter: (data, result) => console.log('Created:', result),
  },
  revokeInvitationAction: {
    onBefore: (invitation) => confirm(`Revoke ${invitation.invitee.email}?`),
  },
});

Key internal mappings for server-side sort:

const INVITATION_SORT_FIELD_MAP: Record<string, string> = {
  invitee: 'email',
  status: 'status',
  created_at: 'created-at',
  expires_at: 'expires-at',
  inviter: 'invited-by',
};

OrganizationMemberManagement Container Component

Connects the hook to the view layer with tab-based navigation (Members / Invitations), renders the invitation table and all modals (create, details, revoke, revoke-resend). Supports theming via getComponentStyles, readOnly mode, hideHeader, and custom CSS classes.

<OrganizationMemberManagement
  defaultTab="invitations"
  hideHeader={false}
  readOnly={false}
  createInvitationAction={{ onAfter: (data, result) => track('invite_sent') }}
  styling={{ classes: { 'OrganizationMemberManagement-root': 'my-custom-class' } }}
/>

Example App Integration

  • Added /member-management page to the next-rwa example app.
  • Added "Members & Invitations" sidebar link with Users icon.
  • Added sidebar.members i18n key.
// examples/next-rwa/src/app/member-management/page.tsx
export default function MemberManagementPage() {
  return (
    <div className="p-6 pt-8 space-y-6">
      <OrganizationMemberManagement defaultTab="members" />
    </div>
  );
}

Exports

  • Added OrganizationMemberManagement to components/index.ts
  • Added useOrganizationMemberManagement to hooks/index.ts

References

Part of the member management invitations feature.

Testing

  • This change adds unit test coverage

Integration tests are in PR 5.

  • This change has been tested on the latest version of the platform/language

Checklist

@rax7389 rax7389 force-pushed the feat/mm-invitations-components branch from 7b93170 to bf603bf Compare March 14, 2026 12:07
@rax7389 rax7389 force-pushed the feat/mm-invitations-hook-container branch from 2d3d1df to 312a1ae Compare March 14, 2026 12:07
@rax7389 rax7389 self-assigned this Mar 15, 2026
@rax7389 rax7389 added enhancement New feature or request examples Changes are limited to the examples folder. labels Mar 15, 2026
@rax7389 rax7389 changed the title feat(react): add invitation hook, container, and example app feat(react. examples): add invitation hook, container, and example app Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request examples Changes are limited to the examples folder.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant