fix(invoices): localize payment method (wallet/gateway/mixed) to Persian

The payment method was rendered as the raw enum ("wallet") in the PDF and in the
invoice detail/list views. Map it through the existing methodWallet/methodGateway/
methodMixed dictionary keys everywhere.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
keyhan
2026-06-20 00:51:23 +03:30
parent 7438b44120
commit b232129ee2
3 changed files with 17 additions and 4 deletions
@@ -65,6 +65,8 @@ export default function AdminInvoicesPage() {
const lineLabel = (label?: string) => (isFa ? translateInvoiceLabel(label) : (label ?? '-'));
const lineDesc = (desc?: string) => (isFa ? translateInvoiceDescription(desc) : (desc ?? ''));
const reasonLabel = (reason?: string) => (isFa ? translateInvoiceReason(reason) : (reason ?? '-'));
const methodLabel = (m?: string) =>
m ? ({ wallet: inv.methodWallet, gateway: inv.methodGateway, mixed: inv.methodMixed } as Record<string, string>)[m] ?? m : '-';
const downloadPdfMutation = useMutation({
mutationFn: (invoice: Invoice) =>
@@ -168,7 +170,7 @@ export default function AdminInvoicesPage() {
<td className="px-4 py-3">
<span className={statusClasses[invoice.status]}>{statusLabel(invoice.status)}</span>
</td>
<td className="px-4 py-3 text-sm text-gray-600">{invoice.paymentMethod || '-'}</td>
<td className="px-4 py-3 text-sm text-gray-600">{methodLabel(invoice.paymentMethod)}</td>
<td className="px-4 py-3 text-right rtl:text-left">
<p className="text-sm font-bold text-gray-900">{formatPrice(invoice.dueAmount)} {t.common.currencyShort}</p>
<p className="text-xs text-gray-400">{inv.total} {formatPrice(invoice.total)} {t.common.currencyShort}</p>
@@ -229,7 +231,7 @@ export default function AdminInvoicesPage() {
</div>
<div className="flex items-center gap-2 text-gray-700">
<Wallet className="w-4 h-4 text-gray-400" />
{inv.method}: {selectedInvoice.paymentMethod || '-'}
{inv.method}: {methodLabel(selectedInvoice.paymentMethod)}
</div>
</div>
@@ -30,6 +30,8 @@ export default function InvoicesPage() {
const lineLabel = (label?: string) => (isFa ? translateInvoiceLabel(label) : (label ?? '-'));
const lineDesc = (desc?: string) => (isFa ? translateInvoiceDescription(desc) : (desc ?? ''));
const reasonLabel = (reason?: string) => (isFa ? translateInvoiceReason(reason) : (reason ?? '-'));
const methodLabel = (m?: string) =>
m ? ({ wallet: inv.methodWallet, gateway: inv.methodGateway, mixed: inv.methodMixed } as Record<string, string>)[m] ?? m : '-';
const authUser = useAuthStore((s) => s.user);
const queryClient = useQueryClient();
const searchParams = useSearchParams();
@@ -234,7 +236,7 @@ export default function InvoicesPage() {
<div className="flex justify-between"><span className="text-gray-500">{inv.total}</span><span className="font-semibold">{formatPrice(selectedInvoice.total)} {inv.toman}</span></div>
<div className="flex justify-between"><span className="text-gray-500">{inv.paidLabel}</span><span className="font-semibold text-green-600">{formatPrice(selectedInvoice.paidAmount)} {inv.toman}</span></div>
<div className="flex justify-between"><span className="text-gray-500">{inv.due}</span><span className="font-semibold text-primary-700">{formatPrice(selectedInvoice.dueAmount)} {inv.toman}</span></div>
<div className="flex justify-between"><span className="text-gray-500">{inv.method}</span><span>{selectedInvoice.paymentMethod || '-'}</span></div>
<div className="flex justify-between"><span className="text-gray-500">{inv.method}</span><span>{methodLabel(selectedInvoice.paymentMethod)}</span></div>
</div>
<div>
+10 -1
View File
@@ -39,6 +39,15 @@ export function buildInvoicePdfData(
const trDesc = (desc?: string) => (isFa ? translateInvoiceDescription(desc) : desc ?? '');
const trReason = (reason?: string) => (isFa ? translateInvoiceReason(reason) : reason ?? '-');
const methodLabel = (m?: string) => {
const map: Record<string, string> = {
wallet: inv.methodWallet,
gateway: inv.methodGateway,
mixed: inv.methodMixed,
};
return m ? map[m] ?? m : '-';
};
const cust = customer ?? invoice.user ?? undefined;
const fullName = [cust?.firstName, cust?.lastName].filter(Boolean).join(' ').trim();
const phone = cust?.phone || undefined;
@@ -50,7 +59,7 @@ export function buildInvoicePdfData(
meta.push(
{ label: pdf.application, value: invoice.application?.name || trReason(invoice.reason) },
{ label: pdf.createdAt, value: formatDate(invoice.createdAt) },
{ label: inv.method, value: invoice.paymentMethod || '-' },
{ label: inv.method, value: methodLabel(invoice.paymentMethod) },
);
if (invoice.paidAt) meta.push({ label: pdf.paidAt, value: formatDate(invoice.paidAt) });
if (invoice.gatewayTrackingCode) meta.push({ label: inv.tracking, value: invoice.gatewayTrackingCode });