feat(admin, i18n): enhance reports, draws, config, and player workflows
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
|
||||
@@ -32,6 +32,13 @@ import {
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -157,6 +164,9 @@ export function PlayConfigDocScreen() {
|
||||
const [rollbackOpen, setRollbackOpen] = useState(false);
|
||||
const [rollbackTarget, setRollbackTarget] = useState<ConfigVersionSummary | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [keyword, setKeyword] = useState("");
|
||||
const [statusFilter, setStatusFilter] = useState<"all" | "enabled" | "disabled">("all");
|
||||
const [categoryFilter, setCategoryFilter] = useState("all");
|
||||
const detailRequestSeq = useRef(0);
|
||||
|
||||
const refreshList = useCallback(async () => {
|
||||
@@ -268,6 +278,61 @@ export function PlayConfigDocScreen() {
|
||||
[draftRows],
|
||||
);
|
||||
|
||||
const categoryOptions = useMemo(() => {
|
||||
const seen = new Set<string>();
|
||||
return orderedRows
|
||||
.map((row) => row.category?.trim() || "")
|
||||
.filter((value) => {
|
||||
if (!value || seen.has(value)) {
|
||||
return false;
|
||||
}
|
||||
seen.add(value);
|
||||
return true;
|
||||
});
|
||||
}, [orderedRows]);
|
||||
|
||||
const filteredRows = useMemo(() => {
|
||||
const normalizedKeyword = keyword.trim().toLowerCase();
|
||||
|
||||
return orderedRows.filter((row) => {
|
||||
const normalizedCategory = row.category?.trim() || "uncategorized";
|
||||
const matchesKeyword =
|
||||
normalizedKeyword === "" ||
|
||||
row.play_code.toLowerCase().includes(normalizedKeyword) ||
|
||||
(row.display_name ?? "").toLowerCase().includes(normalizedKeyword) ||
|
||||
(row.category ?? "").toLowerCase().includes(normalizedKeyword);
|
||||
const matchesStatus =
|
||||
statusFilter === "all" ||
|
||||
(statusFilter === "enabled" && row.is_enabled) ||
|
||||
(statusFilter === "disabled" && !row.is_enabled);
|
||||
const matchesCategory = categoryFilter === "all" || normalizedCategory === categoryFilter;
|
||||
|
||||
return matchesKeyword && matchesStatus && matchesCategory;
|
||||
});
|
||||
}, [categoryFilter, keyword, orderedRows, statusFilter]);
|
||||
|
||||
const groupedRows = useMemo(() => {
|
||||
const groups = new Map<string, PlayConfigItemRow[]>();
|
||||
for (const row of filteredRows) {
|
||||
const groupKey = row.category?.trim() || "uncategorized";
|
||||
const current = groups.get(groupKey);
|
||||
if (current) {
|
||||
current.push(row);
|
||||
} else {
|
||||
groups.set(groupKey, [row]);
|
||||
}
|
||||
}
|
||||
return Array.from(groups.entries());
|
||||
}, [filteredRows]);
|
||||
|
||||
function categoryLabel(categoryKey: string): string {
|
||||
if (categoryKey === "uncategorized") {
|
||||
return t("play.filters.uncategorized", { ns: "config" });
|
||||
}
|
||||
const mapped = t(`play.categories.${categoryKey}`, { ns: "config" });
|
||||
return mapped === `play.categories.${categoryKey}` ? categoryKey : mapped;
|
||||
}
|
||||
|
||||
function updateConfigRow(playCode: string, patch: Partial<PlayConfigItemRow>) {
|
||||
setDraftRows((prev) => prev.map((r) => (r.play_code === playCode ? { ...r, ...patch } : r)));
|
||||
}
|
||||
@@ -474,69 +539,153 @@ export function PlayConfigDocScreen() {
|
||||
>
|
||||
{detail ? (
|
||||
<ConfigSection
|
||||
title={t("play.batchSwitchesTitle", { ns: "config" })}
|
||||
description={!isDraft ? t("play.readOnlyDraftHint", { ns: "config" }) : undefined}
|
||||
title={t("play.filters.sectionTitle", { ns: "config" })}
|
||||
description={isDraft ? t("play.filters.sectionDescription", { ns: "config" }) : undefined}
|
||||
>
|
||||
<ConfigChipGroup>
|
||||
{batchSwitchStates.map((group) => {
|
||||
const groupOn = group.allEnabled;
|
||||
const isPartial =
|
||||
group.total > 0 && group.enabledCount > 0 && group.enabledCount < group.total;
|
||||
return (
|
||||
<div
|
||||
key={group.key}
|
||||
className="flex items-center justify-between gap-4 rounded-xl border border-border/60 bg-card px-4 py-3"
|
||||
{!isDraft ? (
|
||||
<div className="rounded-md border border-amber-200 bg-amber-50/70 px-3 py-2 text-xs text-amber-950">
|
||||
{t("play.readOnlyDraftHint", { ns: "config" })}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="flex flex-col gap-3 lg:flex-row lg:items-end">
|
||||
<div className="flex flex-1 flex-col gap-3 md:flex-row md:flex-wrap md:items-end">
|
||||
<div className="flex min-w-0 flex-col gap-1.5 md:w-[320px]">
|
||||
<span className="text-sm font-medium">{t("play.filters.keyword", { ns: "config" })}</span>
|
||||
<Input
|
||||
value={keyword}
|
||||
onChange={(e) => setKeyword(e.target.value)}
|
||||
placeholder={t("play.filters.keywordPlaceholder", { ns: "config" })}
|
||||
className="h-8"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 md:w-[140px]">
|
||||
<span className="text-sm font-medium">{t("play.filters.category", { ns: "config" })}</span>
|
||||
<Select value={categoryFilter} onValueChange={setCategoryFilter}>
|
||||
<SelectTrigger className="h-8">
|
||||
<SelectValue>
|
||||
{categoryFilter === "all"
|
||||
? t("play.filters.allCategories", { ns: "config" })
|
||||
: categoryLabel(categoryFilter)}
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">{t("play.filters.allCategories", { ns: "config" })}</SelectItem>
|
||||
{categoryOptions.map((category) => (
|
||||
<SelectItem key={category} value={category}>
|
||||
{categoryLabel(category)}
|
||||
</SelectItem>
|
||||
))}
|
||||
<SelectItem value="uncategorized">
|
||||
{t("play.filters.uncategorized", { ns: "config" })}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 md:w-[140px]">
|
||||
<span className="text-sm font-medium">{t("play.filters.status", { ns: "config" })}</span>
|
||||
<Select
|
||||
value={statusFilter}
|
||||
onValueChange={(value) => setStatusFilter(value as "all" | "enabled" | "disabled")}
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<p className="text-sm font-medium text-foreground">{group.label}</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{group.total > 0
|
||||
? isPartial
|
||||
? t("play.batchPartialEnabled", {
|
||||
ns: "config",
|
||||
enabledCount: group.enabledCount,
|
||||
total: group.total,
|
||||
})
|
||||
: t("play.batchEnabledCount", {
|
||||
ns: "config",
|
||||
enabledCount: group.enabledCount,
|
||||
total: group.total,
|
||||
})
|
||||
: t("play.noPlayTypes", { ns: "config" })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center justify-center">
|
||||
<Checkbox
|
||||
checked={groupOn}
|
||||
indeterminate={isPartial}
|
||||
disabled={!isDraft || saving || group.total === 0 || confirmBusy}
|
||||
aria-label={t("play.aria.batchGroupSwitch", {
|
||||
ns: "config",
|
||||
group: group.label,
|
||||
})}
|
||||
onCheckedChange={(checked) => {
|
||||
const enable = checked === true;
|
||||
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", {
|
||||
<SelectTrigger className="h-8">
|
||||
<SelectValue>
|
||||
{statusFilter === "all"
|
||||
? t("play.filters.allStatuses", { ns: "config" })
|
||||
: statusFilter === "enabled"
|
||||
? t("play.states.enabled", { ns: "config" })
|
||||
: t("play.states.disabled", { ns: "config" })}
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">{t("play.filters.allStatuses", { ns: "config" })}</SelectItem>
|
||||
<SelectItem value="enabled">{t("play.states.enabled", { ns: "config" })}</SelectItem>
|
||||
<SelectItem value="disabled">{t("play.states.disabled", { ns: "config" })}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-end justify-start lg:flex-none">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setKeyword("");
|
||||
setCategoryFilter("all");
|
||||
setStatusFilter("all");
|
||||
}}
|
||||
>
|
||||
{t("play.filters.reset", { ns: "config" })}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{isDraft ? (
|
||||
<div className="space-y-2 border-t border-border/60 pt-3">
|
||||
<div className="text-xs font-medium text-muted-foreground">
|
||||
{t("play.batchSwitchesTitle", { ns: "config" })}
|
||||
</div>
|
||||
<ConfigChipGroup>
|
||||
{batchSwitchStates.map((group) => {
|
||||
const groupOn = group.allEnabled;
|
||||
const isPartial =
|
||||
group.total > 0 && group.enabledCount > 0 && group.enabledCount < group.total;
|
||||
return (
|
||||
<div
|
||||
key={group.key}
|
||||
className="flex items-center justify-between gap-3 rounded-lg border border-border/60 bg-card px-3 py-2"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<p className="text-sm font-medium text-foreground">{group.label}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{group.total > 0
|
||||
? isPartial
|
||||
? t("play.batchPartialEnabled", {
|
||||
ns: "config",
|
||||
enabledCount: group.enabledCount,
|
||||
total: group.total,
|
||||
})
|
||||
: t("play.batchEnabledCount", {
|
||||
ns: "config",
|
||||
enabledCount: group.enabledCount,
|
||||
total: group.total,
|
||||
})
|
||||
: t("play.noPlayTypes", { ns: "config" })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center justify-center">
|
||||
<Checkbox
|
||||
checked={groupOn}
|
||||
indeterminate={isPartial}
|
||||
disabled={saving || group.total === 0 || confirmBusy}
|
||||
aria-label={t("play.aria.batchGroupSwitch", {
|
||||
ns: "config",
|
||||
action,
|
||||
group: group.label,
|
||||
count: group.total,
|
||||
}),
|
||||
confirmVariant: enable ? "default" : "destructive",
|
||||
onConfirm: () => applyBatchSwitch(group, enable),
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</ConfigChipGroup>
|
||||
})}
|
||||
onCheckedChange={(checked) => {
|
||||
const enable = checked === true;
|
||||
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),
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</ConfigChipGroup>
|
||||
</div>
|
||||
) : null}
|
||||
</ConfigSection>
|
||||
) : null}
|
||||
|
||||
@@ -546,22 +695,41 @@ export function PlayConfigDocScreen() {
|
||||
<AdminLoadingState minHeight="6rem" className="py-6" />
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="text-center">{t("play.table.playCode", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[100px] text-center">{t("play.table.category", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[88px] text-center">{t("play.table.status", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-36 text-center">{t("play.table.displayName", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-24 text-center">{t("play.table.order", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[110px] text-center">{t("play.table.minBet", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[110px] text-center">{t("play.table.maxBet", { ns: "config" })}</TableHead>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="text-center">{t("play.table.playCode", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[100px] text-center">{t("play.table.category", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[88px] text-center">{t("play.table.status", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-36 text-center">{t("play.table.displayName", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-24 text-center">{t("play.table.order", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[110px] text-center">{t("play.table.minBet", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[110px] text-center">{t("play.table.maxBet", { ns: "config" })}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{groupedRows.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="py-8 text-center text-sm text-muted-foreground">
|
||||
{t("play.filters.empty", { ns: "config" })}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : null}
|
||||
{groupedRows.map(([groupKey, rows]) => (
|
||||
<Fragment key={groupKey}>
|
||||
<TableRow className="bg-muted/30">
|
||||
<TableCell colSpan={7} className="py-2 text-sm font-medium text-foreground">
|
||||
{categoryLabel(groupKey)}
|
||||
<span className="ml-2 text-xs font-normal text-muted-foreground">
|
||||
{t("play.filters.groupCount", { ns: "config", count: rows.length })}
|
||||
</span>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{orderedRows.map((row) => (
|
||||
{rows.map((row) => (
|
||||
<TableRow key={row.play_code}>
|
||||
<TableCell className="text-center font-mono text-sm">{row.play_code}</TableCell>
|
||||
<TableCell className="text-center text-muted-foreground text-sm">{row.category ?? "—"}</TableCell>
|
||||
<TableCell className="text-center text-muted-foreground text-sm">
|
||||
{row.category ? categoryLabel(row.category) : "—"}
|
||||
</TableCell>
|
||||
<TableCell className="text-center">
|
||||
{isDraft ? (
|
||||
<div className="flex justify-center">
|
||||
@@ -691,7 +859,9 @@ export function PlayConfigDocScreen() {
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Fragment>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
publishRiskCapVersion,
|
||||
putRiskCapItems,
|
||||
} from "@/api/admin-config";
|
||||
import { getAdminDraws } from "@/api/admin-draws";
|
||||
import { AdminRowActionsMenu } from "@/components/admin/admin-row-actions-menu";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ConfigDocPage, ConfigDocToolbar } from "@/modules/config/config-doc-page";
|
||||
@@ -32,7 +33,7 @@ import {
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { AdminLoadingState, AdminLoadingInline, AdminTableLoadingRow } from "@/components/admin/admin-loading-state";
|
||||
import { AdminLoadingState } from "@/components/admin/admin-loading-state";
|
||||
import { ConfigVersionSwitcher } from "@/modules/config/config-version-switcher";
|
||||
import { RiskCapRuntimePanel } from "@/modules/config/risk-cap-runtime-panel";
|
||||
import {
|
||||
@@ -43,6 +44,13 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { ConfigReadonlyValue } from "@/modules/config/config-readonly-value";
|
||||
import { ConfigVersionActions } from "@/modules/config/config-version-actions";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
@@ -51,10 +59,13 @@ import { useConfirmAction } from "@/hooks/use-confirm-action";
|
||||
import { useTranslationRef } from "@/hooks/use-translation-ref";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { formatAdminMinorDecimal, parseAdminMajorToMinor } from "@/lib/money";
|
||||
import { PRD_RISK_CAP_MANAGE, PRD_RISK_CAP_VIEW } from "@/lib/admin-prd";
|
||||
import { PRD_RISK_CAP_MANAGE } from "@/lib/admin-prd";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import { pickDefaultConfigVersionId } from "@/lib/config-version-auto-pick";
|
||||
import type {
|
||||
AdminDrawListItem,
|
||||
} from "@/types/api/admin-draws";
|
||||
import type {
|
||||
ConfigVersionSummary,
|
||||
RiskCapItemRow,
|
||||
@@ -102,6 +113,7 @@ export function RiskCapDocScreen() {
|
||||
const [loadingDetail, setLoadingDetail] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [drawOptions, setDrawOptions] = useState<AdminDrawListItem[]>([]);
|
||||
|
||||
const [defaultCapStr, setDefaultCapStr] = useState("");
|
||||
const [syncOpen, setSyncOpen] = useState(false);
|
||||
@@ -124,10 +136,23 @@ export function RiskCapDocScreen() {
|
||||
} finally {
|
||||
setLoadingList(false);
|
||||
}
|
||||
}, []);
|
||||
}, [tRef]);
|
||||
|
||||
useAsyncEffect(() => {
|
||||
void refreshList();
|
||||
}, [tRef]);
|
||||
|
||||
const loadDrawOptions = useCallback(async () => {
|
||||
try {
|
||||
const data = await getAdminDraws({ page: 1, per_page: 100 });
|
||||
setDrawOptions(data.items);
|
||||
} catch {
|
||||
setDrawOptions([]);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useAsyncEffect(() => {
|
||||
void loadDrawOptions();
|
||||
}, []);
|
||||
|
||||
function syncDefaultCapFromRows(rows: DraftRiskRow[]) {
|
||||
@@ -232,12 +257,20 @@ export function RiskCapDocScreen() {
|
||||
toast.error(t("riskCap.validation.defaultGreaterThanZero", { ns: "config" }));
|
||||
return;
|
||||
}
|
||||
if (r.draw_id !== null) {
|
||||
toast.error(t("riskCap.validation.defaultCannotBindDraw", { ns: "config" }));
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!/^[0-9]{4}$/.test(r.normalized_number)) {
|
||||
toast.error(t("riskCap.validation.numberMustBe4Digits", { ns: "config", number: r.normalized_number }));
|
||||
return;
|
||||
}
|
||||
if (r.cap_amount <= 0) {
|
||||
toast.error(t("riskCap.validation.specialGreaterThanZero", { ns: "config", number: r.normalized_number }));
|
||||
return;
|
||||
}
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
@@ -340,6 +373,15 @@ export function RiskCapDocScreen() {
|
||||
() => draftRows.map((row, index) => ({ row, index })).filter(({ row }) => !isDefaultRiskRow(row)),
|
||||
[draftRows],
|
||||
);
|
||||
const globalRows = useMemo(
|
||||
() => specialRows.filter(({ row }) => row.draw_id == null),
|
||||
[specialRows],
|
||||
);
|
||||
const drawRows = useMemo(
|
||||
() => specialRows.filter(({ row }) => row.draw_id != null),
|
||||
[specialRows],
|
||||
);
|
||||
const defaultCapDisplay = defaultCapStr || formatAdminMinorDecimal(0, amountCurrencyCode);
|
||||
|
||||
async function handleDeleteVersion(row: ConfigVersionSummary) {
|
||||
try {
|
||||
@@ -459,6 +501,35 @@ export function RiskCapDocScreen() {
|
||||
>
|
||||
{error ? <p className="text-sm text-destructive">{error}</p> : null}
|
||||
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
{[
|
||||
{
|
||||
key: "default",
|
||||
label: t("riskCap.summary.defaultCap", { ns: "config" }),
|
||||
value: defaultCapDisplay,
|
||||
hint: t("riskCap.summary.defaultHint", { ns: "config" }),
|
||||
},
|
||||
{
|
||||
key: "global",
|
||||
label: t("riskCap.summary.globalCaps", { ns: "config" }),
|
||||
value: t("riskCap.groups.count", { ns: "config", count: globalRows.length }),
|
||||
hint: t("riskCap.summary.globalHint", { ns: "config" }),
|
||||
},
|
||||
{
|
||||
key: "draw",
|
||||
label: t("riskCap.summary.drawCaps", { ns: "config" }),
|
||||
value: t("riskCap.groups.count", { ns: "config", count: drawRows.length }),
|
||||
hint: t("riskCap.summary.drawHint", { ns: "config" }),
|
||||
},
|
||||
].map((card) => (
|
||||
<div key={card.key} className="rounded-xl border border-border/60 bg-background p-4 shadow-sm">
|
||||
<p className="text-xs text-muted-foreground">{card.label}</p>
|
||||
<p className="mt-1 font-mono text-lg font-semibold tabular-nums">{card.value}</p>
|
||||
<p className="mt-2 text-xs leading-5 text-muted-foreground">{card.hint}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<ConfigSection title={t("riskCap.defaultCap.title", { ns: "config" })}>
|
||||
<div className="flex flex-wrap items-end gap-2">
|
||||
<div className="grid gap-1">
|
||||
@@ -466,8 +537,8 @@ export function RiskCapDocScreen() {
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
id="default-cap"
|
||||
type="number"
|
||||
min={0}
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
className="w-[220px] font-mono tabular-nums"
|
||||
disabled={saving}
|
||||
value={defaultCapStr}
|
||||
@@ -490,6 +561,7 @@ export function RiskCapDocScreen() {
|
||||
|
||||
<ConfigSection
|
||||
title={t("riskCap.specialCaps.title", { ns: "config" })}
|
||||
description={t("riskCap.specialCaps.description", { ns: "config" })}
|
||||
actions={
|
||||
canEditDraft ? (
|
||||
<Button
|
||||
@@ -508,79 +580,150 @@ export function RiskCapDocScreen() {
|
||||
) : specialRows.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">{t("riskCap.noDetailRows", { ns: "config" })}</p>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[110px]">{t("riskCap.table.number", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[140px]">{t("riskCap.table.capAmount", { ns: "config" })}</TableHead>
|
||||
<TableHead className="sticky right-0 z-20 bg-muted w-14 text-center shadow-[-1px_0_0_rgba(203,213,225,0.7)]">{t("riskCap.table.actions", { ns: "config" })}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{specialRows.map(({ row: r, index: idx }) => (
|
||||
<TableRow key={r.clientKey}>
|
||||
<TableCell>
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
className="h-8 font-mono tabular-nums"
|
||||
maxLength={4}
|
||||
disabled={saving}
|
||||
value={r.normalized_number}
|
||||
placeholder={t("riskCap.placeholders.number", { ns: "config" })}
|
||||
onChange={(e) =>
|
||||
updateRow(idx, {
|
||||
normalized_number: e.target.value.replace(/\D/g, "").slice(0, 4),
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<ConfigReadonlyValue mono>{r.normalized_number}</ConfigReadonlyValue>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
className="h-8 font-mono tabular-nums"
|
||||
disabled={saving}
|
||||
value={formatAdminMinorDecimal(r.cap_amount, amountCurrencyCode)}
|
||||
placeholder={t("riskCap.placeholders.capAmount", { ns: "config" })}
|
||||
onChange={(e) =>
|
||||
updateRow(idx, {
|
||||
cap_amount:
|
||||
parseAdminMajorToMinor(e.target.value, amountCurrencyCode) ?? 0,
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<ConfigReadonlyValue mono>
|
||||
{formatAdminMinorDecimal(r.cap_amount, amountCurrencyCode)}
|
||||
</ConfigReadonlyValue>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="sticky right-0 z-10 bg-card text-center shadow-[-1px_0_0_rgba(203,213,225,0.7)]">
|
||||
{canEditDraft ? (
|
||||
<AdminRowActionsMenu
|
||||
busy={saving}
|
||||
actions={[
|
||||
{
|
||||
key: "delete",
|
||||
label: t("actions.delete", { ns: "adminUsers" }),
|
||||
icon: Trash2,
|
||||
destructive: true,
|
||||
onClick: () => removeRow(idx),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
) : (
|
||||
<span className="text-sm text-muted-foreground">{t("riskCap.readOnly", { ns: "config" })}</span>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div className="space-y-4">
|
||||
{[
|
||||
{
|
||||
key: "global",
|
||||
title: t("riskCap.groups.globalTitle", { ns: "config" }),
|
||||
description: t("riskCap.groups.globalDescription", { ns: "config" }),
|
||||
rows: globalRows,
|
||||
emptyText: t("riskCap.groups.globalEmpty", { ns: "config" }),
|
||||
},
|
||||
{
|
||||
key: "draw",
|
||||
title: t("riskCap.groups.drawTitle", { ns: "config" }),
|
||||
description: t("riskCap.groups.drawDescription", { ns: "config" }),
|
||||
rows: drawRows,
|
||||
emptyText: t("riskCap.groups.drawEmpty", { ns: "config" }),
|
||||
},
|
||||
].map((group) => (
|
||||
<div key={group.key} className="rounded-xl border border-border/60 bg-muted/10 p-3">
|
||||
<div className="mb-3 flex flex-wrap items-start justify-between gap-2">
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-sm font-semibold text-foreground">{group.title}</h3>
|
||||
<p className="text-xs leading-5 text-muted-foreground">{group.description}</p>
|
||||
</div>
|
||||
<span className="rounded-full bg-background px-2 py-1 text-xs text-muted-foreground">
|
||||
{t("riskCap.groups.count", { ns: "config", count: group.rows.length })}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{group.rows.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">{group.emptyText}</p>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[180px]">{t("riskCap.table.scope", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[110px]">{t("riskCap.table.number", { ns: "config" })}</TableHead>
|
||||
<TableHead className="w-[140px]">{t("riskCap.table.capAmount", { ns: "config" })}</TableHead>
|
||||
<TableHead className="sticky right-0 z-20 w-14 bg-muted text-center shadow-[-1px_0_0_rgba(203,213,225,0.7)]">
|
||||
{t("riskCap.table.actions", { ns: "config" })}
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{group.rows.map(({ row: r, index: idx }) => (
|
||||
<TableRow key={r.clientKey}>
|
||||
<TableCell>
|
||||
{canEditDraft ? (
|
||||
<Select
|
||||
value={r.draw_id == null ? "__global__" : String(r.draw_id)}
|
||||
onValueChange={(value) =>
|
||||
updateRow(idx, { draw_id: value === "__global__" ? null : Number(value) })
|
||||
}
|
||||
>
|
||||
<SelectTrigger className="h-8 min-w-0">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__global__">
|
||||
{t("riskCap.scope.global", { ns: "config" })}
|
||||
</SelectItem>
|
||||
{drawOptions.map((draw) => (
|
||||
<SelectItem key={draw.id} value={String(draw.id)}>
|
||||
{draw.draw_no}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
) : (
|
||||
<ConfigReadonlyValue>
|
||||
{r.draw_id == null
|
||||
? t("riskCap.scope.global", { ns: "config" })
|
||||
: drawOptions.find((draw) => draw.id === r.draw_id)?.draw_no ??
|
||||
t("riskCap.scope.drawId", { ns: "config", id: r.draw_id })}
|
||||
</ConfigReadonlyValue>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
className="h-8 font-mono tabular-nums"
|
||||
maxLength={4}
|
||||
disabled={saving}
|
||||
value={r.normalized_number}
|
||||
placeholder={t("riskCap.placeholders.number", { ns: "config" })}
|
||||
onChange={(e) =>
|
||||
updateRow(idx, {
|
||||
normalized_number: e.target.value.replace(/\D/g, "").slice(0, 4),
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<ConfigReadonlyValue mono>{r.normalized_number}</ConfigReadonlyValue>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{canEditDraft ? (
|
||||
<Input
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
className="h-8 font-mono tabular-nums"
|
||||
disabled={saving}
|
||||
value={formatAdminMinorDecimal(r.cap_amount, amountCurrencyCode)}
|
||||
placeholder={t("riskCap.placeholders.capAmount", { ns: "config" })}
|
||||
onChange={(e) =>
|
||||
updateRow(idx, {
|
||||
cap_amount:
|
||||
parseAdminMajorToMinor(e.target.value, amountCurrencyCode) ?? 0,
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<ConfigReadonlyValue mono>
|
||||
{formatAdminMinorDecimal(r.cap_amount, amountCurrencyCode)}
|
||||
</ConfigReadonlyValue>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="sticky right-0 z-10 bg-card text-center shadow-[-1px_0_0_rgba(203,213,225,0.7)]">
|
||||
{canEditDraft ? (
|
||||
<AdminRowActionsMenu
|
||||
busy={saving}
|
||||
actions={[
|
||||
{
|
||||
key: "delete",
|
||||
label: t("actions.delete", { ns: "adminUsers" }),
|
||||
icon: Trash2,
|
||||
destructive: true,
|
||||
onClick: () => removeRow(idx),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
) : (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t("riskCap.readOnly", { ns: "config" })}
|
||||
</span>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</ConfigSection>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user