Skip to content

Conversation

@reneshen0328
Copy link
Contributor

@reneshen0328 reneshen0328 commented Oct 23, 2025

What

  • Render notifications based on the sendInvitations callbacks API result
  • Fix issue so that user is able to invite external users by free typing the email in the collaborator invite combobox

Testing

  • When all invitations are sent successfully
    • Screenshot 2025-10-22 at 5 48 07 PM
    • Screenshot 2025-10-22 at 5 48 25 PM
  • When none of the invitations are sent
    • Screenshot 2025-10-22 at 5 48 43 PM
    • Screenshot 2025-10-22 at 5 49 01 PM
  • When some of the invitations are sent
    • Screenshot 2025-10-22 at 5 49 50 PM

Summary by CodeRabbit

  • New Features

    • Localized, plural-aware success and error notifications for invitation handling showing correct invited counts.
  • Tests

    • Expanded coverage for notification rendering and intl usage; added cases for all-success, mixed results, all-failure, and empty/null outcomes.
  • Refactor

    • Improved collaborator conversion to include avatar URL mapping and broadened handling of non-group contacts.

@reneshen0328 reneshen0328 requested review from a team as code owners October 23, 2025 00:19
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Walkthrough

Adds localized invitation notifications, threads avatar URL mapping into collaborator conversion, updates collaborator-type handling for non-group contacts, and expands tests to assert formatted notification messages; includes a minor formatting change in contact avatar utility.

Changes

Cohort / File(s) Summary
Internationalization & notification flow
src/elements/content-sharing/hooks/useSharingService.ts, src/elements/content-sharing/messages.js
Added useIntl/formatMessage usage and two new message descriptors (sendInvitationsError, sendInvitationsSuccess); introduced handleSendInvitations wrapper and a sendInvitations path that returns localized notification objects or null based on invite results.
Collaborator conversion & avatar URL mapping
src/elements/content-sharing/utils/convertCollaborators.ts, src/elements/content-sharing/utils/__tests__/convertCollaborators.test.ts
Moved avatarUrlMap into the top-level destructure for convertCollab, passed avatarUrlMap through convertCollabsResponse/call sites, broadened non-group handling to treat contacts without explicit type as users, and updated tests to include avatarUrlMap and cover type-less contacts.
Test updates for notifications
src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts
Added a mockFormatMessage for react-intl, renamed suites to handleSendInvitations, and added tests verifying success/mixed/error/null notification rendering and formatMessage usage.
Minor formatting change
src/elements/content-sharing/hooks/useContactService.ts
Rewrote a guard in getContactsAvatarUrls to use a block {} instead of a single-line return; no behavioral change.

Sequence Diagram(s)

sequenceDiagram
    participant App as Component
    participant Hook as useSharingService
    participant Invites as useInvites
    participant Intl as formatMessage

    App->>Hook: handleSendInvitations(contacts)
    Hook->>Invites: sendInvites(...)
    Invites-->>Hook: result {succeeded[], failed[]} / null

    alt result is null
        Hook-->>App: null
    else
        alt all succeeded
            Hook->>Intl: format(sendInvitationsSuccess, {count})
            Intl-->>Hook: localized success text
            Hook-->>App: { success: { text } }
        else some failed
            Hook->>Intl: format(sendInvitationsError, {countFailed})
            Intl-->>Hook: localized error text
            Hook->>Intl: format(sendInvitationsSuccess, {countSucceeded})
            Intl-->>Hook: localized success text
            Hook-->>App: { error: { text }, success: { text } }
        else all failed
            Hook->>Intl: format(sendInvitationsError, {count})
            Intl-->>Hook: localized error text
            Hook-->>App: { error: { text } }
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • tjuanitas
  • jfox-box

Poem

🐰
I hopped through code with nimble paws,
Messages shaped with plural laws,
Avatars matched to every name,
Tests applaud the localized claim,
Rabbit cheers — invites take flight! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "feat(content-sharing): Render notification for sendInvitations" is directly aligned with the primary objective of the changeset. The raw_summary confirms that the main focus is rendering notifications for the sendInvitations API, and the title accurately reflects this core purpose. The title uses conventional commit format with a clear scope and type, is concise and readable, and provides enough specificity that a teammate reviewing the history would immediately understand the primary change.
Description Check ✅ Passed The PR description provides a well-structured overview with a "## What" section that clearly explains the two main objectives (rendering notifications based on API results and fixing email-based user invitation), and a "## Testing" section with screenshots demonstrating the functionality across three scenarios (all successful, all failed, and mixed results). While the provided template is primarily merge process guidance rather than a prescriptive change description structure, the author has included this guidance at the end and supplemented it with substantive information about changes and testing, making the description complete and informative.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch render-sendInvitations-notification

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b23b98 and 689a752.

⛔ Files ignored due to path filters (1)
  • i18n/en-US.properties is excluded by !i18n/**
📒 Files selected for processing (2)
  • src/elements/content-sharing/hooks/useSharingService.ts (3 hunks)
  • src/elements/content-sharing/messages.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/elements/content-sharing/hooks/useSharingService.ts (2)
src/elements/content-sharing/utils/convertCollaborators.ts (1)
  • convertCollabsRequest (84-120)
src/elements/content-sharing/messages.js (1)
  • messages (3-81)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint_test_build
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Summary
🔇 Additional comments (3)
src/elements/content-sharing/messages.js (1)

62-75: LGTM! Plural-aware messages implemented correctly.

The new sendInvitationsError and sendInvitationsSuccess messages are properly formatted with plural support and are now integrated into the notification rendering flow in useSharingService.ts. The whitespace within the plural clauses is correct, avoiding the leading/trailing whitespace issue.

The coexistence with the older sendInvites* messages is appropriate since they serve different use cases—the new messages provide count-aware plural formatting while the older ones remain for existing code paths.

src/elements/content-sharing/hooks/useSharingService.ts (2)

2-2: LGTM! Internationalization support added correctly.

The integration of useIntl and message imports properly enables localized notification rendering for the invitation flow.

Also applies to: 9-10, 25-26


86-86: LGTM! Avatar URL map correctly threaded through.

Passing avatarUrlMap to convertCollab aligns with the updated function signature and ensures avatar URLs are available during collaborator conversion.


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.

Copy link
Contributor

@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.

Actionable comments posted: 3

🧹 Nitpick comments (7)
src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts (3)

239-257: Good coverage for useInvites wiring.

Asserting isContentSharingV2Enabled: true, handleSuccess, and transformRequest is sufficient. Consider also asserting the exact itemType for folders in the folder block for symmetry.


311-331: All-success path covered; consider asserting single message.

Add expect(sendInvitationsResult.messages).toHaveLength(1); to guard against accidental extra notifications.


100-116: Rename test titles for accuracy.

They assert that API instances aren’t created and that a “sendInvitations-only” sharingService is returned, not that sharingService is null. Rename for clarity (no behavior change).

src/elements/content-sharing/utils/__tests__/convertCollaborators.test.ts (1)

308-345: Missing-type contacts treated as users.

Test correctly validates that non-group contacts without type are added as users. Ensure server-side validations still prevent unintended external invites where policy disallows them.

If policies exist, add a test ensuring external domains are rejected at a higher layer.

src/elements/content-sharing/messages.js (1)

62-74: Normalize ICU plural message formatting.

Minor: remove extra spaces after “{” and before “}” for consistency with our ICU style.

-        defaultMessage:
-            '{ count, plural, one { An invitation to join this item was not sent.} other { {count} invitations to join this item were not sent.}}',
+        defaultMessage:
+            '{count, plural, one {An invitation to join this item was not sent.} other {{count} invitations to join this item were not sent.}}',
src/elements/content-sharing/utils/convertCollaborators.ts (2)

9-15: Fix type-safety and equality checks in ConvertCollabProps.

ownerEmailDomain can be null; currentUserId may be string or number; strict === can miscompare. Update types and compare as strings.

Apply this diff:

 export interface ConvertCollabProps {
-    collab: Collaboration;
-    currentUserId: string;
+    collab: Collaboration;
+    currentUserId: string | number;
     isCurrentUserOwner: boolean;
-    ownerEmailDomain: string;
+    ownerEmailDomain: string | null;
     avatarUrlMap?: AvatarURLMap;
 }
@@
-    const isCurrentUser = collabId === currentUserId;
+    const isCurrentUser = String(collabId) === String(currentUserId);

Consider aligning upstream types for currentUserId and accessible_by.id to the same primitive to avoid future coercions.

Also applies to: 17-23, 33-37


54-59: Broaden owner id typing to match actual data.

Owner ids can be numeric. Loosen the type to avoid down-stream casts.

-export const convertCollabsResponse = (
+export const convertCollabsResponse = (
     collabsApiData: Collaborations,
-    currentUserId: string,
-    owner: { id: string; email: string; name: string },
+    currentUserId: string | number,
+    owner: { id: string | number; email: string; name: string },
     avatarUrlMap?: AvatarURLMap,
 ): Collaborator[] => {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 051319c and b1d1d44.

⛔ Files ignored due to path filters (1)
  • i18n/en-US.properties is excluded by !i18n/**
📒 Files selected for processing (6)
  • src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts (3 hunks)
  • src/elements/content-sharing/hooks/useContactService.ts (1 hunks)
  • src/elements/content-sharing/hooks/useSharingService.ts (3 hunks)
  • src/elements/content-sharing/messages.js (1 hunks)
  • src/elements/content-sharing/utils/__tests__/convertCollaborators.test.ts (6 hunks)
  • src/elements/content-sharing/utils/convertCollaborators.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/elements/content-sharing/hooks/useSharingService.ts (3)
src/elements/content-sharing/SharingNotification.js (1)
  • newCollab (240-244)
src/elements/content-sharing/utils/convertCollaborators.ts (1)
  • convertCollabsRequest (84-120)
src/elements/content-sharing/messages.js (1)
  • messages (3-80)
src/elements/content-sharing/utils/convertCollaborators.ts (1)
src/elements/content-sharing/constants.js (2)
  • COLLAB_USER_TYPE (85-85)
  • COLLAB_USER_TYPE (85-85)
src/elements/content-sharing/utils/__tests__/convertCollaborators.test.ts (2)
src/elements/content-sharing/utils/__mocks__/ContentSharingV2Mocks.js (4)
  • mockAvatarUrlMap (30-32)
  • mockAvatarUrlMap (30-32)
  • mockOwnerId (36-36)
  • mockOwnerId (36-36)
src/elements/content-sharing/utils/convertCollaborators.ts (2)
  • convertCollab (17-52)
  • convertCollabsRequest (84-120)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint_test_build
  • GitHub Check: Summary
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
src/elements/content-sharing/hooks/useContactService.ts (1)

28-30: LGTM! Good formatting practice.

Adding braces to the single-line conditional improves maintainability and follows best practices, preventing potential bugs during future modifications.

src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts (2)

13-19: Intl mock looks good; reset behavior is correct.

jest.clearAllMocks() resets mockFormatMessage calls between tests. No changes needed.


332-357: Partial-success ordering verified.

Nice use of toHaveBeenNthCalledWith to lock message order. LGTM.

src/elements/content-sharing/utils/__tests__/convertCollaborators.test.ts (1)

67-73: Avatar URL map propagation verified.

Passing avatarUrlMap into convertCollab across cases is correct and aligns with implementation. LGTM.

Also applies to: 92-99, 104-112, 116-123, 140-148, 154-164, 173-181

src/elements/content-sharing/hooks/useSharingService.ts (1)

25-26: Intl + avatarUrlMap + useInvites wiring is sound.

Threading avatarUrlMap, adding formatMessage, and passing transformRequest are correct. LGTM.

Also applies to: 86-91, 97-103

src/elements/content-sharing/utils/convertCollaborators.ts (1)

108-116: Non-group → user fallback is correct.

This addresses missing type on contacts and supports free-typed emails. LGTM.

Copy link
Contributor

@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.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1d1d44 and 1b23b98.

⛔ Files ignored due to path filters (1)
  • i18n/en-US.properties is excluded by !i18n/**
📒 Files selected for processing (2)
  • src/elements/content-sharing/hooks/useSharingService.ts (3 hunks)
  • src/elements/content-sharing/messages.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/elements/content-sharing/hooks/useSharingService.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint_test_build
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Summary

@mergify mergify bot merged commit 051bd7c into master Oct 23, 2025
10 checks passed
@mergify mergify bot deleted the render-sendInvitations-notification branch October 23, 2025 18:57
@mergify mergify bot removed the queued label Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants