2025-07-25 09:34:28 -04:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2026-06-02 01:48:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
|
|
;
|
2025-07-25 09:34:28 -04:00
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
return (
|
|
|
|
|
<Layout user={null}>
|
|
|
|
|
<div className="min-h-screen flex items-center justify-center">
|
|
|
|
|
<div className="text-center">
|
|
|
|
|
<div className="animate-spin rounded-full h-16 w-16 border-b-2 mx-auto mb-4" style={{ borderColor: 'var(--text-accent)' }}></div>
|
|
|
|
|
<h2 className="text-xl font-semibold mb-2" style={{ color: 'var(--text-primary)' }}>
|
|
|
|
|
Processing Response...
|
|
|
|
|
</h2>
|
|
|
|
|
<p style={{ color: 'var(--text-secondary)' }}>
|
|
|
|
|
Please wait while we process your response.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Layout>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Layout user={null}>
|
|
|
|
|
<div className="min-h-screen flex items-center justify-center px-4">
|
|
|
|
|
<div className="max-w-md w-full">
|
|
|
|
|
{result ? (
|
|
|
|
|
<div className="text-center p-8 rounded-2xl shadow-lg" style={{ backgroundColor: 'var(--bg-secondary)' }}>
|
|
|
|
|
<div className="text-6xl mb-4">👋</div>
|
|
|
|
|
<h2 className="text-2xl font-bold mb-4" style={{ color: 'var(--text-primary)' }}>
|
|
|
|
|
Invitation Declined
|
|
|
|
|
</h2>
|
|
|
|
|
<p className="mb-6" style={{ color: 'var(--text-secondary)' }}>
|
2026-06-02 01:48:07 -04:00
|
|
|
You have declined the invitation to "{result.collection.name}".
|
2026-05-29 10:53:40 -04:00
|
|
|
You can always ask the list owner for another invitation if you change your mind.
|
2025-07-25 09:34:28 -04:00
|
|
|
</p>
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => 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"
|
|
|
|
|
>
|
2026-05-29 10:53:40 -04:00
|
|
|
Browse Public Lists
|
2025-07-25 09:34:28 -04:00
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => 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
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="text-center p-8 rounded-2xl shadow-lg" style={{ backgroundColor: 'var(--bg-secondary)' }}>
|
|
|
|
|
<div className="text-6xl mb-4">❌</div>
|
|
|
|
|
<h2 className="text-2xl font-bold mb-4" style={{ color: 'var(--text-primary)' }}>
|
|
|
|
|
Error Processing Response
|
|
|
|
|
</h2>
|
|
|
|
|
<p className="mb-6" style={{ color: 'var(--text-secondary)' }}>
|
|
|
|
|
{error}
|
|
|
|
|
</p>
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => 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"
|
|
|
|
|
>
|
2026-05-29 10:53:40 -04:00
|
|
|
Browse Lists
|
2025-07-25 09:34:28 -04:00
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => 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
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Layout>
|
|
|
|
|
);
|
|
|
|
|
}
|