changed pay dialog
This commit is contained in:
@@ -1,163 +1,17 @@
|
||||
// pages/OnlinePaymentHistoryPage.tsx
|
||||
|
||||
import { useState } from "react";
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Eye, Rss } from "lucide-react";
|
||||
import { Eye } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
import type { VisibilityState } from "@tanstack/react-table";
|
||||
import { useGetOnlinePayments, useTriggerPaymentCallback } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||
import { useGetOnlinePayments } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||
import type { OnlinePayment } from "@/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi";
|
||||
import { PaymentStatusBadge } from "../../features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||
|
||||
// ─── Defaults ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const DEFAULT_VISIBILITY = {
|
||||
amount: true,
|
||||
apiClient: true,
|
||||
description: true,
|
||||
status: true,
|
||||
username: true,
|
||||
createdAt: true,
|
||||
};
|
||||
const DEFAULT_ORDER = ["amount", "apiClient", "description", "status", "username", "createdAt", "actions"];
|
||||
|
||||
// ─── OnlinePaymentHistoryPage ─────────────────────────────────────────────────
|
||||
|
||||
export default function OnlinePaymentHistoryPage() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>(DEFAULT_VISIBILITY);
|
||||
const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER);
|
||||
|
||||
const { data, isLoading } = useGetOnlinePayments({ page, perPage, search });
|
||||
const callbackMutation = useTriggerPaymentCallback();
|
||||
|
||||
const handleSearchChange = (val: string) => {
|
||||
setSearch(val);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
// ─── Columns ──────────────────────────────────────────────────────────────
|
||||
|
||||
const columns: ColumnDef<OnlinePayment>[] = [
|
||||
{
|
||||
accessorKey: "amount",
|
||||
header: t("onlinePayments.columns.amount", "MÖÇBERI"),
|
||||
cell: ({ row }) => <span className="tabular-nums text-foreground font-medium">{row.original.amount}</span>,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
accessorKey: "apiClient",
|
||||
header: t("onlinePayments.columns.apiClient", "API CLIENT"),
|
||||
cell: ({ row }) => <span className="text-foreground text-xs font-mono truncate max-w-[180px] block">{row.original.apiClient}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "description",
|
||||
header: t("onlinePayments.columns.description", "DESC"),
|
||||
cell: ({ row }) => <span className="text-foreground text-sm">{row.original.description}</span>,
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
header: t("onlinePayments.columns.status", "STATUS"),
|
||||
cell: ({ row }) => <PaymentStatusBadge status={row.original.status} />,
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
accessorKey: "username",
|
||||
header: t("onlinePayments.columns.username", "USERNAME"),
|
||||
cell: ({ row }) => <span className="text-foreground text-xs font-mono">{row.original.username}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "createdAt",
|
||||
header: t("onlinePayments.columns.createdAt", "DÖREDILEN WAGTY"),
|
||||
cell: ({ row }) => <span className="text-muted-foreground text-xs whitespace-nowrap">{formatDateTime(row.original.createdAt)}</span>,
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
{/* Callback trigger */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||
disabled={callbackMutation.isPending}
|
||||
onClick={() => callbackMutation.mutate(row.original.id)}
|
||||
title={t("onlinePayments.actions.callback", "Callback ugrat")}
|
||||
>
|
||||
<Rss size={15} />
|
||||
</Button>
|
||||
{/* View detail */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/online-payments-history/${row.original.id}`)}
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 90,
|
||||
},
|
||||
];
|
||||
|
||||
const columnMeta = columns
|
||||
.filter((c) => "accessorKey" in c && c.accessorKey)
|
||||
.map((c) => ({
|
||||
id: String(("accessorKey" in c ? c.accessorKey : c.id) ?? ""),
|
||||
label: typeof c.header === "string" ? c.header : "",
|
||||
}));
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-5">{t("onlinePayments.title", "Onlaýn töleg taryhy")}</h1>
|
||||
<DataTable
|
||||
toolbar={
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={handleSearchChange}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
hideAction
|
||||
/>
|
||||
}
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={data?.totalPages ?? 1}
|
||||
totalCount={data?.total ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
import { GatewayStatusBadge, PaidBadge } from "../../features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -170,3 +24,304 @@ function formatDateTime(iso: string): string {
|
||||
const yy = d.getFullYear();
|
||||
return `${hh}:${mm}, ${dd}.${mo}.${yy}`;
|
||||
}
|
||||
|
||||
/** Map i18n language code → backend localized text key. */
|
||||
function resolveLang(lang: string): "en" | "ru" | "tm" {
|
||||
if (lang === "ru") return "ru";
|
||||
if (lang === "tk") return "tm";
|
||||
return "en";
|
||||
}
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
const COLUMN_IDS = ["id", "orderId", "type", "branchName", "passport", "totalAmountTmt", "gatewayStatus", "paid", "createdAt"] as const;
|
||||
|
||||
const DEFAULT_VISIBILITY: VisibilityState = {
|
||||
id: true,
|
||||
orderId: true,
|
||||
type: true,
|
||||
branchName: true,
|
||||
passport: true,
|
||||
totalAmountTmt: true,
|
||||
gatewayStatus: true,
|
||||
paid: true,
|
||||
createdAt: true,
|
||||
};
|
||||
|
||||
const DEFAULT_ORDER = [...COLUMN_IDS, "actions"];
|
||||
|
||||
/** Gateway status options for the filter dropdown. */
|
||||
const GATEWAY_STATUS_OPTIONS = [
|
||||
{ value: "success", label: "Success" },
|
||||
{ value: "failed", label: "Failed" },
|
||||
{ value: "pending", label: "Pending" },
|
||||
{ value: "processing", label: "Processing" },
|
||||
];
|
||||
|
||||
// ─── OnlinePaymentHistoryPage ─────────────────────────────────────────────────
|
||||
|
||||
export default function OnlinePaymentHistoryPage() {
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const lang = resolveLang(i18n.language);
|
||||
|
||||
// ─── Pagination & search
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
// ─── Column state
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>(DEFAULT_VISIBILITY);
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...DEFAULT_ORDER]);
|
||||
|
||||
// ─── Filters — fieldId matches query param name for easy mapping
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ fieldId: "status", value: "" },
|
||||
{ fieldId: "branchId", value: "" },
|
||||
{ fieldId: "orderId", value: "" },
|
||||
{ fieldId: "userId", value: "" },
|
||||
]);
|
||||
|
||||
// ─── Branch infinite-select data
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const {
|
||||
data: branchesInfiniteData,
|
||||
fetchNextPage: fetchNextBranches,
|
||||
hasNextPage: hasNextBranches,
|
||||
isFetchingNextPage: isFetchingNextBranches,
|
||||
isLoading: isBranchesLoading,
|
||||
} = useInfiniteBranches(branchSearch);
|
||||
|
||||
const branchOptions = useMemo(
|
||||
() =>
|
||||
(branchesInfiniteData?.pages ?? []).flatMap((p) =>
|
||||
(p?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
),
|
||||
[branchesInfiniteData, lang],
|
||||
);
|
||||
|
||||
// ─── Derive query params from active filters
|
||||
const filterMap = useMemo(() => Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])), [activeFilters]);
|
||||
|
||||
const queryParams = useMemo(
|
||||
() => ({
|
||||
page,
|
||||
limit: perPage,
|
||||
search: search || undefined,
|
||||
status: filterMap.status || undefined,
|
||||
branchId: filterMap.branchId ? Number(filterMap.branchId) : undefined,
|
||||
orderId: filterMap.orderId ? Number(filterMap.orderId) : undefined,
|
||||
userId: filterMap.userId ? Number(filterMap.userId) : undefined,
|
||||
}),
|
||||
[page, perPage, search, filterMap],
|
||||
);
|
||||
|
||||
const { data, isLoading } = useGetOnlinePayments(queryParams);
|
||||
|
||||
// ─── Handlers
|
||||
const handleSearchChange = useCallback((val: string) => {
|
||||
setSearch(val);
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" })));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
// ─── Filter field definitions
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
id: "status",
|
||||
label: t("onlinePayments.filters.status", "Status"),
|
||||
type: "select",
|
||||
options: GATEWAY_STATUS_OPTIONS,
|
||||
},
|
||||
{
|
||||
id: "branchId",
|
||||
label: t("onlinePayments.filters.branch", "Branch"),
|
||||
type: "infinite-select",
|
||||
options: branchOptions,
|
||||
loading: isBranchesLoading,
|
||||
isLoadingMore: isFetchingNextBranches,
|
||||
hasNextPage: hasNextBranches,
|
||||
onLoadMore: fetchNextBranches,
|
||||
searchValue: branchSearch,
|
||||
onSearchChange: setBranchSearch,
|
||||
},
|
||||
{
|
||||
id: "orderId",
|
||||
label: t("onlinePayments.filters.orderId", "Order ID"),
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
id: "userId",
|
||||
label: t("onlinePayments.filters.userId", "User ID"),
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
[t, branchOptions, isBranchesLoading, isFetchingNextBranches, hasNextBranches, branchSearch],
|
||||
);
|
||||
|
||||
// ─── Columns
|
||||
const columns = useMemo<ColumnDef<OnlinePayment>[]>(
|
||||
() => [
|
||||
{
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("onlinePayments.columns.id", "ID"),
|
||||
cell: ({ row }) => <span className="tabular-nums text-foreground font-medium">{row.original.id}</span>,
|
||||
size: 50,
|
||||
},
|
||||
{
|
||||
id: "orderId",
|
||||
accessorKey: "orderId",
|
||||
header: t("onlinePayments.columns.orderId", "ORDER ID"),
|
||||
cell: ({ row }) => <span className="tabular-nums text-foreground font-medium">{row.original.orderId}</span>,
|
||||
size: 90,
|
||||
},
|
||||
{
|
||||
id: "type",
|
||||
accessorKey: "type",
|
||||
header: t("onlinePayments.columns.type", "TYPE"),
|
||||
cell: ({ row }) => <span className="text-xs font-semibold uppercase tracking-wide text-foreground">{row.original.type}</span>,
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
id: "branchName",
|
||||
accessorKey: "branchName",
|
||||
header: t("onlinePayments.columns.branch", "BRANCH"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground truncate max-w-[200px] block">
|
||||
{row.original.branchName?.[lang] ?? row.original.branchName?.en ?? "—"}
|
||||
</span>
|
||||
),
|
||||
size: 200,
|
||||
},
|
||||
{
|
||||
id: "passport",
|
||||
accessorKey: "passport",
|
||||
header: t("onlinePayments.columns.passport", "PASSPORT"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.passportName} {row.original.passportSurname}
|
||||
</span>
|
||||
),
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
id: "totalAmountTmt",
|
||||
accessorKey: "totalAmountTmt",
|
||||
header: t("onlinePayments.columns.totalAmount", "TOTAL (TMT)"),
|
||||
cell: ({ row }) => <span className="tabular-nums text-foreground font-medium">{row.original.totalAmountTmt.toLocaleString()}</span>,
|
||||
size: 110,
|
||||
},
|
||||
{
|
||||
id: "gatewayStatus",
|
||||
accessorKey: "gatewayStatus",
|
||||
header: t("onlinePayments.columns.gatewayStatus", "GATEWAY STATUS"),
|
||||
cell: ({ row }) => <GatewayStatusBadge status={row.original.gatewayStatus} />,
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: "paid",
|
||||
accessorKey: "paid",
|
||||
header: t("onlinePayments.columns.paid", "PAID"),
|
||||
cell: ({ row }) => <PaidBadge paid={row.original.paid} />,
|
||||
size: 90,
|
||||
},
|
||||
{
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("onlinePayments.columns.createdAt", "CREATED AT"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-muted-foreground text-xs whitespace-nowrap">{formatDateTime(row.original.createdAt)}</span>
|
||||
),
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/online-payments-history/${row.original.orderId}`)}
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 60,
|
||||
},
|
||||
],
|
||||
[t, navigate, lang],
|
||||
);
|
||||
|
||||
const toggleableColumns = useMemo(() => COLUMN_IDS.map((id) => ({ id, label: t(`onlinePayments.columns.${id}`, id) })), [t]);
|
||||
|
||||
// ─── Derived pagination
|
||||
const totalCount = data?.count ?? 0;
|
||||
const totalPages = Math.ceil(totalCount / perPage) || 1;
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("onlinePayments.title", "Onlaýn töleg taryhy")}</h1>
|
||||
|
||||
<DataTable
|
||||
toolbar={
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={handleSearchChange}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={toggleableColumns}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
hideAction
|
||||
filterFields={filterFields}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterReset={handleFilterReset}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
columns={columns}
|
||||
data={data?.items ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={totalCount}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,78 +2,11 @@
|
||||
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Section, InfoRow } from "@/components/viewPageComponents";
|
||||
import { Section } from "@/components/viewPageComponents";
|
||||
import { useGetOnlinePaymentById } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||
import { PaymentStatusBadge } from "../../features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
|
||||
// ─── OnlinePaymentDetailPage ──────────────────────────────────────────────────
|
||||
|
||||
export default function OnlinePaymentDetailPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const numericId = Number(id);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data: payment, isLoading } = useGetOnlinePaymentById(numericId);
|
||||
|
||||
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<Skeleton className="h-6 w-96" />
|
||||
<Skeleton className="h-[560px] w-full rounded-xl" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!payment) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<p className="text-muted-foreground">{t("onlinePayments.notFound", "Töleg tapylmady")}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const title = `${t("onlinePayments.detail.title", "Onlaýn töleg taryhy giňişleýin")}: ${payment.orderId}`;
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold text-foreground mb-6 break-all">{title}</h1>
|
||||
|
||||
{/* Detail Card */}
|
||||
<Section>
|
||||
<InfoRow label={t("common.id", "ID")} value={payment.id} />
|
||||
<InfoRow label={t("onlinePayments.fields.amount", "amount")} value={payment.amount} />
|
||||
<InfoRow label={t("onlinePayments.fields.orderNumber", "orderNumber")} value={payment.orderNumber} />
|
||||
<InfoRow label={t("onlinePayments.fields.apiClient", "Api Client")} value={payment.apiClient} />
|
||||
<InfoRow label={t("onlinePayments.fields.description", "description")} value={payment.description} />
|
||||
<InfoRow label={t("onlinePayments.fields.orderId", "orderId")} value={payment.orderId} />
|
||||
<InfoRow label={t("onlinePayments.fields.formUrl", "formUrl")} isLink href={payment.formUrl ?? undefined} value={payment.formUrl} />
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.successUrl", "successUrl")}
|
||||
isLink
|
||||
href={payment.successUrl ?? undefined}
|
||||
value={payment.successUrl}
|
||||
/>
|
||||
<InfoRow label={t("onlinePayments.fields.status", "Status")}>
|
||||
<PaymentStatusBadge status={payment.status} />
|
||||
</InfoRow>
|
||||
<InfoRow label={t("onlinePayments.fields.callbackStatus", "callbackStatus")} value={payment.callbackStatus ?? "—"} />
|
||||
<InfoRow label={t("onlinePayments.fields.username", "username")} value={payment.username} />
|
||||
<InfoRow label={t("onlinePayments.fields.onlinePaymantableId", "online_paymantable_id")} value={payment.onlinePaymantableId} />
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.onlinePaymantableType", "online_paymantable_type")}
|
||||
value={payment.onlinePaymantableType}
|
||||
/>
|
||||
<InfoRow label={t("onlinePayments.fields.createdAt", "Döredilen wagty")} value={formatDateTime(payment.createdAt)} />
|
||||
<InfoRow label={t("onlinePayments.fields.updatedAt", "Updated at")} value={formatDateTime(payment.updatedAt)} />
|
||||
</Section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
import type { PaymentHistoryStep } from "@/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi";
|
||||
import { GatewayStatusBadge } from "@/features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -86,3 +19,96 @@ function formatDateTime(iso: string): string {
|
||||
const yy = d.getFullYear();
|
||||
return `${hh}:${mm}, ${dd}.${mo}.${yy}`;
|
||||
}
|
||||
|
||||
// ─── StepRow ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function StepRow({ step }: { step: PaymentHistoryStep }) {
|
||||
const detailEntries = Object.entries(step.detail ?? {});
|
||||
|
||||
return (
|
||||
<div className="flex gap-4 relative">
|
||||
{/* Timeline line */}
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="w-3 h-3 rounded-full bg-primary mt-1 shrink-0 z-10" />
|
||||
<div className="w-px flex-1 bg-border mt-1" />
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="pb-6 flex-1 min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-3 mb-1">
|
||||
<GatewayStatusBadge status={step.step} />
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">{formatDateTime(step.createdAt)}</span>
|
||||
<span className="text-xs text-muted-foreground">{step.createdByName}</span>
|
||||
</div>
|
||||
|
||||
{detailEntries.length > 0 && (
|
||||
<div className="mt-2 rounded-md border bg-muted/30 px-3 py-2 space-y-1">
|
||||
{detailEntries.map(([key, value]) => (
|
||||
<div key={key} className="flex gap-2 text-xs">
|
||||
<span className="text-muted-foreground font-medium min-w-[120px]">{key}</span>
|
||||
<span className="text-foreground break-all">{String(value)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── OnlinePaymentDetailPage ──────────────────────────────────────────────────
|
||||
|
||||
export default function OnlinePaymentDetailPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const numericId = Number(id);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data: steps, isLoading } = useGetOnlinePaymentById(numericId);
|
||||
|
||||
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<Skeleton className="h-6 w-72" />
|
||||
<Skeleton className="h-[400px] w-full rounded-xl" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!steps || steps.length === 0) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<p className="text-muted-foreground">{t("onlinePayments.noHistory", "Töleg taryhy tapylmady")}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const orderId = steps[0]?.orderId;
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold text-foreground mb-6">
|
||||
{t("onlinePayments.detail.title", "Onlaýn töleg taryhy giňişleýin")}
|
||||
{orderId ? ` — Order #${orderId}` : ""}
|
||||
</h1>
|
||||
|
||||
<Section>
|
||||
<div className="px-1 py-2">
|
||||
<p className="text-sm font-medium text-muted-foreground mb-6">
|
||||
{t("onlinePayments.detail.stepsCount", "Ädimler")}: {steps.length}
|
||||
</p>
|
||||
|
||||
{/* Timeline */}
|
||||
<div>
|
||||
{steps.map((step) => (
|
||||
<StepRow key={step.id} step={step} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user