Skip to content

Scheduling infrastructure for absolutely everyone.

fix: skip plan on invite to team (#25924)

sean-brydon94e0d476d93b
diff --git a/apps/web/modules/onboarding/getting-started/onboarding-view.tsx b/apps/web/modules/onboarding/getting-started/onboarding-view.tsx
index 4cb6c66a241..3530a618a4b 100644
--- a/apps/web/modules/onboarding/getting-started/onboarding-view.tsx
+++ b/apps/web/modules/onboarding/getting-started/onboarding-view.tsx
@@ -4,6 +4,7 @@ import { AnimatePresence } from "framer-motion";
import { useRouter } from "next/navigation";
import { useEffect, useRef, useTransition } from "react";
+import { useTeamInvites } from "@calcom/features/billing/hooks/useHasPaidPlan";
import { isCompanyEmail } from "@calcom/features/ee/organizations/lib/utils";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import classNames from "@calcom/ui/classNames";
@@ -28,12 +29,23 @@ export const OnboardingView = ({ userEmail }: OnboardingViewProps) => {
const { selectedPlan, setSelectedPlan, resetOnboardingPreservingPlan } = useOnboardingStore();
const previousPlanRef = useRef<PlanType | null>(null);
const [isPending, startTransition] = useTransition();
+ const { listInvites, isPending: isPendingInvites } = useTeamInvites();
// Reset onboarding data when visiting this page, but preserve the selected plan
useEffect(() => {
resetOnboardingPreservingPlan();
}, []);
+ // If user has pending team invites, redirect them directly to personal onboarding
+ useEffect(() => {
+ if (!isPendingInvites && listInvites && listInvites.length > 0) {
+ setSelectedPlan("personal");
+ startTransition(() => {
+ router.push("/onboarding/personal/settings");
+ });
+ }
+ }, [isPendingInvites, listInvites, router, setSelectedPlan]);
+
// Plan order mapping for determining direction
const planOrder: Record<PlanType, number> = {
personal: 0,
@@ -111,6 +123,15 @@ export const OnboardingView = ({ userEmail }: OnboardingViewProps) => {
const selectedPlanData = plans.find((plan) => plan.id === selectedPlan);
+ // Show loading state while checking for invites or if redirecting
+ if (isPendingInvites || (listInvites && listInvites.length > 0)) {
+ return (
+ <OnboardingLayout userEmail={userEmail}>
+ <OnboardingCard title={t("loading")} subtitle="" />
+ </OnboardingLayout>
+ );
+ }
+
return (
<>
<OnboardingContinuationPrompt />
diff --git a/packages/features/auth/lib/onboardingUtils.ts b/packages/features/auth/lib/onboardingUtils.ts
index 80d092e68fd..d0ad21285d4 100644
--- a/packages/features/auth/lib/onboardingUtils.ts
+++ b/packages/features/auth/lib/onboardingUtils.ts
@@ -64,5 +64,19 @@ export async function checkOnboardingRedirect(
// Determine which onboarding path to use
const onboardingV3Enabled = await featuresRepository.checkIfFeatureIsEnabledGlobally("onboarding-v3");
+ const pendingInvite = await prisma.membership.findFirst({
+ where: {
+ userId: userId,
+ accepted: false,
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ if (pendingInvite && onboardingV3Enabled) {
+ return "/onboarding/personal/settings";
+ }
+
return onboardingV3Enabled ? "/onboarding/getting-started" : "/getting-started";
}