Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
71 lines
2.9 KiB
TypeScript
71 lines
2.9 KiB
TypeScript
import { formatPoints } from "@/app/lib/format";
|
|
import type { AdminRefundDetail, AdminRefundRequest } from "@/app/lib/types";
|
|
|
|
// Display helpers for the Refund Requests page (add-refund-requests). Message codes resolve
|
|
// through DEFAULT_MESSAGES (RefundQueue*), so raw status/reason/effect codes never reach the UI.
|
|
|
|
type T = (code: string, params?: Record<string, string | number>) => string;
|
|
type BadgeVariant = "positive" | "warning" | "negative";
|
|
|
|
export function statusLabel(t: T, status: AdminRefundRequest["status"]): string {
|
|
switch (status) {
|
|
case "P":
|
|
return t("RefundQueueStatusPending");
|
|
case "I":
|
|
return t("RefundQueueStatusInProgress");
|
|
case "A":
|
|
return t("RefundQueueStatusApproved");
|
|
default:
|
|
return t("RefundQueueStatusRejected");
|
|
}
|
|
}
|
|
|
|
export function statusVariant(status: AdminRefundRequest["status"]): BadgeVariant {
|
|
if (status === "A") return "positive";
|
|
if (status === "R") return "negative";
|
|
return "warning";
|
|
}
|
|
|
|
export function reasonLabel(t: T, code: string): string {
|
|
const key = `RefundQueueReason_${code}`;
|
|
const label = t(key);
|
|
return label === key ? code : label;
|
|
}
|
|
|
|
/** One line per delivery order: what approving will do to its stock (mirrors RefundStockService). */
|
|
export function effectLabel(t: T, e: AdminRefundDetail["stockEffects"][number]): string {
|
|
const params = { doNo: e.deliveryOrderNo ?? "—", warehouse: e.warehouseId ?? "—" };
|
|
switch (e.effect) {
|
|
case "CANCEL_DO_LINES":
|
|
return t("RefundQueueEffectCancelDo", params);
|
|
case "RELEASE_RESERVATION":
|
|
return t("RefundQueueEffectRelease", params);
|
|
default:
|
|
return t("RefundQueueEffectRestock", params);
|
|
}
|
|
}
|
|
|
|
/** Channel label of a MANUAL payout (add-admin-initiated-refund). */
|
|
export function channelLabel(t: T, channel: AdminRefundRequest["payoutChannel"]): string {
|
|
return channel ? t(`RefundQueueChannel_${channel}`) : "—";
|
|
}
|
|
|
|
/** "Acorns wallet", "Gift card first, then Acorns wallet", or "Manual · Cash" plus the reference when there is one. Old rows have no payoutMethod: Acorns. */
|
|
export function payoutLabel(t: T, r: AdminRefundRequest, giftPaid?: boolean): string {
|
|
if (r.payoutMethod !== "MANUAL") {
|
|
if (giftPaid) return t("RefundQueuePayoutGiftCardFirst");
|
|
return t("RefundQueuePayoutAcorns");
|
|
}
|
|
if (giftPaid) {
|
|
const label = t("RefundQueuePayoutManualGiftCardFirst", { channel: channelLabel(t, r.payoutChannel) });
|
|
return r.payoutReference ? `${label} · ${r.payoutReference}` : label;
|
|
}
|
|
const label = t("RefundQueuePayoutManual", { channel: channelLabel(t, r.payoutChannel) });
|
|
return r.payoutReference ? `${label} · ${r.payoutReference}` : label;
|
|
}
|
|
|
|
/** Formats an amount without a currency prefix (used for RM and Acorn values; message strings add "RM"), null-safe. */
|
|
export function money(amount: number | null | undefined): string {
|
|
return formatPoints(Number(amount ?? 0));
|
|
}
|