removed db icon
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { Link } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Database, AlertTriangle } from "lucide-react";
|
||||
import { Database, AlertTriangle, Eye } 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 { useGetOnlinePaymentDetail, useGetOnlinePaymentById } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||
import { GatewayStatusBadge, PaidBadge } from "@/features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||
import { formatFromApiDate } from "@/lib/utils/dateUtils";
|
||||
import { rawEnumKey } from "@/constants/enumLabels";
|
||||
|
||||
function resolveLang(lang: string): "en" | "ru" | "tm" {
|
||||
if (lang === "ru") return "ru";
|
||||
@@ -200,3 +201,83 @@ export function PaymentDetailDialog({ paymentId, open, onOpenChange }: PaymentDe
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── LastStepDialog ───────────────────────────────────────────────────────────
|
||||
|
||||
interface LastStepDialogProps {
|
||||
/** The order ID (row.original.orderId) used to fetch the step history. */
|
||||
orderId: number | null;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a dialog showing only the most recent payment history step
|
||||
* for the given order. Used by the Eye icon in PaymentHistoryTable.
|
||||
*/
|
||||
export function LastStepDialog({ orderId, open, onOpenChange }: LastStepDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const { data: steps, isLoading } = 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 detailEntries = Object.entries(lastStep?.detail ?? {});
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-lg max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<Eye className="size-5 text-primary" />
|
||||
<DialogTitle className="text-base font-semibold">{t("onlinePayments.lastStep.title", "Iň soňky işlem")}</DialogTitle>
|
||||
</div>
|
||||
{orderId && <DialogDescription className="text-xs">Order #{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" />
|
||||
</div>
|
||||
) : !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>
|
||||
|
||||
{/* Detail key-value grid */}
|
||||
{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">
|
||||
{t("onlinePayments.detail.details", "Jikme-jikler")}
|
||||
</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>
|
||||
))}
|
||||
</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>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Database, Eye } from "lucide-react";
|
||||
import { Eye } from "lucide-react";
|
||||
import type { VisibilityState } from "@tanstack/react-table";
|
||||
|
||||
import { DataTable, type ColumnDef, type SortingState } from "@/components/dataTable";
|
||||
@@ -10,7 +9,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { useGetPaymentGateway } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||
import { ActiveStatusCell } from "@/constants/statusCells";
|
||||
import { formatFromApiDate } from "@/lib/utils/dateUtils";
|
||||
import { PaymentDetailDialog } from "./PaymentDetailDialog";
|
||||
import { PaymentDetailDialog, LastStepDialog } from "./PaymentDetailDialog";
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -101,10 +100,10 @@ interface PaymentHistoryTableProps {
|
||||
|
||||
export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableProps = {}) {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
// ─── Dialog State ──────────────────────────────────────────────────────────
|
||||
const [selectedPaymentId, setSelectedPaymentId] = useState<number | null>(null);
|
||||
const [selectedOrderId, setSelectedOrderId] = useState<number | null>(null);
|
||||
|
||||
// ─── Pagination & Search ───────────────────────────────────────────────────
|
||||
const [page, setPage] = useState(1);
|
||||
@@ -258,7 +257,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"
|
||||
@@ -269,17 +268,17 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP
|
||||
}}
|
||||
>
|
||||
<Database className="size-4" />
|
||||
</Button>
|
||||
</Button> */}
|
||||
|
||||
{/* Eye icon: navigates to audit/history step timeline */}
|
||||
{/* Eye icon: opens last-step dialog */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="size-8 text-muted-foreground hover:text-foreground cursor-pointer"
|
||||
title={t("onlinePayments.auditHistory", "Töleg taryhy")}
|
||||
title={t("onlinePayments.lastStep.title", "Iň soňky işlem")}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
navigate(`/online-payments-history/${row.original.orderId || row.original.id}`);
|
||||
setSelectedOrderId(row.original.orderId || row.original.id);
|
||||
}}
|
||||
>
|
||||
<Eye className="size-4" />
|
||||
@@ -289,7 +288,7 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP
|
||||
size: 80,
|
||||
},
|
||||
],
|
||||
[t, navigate],
|
||||
[t],
|
||||
);
|
||||
|
||||
const columnMeta: ColumnMeta[] = useMemo(
|
||||
@@ -354,6 +353,15 @@ export function PaymentHistoryTable({ orderId, paymentId }: PaymentHistoryTableP
|
||||
if (!open) setSelectedPaymentId(null);
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* ── Last Step Dialog (Triggered on clicking eye icon) ─────────────────── */}
|
||||
<LastStepDialog
|
||||
orderId={selectedOrderId}
|
||||
open={selectedOrderId !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setSelectedOrderId(null);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user