refactor: 合并多语言支持的显示名称字段,优化奖池手动爆发功能的返回数据结构,增强管理端权限控制
This commit is contained in:
@@ -36,8 +36,12 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { PRD_WALLET_WRITE_ANY } from "@/lib/admin-prd";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { useConfirmAction } from "@/hooks/use-confirm-action";
|
||||
import { useExportLabels } from "@/hooks/use-export-labels";
|
||||
import { formatAdminMinorUnits } from "@/lib/money";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
@@ -202,19 +206,31 @@ function walletAdminSelectDisplayedLabel(
|
||||
return key ? (t ? t(key) : key) : v;
|
||||
}
|
||||
|
||||
function canReverseTransferOrder(row: { status: string; can_reverse?: boolean }): boolean {
|
||||
return row.can_reverse ?? row.status === "pending_reconcile";
|
||||
function canReverseTransferOrder(
|
||||
row: { status: string; can_reverse?: boolean },
|
||||
canWriteWallet: boolean,
|
||||
): boolean {
|
||||
return canWriteWallet && (row.can_reverse ?? row.status === "pending_reconcile");
|
||||
}
|
||||
|
||||
function canManuallyProcessTransferOrder(row: {
|
||||
status: string;
|
||||
can_manually_process?: boolean;
|
||||
}): boolean {
|
||||
return row.can_manually_process ?? ["processing", "failed", "pending_reconcile"].includes(row.status);
|
||||
function canManuallyProcessTransferOrder(
|
||||
row: {
|
||||
status: string;
|
||||
can_manually_process?: boolean;
|
||||
},
|
||||
canWriteWallet: boolean,
|
||||
): boolean {
|
||||
return (
|
||||
canWriteWallet &&
|
||||
(row.can_manually_process ?? ["processing", "failed", "pending_reconcile"].includes(row.status))
|
||||
);
|
||||
}
|
||||
|
||||
export function TransferOrdersPanel(): React.ReactElement {
|
||||
const { t } = useTranslation(["wallet", "common"]);
|
||||
const { request: requestConfirm, ConfirmDialog } = useConfirmAction();
|
||||
const profile = useAdminProfile();
|
||||
const canWriteWallet = adminHasAnyPermission(profile?.permissions, [...PRD_WALLET_WRITE_ANY]);
|
||||
const exportLabels = useExportLabels("walletTransferOrders");
|
||||
useAdminCurrencyCatalog();
|
||||
const formatTs = useAdminDateTimeFormatter();
|
||||
@@ -249,10 +265,20 @@ export function TransferOrdersPanel(): React.ReactElement {
|
||||
};
|
||||
|
||||
const handleReverse = (transferNo: string) =>
|
||||
doAction(transferNo, () => reverseTransferOrder(transferNo), t("reverseSuccess"));
|
||||
requestConfirm({
|
||||
title: t("confirm.reverseTitle"),
|
||||
description: t("confirm.reverseDescription", { transferNo }),
|
||||
confirmVariant: "destructive",
|
||||
onConfirm: () => doAction(transferNo, () => reverseTransferOrder(transferNo), t("reverseSuccess")),
|
||||
});
|
||||
|
||||
const handleManuallyProcess = (transferNo: string) =>
|
||||
doAction(transferNo, () => manuallyProcessTransferOrder(transferNo), t("manualProcessSuccess"));
|
||||
requestConfirm({
|
||||
title: t("confirm.manualProcessTitle"),
|
||||
description: t("confirm.manualProcessDescription", { transferNo }),
|
||||
onConfirm: () =>
|
||||
doAction(transferNo, () => manuallyProcessTransferOrder(transferNo), t("manualProcessSuccess")),
|
||||
});
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
@@ -302,6 +328,7 @@ export function TransferOrdersPanel(): React.ReactElement {
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t("transferOrders")}</CardTitle>
|
||||
@@ -480,9 +507,10 @@ export function TransferOrdersPanel(): React.ReactElement {
|
||||
{formatTs(row.finished_at)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{canReverseTransferOrder(row) || canManuallyProcessTransferOrder(row) ? (
|
||||
{canReverseTransferOrder(row, canWriteWallet) ||
|
||||
canManuallyProcessTransferOrder(row, canWriteWallet) ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
{canReverseTransferOrder(row) ? (
|
||||
{canReverseTransferOrder(row, canWriteWallet) ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
@@ -493,7 +521,7 @@ export function TransferOrdersPanel(): React.ReactElement {
|
||||
{actionLoading.has(row.transfer_no) ? t("processing") : t("reverse")}
|
||||
</Button>
|
||||
) : null}
|
||||
{canManuallyProcessTransferOrder(row) ? (
|
||||
{canManuallyProcessTransferOrder(row, canWriteWallet) ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
@@ -532,6 +560,8 @@ export function TransferOrdersPanel(): React.ReactElement {
|
||||
) : null}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<ConfirmDialog />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user