Skip to content

Commit 94e0d47

Browse files
authored
fix: skip plan on invite to team (calcom#25924)
* fix: skip plan on invite to team * address cubic
1 parent 45fcabe commit 94e0d47

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

apps/web/modules/onboarding/getting-started/onboarding-view.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AnimatePresence } from "framer-motion";
44
import { useRouter } from "next/navigation";
55
import { useEffect, useRef, useTransition } from "react";
66

7+
import { useTeamInvites } from "@calcom/features/billing/hooks/useHasPaidPlan";
78
import { isCompanyEmail } from "@calcom/features/ee/organizations/lib/utils";
89
import { useLocale } from "@calcom/lib/hooks/useLocale";
910
import classNames from "@calcom/ui/classNames";
@@ -28,12 +29,23 @@ export const OnboardingView = ({ userEmail }: OnboardingViewProps) => {
2829
const { selectedPlan, setSelectedPlan, resetOnboardingPreservingPlan } = useOnboardingStore();
2930
const previousPlanRef = useRef<PlanType | null>(null);
3031
const [isPending, startTransition] = useTransition();
32+
const { listInvites, isPending: isPendingInvites } = useTeamInvites();
3133

3234
// Reset onboarding data when visiting this page, but preserve the selected plan
3335
useEffect(() => {
3436
resetOnboardingPreservingPlan();
3537
}, []);
3638

39+
// If user has pending team invites, redirect them directly to personal onboarding
40+
useEffect(() => {
41+
if (!isPendingInvites && listInvites && listInvites.length > 0) {
42+
setSelectedPlan("personal");
43+
startTransition(() => {
44+
router.push("/onboarding/personal/settings");
45+
});
46+
}
47+
}, [isPendingInvites, listInvites, router, setSelectedPlan]);
48+
3749
// Plan order mapping for determining direction
3850
const planOrder: Record<PlanType, number> = {
3951
personal: 0,
@@ -111,6 +123,15 @@ export const OnboardingView = ({ userEmail }: OnboardingViewProps) => {
111123

112124
const selectedPlanData = plans.find((plan) => plan.id === selectedPlan);
113125

126+
// Show loading state while checking for invites or if redirecting
127+
if (isPendingInvites || (listInvites && listInvites.length > 0)) {
128+
return (
129+
<OnboardingLayout userEmail={userEmail}>
130+
<OnboardingCard title={t("loading")} subtitle="" />
131+
</OnboardingLayout>
132+
);
133+
}
134+
114135
return (
115136
<>
116137
<OnboardingContinuationPrompt />

packages/features/auth/lib/onboardingUtils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,19 @@ export async function checkOnboardingRedirect(
6464
// Determine which onboarding path to use
6565
const onboardingV3Enabled = await featuresRepository.checkIfFeatureIsEnabledGlobally("onboarding-v3");
6666

67+
const pendingInvite = await prisma.membership.findFirst({
68+
where: {
69+
userId: userId,
70+
accepted: false,
71+
},
72+
select: {
73+
id: true,
74+
},
75+
});
76+
77+
if (pendingInvite && onboardingV3Enabled) {
78+
return "/onboarding/personal/settings";
79+
}
80+
6781
return onboardingV3Enabled ? "/onboarding/getting-started" : "/getting-started";
6882
}

0 commit comments

Comments
 (0)