changed payment history api in visa/master payments

This commit is contained in:
Jelaletdin12 committed 2026-10-24 19:44:25 +05:00
1 parent cbfb467651
commit 879ed77121
15 files changed
+1174 -190

No files matched your search

@@ -0,0 +1,202 @@
import { Link } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Database, AlertTriangle } from "lucide-react";
import { Skeleton } from "@/components/ui/skeleton";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "@/components/ui/dialog";
import { useGetOnlinePaymentDetail } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
import { GatewayStatusBadge, PaidBadge } from "@/features/onlinePaymentHistory/components/PaymentStatusBadge";
import { formatFromApiDate } from "@/lib/utils/dateUtils";
function resolveLang(lang: string): "en" | "ru" | "tm" {
if (lang === "ru") return "ru";
if (lang === "tk") return "tm";
return "en";
}
interface PaymentDetailDialogProps {
paymentId: number | null;
open: boolean;
onOpenChange: (open: boolean) => void;
}
export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDetailDialogProps) {
const { t, i18n } = useTranslation();
const lang = resolveLang(i18n.language);
const { data, isLoading, isError } = useGetOnlinePaymentDetail(paymentId ?? 0);
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-2xl max-h-[85vh] overflow-y-auto">
<DialogHeader>
<div className="flex items-center justify-between gap-3 pr-6">
<div className="flex items-center gap-2">
<Database className="size-5 text-primary" />
<DialogTitle className="text-base font-semibold">
{t("onlinePayments.paymentViewTitle", "Töleg maglumaty")}: #{paymentId}
</DialogTitle>
</div>
{data && (
<div className="flex items-center gap-2">
<GatewayStatusBadge status={data.gatewayStatus} />
<PaidBadge paid={data.paid} />
</div>
)}
</div>
{data?.orderNumber && (
<DialogDescription className="text-xs">
{t("onlinePayments.columns.orderNumber", "Sargyt belgisi")}: {data.orderNumber}
</DialogDescription>
)}
</DialogHeader>
{isLoading ? (
<div className="space-y-4 py-2">
<Skeleton className="h-6 w-1/2" />
<div className="grid grid-cols-2 gap-3">
<Skeleton className="h-24 w-full rounded-lg" />
<Skeleton className="h-24 w-full rounded-lg" />
</div>
<Skeleton className="h-28 w-full rounded-lg" />
</div>
) : isError || !data ? (
<div className="py-8 text-center text-sm text-destructive">{t("common.error", "Maglumat ýüklenende ýalňyşlyk ýüze çykdy")}</div>
) : (
<div className="space-y-4 text-xs">
{/* Gateway Response Alert if Error */}
{data.gatewayResponse && (data.gatewayResponse.errorCode || data.gatewayResponse.errorMessage) && (
<div className="flex items-start gap-2.5 p-3 rounded-lg border border-destructive/30 bg-destructive/10 text-destructive text-xs">
<AlertTriangle className="size-4 shrink-0 mt-0.5" />
<div className="space-y-0.5">
<div className="font-semibold">
Gateway ýalňyşlygy {data.gatewayResponse.errorCode ? `(${data.gatewayResponse.errorCode})` : ""}
</div>
{data.gatewayResponse.errorMessage && <div>{data.gatewayResponse.errorMessage}</div>}
</div>
</div>
)}
{/* Grid 1: General Info */}
<div className="rounded-lg border border-border p-3 space-y-2 bg-muted/10">
<p className="font-semibold text-muted-foreground uppercase text-[11px] tracking-wide">
{t("onlinePayments.sectionGeneral", "Esasy maglumatlar")}
</p>
<div className="grid grid-cols-2 gap-x-4 gap-y-2">
<div>
<span className="text-muted-foreground block">{t("common.id", "ID")}</span>
<span className="font-mono font-medium text-foreground">{data.id}</span>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.orderId", "Sargyt ID")}</span>
<Link to={`/visa-master/${data.orderId}`} className="font-mono text-primary hover:underline">
#{data.orderId}
</Link>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.orderNumber", "Sargyt belgisi")}</span>
<span className="font-mono text-foreground">{data.orderNumber || "—"}</span>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.type", "Görnüşi")}</span>
<span className="uppercase font-medium text-foreground">{data.type}</span>
</div>
{data.description && (
<div className="col-span-2">
<span className="text-muted-foreground block">{t("onlinePayments.columns.description", "Düşündiriş")}</span>
<span className="text-foreground">{data.description}</span>
</div>
)}
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.createdAt", "Döredilen wagty")}</span>
<span className="text-foreground">{formatFromApiDate(data.createdAt)}</span>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.updatedAt", "Täzelenen wagty")}</span>
<span className="text-foreground">{formatFromApiDate(data.updatedAt)}</span>
</div>
</div>
</div>
{/* Grid 2: Financial Info */}
<div className="rounded-lg border border-border p-3 space-y-2 bg-muted/10">
<p className="font-semibold text-muted-foreground uppercase text-[11px] tracking-wide">
{t("onlinePayments.sectionFinancial", "Maliýe maglumatlary")}
</p>
<div className="grid grid-cols-2 gap-x-4 gap-y-2">
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.amountTmt", "Töleg möçberi")}</span>
<span className="font-medium text-foreground">{data.amountTmt?.toLocaleString?.() ?? data.amountTmt} TMT</span>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.totalAmount", "Jemi töleg möçberi")}</span>
<span className="font-semibold text-primary">{data.totalAmountTmt?.toLocaleString?.() ?? data.totalAmountTmt} TMT</span>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.bankFeeTmt", "Bank komissiýasy")}</span>
<span className="text-foreground">{data.bankFeeTmt?.toLocaleString?.() ?? data.bankFeeTmt} TMT</span>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.gbusFeeTmt", "GBUS komissiýasy")}</span>
<span className="text-foreground">{data.gbusFeeTmt?.toLocaleString?.() ?? data.gbusFeeTmt} TMT</span>
</div>
{data.amountUsd != null && (
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.amountUsd", "Möçber (USD)")}</span>
<span className="text-foreground">{data.amountUsd} $</span>
</div>
)}
{data.exchangeRateUsd != null && (
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.exchangeRateUsd", "Hümmet (USD)")}</span>
<span className="text-foreground">{data.exchangeRateUsd} TMT</span>
</div>
)}
{data.paymentPeriod && (
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.paymentPeriod", "Töleg döwri")}</span>
<span className="text-foreground">{formatFromApiDate(data.paymentPeriod)}</span>
</div>
)}
{data.apiClient && (
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.apiClient", "API Client")}</span>
<span className="font-mono text-foreground">{data.apiClient}</span>
</div>
)}
</div>
</div>
{/* Grid 3: Customer & Branch */}
<div className="rounded-lg border border-border p-3 space-y-2 bg-muted/10">
<p className="font-semibold text-muted-foreground uppercase text-[11px] tracking-wide">
{t("onlinePayments.sectionCustomer", "Müşderi we Şahamça")}
</p>
<div className="grid grid-cols-2 gap-x-4 gap-y-2">
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.passport", "Müşderi")}</span>
<span className="font-medium text-foreground">
{[data.passportName, data.passportSurname].filter(Boolean).join(" ") || "—"}
</span>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.userId", "Ulanyjy ID")}</span>
<Link to={`/all-users/${data.userId}`} className="font-mono text-primary hover:underline">
#{data.userId}
</Link>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.branch", "Şahamça")}</span>
<span className="text-foreground">{data.branchName?.[lang] || data.branchName?.tm || data.branchName?.en || "—"}</span>
</div>
<div>
<span className="text-muted-foreground block">{t("onlinePayments.columns.createdByName", "Döreden işgär")}</span>
<span className="text-foreground">{data.createdByName || "—"}</span>
</div>
</div>
</div>
</div>
)}
</DialogContent>
</Dialog>
);
}