'use client'; import { CardDescription } from '@components/Card'; import { CustomCard } from '@components/CustomCard'; import { SchemaOrg } from '@components/SchemaOrg'; import { ResponseType } from '@utils/validationSchemas'; import { useRouter, useSearchParams } from 'next/navigation'; import { Suspense, useEffect, useState } from 'react'; const ConfirmationPage = () => { const router = useRouter(); const searchParams = useSearchParams(); const [loading, setLoading] = useState(true); const [message, setMessage] = useState(''); const code = searchParams.get('code'); useEffect(() => { const fetchData = async () => { if (!code) { router.push('/'); return; } try { const res = await fetch('/api/confirmation', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ code: code }) }); if (!res.ok) { router.push('/'); return; } const response: ResponseType = await res.json(); if (!response.success) { router.push('/'); return; } setMessage(response.message); setLoading(false); } catch (error) { console.error(error); router.push('/'); } }; fetchData(); }, [code, router]); const renderContent = () => { if (!loading) { return ( {message} ); } return ( Just a second... ); }; return ( ); }; const Confirmation = () => { const schema = { '@context': 'https://schema.org', '@type': 'WebSite', name: 'HackerNews Newsletter', title: 'Subscription Confirmation', url: `${process.env.HOME_URL}/confirmation` }; return ( <> Loading...}> ); }; export default Confirmation;