OrganizationInviteError.tsx89 lines · main
1import { useRouter } from 'next/router'
2import { Button } from 'ui'
3import { Admonition } from 'ui-patterns'
4
5import { OrganizationInviteByToken } from '@/data/organization-members/organization-invitation-token-query'
6import { useSignOut } from '@/lib/auth'
7import { useProfile } from '@/lib/profile'
8import type { ResponseError } from '@/types'
9
10interface OrganizationInviteError {
11 data?: OrganizationInviteByToken
12 error?: ResponseError | null
13 isError: boolean
14 isInvalidInvite?: boolean
15}
16
17export const OrganizationInviteError = ({
18 data,
19 error,
20 isError,
21 isInvalidInvite,
22}: OrganizationInviteError) => {
23 const router = useRouter()
24 const signOut = useSignOut()
25 const { profile } = useProfile()
26
27 const handleSignOut = async () => {
28 await signOut()
29 router.reload()
30 }
31
32 if (isInvalidInvite) {
33 return (
34 <Admonition
35 type="warning"
36 description="Open the full invite link again, or ask the organization owner for a new invite."
37 />
38 )
39 }
40
41 if (isError) {
42 return (
43 <Admonition
44 type="danger"
45 description={error?.message ?? 'Open the full invite link again, or ask for a new invite.'}
46 />
47 )
48 }
49
50 if (!data?.email_match) {
51 return (
52 <div className="flex flex-col gap-3">
53 <Admonition
54 type="warning"
55 description={
56 profile?.primary_email ? (
57 <>
58 You are signed in as{' '}
59 <span className="font-medium text-foreground">{profile.primary_email}</span>. Sign
60 in with the email address that received this invite.
61 </>
62 ) : (
63 'Sign in with the email address that received this invite.'
64 )
65 }
66 />
67 <Button type="default" block onClick={handleSignOut}>
68 Sign out
69 </Button>
70 </div>
71 )
72 }
73
74 if (data.expired_token) {
75 return (
76 <Admonition
77 type="warning"
78 description="Ask the organization owner to send you a new invite."
79 />
80 )
81 }
82
83 return (
84 <Admonition
85 type="warning"
86 description="Open the full invite link again, or ask the organization owner for a new invite."
87 />
88 )
89}