refactor: 合并多语言支持的显示名称字段,优化奖池手动爆发功能的返回数据结构,增强管理端权限控制
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
getPlayConfigVersion,
|
||||
getPlayConfigVersions,
|
||||
postPlayConfigVersion,
|
||||
patchAdminPlayType,
|
||||
publishPlayConfigVersion,
|
||||
putPlayConfigItems,
|
||||
} from "@/api/admin-config";
|
||||
@@ -43,6 +44,10 @@ import { ConfigReadonlyValue } from "@/modules/config/config-readonly-value";
|
||||
import { ConfigVersionActions } from "@/modules/config/config-version-actions";
|
||||
import { ConfigVersionSwitcher } from "@/modules/config/config-version-switcher";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { useConfirmAction } from "@/hooks/use-confirm-action";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { PRD_PLAY_SWITCH_MANAGE } from "@/lib/admin-prd";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type {
|
||||
ConfigVersionSummary,
|
||||
@@ -55,9 +60,7 @@ type PlayConfigSaveItemPayload = {
|
||||
category: string;
|
||||
dimension: number | null;
|
||||
bet_mode: string | null;
|
||||
display_name_zh: string;
|
||||
display_name_en: string | null;
|
||||
display_name_ne: string | null;
|
||||
display_name: string;
|
||||
is_enabled: boolean;
|
||||
min_bet_amount: number;
|
||||
max_bet_amount: number;
|
||||
@@ -117,9 +120,7 @@ function buildPlayConfigSavePayload(
|
||||
category: row.category ?? "",
|
||||
dimension: row.dimension,
|
||||
bet_mode: row.bet_mode,
|
||||
display_name_zh: row.display_name_zh ?? row.play_code,
|
||||
display_name_en: row.display_name_en ?? null,
|
||||
display_name_ne: row.display_name_ne ?? null,
|
||||
display_name: row.display_name ?? row.play_code,
|
||||
is_enabled: row.is_enabled,
|
||||
min_bet_amount: row.min_bet_amount,
|
||||
max_bet_amount: row.max_bet_amount,
|
||||
@@ -135,6 +136,9 @@ function buildPlayConfigSavePayload(
|
||||
|
||||
export function PlayConfigDocScreen() {
|
||||
const { t } = useTranslation(["config", "adminUsers", "common"]);
|
||||
const { request: requestConfirm, ConfirmDialog } = useConfirmAction();
|
||||
const profile = useAdminProfile();
|
||||
const canManage = adminHasAnyPermission(profile?.permissions, [PRD_PLAY_SWITCH_MANAGE]);
|
||||
const formatDt = useAdminDateTimeFormatter();
|
||||
const [list, setList] = useState<ConfigVersionSummary[]>([]);
|
||||
const [selectedId, setSelectedId] = useState("");
|
||||
@@ -149,9 +153,7 @@ export function PlayConfigDocScreen() {
|
||||
|
||||
const [nameDialogOpen, setNameDialogOpen] = useState(false);
|
||||
const [namePlayCode, setNamePlayCode] = useState<string | null>(null);
|
||||
const [nameDraftZh, setNameDraftZh] = useState("");
|
||||
const [nameDraftEn, setNameDraftEn] = useState("");
|
||||
const [nameDraftNe, setNameDraftNe] = useState("");
|
||||
const [nameDraft, setNameDraft] = useState("");
|
||||
const [ruleDialogOpen, setRuleDialogOpen] = useState(false);
|
||||
const [rulePlayCode, setRulePlayCode] = useState<string | null>(null);
|
||||
const [ruleDraftZh, setRuleDraftZh] = useState("");
|
||||
@@ -269,10 +271,25 @@ export function PlayConfigDocScreen() {
|
||||
setDraftRows((prev) => prev.map((r) => (r.play_code === playCode ? { ...r, ...patch } : r)));
|
||||
}
|
||||
|
||||
function applyBatchSwitch(group: PlayBatchSwitchGroup, enabled: boolean) {
|
||||
async function applyPlayToggleInstant(playCode: string, enabled: boolean) {
|
||||
try {
|
||||
await patchAdminPlayType(playCode, { is_enabled: enabled });
|
||||
} catch (e) {
|
||||
toast.error(
|
||||
e instanceof LotteryApiBizError ? e.message : t("play.toggleInstantFailed", { ns: "config" }),
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function applyBatchSwitch(group: PlayBatchSwitchGroup, enabled: boolean) {
|
||||
const targets = draftRows.filter(group.match);
|
||||
setDraftRows((prev) =>
|
||||
prev.map((row) => (group.match(row) ? { ...row, is_enabled: enabled } : row)),
|
||||
);
|
||||
for (const row of targets) {
|
||||
await applyPlayToggleInstant(row.play_code, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
const batchSwitchStates = useMemo(
|
||||
@@ -359,9 +376,7 @@ export function PlayConfigDocScreen() {
|
||||
function openNameEditor(play_code: string) {
|
||||
const item = draftRows.find((row) => row.play_code === play_code);
|
||||
setNamePlayCode(play_code);
|
||||
setNameDraftZh(item?.display_name_zh ?? item?.play_code ?? "");
|
||||
setNameDraftEn(item?.display_name_en ?? "");
|
||||
setNameDraftNe(item?.display_name_ne ?? "");
|
||||
setNameDraft(item?.display_name ?? item?.play_code ?? "");
|
||||
setNameDialogOpen(true);
|
||||
}
|
||||
|
||||
@@ -369,15 +384,13 @@ export function PlayConfigDocScreen() {
|
||||
if (!namePlayCode) {
|
||||
return;
|
||||
}
|
||||
const zh = nameDraftZh.trim();
|
||||
if (!zh) {
|
||||
toast.error(t("play.validation.nameZhRequired", { ns: "config" }));
|
||||
const name = nameDraft.trim();
|
||||
if (!name) {
|
||||
toast.error(t("play.validation.displayNameRequired", { ns: "config" }));
|
||||
return;
|
||||
}
|
||||
updateConfigRow(namePlayCode, {
|
||||
display_name_zh: zh,
|
||||
display_name_en: nameDraftEn.trim() || null,
|
||||
display_name_ne: nameDraftNe.trim() || null,
|
||||
display_name: name,
|
||||
});
|
||||
setNameDialogOpen(false);
|
||||
setNamePlayCode(null);
|
||||
@@ -408,26 +421,8 @@ export function PlayConfigDocScreen() {
|
||||
}
|
||||
|
||||
function renderDisplayNameReadonly(row: PlayConfigItemRow) {
|
||||
const lines = [
|
||||
{ label: t("play.locales.zh", { ns: "config" }), value: row.display_name_zh },
|
||||
{ label: t("play.locales.en", { ns: "config" }), value: row.display_name_en },
|
||||
{ label: t("play.locales.ne", { ns: "config" }), value: row.display_name_ne },
|
||||
].filter((line) => line.value?.trim());
|
||||
|
||||
if (lines.length === 0) {
|
||||
return <span>—</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-0.5 text-center text-sm">
|
||||
{lines.map((line) => (
|
||||
<p key={line.label}>
|
||||
<span className="text-muted-foreground text-xs">{line.label}: </span>
|
||||
{line.value}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
const name = row.display_name?.trim();
|
||||
return <span>{name || row.play_code}</span>;
|
||||
}
|
||||
|
||||
const activeHead = list.find((x) => x.status === "active");
|
||||
@@ -461,13 +456,22 @@ export function PlayConfigDocScreen() {
|
||||
actions={
|
||||
<ConfigVersionActions
|
||||
isDraft={isDraft}
|
||||
canManage={canManage}
|
||||
loadingList={loadingList}
|
||||
loadingDetail={loadingDetail}
|
||||
saving={saving}
|
||||
onRefresh={() => void refreshList()}
|
||||
onNewDraft={() => void handleNewDraft()}
|
||||
onSaveDraft={() => void handleSaveDraft()}
|
||||
onPublish={() => void handlePublish()}
|
||||
onPublish={() =>
|
||||
requestConfirm({
|
||||
title: t("play.publishDialog.title", { ns: "config" }),
|
||||
description: t("play.publishDialog.description", { ns: "config" }),
|
||||
confirmLabel: t("play.publishDialog.confirm", { ns: "config" }),
|
||||
confirmVariant: "destructive",
|
||||
onConfirm: () => handlePublish(),
|
||||
})
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
@@ -519,7 +523,23 @@ export function PlayConfigDocScreen() {
|
||||
size="sm"
|
||||
variant={group.allEnabled ? "secondary" : "outline"}
|
||||
disabled={!isDraft || saving || group.total === 0}
|
||||
onClick={() => applyBatchSwitch(group, !group.allEnabled)}
|
||||
onClick={() => {
|
||||
const enable = !group.allEnabled;
|
||||
const action = enable
|
||||
? t("play.batchSwitchEnable", { ns: "config" })
|
||||
: t("play.batchSwitchDisable", { ns: "config" });
|
||||
requestConfirm({
|
||||
title: t("play.batchSwitchConfirmTitle", { ns: "config", action }),
|
||||
description: t("play.batchSwitchConfirmDescription", {
|
||||
ns: "config",
|
||||
action,
|
||||
group: group.label,
|
||||
count: group.total,
|
||||
}),
|
||||
confirmVariant: enable ? "default" : "destructive",
|
||||
onConfirm: () => applyBatchSwitch(group, enable),
|
||||
});
|
||||
}}
|
||||
>
|
||||
{group.allEnabled
|
||||
? t("play.actions.disable", { ns: "config" })
|
||||
@@ -560,7 +580,23 @@ export function PlayConfigDocScreen() {
|
||||
checked={row.is_enabled}
|
||||
disabled={saving}
|
||||
onCheckedChange={(v) => {
|
||||
updateConfigRow(row.play_code, { is_enabled: v === true });
|
||||
const enabled = v === true;
|
||||
const action = enabled
|
||||
? t("play.toggleEnable", { ns: "config" })
|
||||
: t("play.toggleDisable", { ns: "config" });
|
||||
requestConfirm({
|
||||
title: t("play.toggleConfirmTitle", {
|
||||
ns: "config",
|
||||
action,
|
||||
playCode: row.play_code,
|
||||
}),
|
||||
description: t("play.toggleConfirmDescription", { ns: "config" }),
|
||||
confirmVariant: enabled ? "default" : "destructive",
|
||||
onConfirm: () => {
|
||||
updateConfigRow(row.play_code, { is_enabled: enabled });
|
||||
void applyPlayToggleInstant(row.play_code, enabled);
|
||||
},
|
||||
});
|
||||
}}
|
||||
aria-label={t("play.aria.enablePlay", { ns: "config", playCode: row.play_code })}
|
||||
/>
|
||||
@@ -578,7 +614,7 @@ export function PlayConfigDocScreen() {
|
||||
{isDraft ? (
|
||||
<div className="flex flex-col items-center gap-1.5">
|
||||
<p className="max-w-[10rem] truncate text-sm font-medium">
|
||||
{row.display_name_zh ?? row.play_code}
|
||||
{row.display_name ?? row.play_code}
|
||||
</p>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -588,7 +624,7 @@ export function PlayConfigDocScreen() {
|
||||
disabled={saving}
|
||||
onClick={() => openNameEditor(row.play_code)}
|
||||
>
|
||||
{t("play.actions.displayNames", { ns: "config" })}
|
||||
{t("play.actions.editDisplayName", { ns: "config" })}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
@@ -688,31 +724,13 @@ export function PlayConfigDocScreen() {
|
||||
{t("play.nameDialog.description", { ns: "config", playCode: namePlayCode ?? "—" })}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="name-zh">{t("play.locales.zh", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="name-zh"
|
||||
value={nameDraftZh}
|
||||
onChange={(e) => setNameDraftZh(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="name-en">{t("play.locales.en", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="name-en"
|
||||
value={nameDraftEn}
|
||||
onChange={(e) => setNameDraftEn(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="name-ne">{t("play.locales.ne", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="name-ne"
|
||||
value={nameDraftNe}
|
||||
onChange={(e) => setNameDraftNe(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="play-display-name">{t("play.table.displayName", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="play-display-name"
|
||||
value={nameDraft}
|
||||
onChange={(e) => setNameDraft(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => setNameDialogOpen(false)}>
|
||||
@@ -774,6 +792,7 @@ export function PlayConfigDocScreen() {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<ConfirmDialog />
|
||||
</ConfigDocPage>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user