MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / InvitationPage

Function InvitationPage

web/src/app/invites/[token]/page.tsx:27–252  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25}
26
27export default function InvitationPage() {
28 const params = useParams<{ token: string }>()
29 const token = params?.token ?? ''
30 const { data: session, status } = useSession()
31 const router = useRouter()
32 const [invitation, setInvitation] = useState<InvitationData | null>(null)
33 const [loading, setLoading] = useState(true)
34 const [accepting, setAccepting] = useState(false)
35 const [error, setError] = useState<string | null>(null)
36 const [success, setSuccess] = useState(false)
37
38 useEffect(() => {
39 fetchInvitation()
40 }, [token])
41
42 const fetchInvitation = async () => {
43 try {
44 const response = await fetch(`/api/invites/${token}`)
45 const data = await response.json()
46
47 if (!response.ok) {
48 setError(data.error || 'Failed to load invitation')
49 return
50 }
51
52 setInvitation(data.invitation)
53 } catch (error) {
54 setError('Failed to load invitation')
55 } finally {
56 setLoading(false)
57 }
58 }
59
60 const acceptInvitation = async () => {
61 if (!session) {
62 router.push(
63 `/login?callbackUrl=${encodeURIComponent(window.location.href)}`,
64 )
65 return
66 }
67
68 setAccepting(true)
69 setError(null)
70
71 try {
72 const response = await fetch(`/api/invites/${token}`, {
73 method: 'POST',
74 })
75 const data = await response.json()
76
77 if (!response.ok) {
78 setError(data.error || 'Failed to accept invitation')
79 return
80 }
81
82 setSuccess(true)
83 setTimeout(() => {
84 router.push(`/orgs/${data.organization.slug}`)

Callers

nothing calls this directly

Calls 1

fetchInvitationFunction · 0.85

Tested by

no test coverage detected