import { BasePage } from "@/components/design-elements"; import Stack from "@mui/material/Stack"; import CircularProgress from "@mui/material/CircularProgress"; import Typography from "@mui/material/Typography"; import { Button } from "@/components/inputs"; import { useTheme } from "@mui/material/styles"; import { Navigate, useSearchParams } from "react-router-dom"; import { useGet } from "@/hooks/UseApi"; import type { ApiResponse } from "@/types/api"; import { useEffect, useMemo, useState } from "react"; const BillingSuccessPage = () => { const theme = useTheme(); const [searchParams] = useSearchParams(); const plan = searchParams.get("plan"); const query = useMemo(() => `/billing/confirm?plan=${plan ?? ""}`, [plan]); const { response, refetch } = useGet>( query, {}, { refreshInterval: 2000 } ); const success = response?.data?.success ?? false; const [elapsed, setElapsed] = useState(0); useEffect(() => { if (success) return; const id = setInterval(() => setElapsed((s) => s + 1), 1000); return () => clearInterval(id); }, [success]); if (success === true) { return ; } else { return ( Finishing subscription update... {plan ? ( <> {"Selected plan: "} {plan.charAt(0).toUpperCase() + plan.slice(1)} ) : ( "" )} Awaiting confirmation… {elapsed > 0 ? ` (${elapsed}s)` : ""} {elapsed >= 30 && ( No changes detected yet. If you didn’t confirm in the portal, nothing will change. )} ); } }; export default BillingSuccessPage;