import { useState, useEffect } from 'react'; import { useRouter } from 'next/router'; import Layout from '../../components/Layout'; import { GlassSurface, Button } from '../../components/ui'; export default function AcceptInvite() { const router = useRouter(); const { token } = router.query; const [loading, setLoading] = useState(true); const [result, setResult] = useState(null); const [error, setError] = useState(null); const handleAcceptInvitation = async () => { try { const response = await fetch('/api/invite/accept', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ token }) }); const data = await response.json(); if (response.ok) { setResult(data); } else { setError(data.error || 'Failed to accept invitation'); } } catch (err) { setError('Network error. Please try again.'); } finally { setLoading(false); } } useEffect(() => { if (token) { // eslint-disable-next-line react-hooks/set-state-in-effect -- process invite token on mount handleAcceptInvitation(); } // eslint-disable-next-line react-hooks/exhaustive-deps -- run once per invite token }, [token]); ; if (loading) { return ( Processing Invitation... Please wait while we accept your invitation. ); } return ( {result ? ( 🎉 Invitation Accepted! You now have access to the list "{result.collection.name}". router.push(`/collection/${result.collection.id}`)} className="w-full" > View List router.push('/collections')} className="w-full" > View All Lists ) : ( ❌ Invitation Error {error} router.push('/collections')} className="w-full" > Browse Lists router.push('/')} className="w-full" > Go Home )} ); }
Please wait while we accept your invitation.
You now have access to the list "{result.collection.name}".
{error}