import { useState, useEffect } from 'react'; import { useRouter } from 'next/router'; import Layout from '../../components/Layout'; 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); useEffect(() => { if (token) { handleAcceptInvitation(); } }, [token]); 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); } }; if (loading) { return ( Processing Invitation... Please wait while we accept your invitation. ); } return ( {result ? ( 🎉 Invitation Accepted! You now have access to the collection "{result.collection.name}". router.push(`/collection/${result.collection.id}`)} className="w-full px-6 py-3 rounded-lg font-medium gradient-bg-purple text-white hover:shadow-lg transform hover:scale-105 transition-all duration-200" > View Collection router.push('/collections')} className="w-full px-6 py-3 rounded-lg font-medium border transition-all duration-200" style={{ borderColor: 'var(--border)', color: 'var(--text-primary)' }} > View All Collections ) : ( ❌ Invitation Error {error} router.push('/collections')} className="w-full px-6 py-3 rounded-lg font-medium gradient-bg-purple text-white hover:shadow-lg transform hover:scale-105 transition-all duration-200" > Browse Collections router.push('/')} className="w-full px-6 py-3 rounded-lg font-medium border transition-all duration-200" style={{ borderColor: 'var(--border)', color: 'var(--text-primary)' }} > Go Home )} ); }
Please wait while we accept your invitation.
You now have access to the collection "{result.collection.name}".
{error}