import { useState, useEffect } from 'react'; import { useRouter } from 'next/router'; import Layout from '../../components/Layout'; export default function DeclineInvite() { 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) { handleDeclineInvitation(); } }, [token]); const handleDeclineInvitation = async () => { try { const response = await fetch('/api/invite/decline', { 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 decline invitation'); } } catch (err) { setError('Network error. Please try again.'); } finally { setLoading(false); } }; if (loading) { return ( Processing Response... Please wait while we process your response. ); } return ( {result ? ( 👋 Invitation Declined You have declined the invitation to "{result.collection.name}". You can always ask the list owner for another invitation if you change your mind. 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 Public Lists 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 ) : ( ❌ Error Processing Response {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 Lists 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 process your response.
You have declined the invitation to "{result.collection.name}". You can always ask the list owner for another invitation if you change your mind.
{error}