|
1 | 1 | import { sendTeamInviteEmail } from "@calcom/emails"; |
| 2 | +import { UserRepository } from "@calcom/features/users/repositories/UserRepository"; |
2 | 3 | import { WEBAPP_URL } from "@calcom/lib/constants"; |
3 | 4 | import { getTranslation } from "@calcom/lib/server/i18n"; |
4 | 5 | import { VerificationTokenRepository } from "@calcom/lib/server/repository/verificationToken"; |
| 6 | +import { prisma } from "@calcom/prisma"; |
5 | 7 | import type { TrpcSessionUser } from "@calcom/trpc/server/types"; |
6 | 8 |
|
7 | 9 | import { ensureAtleastAdminPermissions, getTeamOrThrow } from "./inviteMember/utils"; |
@@ -37,15 +39,24 @@ export const resendInvitationHandler = async ({ ctx, input }: InviteMemberOption |
37 | 39 | } |
38 | 40 |
|
39 | 41 | const inviteTeamOptions = { |
40 | | - joinLink: `${WEBAPP_URL}/teams?token=${verificationToken?.token}&autoAccept=true`, |
| 42 | + joinLink: `${WEBAPP_URL}/auth/login?callbackUrl=/settings/teams`, |
41 | 43 | isCalcomMember: true, |
42 | 44 | isAutoJoin: false, |
43 | 45 | }; |
44 | 46 |
|
45 | 47 | if (verificationToken) { |
46 | | - // Token only exists if user is CAL user but hasn't completed onboarding. |
47 | | - inviteTeamOptions.joinLink = `${WEBAPP_URL}/signup?token=${verificationToken.token}&callbackUrl=/getting-started`; |
48 | | - inviteTeamOptions.isCalcomMember = false; |
| 48 | + try { |
| 49 | + const user = await new UserRepository(prisma).findByEmail({ email: input.email }); |
| 50 | + |
| 51 | + if (user?.completedOnboarding) { |
| 52 | + inviteTeamOptions.joinLink = `${WEBAPP_URL}/teams?token=${verificationToken.token}&autoAccept=true`; |
| 53 | + } else { |
| 54 | + inviteTeamOptions.joinLink = `${WEBAPP_URL}/signup?token=${verificationToken.token}&callbackUrl=/getting-started`; |
| 55 | + inviteTeamOptions.isCalcomMember = false; |
| 56 | + } |
| 57 | + } catch (error) { |
| 58 | + console.error("[resendInvitationHandler] Error fetching user: ", error); |
| 59 | + } |
49 | 60 | } |
50 | 61 |
|
51 | 62 | const translation = await getTranslation(input.language ?? "en", "common"); |
|
0 commit comments