changes some status
This commit is contained in:
1 parent
cbd17608c1
commit
6e626482f6
15 files changed
+553
-99
No files matched your search
@@ -11,6 +11,7 @@ import type { VisibilityState } from "@tanstack/react-table";
|
||||
import { useGetOnlinePayments } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||
import type { OnlinePayment } from "@/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi";
|
||||
import { GatewayStatusBadge, PaidBadge } from "../../features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||
import { getGatewayStatusOptions } from "@/constants/paymentStatus";
|
||||
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
@@ -50,13 +51,18 @@ const DEFAULT_VISIBILITY: VisibilityState = {
|
||||
|
||||
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" },
|
||||
];
|
||||
/** Column id → i18n key, shared by the table headers and the column-toggle list. */
|
||||
const COLUMN_LABEL_KEYS: Record<(typeof COLUMN_IDS)[number], string> = {
|
||||
id: "onlinePayments.columns.id",
|
||||
orderId: "onlinePayments.columns.orderId",
|
||||
type: "onlinePayments.columns.type",
|
||||
branchName: "onlinePayments.columns.branch",
|
||||
passport: "onlinePayments.columns.passport",
|
||||
totalAmountTmt: "onlinePayments.columns.totalAmount",
|
||||
gatewayStatus: "onlinePayments.columns.gatewayStatus",
|
||||
paid: "onlinePayments.columns.paid",
|
||||
createdAt: "onlinePayments.columns.createdAt",
|
||||
};
|
||||
|
||||
// ─── OnlinePaymentHistoryPage ─────────────────────────────────────────────────
|
||||
|
||||
@@ -109,6 +115,8 @@ export default function OnlinePaymentHistoryPage() {
|
||||
// ─── Derive query params from active filters
|
||||
const filterMap = useMemo(() => Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])), [activeFilters]);
|
||||
|
||||
const gatewayStatusOptions = useMemo(() => getGatewayStatusOptions(t), [t]);
|
||||
|
||||
const queryParams = useMemo(
|
||||
() => ({
|
||||
page,
|
||||
@@ -147,7 +155,7 @@ export default function OnlinePaymentHistoryPage() {
|
||||
id: "status",
|
||||
label: t("onlinePayments.filters.status", "Status"),
|
||||
type: "select",
|
||||
options: GATEWAY_STATUS_OPTIONS,
|
||||
options: gatewayStatusOptions,
|
||||
},
|
||||
{
|
||||
id: "branchId",
|
||||
@@ -172,7 +180,7 @@ export default function OnlinePaymentHistoryPage() {
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
[t, branchOptions, isBranchesLoading, isFetchingNextBranches, hasNextBranches, branchSearch],
|
||||
[t, branchOptions, isBranchesLoading, isFetchingNextBranches, hasNextBranches, branchSearch, gatewayStatusOptions],
|
||||
);
|
||||
|
||||
// ─── Columns
|
||||
@@ -181,28 +189,28 @@ export default function OnlinePaymentHistoryPage() {
|
||||
{
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("onlinePayments.columns.id", "ID"),
|
||||
header: t(COLUMN_LABEL_KEYS.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"),
|
||||
header: t(COLUMN_LABEL_KEYS.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"),
|
||||
header: t(COLUMN_LABEL_KEYS.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"),
|
||||
header: t(COLUMN_LABEL_KEYS.branchName, "BRANCH"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground truncate max-w-[200px] block">
|
||||
{row.original.branchName?.[lang] ?? row.original.branchName?.en ?? "—"}
|
||||
@@ -213,7 +221,7 @@ export default function OnlinePaymentHistoryPage() {
|
||||
{
|
||||
id: "passport",
|
||||
accessorKey: "passport",
|
||||
header: t("onlinePayments.columns.passport", "PASSPORT"),
|
||||
header: t(COLUMN_LABEL_KEYS.passport, "PASSPORT"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.passportName} {row.original.passportSurname}
|
||||
@@ -224,28 +232,28 @@ export default function OnlinePaymentHistoryPage() {
|
||||
{
|
||||
id: "totalAmountTmt",
|
||||
accessorKey: "totalAmountTmt",
|
||||
header: t("onlinePayments.columns.totalAmount", "TOTAL (TMT)"),
|
||||
header: t(COLUMN_LABEL_KEYS.totalAmountTmt, "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"),
|
||||
header: t(COLUMN_LABEL_KEYS.gatewayStatus, "GATEWAY STATUS"),
|
||||
cell: ({ row }) => <GatewayStatusBadge status={row.original.gatewayStatus} />,
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: "paid",
|
||||
accessorKey: "paid",
|
||||
header: t("onlinePayments.columns.paid", "PAID"),
|
||||
header: t(COLUMN_LABEL_KEYS.paid, "PAID"),
|
||||
cell: ({ row }) => <PaidBadge paid={row.original.paid} />,
|
||||
size: 90,
|
||||
},
|
||||
{
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("onlinePayments.columns.createdAt", "CREATED AT"),
|
||||
header: t(COLUMN_LABEL_KEYS.createdAt, "CREATED AT"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-muted-foreground text-xs whitespace-nowrap">{formatDateTime(row.original.createdAt)}</span>
|
||||
),
|
||||
@@ -275,7 +283,7 @@ export default function OnlinePaymentHistoryPage() {
|
||||
[t, navigate, lang],
|
||||
);
|
||||
|
||||
const toggleableColumns = useMemo(() => COLUMN_IDS.map((id) => ({ id, label: t(`onlinePayments.columns.${id}`, id) })), [t]);
|
||||
const toggleableColumns = useMemo(() => COLUMN_IDS.map((id) => ({ id, label: t(COLUMN_LABEL_KEYS[id], id) })), [t]);
|
||||
|
||||
// ─── Derived pagination
|
||||
const totalCount = data?.count ?? 0;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useGetOnlinePaymentById } from "@/features/onlinePaymentHistory/hooks/u
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import type { PaymentHistoryStep } from "@/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi";
|
||||
import { GatewayStatusBadge } from "@/features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||
import { rawEnumKey, type TranslateFn } from "@/constants/enumLabels";
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -20,9 +21,15 @@ function formatDateTime(iso: string): string {
|
||||
return `${hh}:${mm}, ${dd}.${mo}.${yy}`;
|
||||
}
|
||||
|
||||
/** Backend sends raw keys like "gateway_reference" — look them up under `onlinePayments.detailKeys`. */
|
||||
function detailKeyLabel(key: string, t: TranslateFn): string {
|
||||
return t(`onlinePayments.detailKeys.${key}`, rawEnumKey(key));
|
||||
}
|
||||
|
||||
// ─── StepRow ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function StepRow({ step }: { step: PaymentHistoryStep }) {
|
||||
const { t } = useTranslation();
|
||||
const detailEntries = Object.entries(step.detail ?? {});
|
||||
|
||||
return (
|
||||
@@ -45,7 +52,7 @@ function StepRow({ step }: { step: PaymentHistoryStep }) {
|
||||
<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-muted-foreground font-medium min-w-[120px]">{detailKeyLabel(key, t)}</span>
|
||||
<span className="text-foreground break-all">{String(value)}</span>
|
||||
</div>
|
||||
))}
|
||||
|
||||
Reference in new issue
Block a user