1- import { getOrganizations } from '@/data/getOrganizations ' ;
1+ import { OnboardingLayout } from '@/components/onboarding/OnboardingLayout ' ;
22import { auth } from '@/utils/auth' ;
3- import type { Organization } from '@db' ;
43import { db } from '@db' ;
54import { headers } from 'next/headers' ;
6- import { notFound , redirect } from 'next/navigation' ;
5+ import { redirect } from 'next/navigation' ;
76import { AcceptInvite } from '../../setup/components/accept-invite' ;
7+ import { InviteNotMatchCard } from './components/InviteNotMatchCard' ;
8+ import { InviteStatusCard } from './components/InviteStatusCard' ;
9+ import { maskEmail } from './utils' ;
810
911interface InvitePageProps {
1012 params : Promise < { code : string } > ;
@@ -17,26 +19,12 @@ export default async function InvitePage({ params }: InvitePageProps) {
1719 } ) ;
1820
1921 if ( ! session ) {
20- // Redirect to auth with the invite code
2122 return redirect ( `/auth?inviteCode=${ code } ` ) ;
2223 }
2324
24- // Fetch existing organizations
25- let organizations : Organization [ ] = [ ] ;
26- try {
27- const result = await getOrganizations ( ) ;
28- organizations = result . organizations ;
29- } catch ( error ) {
30- // If user has no organizations, continue with empty array
31- console . error ( 'Failed to fetch organizations:' , error ) ;
32- }
33-
34- // Check if this invitation exists and is valid for this user
3525 const invitation = await db . invitation . findFirst ( {
3626 where : {
3727 id : code ,
38- email : session . user . email ,
39- status : 'pending' ,
4028 } ,
4129 include : {
4230 organization : {
@@ -48,16 +36,60 @@ export default async function InvitePage({ params }: InvitePageProps) {
4836 } ) ;
4937
5038 if ( ! invitation ) {
51- // Either invitation doesn't exist, already accepted, or not for this user
52- notFound ( ) ;
39+ return (
40+ < OnboardingLayout variant = "setup" currentOrganization = { null } >
41+ < div className = "flex min-h-[calc(100dvh-80px)] w-full items-center justify-center p-4" >
42+ < InviteStatusCard
43+ title = "Invite not found"
44+ description = "This invitation code does not exist. Please check the link or ask your admin to resend the invite."
45+ primaryHref = "/"
46+ primaryLabel = "Go home"
47+ />
48+ </ div >
49+ </ OnboardingLayout >
50+ ) ;
51+ }
52+
53+ if ( invitation . status !== 'pending' ) {
54+ return (
55+ < OnboardingLayout variant = "setup" currentOrganization = { null } >
56+ < div className = "flex min-h-[calc(100dvh-80px)] w-full items-center justify-center p-4" >
57+ < InviteStatusCard
58+ title = { invitation . status === 'accepted' ? 'Invite already accepted' : 'Invite expired' }
59+ description = {
60+ invitation . status === 'accepted'
61+ ? 'This invitation has already been accepted. If you believe this is a mistake, contact your organization admin.'
62+ : 'This invitation has expired. Please ask your organization admin to send a new invite.'
63+ }
64+ primaryHref = "/"
65+ primaryLabel = "Go home"
66+ />
67+ </ div >
68+ </ OnboardingLayout >
69+ ) ;
70+ }
71+
72+ if ( invitation . email !== session . user . email ) {
73+ return (
74+ < OnboardingLayout variant = "setup" currentOrganization = { null } >
75+ < div className = "flex min-h-[calc(100dvh-80px)] w-full items-center justify-center p-4" >
76+ < InviteNotMatchCard
77+ currentEmail = { session . user . email }
78+ invitedEmail = { maskEmail ( invitation . email ) }
79+ />
80+ </ div >
81+ </ OnboardingLayout >
82+ ) ;
5383 }
5484
5585 return (
56- < div className = "flex flex-1 items-center justify-center p-4" >
57- < AcceptInvite
58- inviteCode = { invitation . id }
59- organizationName = { invitation . organization . name || '' }
60- />
61- </ div >
86+ < OnboardingLayout variant = "setup" currentOrganization = { null } >
87+ < div className = "flex min-h-[calc(100dvh-80px)] w-full items-center justify-center p-4" >
88+ < AcceptInvite
89+ inviteCode = { invitation . id }
90+ organizationName = { invitation . organization . name || '' }
91+ />
92+ </ div >
93+ </ OnboardingLayout >
6294 ) ;
6395}
0 commit comments