Add payment module, BFF proxy, hub/dashboard/ops/PSP/merchant screens wired to real APIs, and mark payment-frontend complete in project status. Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
"use client";
|
|
|
|
import { LoadingState, ErrorState, EmptyState } from "@/components/ds";
|
|
import { PaymentApiError } from "@/modules/payment/services/payment-api";
|
|
import { PermissionDeniedState } from "@/src/shared/ui";
|
|
|
|
export function PaymentPageLoader({ label = "در حال بارگذاری تربتپی…" }: { label?: string }) {
|
|
return <LoadingState label={label} />;
|
|
}
|
|
|
|
export function PaymentPageError({ error, onRetry }: { error: unknown; onRetry?: () => void }) {
|
|
if (error instanceof PaymentApiError && error.status === 403) {
|
|
return (
|
|
<PermissionDeniedState
|
|
message={
|
|
error.code === "bundle_inactive"
|
|
? "باندل لازم برای این بخش فعال نیست."
|
|
: error.message || "مجوز لازم وجود ندارد."
|
|
}
|
|
/>
|
|
);
|
|
}
|
|
const offline = typeof navigator !== "undefined" && !navigator.onLine;
|
|
if (offline) {
|
|
return <ErrorState message="اتصال اینترنت قطع است." onRetry={onRetry} />;
|
|
}
|
|
const message = error instanceof Error ? error.message : "خطا در دریافت دادهها";
|
|
return <ErrorState message={message} onRetry={onRetry} />;
|
|
}
|
|
|
|
export function PaymentEmptyState({
|
|
title = "موردی یافت نشد",
|
|
description = "هنوز دادهای از سرویس پرداخت دریافت نشده است.",
|
|
action,
|
|
}: {
|
|
title?: string;
|
|
description?: string;
|
|
action?: React.ReactNode;
|
|
}) {
|
|
return <EmptyState title={title} description={description} action={action} />;
|
|
}
|
|
|
|
export function exportToCsv(title: string, rows: Record<string, unknown>[], columns: string[]) {
|
|
if (rows.length === 0) return;
|
|
const header = columns.join(",");
|
|
const body = rows
|
|
.map((r) => columns.map((c) => JSON.stringify(r[c] ?? "")).join(","))
|
|
.join("\n");
|
|
const blob = new Blob(["\uFEFF" + header + "\n" + body], {
|
|
type: "text/csv;charset=utf-8",
|
|
});
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement("a");
|
|
a.href = url;
|
|
a.download = `${title}-export.csv`;
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
}
|