fixed pay dialog flow

This commit is contained in:
Jelaletdin12
2026-09-25 21:14:38 +05:00
parent 6ccda86eff
commit 9e2a2606c9
6 changed files with 139 additions and 76 deletions

View File

@@ -0,0 +1,51 @@
import { CheckCircle2, Loader2, XCircle } from "lucide-react";
import { Link, useSearchParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { useIntlPaymentCallback } from "@/features/visaMasterPayments/hooks/useVisaMasterPayments";
function getPaymentId(value: string | null): number | null {
if (!value || !/^\d+$/.test(value)) return null;
const paymentId = Number(value);
return Number.isSafeInteger(paymentId) && paymentId > 0 ? paymentId : null;
}
export default function VisaMasterPaymentCallbackPage() {
const { t } = useTranslation();
const [searchParams] = useSearchParams();
const paymentId = getPaymentId(searchParams.get("paymentId"));
const { data, isLoading, isError } = useIntlPaymentCallback(paymentId);
const invalidPaymentId = paymentId === null;
const failed = invalidPaymentId || isError;
return (
<main className="flex min-h-screen items-center justify-center bg-muted/30 px-4 py-8">
<div className="w-full max-w-md space-y-4">
{isLoading ? (
<Alert>
<Loader2 className="h-4 w-4 animate-spin" />
<AlertDescription>{t("common.loading", "Ýüklenýär...")}</AlertDescription>
</Alert>
) : failed ? (
<Alert variant="destructive">
<XCircle className="h-4 w-4" />
<AlertDescription>{t("intlPayment.pay.callbackError", "Töleg netijesi tapylmady.")}</AlertDescription>
</Alert>
) : data ? (
<Alert variant={data.paid ? "default" : "destructive"}>
{data.paid ? <CheckCircle2 className="h-4 w-4" /> : <XCircle className="h-4 w-4" />}
<AlertDescription>{data.data}</AlertDescription>
</Alert>
) : null}
{!isLoading && (
<Button asChild className="w-full">
<Link to="/visa-master">{t("intlPayment.title", "Halkara tölegler (Visa/Mastercard)")}</Link>
</Button>
)}
</div>
</main>
);
}