@@ -4,6 +4,7 @@ import { AnimatePresence } from "framer-motion";
44import { useRouter } from "next/navigation" ;
55import { useEffect , useRef , useTransition } from "react" ;
66
7+ import { useTeamInvites } from "@calcom/features/billing/hooks/useHasPaidPlan" ;
78import { isCompanyEmail } from "@calcom/features/ee/organizations/lib/utils" ;
89import { useLocale } from "@calcom/lib/hooks/useLocale" ;
910import 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 />
0 commit comments