From ae68d705b3f2709f6c9c1009c5bd3c6ef4e0fb80 Mon Sep 17 00:00:00 2001 From: Jelaletdin12 Date: Mon, 26 Oct 2026 09:04:53 +0500 Subject: [PATCH] added actions to sber payments view --- src/app/router/index.tsx | 6 ++ src/components/viewPageComponents.tsx | 2 +- .../api/visaMasterPaymentsApi.ts | 32 +++++++ .../hooks/useVisaMasterPayments.ts | 17 ++++ .../sberPaymentActionView/index.tsx | 94 +++++++++++++++++++ .../sberPaymentsView/index.tsx | 40 ++++---- 6 files changed, 174 insertions(+), 17 deletions(-) create mode 100644 src/pages/internationalPayments/sberPaymentActionView/index.tsx diff --git a/src/app/router/index.tsx b/src/app/router/index.tsx index 3260ce9..70b4888 100644 --- a/src/app/router/index.tsx +++ b/src/app/router/index.tsx @@ -55,6 +55,7 @@ const VisaMasterPaymentCallbackPage = lazy(() => import("@/pages/internationalPa const SberPaymentPage = lazy(() => import("@/pages/internationalPayments/sberPayments")); const SberPaymentCreatePage = lazy(() => import("@/pages/internationalPayments/sberPaymentsCreate")); const SberPaymentViewPage = lazy(() => import("@/pages/internationalPayments/sberPaymentsView")); +const SberPaymentActionViewPage = lazy(() => import("@/pages/internationalPayments/sberPaymentActionView")); const SberPaymentEditPage = lazy(() => import("@/pages/internationalPayments/sberPaymentsEdit")); const OperatorsPage = lazy(() => import("@/pages/users/operators")); const OperatorCreatePage = lazy(() => import("@/pages/users/operatorsCreate")); @@ -462,6 +463,11 @@ const routes: AppRoute[] = [ handle: { title: (t) => t("sberPayments.editTitle", "Sber töleg üýtgetmek") }, element: page(SberPaymentEditPage), }, + { + path: "/sber-payments/:id/actions/:actionId", + handle: { title: (t) => t("sberPayments.actionViewTitle", "Hereket giňişleýin") }, + element: page(SberPaymentActionViewPage), + }, ], }, diff --git a/src/components/viewPageComponents.tsx b/src/components/viewPageComponents.tsx index 49678a8..48fa349 100644 --- a/src/components/viewPageComponents.tsx +++ b/src/components/viewPageComponents.tsx @@ -229,7 +229,7 @@ export interface AuditRowProps { export function StatusBadge({ status }: { status: string }) { const normalized = status.toLowerCase(); const variant = - normalized === "success" || normalized === "completed" + normalized === "success" || normalized === "completed" || normalized === "finished" ? "default" : normalized === "failed" || normalized === "error" ? "destructive" diff --git a/src/features/visaMasterPayments/api/visaMasterPaymentsApi.ts b/src/features/visaMasterPayments/api/visaMasterPaymentsApi.ts index 0362587..1b71930 100644 --- a/src/features/visaMasterPayments/api/visaMasterPaymentsApi.ts +++ b/src/features/visaMasterPayments/api/visaMasterPaymentsApi.ts @@ -169,6 +169,26 @@ export type IntlPaymentCreatePayload = IntlPaymentDocs & { export type IntlPaymentUpdatePayload = Partial; +export interface PaymentOrderAction { + id: number; + orderId: number; + name: string; + nameLabel: string; + status: string; + target: { id: number; uniqueId?: string; type?: string; label: string }; + createdById?: number | null; + createdByName?: string | null; + createdAt: string; + original?: Record | null; + changes?: Record | null; + exception?: unknown; +} + +export interface PaymentOrderActionsResponse { + count: number; + actions: PaymentOrderAction[]; +} + // ─── Backend types ───────────────────────────────────────────────────────────── interface BackendIntlPayment { @@ -404,6 +424,18 @@ export const intlPaymentApi = { return mapBackendToUI(data); }, + async listActions(orderId: string, page = 1, limit = 25): Promise { + const { data } = await apiClient.get(`/visa-master-payment-orders/${orderId}/actions`, { + params: { page, limit }, + }); + return data; + }, + + async getAction(orderId: string, actionId: string): Promise { + const { data } = await apiClient.get(`/visa-master-payment-orders/${orderId}/actions/${actionId}`); + return data; + }, + async create(payload: IntlPaymentCreatePayload): Promise { const body = await mapPayloadToBackend(payload); const { data } = await apiClient.post("/visa-master-payment-orders", body); diff --git a/src/features/visaMasterPayments/hooks/useVisaMasterPayments.ts b/src/features/visaMasterPayments/hooks/useVisaMasterPayments.ts index ae97871..7116fec 100644 --- a/src/features/visaMasterPayments/hooks/useVisaMasterPayments.ts +++ b/src/features/visaMasterPayments/hooks/useVisaMasterPayments.ts @@ -8,6 +8,7 @@ import { type IntlPaymentCreatePayload, type IntlPaymentUpdatePayload, type PayPayload, + type PaymentOrderAction, } from "../api/visaMasterPaymentsApi"; export const INTL_PAYMENT_KEYS = { @@ -37,6 +38,22 @@ export function useIntlPayment(id: string) { }); } +export function useIntlPaymentActions(orderId: string, page = 1, limit = 25) { + return useQuery({ + queryKey: [...INTL_PAYMENT_KEYS.detail(orderId), "actions", page, limit] as const, + queryFn: () => intlPaymentApi.listActions(orderId, page, limit), + enabled: !!orderId, + }); +} + +export function useIntlPaymentAction(orderId: string, actionId: string) { + return useQuery({ + queryKey: [...INTL_PAYMENT_KEYS.detail(orderId), "action", actionId] as const, + queryFn: () => intlPaymentApi.getAction(orderId, actionId), + enabled: !!orderId && !!actionId, + }); +} + export function useCreateIntlPayment() { const qc = useQueryClient(); const { t } = useTranslation(); diff --git a/src/pages/internationalPayments/sberPaymentActionView/index.tsx b/src/pages/internationalPayments/sberPaymentActionView/index.tsx new file mode 100644 index 0000000..0d49e33 --- /dev/null +++ b/src/pages/internationalPayments/sberPaymentActionView/index.tsx @@ -0,0 +1,94 @@ +import { format } from "date-fns"; +import { ArrowLeft } from "lucide-react"; +import { useNavigate, useParams } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Skeleton } from "@/components/ui/skeleton"; +import { Button } from "@/components/ui/button"; +import { InfoRow, Section, StatusBadge } from "@/components/viewPageComponents"; +import { useIntlPaymentAction } from "@/features/visaMasterPayments/hooks/useVisaMasterPayments"; + +function formatDate(value?: string | null) { + if (!value) return "—"; + const date = new Date(value); + return Number.isNaN(date.getTime()) ? "—" : `${format(date, "MM/dd/yyyy, hh:mm a")} GMT+5`; +} + +function displayValue(value: unknown) { + if (value === null || value === undefined || value === "") return "—"; + if (typeof value === "object") return JSON.stringify(value); + return String(value); +} + +function ChangesTable({ title, values }: { title: string; values?: Record | null }) { + const entries = Object.entries(values ?? {}); + if (!entries.length) return ; + + return ( +
+ {title} +
+
+ AÇAR + GYMMATLYK +
+ {entries.map(([key, value]) => ( +
+ {key} + {displayValue(value)} +
+ ))} +
+
+ ); +} + +export default function SberPaymentActionViewPage() { + const { t } = useTranslation(); + const navigate = useNavigate(); + const { id = "", actionId = "" } = useParams<{ id: string; actionId: string }>(); + const { data: action, isLoading, isError } = useIntlPaymentAction(id, actionId); + + if (isLoading) { + return ( +
+ + +
+ ); + } + + if (isError || !action) { + return ( +
{t("common.error", "Maglumat ýüklenende ýalňyşlyk ýüze çykdy")}
+ ); + } + + return ( +
+
+ +

+ {t("sberPayments.actionViewTitle", "Hereket giňişleýin")}: {action.nameLabel || action.name} +

+
+ +
+ + + + + {action.target?.label || "—"} + + + + + + + + +
+
+ ); +} diff --git a/src/pages/internationalPayments/sberPaymentsView/index.tsx b/src/pages/internationalPayments/sberPaymentsView/index.tsx index ba401c7..ef5eba7 100644 --- a/src/pages/internationalPayments/sberPaymentsView/index.tsx +++ b/src/pages/internationalPayments/sberPaymentsView/index.tsx @@ -1,11 +1,12 @@ import { format } from "date-fns"; +import { useState } from "react"; import { Search, Download } from "lucide-react"; import { useParams, useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Skeleton } from "@/components/ui/skeleton"; import { StatusCell } from "@/constants"; import { BentoGrid, BentoCard, InfoRow, AuditLog, ViewActions, type AuditRowProps } from "@/components/viewPageComponents"; -import { useIntlPayment, useDeleteIntlPayment } from "@/features/visaMasterPayments/hooks/useVisaMasterPayments"; +import { useIntlPayment, useDeleteIntlPayment, useIntlPaymentActions } from "@/features/visaMasterPayments/hooks/useVisaMasterPayments"; import { PaymentHistoryTable } from "@/features/visaMasterPayments/components/PaymentHistoryTable"; import { ACCEPTED_DOC_DEFS, SENT_DOC_DEFS, docLabel, type TFn } from "@/features/sberPayments/constants/documents"; @@ -88,8 +89,10 @@ export default function SberPaymentViewPage() { const t: TFn = (key, fallback) => _t(key, fallback ?? key) as string; const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); + const [actionsPage, setActionsPage] = useState(1); const { data: order, isLoading } = useIntlPayment(id ?? ""); + const { data: actionsData, isLoading: actionsLoading } = useIntlPaymentActions(id ?? "", actionsPage); const deleteMutation = useDeleteIntlPayment(); const handleDelete = async () => { @@ -109,19 +112,14 @@ export default function SberPaymentViewPage() { const payerInfo = [order.passport_series, order.passport_number, order.payer_full_name].filter(Boolean).join(" "); - // Backend gives no activity log; only the creation event is derivable from real data. - const auditLogs: AuditRowProps[] = order.created_at - ? [ - { - id: order.id, - action: t("sberPayments.audit.created", "Döredildi"), - by: order.created_by_label || "—", - target: order.id, - status: "FINISHED" as AuditRowProps["status"], - date: formatDate(order.created_at), - }, - ] - : []; + const auditLogs: AuditRowProps[] = (actionsData?.actions ?? []).map((action) => ({ + id: String(action.id), + action: action.nameLabel || action.name, + by: action.createdByName || "—", + target: action.target?.label || "—", + status: action.status, + date: formatDate(action.createdAt), + })); return (
@@ -226,8 +224,18 @@ export default function SberPaymentViewPage() { - {/* ── Audit log ────────────────────────────────────────────────────── */} - + {/* ── Row 6: Audit log ──────────────────────────────────────────────── */} + + navigate(`/sber-payments/${id}/actions/${action.id}`)} + /> +
); }