added actions to sber payments view
This commit is contained in:
@@ -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),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -169,6 +169,26 @@ export type IntlPaymentCreatePayload = IntlPaymentDocs & {
|
||||
|
||||
export type IntlPaymentUpdatePayload = Partial<IntlPaymentCreatePayload>;
|
||||
|
||||
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<string, unknown> | null;
|
||||
changes?: Record<string, unknown> | 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<PaymentOrderActionsResponse> {
|
||||
const { data } = await apiClient.get<PaymentOrderActionsResponse>(`/visa-master-payment-orders/${orderId}/actions`, {
|
||||
params: { page, limit },
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
async getAction(orderId: string, actionId: string): Promise<PaymentOrderAction> {
|
||||
const { data } = await apiClient.get<PaymentOrderAction>(`/visa-master-payment-orders/${orderId}/actions/${actionId}`);
|
||||
return data;
|
||||
},
|
||||
|
||||
async create(payload: IntlPaymentCreatePayload): Promise<IntlPaymentItem> {
|
||||
const body = await mapPayloadToBackend(payload);
|
||||
const { data } = await apiClient.post<BackendIntlPayment>("/visa-master-payment-orders", body);
|
||||
|
||||
@@ -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<PaymentOrderAction>({
|
||||
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();
|
||||
|
||||
@@ -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<string, unknown> | null }) {
|
||||
const entries = Object.entries(values ?? {});
|
||||
if (!entries.length) return <InfoRow label={title} value="—" />;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col sm:grid sm:grid-cols-[minmax(0,24%)_minmax(0,76%)] items-start py-2.5 px-4 border-b border-border last:border-0 gap-2 sm:gap-0">
|
||||
<span className="text-xs sm:text-sm text-muted-foreground pt-1">{title}</span>
|
||||
<div className="w-full overflow-hidden rounded-lg border border-border">
|
||||
<div className="grid grid-cols-2 bg-muted/30 border-b border-border text-xs uppercase text-muted-foreground">
|
||||
<span className="px-4 py-2">AÇAR</span>
|
||||
<span className="px-4 py-2 border-l border-border">GYMMATLYK</span>
|
||||
</div>
|
||||
{entries.map(([key, value]) => (
|
||||
<div key={key} className="grid grid-cols-2 text-sm border-b last:border-0 border-border">
|
||||
<span className="px-4 py-2.5 font-mono text-muted-foreground">{key}</span>
|
||||
<span className="px-4 py-2.5 border-l border-border break-words">{displayValue(value)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<div className="space-y-4">
|
||||
<Skeleton className="h-7 w-72" />
|
||||
<Skeleton className="h-96 w-full rounded-xl" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isError || !action) {
|
||||
return (
|
||||
<div className="py-12 text-center text-sm text-destructive">{t("common.error", "Maglumat ýüklenende ýalňyşlyk ýüze çykdy")}</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<Button variant="ghost" size="sm" onClick={() => navigate(`/sber-payments/${id}`)} aria-label={t("common.back", "Yza")}>
|
||||
<ArrowLeft size={16} />
|
||||
</Button>
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{t("sberPayments.actionViewTitle", "Hereket giňişleýin")}: {action.nameLabel || action.name}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<Section>
|
||||
<InfoRow label={t("common.id", "ID")} value={action.id} />
|
||||
<InfoRow label={t("audit.columns.action", "Amalyň ady")} value={action.nameLabel || action.name} />
|
||||
<InfoRow label={t("audit.columns.by", "Kim tarapyndan")} value={action.createdByName} />
|
||||
<InfoRow label={t("audit.columns.target", "Amalyň nyşany (targeted)")}>
|
||||
<span className="font-medium text-primary">{action.target?.label || "—"}</span>
|
||||
</InfoRow>
|
||||
<InfoRow label={t("audit.columns.status", "Amalyň statusy")}>
|
||||
<StatusBadge status={action.status} />
|
||||
</InfoRow>
|
||||
<ChangesTable title={t("audit.original", "Asyl")} values={action.original} />
|
||||
<ChangesTable title={t("audit.changes", "Üýtgeşmeler")} values={action.changes} />
|
||||
<InfoRow label="Exception" value={displayValue(action.exception)} />
|
||||
<InfoRow label={t("audit.columns.date", "Sene")} value={formatDate(action.createdAt)} />
|
||||
</Section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="flex flex-col gap-6">
|
||||
@@ -226,8 +224,18 @@ export default function SberPaymentViewPage() {
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Audit log ────────────────────────────────────────────────────── */}
|
||||
<AuditLog logs={auditLogs} />
|
||||
{/* ── Row 6: Audit log ──────────────────────────────────────────────── */}
|
||||
<BentoCard title={t("sberPayments.view.sections.actions", "Ýerine ýetirilen hereketler")}>
|
||||
<AuditLog
|
||||
logs={auditLogs}
|
||||
isLoading={actionsLoading}
|
||||
currentPage={actionsPage}
|
||||
totalPages={Math.max(1, Math.ceil((actionsData?.count ?? 0) / 25))}
|
||||
totalCount={actionsData?.count ?? 0}
|
||||
onPageChange={setActionsPage}
|
||||
onView={(action) => navigate(`/sber-payments/${id}/actions/${action.id}`)}
|
||||
/>
|
||||
</BentoCard>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user