import { useState, useEffect } from 'react'; import { useRouter } from 'next/router'; import Layout from '../../components/Layout'; import { GlassSurface, Button } from '../../components/ui'; 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); 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); } } useEffect(() => { if (token) { // eslint-disable-next-line react-hooks/set-state-in-effect -- process invite token on mount handleDeclineInvitation(); } // eslint-disable-next-line react-hooks/exhaustive-deps -- run once per invite token }, [token]); ; 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" > Browse Public Lists router.push('/')} className="w-full" > Go Home ) : ( ❌ Error Processing Response {error} router.push('/collections')} className="w-full" > Browse Lists router.push('/')} className="w-full" > 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}