fix: update resend invitation handler to follow auto accept#24447
fix: update resend invitation handler to follow auto accept#24447anikdhabal merged 2 commits intomainfrom
Conversation
WalkthroughAdds imports for Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
📒 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 useinclude, always useselect
Ensure thecredential.keyfield 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
prismaandUserRepositoryare 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
joinLinknow points to/auth/login?callbackUrl=/settings/teamsinstead 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:
packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts
Outdated
Show resolved
Hide resolved
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
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, setisAutoJoin = trueto 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.errorif 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 onlyEnsure 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.
📒 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 useinclude, always useselect
Ensure thecredential.keyfield 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 usesselectonly—complies with guidelines.
E2E results are ready! |
What does this PR do?
Follow up to this:- #24091