import { useEffect, useState } from 'react'; import { Container, Center, Stack, Loader, Text, Title, Alert, Button } from '@mantine/core'; import { IconCheck, IconAlertCircle } from '@tabler/icons-react'; import { useSearchParams, useNavigate } from 'react-router-dom'; import api from '../../services/api'; export function OnboardingPendingPage() { const [searchParams] = useSearchParams(); const navigate = useNavigate(); const sessionId = searchParams.get('session_id'); const [status, setStatus] = useState('polling'); const [error, setError] = useState(''); useEffect(() => { if (!sessionId) { setError('No session ID provided'); return; } let cancelled = false; const poll = async () => { try { const { data } = await api.get(`/billing/status?session_id=${sessionId}`); if (cancelled) return; if (data.status === 'active') { setStatus('complete'); // Redirect to login page — user will get activation email setTimeout(() => navigate('/login'), 3000); } else if (data.status === 'not_configured') { setError('Payment system is not configured. Please contact support.'); } else { // Still provisioning — poll again setTimeout(poll, 3000); } } catch (err: any) { if (!cancelled) { setError(err.response?.data?.message || 'Failed to check status'); } } }; poll(); return () => { cancelled = true; }; }, [sessionId, navigate]); return (
{error ? ( <> } color="red" variant="light"> {error} ) : status === 'complete' ? ( <> Your account is ready! Check your email for an activation link to set your password and get started. Redirecting to login... ) : ( <> Setting up your account... We're creating your HOA workspace. This usually takes just a few seconds. )}
); }