added lang param to api

This commit is contained in:
Jelaletdin12
2026-10-25 00:30:50 +05:00
parent 11903e23bf
commit 524733ad9f
50 changed files with 798 additions and 361 deletions

View File

@@ -1,6 +1,7 @@
import type React from "react";
import { Link } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Database, AlertTriangle, Eye } from "lucide-react";
import { Database, AlertTriangle, Eye, ExternalLink } from "lucide-react";
import { Skeleton } from "@/components/ui/skeleton";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "@/components/ui/dialog";
@@ -28,20 +29,18 @@ export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDe
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-2xl max-h-[85vh] overflow-y-auto">
<DialogContent className="sm:max-w-lg 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>
<div className="flex items-center gap-2 pr-6 flex-wrap">
<Database className="size-5 text-primary shrink-0" />
<DialogTitle className="text-base font-semibold">
{t("onlinePayments.paymentViewTitle", "Töleg maglumaty")}: #{paymentId}
</DialogTitle>
{data && (
<div className="flex items-center gap-2">
<>
<GatewayStatusBadge status={data.gatewayStatus} />
<PaidBadge paid={data.paid} />
</div>
</>
)}
</div>
{data?.orderNumber && (
@@ -52,21 +51,19 @@ export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDe
</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>
<div className="space-y-3 py-2">
<Skeleton className="h-6 w-1/3" />
<Skeleton className="h-4 w-1/2" />
<Skeleton className="h-28 w-full rounded-lg" />
<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 */}
<div className="space-y-3 text-xs">
{/* Gateway error alert */}
{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">
<div className="flex items-start gap-2.5 p-3 rounded-lg border border-destructive/30 bg-destructive/10 text-destructive">
<AlertTriangle className="size-4 shrink-0 mt-0.5" />
<div className="space-y-0.5">
<div className="font-semibold">
@@ -77,122 +74,105 @@ export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDe
</div>
)}
{/* Grid 1: General Info */}
{/* Section 1: General */}
<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>
<div className="space-y-1.5">
<Row label={t("common.id", "ID")}>
<span className="font-mono font-medium">{data.id}</span>
</Row>
<Row label={t("onlinePayments.columns.orderId", "Sargyt ID")}>
<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>
</Row>
<Row label={t("onlinePayments.columns.orderNumber", "Sargyt belgisi")}>
<span className="font-mono">{data.orderNumber || "—"}</span>
</Row>
<Row label={t("onlinePayments.columns.type", "Görnüşi")}>
<span className="uppercase font-medium">{data.type}</span>
</Row>
{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>
<Row label={t("onlinePayments.columns.description", "Düşündiriş")}>
<span>{data.description}</span>
</Row>
)}
<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>
<Row label={t("onlinePayments.columns.createdAt", "Döredilen wagty")}>
<span>{formatFromApiDate(data.createdAt)}</span>
</Row>
<Row label={t("onlinePayments.columns.updatedAt", "Täzelenen wagty")}>
<span>{formatFromApiDate(data.updatedAt)}</span>
</Row>
</div>
</div>
{/* Grid 2: Financial Info */}
{/* Section 2: Financial */}
<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>
<div className="space-y-1.5">
<Row label={t("onlinePayments.columns.amountTmt", "Töleg möçberi")}>
<span className="font-medium">{data.amountTmt?.toLocaleString?.() ?? data.amountTmt} TMT</span>
</Row>
<Row label={t("onlinePayments.columns.totalAmount", "Jemi töleg möçberi")}>
<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>
</Row>
<Row label={t("onlinePayments.columns.bankFeeTmt", "Bank komissiýasy")}>
<span>{data.bankFeeTmt?.toLocaleString?.() ?? data.bankFeeTmt} TMT</span>
</Row>
<Row label={t("onlinePayments.columns.gbusFeeTmt", "GBUS komissiýasy")}>
<span>{data.gbusFeeTmt?.toLocaleString?.() ?? data.gbusFeeTmt} TMT</span>
</Row>
{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>
<Row label={t("onlinePayments.columns.amountUsd", "Möçber (USD)")}>
<span>{data.amountUsd} $</span>
</Row>
)}
{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>
<Row label={t("onlinePayments.columns.exchangeRateUsd", "Hümmet (USD)")}>
<span>{data.exchangeRateUsd} TMT</span>
</Row>
)}
{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>
<Row label={t("onlinePayments.columns.paymentPeriod", "Töleg döwri")}>
<span>{formatFromApiDate(data.paymentPeriod)}</span>
</Row>
)}
{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>
<Row label={t("onlinePayments.columns.apiClient", "API Client")}>
<span className="font-mono">{data.apiClient}</span>
</Row>
)}
</div>
</div>
{/* Grid 3: Customer & Branch */}
{/* Section 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>
<div className="space-y-1.5">
<Row label={t("onlinePayments.columns.passport", "Müşderi")}>
<span className="font-medium">{[data.passportName, data.passportSurname].filter(Boolean).join(" ") || "—"}</span>
</Row>
<Row label={t("onlinePayments.columns.userId", "Ulanyjy ID")}>
<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>
</Row>
<Row label={t("onlinePayments.columns.branch", "Şahamça")}>
<span>
{(typeof data.branchName === "string"
? data.branchName
: data.branchName?.[lang] || data.branchName?.tm || data.branchName?.en) || "—"}
</span>
</Row>
<Row label={t("onlinePayments.columns.createdByName", "Döreden işgär")}>
<span>{data.createdByName || "—"}</span>
</Row>
</div>
</div>
</div>
@@ -202,57 +182,276 @@ export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDe
);
}
// ─── Shared Row helper ────────────────────────────────────────────────────────
function Row({ label, children }: { label: string; children: React.ReactNode }) {
return (
<div className="flex gap-2 text-xs">
<span className="text-muted-foreground font-medium min-w-[130px] shrink-0">{label}</span>
<span className="text-foreground break-all">{children}</span>
</div>
);
}
// ─── LastStepDialog ───────────────────────────────────────────────────────────
interface LastStepDialogProps {
/** The order ID (row.original.orderId) used to fetch the step history. */
export interface LastStepDialogProps {
/** The ID used to fetch the step history from /payment-history/:id. */
orderId: number | null;
open: boolean;
onOpenChange: (open: boolean) => void;
}
/**
* Opens a dialog showing only the most recent payment history step
* Opens a dialog showing only the most recent payment history step / operation
* for the given order. Used by the Eye icon in PaymentHistoryTable.
* Fetches its own data independently via useGetOnlinePaymentById (/payment-history/:id).
*/
export function LastStepDialog({ orderId, open, onOpenChange }: LastStepDialogProps) {
const { t } = useTranslation();
const { data: steps, isLoading } = useGetOnlinePaymentById(orderId ?? 0);
const { t, i18n } = useTranslation();
const lang = resolveLang(i18n.language);
const { data: rawSteps, isLoading, isError } = useGetOnlinePaymentById(orderId ?? 0);
// The "last" step is the one with the highest createdAt (or last element if already sorted desc).
const lastStep = steps?.length ? [...steps].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())[0] : null;
const steps: any[] = Array.isArray(rawSteps)
? rawSteps
: (rawSteps as any)?.data && Array.isArray((rawSteps as any).data)
? (rawSteps as any).data
: (rawSteps as any)?.items && Array.isArray((rawSteps as any).items)
? (rawSteps as any).items
: rawSteps && typeof rawSteps === "object" && (rawSteps as any).id
? [rawSteps]
: [];
const lastStep = steps.length
? [...steps].sort((a, b) => new Date(b.createdAt || 0).getTime() - new Date(a.createdAt || 0).getTime())[0]
: null;
const branchDisplay =
typeof lastStep?.branchName === "string"
? lastStep.branchName
: lastStep?.branchName?.[lang] || lastStep?.branchName?.tm || lastStep?.branchName?.en || null;
const fullName = [lastStep?.passportName, lastStep?.passportSurname].filter(Boolean).join(" ");
const detailEntries = Object.entries(lastStep?.detail ?? {});
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-lg max-h-[80vh] overflow-y-auto">
<DialogContent className="sm:max-w-lg max-h-[85vh] overflow-y-auto">
<DialogHeader>
<div className="flex items-center gap-2">
<Eye className="size-5 text-primary" />
<div className="flex items-center gap-2 pr-6 flex-wrap">
<Eye className="size-5 text-primary shrink-0" />
<DialogTitle className="text-base font-semibold">{t("onlinePayments.lastStep.title", "Iň soňky işlem")}</DialogTitle>
{lastStep && (
<>
{(lastStep.gatewayStatus || lastStep.step) && <GatewayStatusBadge status={lastStep.gatewayStatus || lastStep.step} />}
{typeof lastStep.paid === "boolean" && <PaidBadge paid={lastStep.paid} />}
</>
)}
</div>
{orderId && <DialogDescription className="text-xs">Order #{orderId}</DialogDescription>}
{(lastStep?.orderNumber || lastStep?.orderId || orderId) && (
<DialogDescription className="text-xs">
{t("onlinePayments.columns.orderNumber", "Sargyt belgisi")}:{" "}
{lastStep?.orderNumber || `Order #${lastStep?.orderId || orderId}`}
</DialogDescription>
)}
</DialogHeader>
{isLoading ? (
<div className="space-y-3 py-2">
<Skeleton className="h-6 w-1/3" />
<Skeleton className="h-4 w-1/2" />
<Skeleton className="h-24 w-full rounded-lg" />
<Skeleton className="h-28 w-full rounded-lg" />
<Skeleton className="h-28 w-full rounded-lg" />
</div>
) : !lastStep ? (
) : isError || !lastStep ? (
<div className="py-8 text-center text-sm text-muted-foreground">{t("onlinePayments.noHistory", "Töleg taryhy tapylmady")}</div>
) : (
<div className="space-y-4 text-xs">
{/* Step header: status badge + time + operator */}
<div className="flex flex-wrap items-center gap-3 px-1">
<GatewayStatusBadge status={lastStep.step} />
<span className="text-muted-foreground whitespace-nowrap">{formatFromApiDate(lastStep.createdAt)}</span>
{lastStep.createdByName && <span className="text-muted-foreground">{lastStep.createdByName}</span>}
<div className="space-y-3 text-xs">
{/* Section 1: General */}
<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="space-y-1.5">
{lastStep.id != null && (
<Row label={t("common.id", "ID")}>
<span className="font-mono font-medium">{lastStep.id}</span>
</Row>
)}
{lastStep.orderId != null && (
<Row label={t("onlinePayments.columns.orderId", "Sargyt ID")}>
<Link to={`/visa-master/${lastStep.orderId}`} className="font-mono text-primary hover:underline">
#{lastStep.orderId}
</Link>
</Row>
)}
{lastStep.orderNumber && (
<Row label={t("onlinePayments.columns.orderNumber", "Sargyt belgisi")}>
<span className="font-mono">{lastStep.orderNumber}</span>
</Row>
)}
{lastStep.type && (
<Row label={t("onlinePayments.columns.type", "Görnüşi")}>
<span className="uppercase font-medium">{lastStep.type}</span>
</Row>
)}
{lastStep.description && (
<Row label={t("onlinePayments.columns.description", "Düşündiriş")}>
<span>{lastStep.description}</span>
</Row>
)}
{lastStep.gatewayReference && (
<Row label={t("onlinePayments.columns.gatewayReference", "Gateway Ref")}>
<span className="font-mono text-[11px] break-all">{lastStep.gatewayReference}</span>
</Row>
)}
{(lastStep.apiClientName || lastStep.apiClient) && (
<Row label={t("onlinePayments.columns.apiClient", "API Client")}>
<span className="font-mono">{lastStep.apiClientName || lastStep.apiClient}</span>
</Row>
)}
{lastStep.callbackStatus && (
<Row label={t("onlinePayments.columns.callbackStatus", "Callback ýagdaýy")}>
<span className="uppercase font-medium">{lastStep.callbackStatus}</span>
</Row>
)}
{lastStep.createdAt && (
<Row label={t("onlinePayments.columns.createdAt", "Döredilen wagty")}>
<span>{formatFromApiDate(lastStep.createdAt)}</span>
</Row>
)}
{lastStep.callbackAt && (
<Row label={t("onlinePayments.columns.callbackAt", "Callback wagty")}>
<span>{formatFromApiDate(lastStep.callbackAt)}</span>
</Row>
)}
{lastStep.updatedAt && (
<Row label={t("onlinePayments.columns.updatedAt", "Täzelenen wagty")}>
<span>{formatFromApiDate(lastStep.updatedAt)}</span>
</Row>
)}
</div>
</div>
{/* Detail key-value grid */}
{/* Section 2: Financial */}
{(lastStep.amountTmt != null || lastStep.totalAmountTmt != null || lastStep.amountUsd != null) && (
<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="space-y-1.5">
{lastStep.totalAmountTmt != null && (
<Row label={t("onlinePayments.columns.totalAmount", "Jemi töleg möçberi")}>
<span className="font-semibold text-primary">
{lastStep.totalAmountTmt?.toLocaleString?.() ?? lastStep.totalAmountTmt} TMT
</span>
</Row>
)}
{lastStep.amountTmt != null && (
<Row label={t("onlinePayments.columns.amountTmt", "Töleg möçberi")}>
<span className="font-medium">{lastStep.amountTmt?.toLocaleString?.() ?? lastStep.amountTmt} TMT</span>
</Row>
)}
{lastStep.bankFeeTmt != null && (
<Row label={t("onlinePayments.columns.bankFeeTmt", "Bank komissiýasy")}>
<span>{lastStep.bankFeeTmt?.toLocaleString?.() ?? lastStep.bankFeeTmt} TMT</span>
</Row>
)}
{lastStep.gbusFeeTmt != null && (
<Row label={t("onlinePayments.columns.gbusFeeTmt", "GBUS komissiýasy")}>
<span>{lastStep.gbusFeeTmt?.toLocaleString?.() ?? lastStep.gbusFeeTmt} TMT</span>
</Row>
)}
{lastStep.amountUsd != null && (
<Row label={t("onlinePayments.columns.amountUsd", "Möçber (USD)")}>
<span>{lastStep.amountUsd} $</span>
</Row>
)}
{lastStep.exchangeRateUsd != null && (
<Row label={t("onlinePayments.columns.exchangeRateUsd", "Hümmet (USD)")}>
<span>{lastStep.exchangeRateUsd} TMT</span>
</Row>
)}
{lastStep.paymentPeriod && (
<Row label={t("onlinePayments.columns.paymentPeriod", "Töleg döwri")}>
<span>{formatFromApiDate(lastStep.paymentPeriod)}</span>
</Row>
)}
</div>
</div>
)}
{/* Section 3: Customer & Branch */}
{(fullName || lastStep.branchName || lastStep.createdByName || lastStep.userId) && (
<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="space-y-1.5">
{fullName && (
<Row label={t("onlinePayments.columns.passport", "Müşderi")}>
<span className="font-medium">{fullName}</span>
</Row>
)}
{lastStep.userId != null && (
<Row label={t("onlinePayments.columns.userId", "Ulanyjy ID")}>
<Link to={`/all-users/${lastStep.userId}`} className="font-mono text-primary hover:underline">
#{lastStep.userId}
</Link>
</Row>
)}
{branchDisplay && (
<Row label={t("onlinePayments.columns.branch", "Şahamça")}>
<span>{branchDisplay}</span>
</Row>
)}
{lastStep.createdByName && (
<Row label={t("onlinePayments.columns.createdByName", "Döreden işgär")}>
<span>{lastStep.createdByName}</span>
</Row>
)}
</div>
</div>
)}
{/* Section 4: External URLs */}
{(lastStep.formUrl || lastStep.successUrl) && (
<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.sectionUrls", "Baglanyşyklar")}
</p>
<div className="space-y-1.5">
{lastStep.formUrl && (
<Row label={t("onlinePayments.columns.formUrl", "Töleg Form URL")}>
<a
href={lastStep.formUrl}
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-1 text-primary hover:underline break-all"
>
<ExternalLink className="size-3 shrink-0" />
<span className="truncate max-w-[260px]">{lastStep.formUrl}</span>
</a>
</Row>
)}
{lastStep.successUrl && (
<Row label={t("onlinePayments.columns.successUrl", "Success URL")}>
<a
href={lastStep.successUrl}
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-1 text-primary hover:underline break-all"
>
<ExternalLink className="size-3 shrink-0" />
<span className="truncate max-w-[260px]">{lastStep.successUrl}</span>
</a>
</Row>
)}
</div>
</div>
)}
{/* Legacy detail entries if present */}
{detailEntries.length > 0 && (
<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">
@@ -260,21 +459,13 @@ export function LastStepDialog({ orderId, open, onOpenChange }: LastStepDialogPr
</p>
<div className="space-y-1.5">
{detailEntries.map(([key, value]) => (
<div key={key} className="flex gap-2">
<span className="text-muted-foreground font-medium min-w-[130px] shrink-0">
{t(`onlinePayments.detailKeys.${key}`, rawEnumKey(key))}
</span>
<span className="text-foreground break-all">{String(value)}</span>
</div>
<Row key={key} label={t(`onlinePayments.detailKeys.${key}`, rawEnumKey(key))}>
<span>{String(value)}</span>
</Row>
))}
</div>
</div>
)}
{/* Step ID */}
<p className="text-muted-foreground text-[11px] px-1">
Step ID: <span className="font-mono">{lastStep.id}</span>
</p>
</div>
)}
</DialogContent>

View File

@@ -1,13 +1,14 @@
import { useState, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { Eye } from "lucide-react";
import { ScanLine, Eye } from "lucide-react";
import type { VisibilityState } from "@tanstack/react-table";
import { DataTable, type ColumnDef, type SortingState } from "@/components/dataTable";
import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar";
import { Button } from "@/components/ui/button";
import { useGetPaymentGateway } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
import { ActiveStatusCell } from "@/constants/statusCells";
import { useGetOrderPaymentHistory } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
import { GatewayStatusCell } from "@/constants/statusCells";
import { PaidBadge } from "@/features/onlinePaymentHistory/components/PaymentStatusBadge";
import { formatFromApiDate } from "@/lib/utils/dateUtils";
import { PaymentDetailDialog, LastStepDialog } from "./PaymentDetailDialog";
@@ -78,27 +79,15 @@ function isPaid(row: any): boolean {
return Boolean(row.paid ?? (row.detail?.paid === "true" || row.detail?.paid === true));
}
function isSynced(row: any): boolean {
if (row.gatewayResponse?.orderStatus === 0 || row.gatewayResponse?.errorMessage === "Успешно") return true;
return Boolean(
row.synced ??
row.isSynced ??
row.systemSynced ??
row.syncedWithSystem ??
(row.detail?.synced === "true" || row.detail?.synced === true),
);
}
const PER_PAGE = 25;
// ─── Main Component ───────────────────────────────────────────────────────────
interface PaymentHistoryTableProps {
orderId?: string | number;
paymentId?: string | number;
}
export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableProps = {}) {
export function PaymentHistoryTable({ orderId }: PaymentHistoryTableProps = {}) {
const { t } = useTranslation();
// ─── Dialog State ──────────────────────────────────────────────────────────
@@ -117,19 +106,11 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
const [columnOrder, setColumnOrder] = useState<string[]>([]);
// ─── Query: /payment-history/payments/:id/gateway ──────────────────────────
const effectiveId = paymentId || orderId;
const { data: rawData, isLoading } = useGetPaymentGateway(effectiveId);
// ─── Query: /payment-history/:id?lang=tm ───────────────────────────────────
const { data: historyData, isLoading } = useGetOrderPaymentHistory(orderId, { lang: "tm" });
const items = useMemo(() => {
let list: any[] = [];
if (Array.isArray(rawData)) {
list = rawData;
} else if (rawData && typeof rawData === "object" && (rawData as any).id) {
list = [rawData];
} else if (rawData && Array.isArray((rawData as any).items)) {
list = (rawData as any).items;
}
const list = historyData?.items ?? [];
if (!search.trim()) return list;
const q = search.trim().toLowerCase();
@@ -137,13 +118,11 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP
const haystack = [r.id, getPayerFullName(r), getMaskedCard(r), getReference(r), r.orderId].join(" ").toLowerCase();
return haystack.includes(q);
});
}, [rawData, search]);
}, [historyData, search]);
const totalCount = useMemo(() => {
if (Array.isArray(rawData)) return rawData.length;
if (rawData && typeof (rawData as any).count === "number") return (rawData as any).count;
return items.length;
}, [rawData, items]);
return historyData?.count ?? items.length;
}, [historyData, items]);
const totalPages = Math.ceil(totalCount / perPage) || 1;
@@ -234,21 +213,14 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP
{
id: "isPaid",
header: t("intlPayment.historyColumns.isPaid", "Tölenen"),
cell: ({ row }) => (
<ActiveStatusCell
active={isPaid(row.original)}
labelActive={t("onlinePayments.statuses.paid", "Tölendi")}
labelInactive={t("onlinePayments.statuses.unpaid", "Tölenmedi")}
/>
),
cell: ({ row }) => <PaidBadge paid={isPaid(row.original)} />,
size: 110,
},
{
id: "isSynced",
header: t("intlPayment.historyColumns.isSynced", "Ulgam bn birikdirilen"),
cell: ({ row }) => (
<ActiveStatusCell active={isSynced(row.original)} labelActive={t("common.yes", "Hawa")} labelInactive={t("common.no", "Ýok")} />
),
id: "gatewayStatus",
accessorKey: "gatewayStatus",
header: t("onlinePayments.columns.gatewayStatus", "Gateway statusy"),
cell: ({ row }) => <GatewayStatusCell status={row.original.gatewayStatus} />,
size: 130,
},
{
@@ -257,7 +229,7 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP
cell: ({ row }) => (
<div className="flex items-center justify-end gap-1">
{/* Storage (Database) icon: opens payment detail dialog */}
{/* <Button
<Button
variant="ghost"
size="icon"
className="size-8 text-muted-foreground hover:text-foreground cursor-pointer"
@@ -267,8 +239,8 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP
setSelectedPaymentId(row.original.id);
}}
>
<Database className="size-4" />
</Button> */}
<ScanLine className="size-4" />
</Button>
{/* Eye icon: opens last-step dialog */}
<Button
@@ -278,7 +250,7 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP
title={t("onlinePayments.lastStep.title", "Iň soňky işlem")}
onClick={(e) => {
e.stopPropagation();
setSelectedOrderId(row.original.orderId || row.original.id);
setSelectedOrderId(row.original.orderId ?? row.original.id);
}}
>
<Eye className="size-4" />