Skip to content

Comments

fix: update resend invitation handler to follow auto accept#24447

Merged
anikdhabal merged 2 commits intomainfrom
resend-Invitation
Oct 14, 2025
Merged

fix: update resend invitation handler to follow auto accept#24447
anikdhabal merged 2 commits intomainfrom
resend-Invitation

Conversation

@anikdhabal
Copy link
Contributor

@anikdhabal anikdhabal commented Oct 14, 2025

What does this PR do?

Follow up to this:- #24091

@graphite-app graphite-app bot requested a review from a team October 14, 2025 09:41
@keithwillcode keithwillcode added the core area: core, team members only label Oct 14, 2025
@anikdhabal anikdhabal enabled auto-merge (squash) October 14, 2025 09:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

Walkthrough

Adds imports for prisma and UserRepository and updates resendInvitation.handler.ts to change invite-link generation when a verification token exists. Instead of always using a teams join link, the handler now defaults to an auth login/signup flow with a settings callback. If a user with the target email exists and has completed onboarding (determined via UserRepository), the handler uses a teams join link with the token and autoAccept; otherwise it falls back to a signup/login link with the token and a callback to /getting-started and marks the recipient as not a CAL member. Token-expiration error handling is preserved.

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description Check ❓ Inconclusive The description only notes that this PR is a follow-up to a previous pull request and does not summarize the specific changes, rationale, or testing details, making it too vague to inform reviewers about the scope or purpose of this update. Please update the description to include a concise summary of what this PR changes, why those changes were made, and any instructions needed to test or verify the new behavior.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely describes the primary change by stating that the resend invitation handler is being updated to follow the auto-accept behavior, which matches the core functionality adjustments made in the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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 resend-Invitation

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.

dhairyashiil
dhairyashiil previously approved these changes Oct 14, 2025
@dosubot dosubot bot added teams area: teams, round robin, collective, managed event-types 🐛 bug Something isn't working labels Oct 14, 2025
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: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between dac1069 and a8b4c61.

📒 Files selected for processing (1)
  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: anglerfishlyy
PR: calcom/cal.com#0
File: :0-0
Timestamp: 2025-08-27T16:39:38.192Z
Learning: anglerfishlyy successfully implemented CAL-3076 email invitation feature for Cal.com team event-types in PR #23312. The feature allows inviting people via email directly from assignment flow, with automatic team invitation if email doesn't belong to existing team member. Implementation includes Host type modifications (userId?: number, email?: string, isPending?: boolean), CheckedTeamSelect component updates with CreatableSelect, TRPC schema validation with zod email validation, and integration with existing teamInvite system.
Learnt from: anglerfishlyy
PR: calcom/cal.com#0
File: :0-0
Timestamp: 2025-09-16T08:59:45.884Z
Learning: anglerfishlyy's PR #23467 demonstrates excellent software architecture with proper email validation (regex + zod), secure token generation using randomBytes, comprehensive host type system using discriminated unions (userId OR email), and smart reuse of existing team invitation infrastructure. The implementation includes robust error handling, type safety, and maintains backward compatibility while adding CreatableSelect-based email invitation functionality.
📚 Learning: 2025-08-27T16:39:38.192Z
Learnt from: anglerfishlyy
PR: calcom/cal.com#0
File: :0-0
Timestamp: 2025-08-27T16:39:38.192Z
Learning: anglerfishlyy successfully implemented CAL-3076 email invitation feature for Cal.com team event-types in PR #23312. The feature allows inviting people via email directly from assignment flow, with automatic team invitation if email doesn't belong to existing team member. Implementation includes Host type modifications (userId?: number, email?: string, isPending?: boolean), CheckedTeamSelect component updates with CreatableSelect, TRPC schema validation with zod email validation, and integration with existing teamInvite system.

Applied to files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
📚 Learning: 2025-09-16T08:59:45.884Z
Learnt from: anglerfishlyy
PR: calcom/cal.com#0
File: :0-0
Timestamp: 2025-09-16T08:59:45.884Z
Learning: anglerfishlyy's PR #23467 demonstrates excellent software architecture with proper email validation (regex + zod), secure token generation using randomBytes, comprehensive host type system using discriminated unions (userId OR email), and smart reuse of existing team invitation infrastructure. The implementation includes robust error handling, type safety, and maintains backward compatibility while adding CreatableSelect-based email invitation functionality.

Applied to files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
🔇 Additional comments (2)
packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts (2)

6-6: LGTM!

The new imports for prisma and UserRepository are appropriate for the added user lookup functionality.

Also applies to: 10-10


42-42: Verify the default joinLink behavior when verification token is absent.

The default joinLink now points to /auth/login?callbackUrl=/settings/teams instead of a direct teams URL. This default is used when the verification token update fails (lines 37-39 catch the error but continue execution). Please confirm this is the intended fallback behavior.

Run the following script to check how the verification token is handled elsewhere and what the previous default might have been:

@vercel
Copy link

vercel bot commented Oct 14, 2025

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

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Oct 14, 2025 9:50am
cal-eu Ignored Ignored Oct 14, 2025 9:50am

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: 0

♻️ Duplicate comments (1)
packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts (1)

48-59: Preserve auto‑accept flow on repo error and set isAutoJoin when used.

If the lookup throws, we drop the tokenized path and may break auto‑accept. Also, when using autoAccept=true, set isAutoJoin = true to align template/UI.

-      if (user?.completedOnboarding) {
-        inviteTeamOptions.joinLink = `${WEBAPP_URL}/teams?token=${verificationToken.token}&autoAccept=true`;
-      } else {
-        inviteTeamOptions.joinLink = `${WEBAPP_URL}/signup?token=${verificationToken.token}&callbackUrl=/getting-started`;
-        inviteTeamOptions.isCalcomMember = false;
-      }
+      if (user?.completedOnboarding) {
+        inviteTeamOptions.joinLink = `${WEBAPP_URL}/teams?token=${encodeURIComponent(verificationToken.token)}&autoAccept=true`;
+        inviteTeamOptions.isAutoJoin = true;
+      } else {
+        inviteTeamOptions.joinLink = `${WEBAPP_URL}/signup?token=${encodeURIComponent(verificationToken.token)}&callbackUrl=${encodeURIComponent("/getting-started")}`;
+        inviteTeamOptions.isCalcomMember = false;
+        inviteTeamOptions.isAutoJoin = false;
+      }
     } catch (error) {
-      console.error("[resendInvitationHandler] Error fetching user: ", error);
+      console.error("[resendInvitationHandler] Error fetching user: ", error);
+      // Fallback: treat as not onboarded to keep tokenized flow working
+      inviteTeamOptions.joinLink = `${WEBAPP_URL}/signup?token=${encodeURIComponent(verificationToken.token)}&callbackUrl=${encodeURIComponent("/getting-started")}`;
+      inviteTeamOptions.isCalcomMember = false;
+      inviteTeamOptions.isAutoJoin = false;
     }

Optional: prefer the project logger over console.error if available.

🧹 Nitpick comments (2)
packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts (2)

42-42: URL‑encode token and callbackUrl in links.

Avoid surprises with special characters; encode query params.

-    joinLink: `${WEBAPP_URL}/auth/login?callbackUrl=/settings/teams`,
+    joinLink: `${WEBAPP_URL}/auth/login?callbackUrl=${encodeURIComponent("/settings/teams")}`,
@@
-        inviteTeamOptions.joinLink = `${WEBAPP_URL}/teams?token=${verificationToken.token}&autoAccept=true`;
+        inviteTeamOptions.joinLink = `${WEBAPP_URL}/teams?token=${encodeURIComponent(verificationToken.token)}&autoAccept=true`;
@@
-        inviteTeamOptions.joinLink = `${WEBAPP_URL}/signup?token=${verificationToken.token}&callbackUrl=/getting-started`;
+        inviteTeamOptions.joinLink = `${WEBAPP_URL}/signup?token=${encodeURIComponent(verificationToken.token)}&callbackUrl=${encodeURIComponent("/getting-started")}`;

Also applies to: 52-53, 54-55


81-81: Avoid default export; prefer named export.

You already export a named resendInvitationHandler. Drop the default export to align with repo guidelines.

As per coding guidelines

-export default resendInvitationHandler;
+// Prefer named exports only

Ensure import sites don’t rely on the default export before applying.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a8b4c61 and ff57fdc.

📒 Files selected for processing (1)
  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: anglerfishlyy
PR: calcom/cal.com#0
File: :0-0
Timestamp: 2025-08-27T16:39:38.192Z
Learning: anglerfishlyy successfully implemented CAL-3076 email invitation feature for Cal.com team event-types in PR #23312. The feature allows inviting people via email directly from assignment flow, with automatic team invitation if email doesn't belong to existing team member. Implementation includes Host type modifications (userId?: number, email?: string, isPending?: boolean), CheckedTeamSelect component updates with CreatableSelect, TRPC schema validation with zod email validation, and integration with existing teamInvite system.
Learnt from: anglerfishlyy
PR: calcom/cal.com#0
File: :0-0
Timestamp: 2025-09-16T08:59:45.884Z
Learning: anglerfishlyy's PR #23467 demonstrates excellent software architecture with proper email validation (regex + zod), secure token generation using randomBytes, comprehensive host type system using discriminated unions (userId OR email), and smart reuse of existing team invitation infrastructure. The implementation includes robust error handling, type safety, and maintains backward compatibility while adding CreatableSelect-based email invitation functionality.
📚 Learning: 2025-08-27T16:39:38.192Z
Learnt from: anglerfishlyy
PR: calcom/cal.com#0
File: :0-0
Timestamp: 2025-08-27T16:39:38.192Z
Learning: anglerfishlyy successfully implemented CAL-3076 email invitation feature for Cal.com team event-types in PR #23312. The feature allows inviting people via email directly from assignment flow, with automatic team invitation if email doesn't belong to existing team member. Implementation includes Host type modifications (userId?: number, email?: string, isPending?: boolean), CheckedTeamSelect component updates with CreatableSelect, TRPC schema validation with zod email validation, and integration with existing teamInvite system.

Applied to files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
📚 Learning: 2025-09-16T08:59:45.884Z
Learnt from: anglerfishlyy
PR: calcom/cal.com#0
File: :0-0
Timestamp: 2025-09-16T08:59:45.884Z
Learning: anglerfishlyy's PR #23467 demonstrates excellent software architecture with proper email validation (regex + zod), secure token generation using randomBytes, comprehensive host type system using discriminated unions (userId OR email), and smart reuse of existing team invitation infrastructure. The implementation includes robust error handling, type safety, and maintains backward compatibility while adding CreatableSelect-based email invitation functionality.

Applied to files:

  • packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
🧬 Code graph analysis (1)
packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts (1)
packages/lib/constants.ts (1)
  • WEBAPP_URL (12-18)
🔇 Additional comments (1)
packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts (1)

2-2: UserRepository.findByEmail uses select only—complies with guidelines.

@anikdhabal anikdhabal merged commit 243012e into main Oct 14, 2025
38 of 39 checks passed
@anikdhabal anikdhabal deleted the resend-Invitation branch October 14, 2025 10:13
@github-actions
Copy link
Contributor

E2E results are ready!

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

Labels

🐛 bug Something isn't working core area: core, team members only ready-for-e2e size/S teams area: teams, round robin, collective, managed event-types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants