Files
Checkmate/client/src/pages/billing/Success.tsx
T

90 lines
2.8 KiB
TypeScript
Raw Normal View History

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";
import type { ApiResponse } from "@/hooks/UseApi";
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)}>
<CircularProgress color="accent" size={28} />
<Stack>
<Typography variant="h2">
{plan ? (
<>
{"Selected plan: "}
<span style={{ color: theme.palette.accent.main }}>
{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
color="accent"
variant="outlined"
onClick={() => refetch?.()}
>
Try again
</Button>
<Button color="accent" variant="contained" href="/billing">
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;