2025-12-02 00:20:09 +00:00
|
|
|
|
import { BasePage } from "@/components/design-elements";
|
|
|
|
|
|
import Stack from "@mui/material/Stack";
|
|
|
|
|
|
import CircularProgress from "@mui/material/CircularProgress";
|
|
|
|
|
|
import Typography from "@mui/material/Typography";
|
2025-12-02 17:00:37 +00:00
|
|
|
|
import { Button } from "@/components/inputs";
|
2025-12-02 00:20:09 +00:00
|
|
|
|
|
|
|
|
|
|
import { useTheme } from "@mui/material/styles";
|
|
|
|
|
|
import { Navigate, useSearchParams } from "react-router-dom";
|
|
|
|
|
|
import { useGet } from "@/hooks/UseApi";
|
2025-12-16 19:09:08 +00:00
|
|
|
|
import type { ApiResponse } from "@/types/api";
|
2025-12-02 17:00:37 +00:00
|
|
|
|
import { useEffect, useMemo, useState } from "react";
|
2025-12-02 00:20:09 +00:00
|
|
|
|
|
2025-12-01 03:45:57 +00:00
|
|
|
|
const BillingSuccessPage = () => {
|
2025-12-02 00:20:09 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
const [searchParams] = useSearchParams();
|
|
|
|
|
|
const plan = searchParams.get("plan");
|
|
|
|
|
|
|
2025-12-02 17:00:37 +00:00
|
|
|
|
const query = useMemo(() => `/billing/confirm?plan=${plan ?? ""}`, [plan]);
|
|
|
|
|
|
const { response, refetch } = useGet<ApiResponse<any>>(
|
|
|
|
|
|
query,
|
2025-12-02 00:20:09 +00:00
|
|
|
|
{},
|
2025-12-02 17:00:37 +00:00
|
|
|
|
{ refreshInterval: 2000 }
|
2025-12-02 00:20:09 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const success = response?.data?.success ?? false;
|
2025-12-02 17:00:37 +00:00
|
|
|
|
const [elapsed, setElapsed] = useState(0);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (success) return;
|
|
|
|
|
|
const id = setInterval(() => setElapsed((s) => s + 1), 1000);
|
|
|
|
|
|
return () => clearInterval(id);
|
|
|
|
|
|
}, [success]);
|
|
|
|
|
|
|
2025-12-02 00:20:09 +00:00
|
|
|
|
if (success === true) {
|
|
|
|
|
|
return <Navigate to="/billing" replace />;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<BasePage>
|
2025-12-02 17:00:37 +00:00
|
|
|
|
<Stack
|
|
|
|
|
|
direction="column"
|
|
|
|
|
|
gap={theme.spacing(10)}
|
|
|
|
|
|
justifyContent={"center"}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Typography variant="h1">Finishing subscription update...</Typography>
|
|
|
|
|
|
<Stack direction="row" alignItems={"center"} gap={theme.spacing(10)}>
|
2025-12-08 19:55:29 +00:00
|
|
|
|
<CircularProgress color="primary" size={28} />
|
2025-12-02 17:00:37 +00:00
|
|
|
|
<Stack>
|
|
|
|
|
|
<Typography variant="h2">
|
|
|
|
|
|
{plan ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
{"Selected plan: "}
|
2025-12-08 19:55:29 +00:00
|
|
|
|
<span style={{ color: theme.palette.primary.main }}>
|
2025-12-02 17:00:37 +00:00
|
|
|
|
{plan.charAt(0).toUpperCase() + plan.slice(1)}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
""
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
<Typography variant="h2">
|
|
|
|
|
|
Awaiting confirmation…
|
|
|
|
|
|
{elapsed > 0 ? ` (${elapsed}s)` : ""}
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
</Stack>
|
|
|
|
|
|
</Stack>
|
|
|
|
|
|
{elapsed >= 30 && (
|
|
|
|
|
|
<Stack direction="row" gap={theme.spacing(4)}>
|
|
|
|
|
|
<Typography>
|
|
|
|
|
|
No changes detected yet. If you didn’t confirm in the portal,
|
|
|
|
|
|
nothing will change.
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
<Button
|
2025-12-08 19:55:29 +00:00
|
|
|
|
color="primary"
|
2025-12-02 17:00:37 +00:00
|
|
|
|
variant="outlined"
|
|
|
|
|
|
onClick={() => refetch?.()}
|
|
|
|
|
|
>
|
|
|
|
|
|
Try again
|
|
|
|
|
|
</Button>
|
2025-12-08 19:55:29 +00:00
|
|
|
|
<Button color="primary" variant="contained" href="/billing">
|
2025-12-02 17:00:37 +00:00
|
|
|
|
Back to billing
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</Stack>
|
|
|
|
|
|
)}
|
2025-12-02 00:20:09 +00:00
|
|
|
|
</Stack>
|
|
|
|
|
|
</BasePage>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-12-01 03:45:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default BillingSuccessPage;
|