'use client'; import { useEffect, useState, Suspense } from 'react'; import { useSearchParams, useRouter } from 'next/navigation'; const StartTaskContent = () => { const searchParams = useSearchParams(); const router = useRouter(); const [status, setStatus] = useState<'loading' | 'error' | 'redirecting'>('loading'); const [error, setError] = useState(null); useEffect(() => { const uuid = searchParams.get('uuid'); if (!uuid) { setError('no experiment UUID provided'); setStatus('error'); return; } const validateAndStore = async () => { try { const res = await fetch(`/api/admin/experiments?id=${uuid}`); if (!res.ok) throw new Error('experiment not found'); const data = await res.json(); const exp = data.experiment; if (!exp) throw new Error('invalid experiment UUID'); localStorage.setItem('phantom_experiment_id', uuid); await fetch('/api/session', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ experimentId: uuid }), }); setStatus('redirecting'); setTimeout(() => { router.push("/"); }, 800); } catch (err: any) { setError(err.message || 'failed to start task'); setStatus('error'); } }; validateAndStore(); }, [searchParams, router]); return (
{status === 'loading' && (

validating browser...

)} {status === 'redirecting' && (

website loaded

redirecting to page...

)} {status === 'error' && (

error

{error}

)}
); }; export default function StartTaskPage() { return (

loading...

}> ); }