import { useEffect, useState, useContext } from 'react'; import { useLocation, Link } from 'react-router-dom'; import { Button } from './ui/button.js'; import { ProfileCtx } from '../App.js'; // <- exported at very top of App.jsx export default function BillingResult() { const { setUser } = useContext(ProfileCtx) || {}; const q = new URLSearchParams(useLocation().search); const outcome = q.get('ck'); // 'success' | 'cancel' | null const [loading, setLoading] = useState(true); /* ───────────────────────────────────────────────────────── 1) Ask the API for the latest user profile (flags, etc.) – will be fast because JWT is already cached ───────────────────────────────────────────────────────── */ useEffect(() => { const token = localStorage.getItem('token') || ''; fetch('/api/user-profile', { headers: { Authorization: `Bearer ${token}` } }) .then(r => r.ok ? r.json() : null) .then(profile => { if (profile && setUser) setUser(profile); }) .finally(() => setLoading(false)); }, [setUser]); /* ───────────────────────────────────────────────────────── 2) UX while waiting for that round‑trip ───────────────────────────────────────────────────────── */ if (loading) { return
Checking your subscription…
; } /* ───────────────────────────────────────────────────────── 3) Success – Stripe completed the checkout flow ───────────────────────────────────────────────────────── */ if (outcome === 'success') { return (Premium features have been unlocked on your account.
No changes were made to your account.