refactor: 合并多语言支持的显示名称字段,优化奖池手动爆发功能的返回数据结构,增强管理端权限控制
This commit is contained in:
@@ -32,6 +32,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 { resolveAdminPlayTypeDisplayName } from "@/lib/admin-play-types";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { PRD_ODDS_MANAGE, PRD_REBATE_MANAGE } from "@/lib/admin-prd";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type {
|
||||
AdminPlayTypeRow,
|
||||
@@ -41,9 +45,9 @@ import type {
|
||||
} from "@/types/api/admin-config";
|
||||
|
||||
import {
|
||||
PRIZE_SCOPE_LABELS,
|
||||
PRIZE_SCOPE_MULTIPLIER_HINT,
|
||||
PRIZE_SCOPE_ORDER,
|
||||
prizeScopeLabel,
|
||||
type PrizeScopeCode,
|
||||
} from "@/modules/config/doc/prize-scopes";
|
||||
|
||||
@@ -67,7 +71,9 @@ type OddsConfigDocScreenProps = {
|
||||
};
|
||||
|
||||
export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenProps) {
|
||||
const { t } = useTranslation(["config", "adminUsers", "common"]);
|
||||
const { t, i18n } = useTranslation(["config", "adminUsers", "common"]);
|
||||
const profile = useAdminProfile();
|
||||
const canManage = adminHasAnyPermission(profile?.permissions, [PRD_ODDS_MANAGE, PRD_REBATE_MANAGE]);
|
||||
const formatDt = useAdminDateTimeFormatter();
|
||||
const [types, setTypes] = useState<AdminPlayTypeRow[]>([]);
|
||||
const [list, setList] = useState<ConfigVersionSummary[]>([]);
|
||||
@@ -190,6 +196,7 @@ export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenPro
|
||||
const isSelectedDetail = detail !== null && String(detail.id) === selectedId;
|
||||
const selectedStatus = isSelectedDetail ? detail.status : selectedVersionSummary?.status;
|
||||
const isDraft = selectedStatus === "draft";
|
||||
const canEditDraft = isDraft && canManage;
|
||||
|
||||
const scopeRows = useMemo(() => {
|
||||
const rows: Partial<Record<PrizeScopeCode, OddsItemRow>> = {};
|
||||
@@ -243,7 +250,7 @@ export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenPro
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!detail || !isDraft) {
|
||||
if (!detail || !canEditDraft) {
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
@@ -270,7 +277,7 @@ export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenPro
|
||||
}
|
||||
|
||||
async function handlePublish() {
|
||||
if (!detail || !isDraft) {
|
||||
if (!detail || !canEditDraft) {
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
@@ -289,7 +296,7 @@ export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenPro
|
||||
}
|
||||
|
||||
async function requestPublishConfirm() {
|
||||
if (!detail || !isDraft) {
|
||||
if (!detail || !canEditDraft) {
|
||||
return;
|
||||
}
|
||||
const active = list.find((x) => x.status === "active");
|
||||
@@ -386,12 +393,12 @@ export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenPro
|
||||
const old = activeCompareRows.find((r) => r.play_code === selectedPlay && r.prize_scope === scope);
|
||||
return {
|
||||
scope,
|
||||
label: PRIZE_SCOPE_LABELS[scope],
|
||||
label: prizeScopeLabel(scope, t),
|
||||
oldValue: old?.odds_value ?? null,
|
||||
newValue: next?.odds_value ?? null,
|
||||
};
|
||||
});
|
||||
}, [activeCompareRows, detail, draftRows, resolvedPlayCode]);
|
||||
}, [activeCompareRows, detail, draftRows, resolvedPlayCode, t, i18n.language]);
|
||||
|
||||
const catTabs: { id: CatTab; label: string }[] = [
|
||||
{ id: "all", label: t("odds.tabs.all", { ns: "config" }) },
|
||||
@@ -423,7 +430,7 @@ export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenPro
|
||||
active={resolvedPlayCode === type.play_code}
|
||||
onClick={() => setPlayCode(type.play_code)}
|
||||
>
|
||||
{type.display_name_zh ?? type.play_code}
|
||||
{resolveAdminPlayTypeDisplayName(type.play_code, i18n.language, type)}
|
||||
</ConfigChip>
|
||||
))
|
||||
)}
|
||||
@@ -449,6 +456,7 @@ export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenPro
|
||||
actions={
|
||||
<ConfigVersionActions
|
||||
isDraft={isDraft}
|
||||
canManage={canManage}
|
||||
loadingList={loadingList}
|
||||
loadingDetail={loadingDetail}
|
||||
saving={saving}
|
||||
@@ -499,12 +507,12 @@ export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenPro
|
||||
return (
|
||||
<div key={scope} className="grid gap-1">
|
||||
<Label className="flex items-baseline gap-2">
|
||||
{PRIZE_SCOPE_LABELS[scope]}
|
||||
{prizeScopeLabel(scope, t)}
|
||||
{hint ? <span className="text-sm text-muted-foreground font-normal">{hint}</span> : null}
|
||||
</Label>
|
||||
{row && idx >= 0 ? (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
@@ -540,7 +548,7 @@ export function OddsConfigDocScreen({ embedded = false }: OddsConfigDocScreenPro
|
||||
})}
|
||||
<div className="grid gap-1 pt-2 border-t">
|
||||
<Label>{t("odds.rebateRate", { ns: "config" })}</Label>
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/** Prize scope order, including starter and consolation. */
|
||||
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
export const PRIZE_SCOPE_ORDER = [
|
||||
"first",
|
||||
"second",
|
||||
@@ -10,16 +12,13 @@ export const PRIZE_SCOPE_ORDER = [
|
||||
|
||||
export type PrizeScopeCode = (typeof PRIZE_SCOPE_ORDER)[number];
|
||||
|
||||
export const PRIZE_SCOPE_LABELS: Record<PrizeScopeCode, string> = {
|
||||
first: "First Prize Odds",
|
||||
second: "Second Prize Odds",
|
||||
third: "Third Prize Odds",
|
||||
starter: "Starter Prize Odds",
|
||||
consolation: "Consolation Prize Odds",
|
||||
};
|
||||
|
||||
/** Display-only multiplier hints for starter and consolation grouped prizes. */
|
||||
export const PRIZE_SCOPE_MULTIPLIER_HINT: Partial<Record<PrizeScopeCode, string>> = {
|
||||
starter: "× 10",
|
||||
consolation: "× 10",
|
||||
};
|
||||
|
||||
/** Localized prize-scope label for odds / rebate config screens. */
|
||||
export function prizeScopeLabel(scope: PrizeScopeCode, t: TFunction): string {
|
||||
return t(`prizeScopes.${scope}`, { ns: "config" });
|
||||
}
|
||||
|
||||
@@ -23,6 +23,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_REBATE_MANAGE } from "@/lib/admin-prd";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type {
|
||||
AdminPlayTypeRow,
|
||||
@@ -54,6 +58,9 @@ type RebateConfigDocScreenProps = {
|
||||
|
||||
export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScreenProps) {
|
||||
const { t } = useTranslation(["config", "common"]);
|
||||
const { request: requestConfirm, ConfirmDialog } = useConfirmAction();
|
||||
const profile = useAdminProfile();
|
||||
const canManage = adminHasAnyPermission(profile?.permissions, [PRD_REBATE_MANAGE]);
|
||||
const formatDt = useAdminDateTimeFormatter();
|
||||
const [types, setTypes] = useState<AdminPlayTypeRow[]>([]);
|
||||
const [listRows, setListRows] = useState<ConfigVersionSummary[]>([]);
|
||||
@@ -162,6 +169,7 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
const isSelectedDetail = detail !== null && String(detail.id) === selectedId;
|
||||
const selectedStatus = isSelectedDetail ? detail.status : selectedVersionSummary?.status;
|
||||
const isDraft = selectedStatus === "draft";
|
||||
const canEditDraft = isDraft && canManage;
|
||||
|
||||
function applyDimensionPercentsToRows(rows: OddsItemRow[]): OddsItemRow[] {
|
||||
const r2 = Number.parseFloat(p2);
|
||||
@@ -179,7 +187,7 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!detail || !isDraft) {
|
||||
if (!detail || !canEditDraft) {
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
@@ -211,7 +219,7 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
}
|
||||
|
||||
async function handlePublish() {
|
||||
if (!detail || !isDraft) {
|
||||
if (!detail || !canEditDraft) {
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
@@ -286,6 +294,7 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
actions={
|
||||
<ConfigVersionActions
|
||||
isDraft={isDraft}
|
||||
canManage={canManage}
|
||||
loadingList={loading}
|
||||
loadingDetail={loadingDetail}
|
||||
saving={saving}
|
||||
@@ -293,7 +302,15 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
onRefresh={() => void refreshList()}
|
||||
onNewDraft={() => void handleNewDraft()}
|
||||
onSaveDraft={() => void handleSave()}
|
||||
onPublish={() => void handlePublish()}
|
||||
onPublish={() =>
|
||||
requestConfirm({
|
||||
title: t("rebate.publishDialog.title", { ns: "config" }),
|
||||
description: t("rebate.publishDialog.description", { ns: "config" }),
|
||||
confirmLabel: t("rebate.publishDialog.confirm", { ns: "config" }),
|
||||
confirmVariant: "destructive",
|
||||
onConfirm: () => handlePublish(),
|
||||
})
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
@@ -326,7 +343,7 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
<div className="grid gap-5 sm:grid-cols-3">
|
||||
<div className="grid gap-2">
|
||||
<Label>{t("rebate.fields.d2", { ns: "config" })}</Label>
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
@@ -342,7 +359,7 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label>{t("rebate.fields.d3", { ns: "config" })}</Label>
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
@@ -358,7 +375,7 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label>{t("rebate.fields.d4", { ns: "config" })}</Label>
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
@@ -409,6 +426,7 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
<div className="space-y-6">
|
||||
{contextBlock}
|
||||
{fieldsBlock}
|
||||
<ConfirmDialog />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -420,6 +438,7 @@ export function RebateConfigDocScreen({ embedded = false }: RebateConfigDocScree
|
||||
context={contextBlock}
|
||||
>
|
||||
{fieldsBlock}
|
||||
<ConfirmDialog />
|
||||
</ConfigDocPage>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ import {
|
||||
import { ConfigReadonlyValue } from "@/modules/config/config-readonly-value";
|
||||
import { ConfigVersionActions } from "@/modules/config/config-version-actions";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { useConfirmAction } from "@/hooks/use-confirm-action";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { PRD_RISK_CAP_MANAGE, PRD_RISK_CAP_VIEW } from "@/lib/admin-prd";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type {
|
||||
ConfigVersionSummary,
|
||||
@@ -74,6 +78,9 @@ function defaultRiskRowFromAmount(amount: number): DraftRiskRow {
|
||||
|
||||
export function RiskCapDocScreen() {
|
||||
const { t } = useTranslation(["config", "adminUsers", "common"]);
|
||||
const { request: requestConfirm, ConfirmDialog } = useConfirmAction();
|
||||
const profile = useAdminProfile();
|
||||
const canManage = adminHasAnyPermission(profile?.permissions, [PRD_RISK_CAP_MANAGE]);
|
||||
const formatDt = useAdminDateTimeFormatter();
|
||||
const [list, setList] = useState<ConfigVersionSummary[]>([]);
|
||||
const [selectedId, setSelectedId] = useState("");
|
||||
@@ -177,6 +184,7 @@ export function RiskCapDocScreen() {
|
||||
const isSelectedDetail = detail !== null && String(detail.id) === selectedId;
|
||||
const selectedStatus = isSelectedDetail ? detail.status : selectedVersionSummary?.status;
|
||||
const isDraft = selectedStatus === "draft";
|
||||
const canEditDraft = isDraft && canManage;
|
||||
|
||||
const updateRow = (idx: number, patch: Partial<DraftRiskRow>) => {
|
||||
setDraftRows((prev) => prev.map((r, i) => (i === idx ? { ...r, ...patch } : r)));
|
||||
@@ -187,7 +195,7 @@ export function RiskCapDocScreen() {
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!detail || !isDraft) {
|
||||
if (!detail || !canEditDraft) {
|
||||
return;
|
||||
}
|
||||
if (draftRows.length === 0) {
|
||||
@@ -236,7 +244,7 @@ export function RiskCapDocScreen() {
|
||||
}
|
||||
|
||||
async function handlePublish() {
|
||||
if (!detail || !isDraft) {
|
||||
if (!detail || !canEditDraft) {
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
@@ -347,13 +355,22 @@ export function RiskCapDocScreen() {
|
||||
actions={
|
||||
<ConfigVersionActions
|
||||
isDraft={isDraft}
|
||||
canManage={canManage}
|
||||
loadingList={loadingList}
|
||||
loadingDetail={loadingDetail}
|
||||
saving={saving}
|
||||
onRefresh={() => void refreshList()}
|
||||
onNewDraft={() => void handleNewDraft()}
|
||||
onSaveDraft={() => void handleSave()}
|
||||
onPublish={() => void handlePublish()}
|
||||
onPublish={() =>
|
||||
requestConfirm({
|
||||
title: t("riskCap.publishDialog.title", { ns: "config" }),
|
||||
description: t("riskCap.publishDialog.description", { ns: "config" }),
|
||||
confirmLabel: t("riskCap.publishDialog.confirm", { ns: "config" }),
|
||||
confirmVariant: "destructive",
|
||||
onConfirm: () => handlePublish(),
|
||||
})
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
@@ -379,7 +396,7 @@ export function RiskCapDocScreen() {
|
||||
<div className="flex flex-wrap items-end gap-2">
|
||||
<div className="grid gap-1">
|
||||
<Label htmlFor="default-cap">{t("riskCap.defaultCap.fieldLabel", { ns: "config" })}</Label>
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
id="default-cap"
|
||||
type="number"
|
||||
@@ -395,7 +412,7 @@ export function RiskCapDocScreen() {
|
||||
</ConfigReadonlyValue>
|
||||
)}
|
||||
</div>
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Button type="button" variant="secondary" disabled={saving} onClick={() => setSyncOpen(true)}>
|
||||
{t("riskCap.actions.update", { ns: "config" })}
|
||||
</Button>
|
||||
@@ -406,7 +423,7 @@ export function RiskCapDocScreen() {
|
||||
<ConfigSection
|
||||
title={t("riskCap.specialCaps.title", { ns: "config" })}
|
||||
actions={
|
||||
isDraft ? (
|
||||
canEditDraft ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
@@ -438,7 +455,7 @@ export function RiskCapDocScreen() {
|
||||
{specialRows.map(({ row: r, index: idx }) => (
|
||||
<TableRow key={r.clientKey}>
|
||||
<TableCell>
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
className="h-8 font-mono tabular-nums"
|
||||
maxLength={4}
|
||||
@@ -455,7 +472,7 @@ export function RiskCapDocScreen() {
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
@@ -476,7 +493,7 @@ export function RiskCapDocScreen() {
|
||||
<TableCell className="text-right text-muted-foreground tabular-nums text-sm">—</TableCell>
|
||||
<TableCell className="text-center text-muted-foreground text-sm">—</TableCell>
|
||||
<TableCell>
|
||||
{isDraft ? (
|
||||
{canEditDraft ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
@@ -568,6 +585,7 @@ export function RiskCapDocScreen() {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<ConfirmDialog />
|
||||
</ConfigDocPage>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
getAdminSettings,
|
||||
updateAdminSetting,
|
||||
} from "@/api/admin-settings";
|
||||
import { useConfirmAction } from "@/hooks/use-confirm-action";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ConfigDocPage } from "@/modules/config/config-doc-page";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -47,7 +48,8 @@ type WalletConfigDocScreenProps = {
|
||||
};
|
||||
|
||||
export function WalletConfigDocScreen({ embedded = false }: WalletConfigDocScreenProps) {
|
||||
const { t } = useTranslation(["config", "adminUsers"]);
|
||||
const { t } = useTranslation(["config", "adminUsers", "common"]);
|
||||
const { request: requestConfirm, ConfirmDialog } = useConfirmAction();
|
||||
const [draft, setDraft] = useState<Draft>({
|
||||
inMin: "",
|
||||
inMax: "",
|
||||
@@ -170,7 +172,17 @@ export function WalletConfigDocScreen({ embedded = false }: WalletConfigDocScree
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 pt-2">
|
||||
<Button onClick={() => void handleSave()} disabled={!dirty || loading || saving}>
|
||||
<Button
|
||||
onClick={() =>
|
||||
requestConfirm({
|
||||
title: t("wallet.confirmSaveTitle", { ns: "config" }),
|
||||
description: t("wallet.confirmSaveDescription", { ns: "config" }),
|
||||
confirmLabel: t("confirm.confirmSave", { ns: "common" }),
|
||||
onConfirm: () => handleSave(),
|
||||
})
|
||||
}
|
||||
disabled={!dirty || loading || saving}
|
||||
>
|
||||
{saving ? t("saving", { ns: "adminUsers" }) : t("actions.save", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
{dirty && (
|
||||
@@ -185,6 +197,7 @@ export function WalletConfigDocScreen({ embedded = false }: WalletConfigDocScree
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<ConfirmDialog />
|
||||
</>
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user