feat: 添加货币管理功能,更新国际化支持,移除报表相关代码
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
import {
|
||||
CalendarClock,
|
||||
FileSpreadsheet,
|
||||
CircleDollarSign,
|
||||
Landmark,
|
||||
LayoutDashboard,
|
||||
LogIn,
|
||||
@@ -29,11 +29,11 @@ export const adminNavIconBySegment: Record<AdminNavItem["segment"], LucideIcon>
|
||||
wallet: Wallet,
|
||||
risk: ShieldAlert,
|
||||
settlement: Landmark,
|
||||
reports: FileSpreadsheet,
|
||||
reconcile: Scale,
|
||||
audit: ScrollText,
|
||||
admin_users: ShieldCheck,
|
||||
admin_roles: ShieldCheck,
|
||||
currencies: CircleDollarSign,
|
||||
settings: Settings,
|
||||
};
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ export type AdminNavSegment =
|
||||
| "risk"
|
||||
| "settings"
|
||||
| "settlement"
|
||||
| "reports"
|
||||
| "reconcile"
|
||||
| "audit"
|
||||
| "admin_users"
|
||||
| "admin_roles";
|
||||
| "admin_roles"
|
||||
| "currencies";
|
||||
|
||||
export type AdminNavItem = {
|
||||
label: string;
|
||||
|
||||
@@ -77,6 +77,10 @@ export function AdminRolesConsole(): React.ReactElement {
|
||||
() => roles.find((role) => role.id === selectedRoleId) ?? null,
|
||||
[roles, selectedRoleId],
|
||||
);
|
||||
const selectedPermissionSet = useMemo(
|
||||
() => new Set(draftRolePermissions),
|
||||
[draftRolePermissions],
|
||||
);
|
||||
|
||||
const selectClassName = cn(
|
||||
"h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base outline-none transition-colors",
|
||||
@@ -141,6 +145,16 @@ export function AdminRolesConsole(): React.ReactElement {
|
||||
});
|
||||
}
|
||||
|
||||
function toggleGroupPermissions(slugs: string[], checked: boolean): void {
|
||||
setDraftRolePermissions((prev) => {
|
||||
if (checked) {
|
||||
return Array.from(new Set([...prev, ...slugs])).sort();
|
||||
}
|
||||
const remove = new Set(slugs);
|
||||
return prev.filter((value) => !remove.has(value));
|
||||
});
|
||||
}
|
||||
|
||||
function openCreateRole(): void {
|
||||
setRoleMode("create");
|
||||
setEditingRoleId(null);
|
||||
@@ -182,6 +196,20 @@ export function AdminRolesConsole(): React.ReactElement {
|
||||
}
|
||||
}
|
||||
|
||||
function getGroupSelectionState(slugs: string[]): boolean | "indeterminate" {
|
||||
if (slugs.length === 0) {
|
||||
return false;
|
||||
}
|
||||
const selectedCount = slugs.filter((slug) => selectedPermissionSet.has(slug)).length;
|
||||
if (selectedCount === 0) {
|
||||
return false;
|
||||
}
|
||||
if (selectedCount === slugs.length) {
|
||||
return true;
|
||||
}
|
||||
return "indeterminate";
|
||||
}
|
||||
|
||||
async function saveRolePermissions(): Promise<void> {
|
||||
if (!selectedRole) {
|
||||
return;
|
||||
@@ -381,68 +409,94 @@ export function AdminRolesConsole(): React.ReactElement {
|
||||
<Dialog open={rolePermissionOpen} onOpenChange={handleRolePermissionDialogOpenChange}>
|
||||
<DialogContent
|
||||
showCloseButton
|
||||
className="flex h-[min(86vh,780px)] !max-w-[min(760px,calc(100vw-2rem))] flex-col gap-0 overflow-hidden p-0"
|
||||
className="flex h-[min(84vh,760px)] !max-w-[min(720px,calc(100vw-2rem))] flex-col gap-0 overflow-hidden rounded-2xl border bg-background p-0 shadow-2xl"
|
||||
>
|
||||
<DialogHeader className="shrink-0 space-y-1 border-b bg-background px-5 py-4 pr-12">
|
||||
<DialogTitle className="text-base">{t("rolePermissionDialog.title")}</DialogTitle>
|
||||
<DialogDescription>
|
||||
<DialogTitle className="text-[15px] font-semibold tracking-tight text-foreground">
|
||||
{t("rolePermissionDialog.title")}
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-sm text-muted-foreground">
|
||||
{selectedRole ? selectedRole.name : null}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain bg-muted/25 px-5 py-4">
|
||||
<div className="space-y-3">
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain bg-muted/15 px-5 py-4">
|
||||
<div className="overflow-hidden rounded-xl border border-border/70 bg-background">
|
||||
{directPermissionGroups.map((group) => {
|
||||
const isOpen = isDirectGroupOpen(group.key);
|
||||
const groupSlugs = group.permissions.map((permission) => permission.slug);
|
||||
const selectedCount = group.permissions.filter((permission) =>
|
||||
draftRolePermissions.includes(permission.slug),
|
||||
selectedPermissionSet.has(permission.slug),
|
||||
).length;
|
||||
const checkedState = getGroupSelectionState(groupSlugs);
|
||||
|
||||
return (
|
||||
<section key={group.key} className="overflow-hidden rounded-lg border bg-background shadow-sm">
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center gap-3 border-b px-4 py-3 text-left text-sm hover:bg-muted/45"
|
||||
onClick={() => toggleDirectGroup(group.key)}
|
||||
>
|
||||
<ChevronDown
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"size-4 shrink-0 text-muted-foreground transition-transform",
|
||||
isOpen && "rotate-180",
|
||||
)}
|
||||
<div key={group.key} className={cn("border-b border-border/60 last:border-b-0", isOpen && "bg-muted/10")}>
|
||||
<div className="flex items-center gap-3 px-4 py-3 text-sm transition-colors hover:bg-muted/20">
|
||||
<button
|
||||
type="button"
|
||||
className="flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted"
|
||||
onClick={() => toggleDirectGroup(group.key)}
|
||||
aria-label={isOpen ? "收起" : "展开"}
|
||||
>
|
||||
<ChevronDown
|
||||
aria-hidden
|
||||
className={cn("size-4 transition-transform", isOpen && "rotate-180")}
|
||||
/>
|
||||
</button>
|
||||
<Checkbox
|
||||
checked={checkedState === true}
|
||||
indeterminate={checkedState === "indeterminate"}
|
||||
onCheckedChange={(value) => toggleGroupPermissions(groupSlugs, value === true)}
|
||||
/>
|
||||
<span className="min-w-0 flex-1 text-base font-semibold leading-none">
|
||||
{permissionGroupLabel(group.key, group.label, t)}
|
||||
</span>
|
||||
<span className="shrink-0 rounded-full bg-muted px-2.5 py-1 tabular-nums text-xs font-medium text-muted-foreground">
|
||||
<button
|
||||
type="button"
|
||||
className="min-w-0 flex-1 text-left"
|
||||
onClick={() => toggleDirectGroup(group.key)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<span className="min-w-0 truncate text-[15px] font-medium leading-6 text-foreground">
|
||||
{permissionGroupLabel(group.key, group.label, t)}
|
||||
</span>
|
||||
{group.permissions.length > 0 ? (
|
||||
<span className="shrink-0 rounded bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground">
|
||||
{group.permissions.length}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</button>
|
||||
<span className="shrink-0 tabular-nums text-xs text-muted-foreground">
|
||||
{selectedCount}/{group.permissions.length}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
{isOpen ? (
|
||||
<div className="divide-y">
|
||||
{group.permissions.map((permission) => (
|
||||
<div className="pb-2">
|
||||
{group.permissions.map((permission, index) => (
|
||||
<label
|
||||
key={permission.slug}
|
||||
className={cn(
|
||||
"flex cursor-pointer items-start gap-3 px-4 py-3 text-sm transition-colors hover:bg-muted/35",
|
||||
draftRolePermissions.includes(permission.slug) && "bg-muted/25",
|
||||
"flex cursor-pointer items-start gap-3 px-4 py-2.5 text-sm transition-colors hover:bg-muted/20",
|
||||
index === 0 && "border-t border-border/50",
|
||||
selectedPermissionSet.has(permission.slug) && "bg-muted/20",
|
||||
)}
|
||||
>
|
||||
<span className="mt-1 flex h-4 w-8 shrink-0 items-center">
|
||||
<span className="h-px w-full bg-border/70" />
|
||||
</span>
|
||||
<Checkbox
|
||||
className="mt-0.5"
|
||||
checked={draftRolePermissions.includes(permission.slug)}
|
||||
checked={selectedPermissionSet.has(permission.slug)}
|
||||
onCheckedChange={(value) =>
|
||||
toggleRolePermission(permission.slug, value === true)
|
||||
}
|
||||
/>
|
||||
<span className="min-w-0 whitespace-normal break-words font-medium leading-6 text-foreground">
|
||||
<span className="min-w-0 whitespace-normal break-words leading-6 text-foreground">
|
||||
{permissionLabel(permission.slug, permission.name, t)}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -44,7 +44,7 @@ export function AdminUsersConsole(): React.ReactElement {
|
||||
const { t } = useTranslation(["adminUsers", "common"]);
|
||||
const profile = useAdminProfile();
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [keyword, setKeyword] = useState("");
|
||||
const [query, setQuery] = useState("");
|
||||
|
||||
@@ -365,7 +365,7 @@ export function AdminUsersConsole(): React.ReactElement {
|
||||
<TableHead className="w-20 whitespace-nowrap">{t("table.status")}</TableHead>
|
||||
<TableHead>{t("table.roles")}</TableHead>
|
||||
<TableHead>{t("table.effective")}</TableHead>
|
||||
<TableHead className="min-w-[11rem]">{t("table.actions")}</TableHead>
|
||||
<TableHead className="w-[15rem] whitespace-nowrap text-center">{t("table.actions")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
@@ -414,8 +414,8 @@ export function AdminUsersConsole(): React.ReactElement {
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="tabular-nums">{row.effective_permissions.length}</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
<TableCell className="text-center">
|
||||
<div className="flex w-full flex-nowrap justify-center gap-1 whitespace-nowrap">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
|
||||
@@ -29,7 +29,7 @@ export function AuditLogsConsole(): React.ReactElement {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [moduleCode, setModuleCode] = useState("");
|
||||
const [actionCode, setActionCode] = useState("");
|
||||
const [operatorType, setOperatorType] = useState("");
|
||||
|
||||
@@ -5,41 +5,26 @@ import { usePathname } from "next/navigation";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const LINKS: { href: string; key: string; match?: "exact" | "prefix" }[] = [
|
||||
{ href: "/admin/config/plays", key: "plays" },
|
||||
{ href: "/admin/config/odds", key: "odds" },
|
||||
{ href: "/admin/config/rebate", key: "rebate" },
|
||||
{ href: "/admin/config/risk-cap", key: "risk-cap" },
|
||||
];
|
||||
|
||||
function linkActive(pathname: string, href: string, match: "exact" | "prefix"): boolean {
|
||||
if (match === "exact") {
|
||||
return pathname === href || pathname === `${href}/`;
|
||||
}
|
||||
return pathname === href || pathname.startsWith(`${href}/`);
|
||||
}
|
||||
import { CONFIG_NAV_GROUPS } from "@/modules/config/config-nav-model";
|
||||
|
||||
export function ConfigSubNav() {
|
||||
const { t } = useTranslation("config");
|
||||
const pathname = usePathname();
|
||||
const links = CONFIG_NAV_GROUPS.flatMap((group) => group.items);
|
||||
|
||||
return (
|
||||
<nav
|
||||
className="flex flex-wrap gap-2 border-b border-border pb-3 mb-6"
|
||||
aria-label={t("nav.aria")}
|
||||
>
|
||||
{LINKS.map(({ href, key, match = "prefix" }) => {
|
||||
const active = linkActive(pathname, href, match);
|
||||
<nav className="flex w-full flex-wrap items-end gap-1 border-b border-border/60 px-1" aria-label={t("nav.aria")}>
|
||||
{links.map(({ href, key }) => {
|
||||
const active = pathname === href || pathname.startsWith(`${href}/`);
|
||||
return (
|
||||
<Link
|
||||
key={href}
|
||||
href={href}
|
||||
className={cn(
|
||||
"rounded-md px-3 py-1.5 text-sm transition-colors",
|
||||
"border-b-2 px-4 py-3 text-sm font-medium transition-colors",
|
||||
active
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "bg-muted/60 text-muted-foreground hover:bg-muted hover:text-foreground",
|
||||
? "border-primary text-primary"
|
||||
: "border-transparent text-muted-foreground hover:border-border/80 hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{t(`nav.items.${key}`)}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { Layers } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -165,22 +164,23 @@ export function ConfigVersionSwitcher({
|
||||
</SheetHeader>
|
||||
</div>
|
||||
<div className="border-b bg-white px-4 py-3">
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{statusCounts.map((s) => (
|
||||
<div key={s.status} className="rounded-xl border bg-white px-3 py-2">
|
||||
<p className="text-[11px] font-medium text-slate-500">{s.label}</p>
|
||||
<p className="mt-0.5 text-lg font-semibold tabular-nums text-slate-950">
|
||||
{s.count}
|
||||
</p>
|
||||
<div
|
||||
key={s.status}
|
||||
className="inline-flex items-center gap-2 rounded-full border border-border/60 bg-background px-3 py-1.5 text-xs text-muted-foreground"
|
||||
>
|
||||
<span className="font-medium text-foreground/80">{s.label}</span>
|
||||
<span className="font-mono tabular-nums">{s.count}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-1 overflow-auto space-y-5 px-4 py-4">
|
||||
<div className="flex-1 overflow-auto px-4 py-4">
|
||||
{sortedVersions.length === 0 ? (
|
||||
<Card className="border-dashed border-slate-200 bg-white/80 p-5 text-center text-sm text-slate-500 shadow-none">
|
||||
<div className="rounded-2xl border border-dashed border-border/60 bg-white/70 p-5 text-center text-sm text-muted-foreground">
|
||||
{t("versionSwitcher.empty", { ns: "config" })}
|
||||
</Card>
|
||||
</div>
|
||||
) : (
|
||||
STATUS_ORDER.map((status) => {
|
||||
const rows = groupedVersions.get(status) ?? [];
|
||||
@@ -188,8 +188,8 @@ export function ConfigVersionSwitcher({
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<section key={status} className="space-y-2.5">
|
||||
<div className="flex items-center justify-between px-1">
|
||||
<section key={status} className="border-b border-border/60 pb-4 last:border-b-0 last:pb-0">
|
||||
<div className="mb-2 flex items-center justify-between px-1">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div
|
||||
className={cn(
|
||||
@@ -199,111 +199,109 @@ export function ConfigVersionSwitcher({
|
||||
status === "archived" && "bg-slate-400 shadow-slate-100",
|
||||
)}
|
||||
/>
|
||||
<p className="text-[15px] font-semibold text-slate-950">
|
||||
<p className="text-[15px] font-semibold text-foreground">
|
||||
{t(`versionStatus.${status}`, { ns: "config" })}
|
||||
</p>
|
||||
</div>
|
||||
<p className="rounded-full bg-white px-2 py-0.5 text-xs font-medium tabular-nums text-slate-500 ring-1 ring-slate-200">
|
||||
<p className="rounded-full bg-muted/50 px-2 py-0.5 text-xs font-medium tabular-nums text-muted-foreground">
|
||||
{t("versionSwitcher.count", { ns: "config", count: rows.length })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2.5">
|
||||
<div className="space-y-1.5">
|
||||
{rows.map((v) => {
|
||||
const isCurrent = selectedId === String(v.id);
|
||||
return (
|
||||
<Card
|
||||
<div
|
||||
key={v.id}
|
||||
className={cn(
|
||||
"group overflow-hidden rounded-2xl border bg-white p-0 shadow-none transition-colors hover:border-slate-300",
|
||||
isCurrent && "border-slate-900 ring-1 ring-slate-900/10",
|
||||
"group flex gap-3 rounded-xl border border-transparent px-2 py-3 transition-colors hover:bg-muted/30",
|
||||
isCurrent && "border-border/60 bg-muted/20",
|
||||
)}
|
||||
>
|
||||
<div className="flex gap-3 p-3.5">
|
||||
<div
|
||||
className={cn(
|
||||
"mt-1 h-auto w-1 shrink-0 rounded-full bg-slate-200",
|
||||
v.status === "draft" && "bg-amber-300",
|
||||
v.status === "active" && "bg-emerald-400",
|
||||
v.status === "archived" && "bg-slate-300",
|
||||
)}
|
||||
/>
|
||||
<div className="min-w-0 flex-1 space-y-3">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0 space-y-1.5">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="font-mono text-lg font-semibold leading-none tabular-nums text-slate-950">
|
||||
v{v.version_no}
|
||||
</span>
|
||||
<ConfigStatusBadge status={v.status} />
|
||||
<span className="rounded-full bg-slate-100 px-2 py-0.5 text-xs font-medium tabular-nums text-slate-500">
|
||||
#{v.id}
|
||||
</span>
|
||||
</div>
|
||||
<p className="line-clamp-2 text-[13px] leading-5 text-slate-500">
|
||||
{t("versionSwitcher.effectiveAt", {
|
||||
ns: "config",
|
||||
value: v.effective_at ? formatDt(v.effective_at) : "—",
|
||||
})}
|
||||
{v.reason
|
||||
? ` · ${t("versionSwitcher.note", {
|
||||
ns: "config",
|
||||
value: v.reason,
|
||||
})}`
|
||||
: ""}
|
||||
</p>
|
||||
</div>
|
||||
{isCurrent ? (
|
||||
<span className="shrink-0 rounded-full bg-slate-950 px-2.5 py-1 text-xs font-medium text-white shadow-sm">
|
||||
{t("versionSwitcher.current", { ns: "config" })}
|
||||
<div
|
||||
className={cn(
|
||||
"mt-1 h-auto w-1 shrink-0 rounded-full bg-slate-200",
|
||||
v.status === "draft" && "bg-amber-300",
|
||||
v.status === "active" && "bg-emerald-400",
|
||||
v.status === "archived" && "bg-slate-300",
|
||||
)}
|
||||
/>
|
||||
<div className="min-w-0 flex-1 space-y-2">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0 space-y-1.5">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="font-mono text-lg font-semibold leading-none tabular-nums text-foreground">
|
||||
v{v.version_no}
|
||||
</span>
|
||||
) : null}
|
||||
<ConfigStatusBadge status={v.status} />
|
||||
<span className="rounded-full bg-muted px-2 py-0.5 text-xs font-medium tabular-nums text-muted-foreground">
|
||||
#{v.id}
|
||||
</span>
|
||||
</div>
|
||||
<p className="line-clamp-2 text-[13px] leading-5 text-muted-foreground">
|
||||
{t("versionSwitcher.effectiveAt", {
|
||||
ns: "config",
|
||||
value: v.effective_at ? formatDt(v.effective_at) : "—",
|
||||
})}
|
||||
{v.reason
|
||||
? ` · ${t("versionSwitcher.note", {
|
||||
ns: "config",
|
||||
value: v.reason,
|
||||
})}`
|
||||
: ""}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2 border-t border-slate-100 pt-3">
|
||||
{isCurrent ? (
|
||||
<span className="shrink-0 rounded-full bg-foreground px-2.5 py-1 text-xs font-medium text-background">
|
||||
{t("versionSwitcher.current", { ns: "config" })}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant={isCurrent ? "secondary" : "outline"}
|
||||
size="sm"
|
||||
className={cn(
|
||||
"h-8 rounded-full px-3 text-xs",
|
||||
isCurrent && "bg-muted text-muted-foreground hover:bg-muted",
|
||||
)}
|
||||
onClick={() => switchTo(v.id)}
|
||||
>
|
||||
{isCurrent
|
||||
? t("versionSwitcher.selected", { ns: "config" })
|
||||
: t("versionSwitcher.view", { ns: "config" })}
|
||||
</Button>
|
||||
{onRollbackVersion && v.status !== "draft" ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant={isCurrent ? "secondary" : "outline"}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className={cn(
|
||||
"h-8 rounded-full px-3 text-xs",
|
||||
isCurrent && "bg-slate-100 text-slate-500 hover:bg-slate-100",
|
||||
)}
|
||||
onClick={() => switchTo(v.id)}
|
||||
className="rounded-full text-xs text-muted-foreground hover:bg-muted hover:text-foreground"
|
||||
disabled={rollbackBusy}
|
||||
onClick={() => {
|
||||
onRollbackVersion(v);
|
||||
setSheetOpen(false);
|
||||
}}
|
||||
>
|
||||
{isCurrent
|
||||
? t("versionSwitcher.selected", { ns: "config" })
|
||||
: t("versionSwitcher.view", { ns: "config" })}
|
||||
{t("versionSwitcher.rollback", { ns: "config" })}
|
||||
</Button>
|
||||
{onRollbackVersion && v.status !== "draft" ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="rounded-full text-xs text-slate-600 hover:bg-slate-100 hover:text-slate-950"
|
||||
disabled={rollbackBusy}
|
||||
onClick={() => {
|
||||
onRollbackVersion(v);
|
||||
setSheetOpen(false);
|
||||
}}
|
||||
>
|
||||
{t("versionSwitcher.rollback", { ns: "config" })}
|
||||
</Button>
|
||||
) : null}
|
||||
{onDeleteVersion && v.status !== "active" ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="rounded-full text-xs text-rose-600 hover:bg-rose-50 hover:text-rose-700"
|
||||
disabled={deletingId === v.id}
|
||||
onClick={() => setDeleteTarget(v)}
|
||||
>
|
||||
{t("versionSwitcher.delete", { ns: "config" })}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{onDeleteVersion && v.status !== "active" ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="rounded-full text-xs text-rose-600 hover:bg-rose-50 hover:text-rose-700"
|
||||
disabled={deletingId === v.id}
|
||||
onClick={() => setDeleteTarget(v)}
|
||||
>
|
||||
{t("versionSwitcher.delete", { ns: "config" })}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -1,88 +1,16 @@
|
||||
"use client";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { CONFIG_NAV_GROUPS } from "@/modules/config/config-nav-model";
|
||||
|
||||
function navLinkActive(pathname: string, href: string): boolean {
|
||||
return pathname === href || pathname.startsWith(`${href}/`);
|
||||
}
|
||||
import { ConfigSubNav } from "@/modules/config/config-subnav";
|
||||
|
||||
export function ConfigWorkspaceShell({ children }: { children: ReactNode }) {
|
||||
const { t } = useTranslation("config");
|
||||
const pathname = usePathname() ?? "";
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-7xl flex-col gap-6">
|
||||
<div className="flex flex-col gap-6 lg:flex-row lg:items-start">
|
||||
<aside className="shrink-0 lg:sticky lg:top-[72px] lg:w-56 lg:self-start">
|
||||
<div className="rounded-2xl border border-border/70 bg-card/80 p-3 shadow-sm backdrop-blur lg:max-h-[calc(100vh-7rem)] lg:overflow-y-auto">
|
||||
<div className="mb-3 px-1">
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.18em] text-muted-foreground">
|
||||
{t("nav.sidebarTitle")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<nav className="hidden space-y-3 lg:block" aria-label={t("nav.aria")}>
|
||||
{CONFIG_NAV_GROUPS.map((group) => (
|
||||
<div key={group.id} className="space-y-1.5">
|
||||
<p className="px-2 text-xs font-semibold uppercase tracking-[0.14em] text-muted-foreground">
|
||||
{t(`nav.groups.${group.id}`)}
|
||||
</p>
|
||||
<ul className="space-y-1">
|
||||
{group.items.map((item) => {
|
||||
const active = navLinkActive(pathname, item.href);
|
||||
return (
|
||||
<li key={item.href}>
|
||||
<Link
|
||||
href={item.href}
|
||||
className={cn(
|
||||
"block rounded-xl border px-3 py-2.5 text-sm transition-all outline-none ring-offset-background focus-visible:ring-2 focus-visible:ring-ring",
|
||||
active
|
||||
? "border-primary/20 bg-primary/10 text-primary shadow-sm"
|
||||
: "border-transparent bg-transparent text-foreground hover:border-border hover:bg-muted/60",
|
||||
)}
|
||||
>
|
||||
<div className="font-medium">{t(`nav.items.${item.key}`)}</div>
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<div className="lg:hidden overflow-x-auto pb-1 -mx-1 px-1">
|
||||
<div className="flex w-max gap-2">
|
||||
{CONFIG_NAV_GROUPS.flatMap((g) => g.items).map((item) => {
|
||||
const active = navLinkActive(pathname, item.href);
|
||||
return (
|
||||
<Link
|
||||
key={`m-${item.href}`}
|
||||
href={item.href}
|
||||
className={cn(
|
||||
"shrink-0 rounded-full border px-3 py-1.5 text-xs font-medium transition-colors whitespace-nowrap",
|
||||
active
|
||||
? "border-primary bg-primary/10 text-primary"
|
||||
: "border-border bg-background text-foreground hover:bg-muted/60",
|
||||
)}
|
||||
>
|
||||
{t(`nav.items.${item.key}`)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div className="min-w-0 flex-1">{children}</div>
|
||||
<div className="mx-auto flex w-full max-w-[1680px] flex-col gap-6 px-4 py-5 sm:px-6 lg:px-8 lg:py-6">
|
||||
<div className="sticky top-14 z-20 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80">
|
||||
<ConfigSubNav />
|
||||
</div>
|
||||
<div className="min-w-0">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -445,32 +445,30 @@ export function OddsConfigDocScreen() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-xl border bg-muted/20 p-3">
|
||||
<div className="flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
|
||||
<ConfigVersionSwitcher
|
||||
versions={list}
|
||||
selectedId={selectedId}
|
||||
onSelectedIdChange={setSelectedId}
|
||||
loading={loadingList}
|
||||
sheetTitle={`${t("nav.items.odds", { ns: "config" })} ${t("versionSwitcher.sheetTitle", { ns: "config" })}`}
|
||||
sheetDescription={t("odds.sheetDescription", { ns: "config" })}
|
||||
onDeleteVersion={handleDeleteVersion}
|
||||
onRollbackVersion={requestRollback}
|
||||
rollbackBusy={saving}
|
||||
className="lg:flex-1"
|
||||
/>
|
||||
<div className="flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
|
||||
<ConfigVersionSwitcher
|
||||
versions={list}
|
||||
selectedId={selectedId}
|
||||
onSelectedIdChange={setSelectedId}
|
||||
loading={loadingList}
|
||||
sheetTitle={`${t("nav.items.odds", { ns: "config" })} ${t("versionSwitcher.sheetTitle", { ns: "config" })}`}
|
||||
sheetDescription={t("odds.sheetDescription", { ns: "config" })}
|
||||
onDeleteVersion={handleDeleteVersion}
|
||||
onRollbackVersion={requestRollback}
|
||||
rollbackBusy={saving}
|
||||
className="lg:flex-1"
|
||||
/>
|
||||
|
||||
<ConfigVersionActions
|
||||
isDraft={isDraft}
|
||||
loadingList={loadingList}
|
||||
loadingDetail={loadingDetail}
|
||||
saving={saving}
|
||||
onRefresh={() => void refreshList()}
|
||||
onNewDraft={() => void handleNewDraft()}
|
||||
onSaveDraft={() => void handleSave()}
|
||||
onPublish={() => void requestPublishConfirm()}
|
||||
/>
|
||||
</div>
|
||||
<ConfigVersionActions
|
||||
isDraft={isDraft}
|
||||
loadingList={loadingList}
|
||||
loadingDetail={loadingDetail}
|
||||
saving={saving}
|
||||
onRefresh={() => void refreshList()}
|
||||
onNewDraft={() => void handleNewDraft()}
|
||||
onSaveDraft={() => void handleSave()}
|
||||
onPublish={() => void requestPublishConfirm()}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{detail ? (
|
||||
|
||||
@@ -380,29 +380,27 @@ export function PlayConfigDocScreen() {
|
||||
<CardTitle className="text-lg">{t("nav.items.plays", { ns: "config" })}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="rounded-xl border bg-muted/20 p-3">
|
||||
<div className="flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
|
||||
<ConfigVersionSwitcher
|
||||
versions={list}
|
||||
selectedId={selectedId}
|
||||
onSelectedIdChange={setSelectedId}
|
||||
loading={loadingList}
|
||||
sheetTitle={`${t("nav.items.plays", { ns: "config" })} ${t("versionSwitcher.sheetTitle", { ns: "config" })}`}
|
||||
onDeleteVersion={handleDeleteVersion}
|
||||
className="lg:flex-1"
|
||||
/>
|
||||
<div className="flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
|
||||
<ConfigVersionSwitcher
|
||||
versions={list}
|
||||
selectedId={selectedId}
|
||||
onSelectedIdChange={setSelectedId}
|
||||
loading={loadingList}
|
||||
sheetTitle={`${t("nav.items.plays", { ns: "config" })} ${t("versionSwitcher.sheetTitle", { ns: "config" })}`}
|
||||
onDeleteVersion={handleDeleteVersion}
|
||||
className="lg:flex-1"
|
||||
/>
|
||||
|
||||
<ConfigVersionActions
|
||||
isDraft={isDraft}
|
||||
loadingList={loadingList}
|
||||
loadingDetail={loadingDetail}
|
||||
saving={saving}
|
||||
onRefresh={() => void refreshList()}
|
||||
onNewDraft={() => void handleNewDraft()}
|
||||
onSaveDraft={() => void handleSaveDraft()}
|
||||
onPublish={() => void handlePublish()}
|
||||
/>
|
||||
</div>
|
||||
<ConfigVersionActions
|
||||
isDraft={isDraft}
|
||||
loadingList={loadingList}
|
||||
loadingDetail={loadingDetail}
|
||||
saving={saving}
|
||||
onRefresh={() => void refreshList()}
|
||||
onNewDraft={() => void handleNewDraft()}
|
||||
onSaveDraft={() => void handleSaveDraft()}
|
||||
onPublish={() => void handlePublish()}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{detail ? (
|
||||
@@ -423,11 +421,9 @@ export function PlayConfigDocScreen() {
|
||||
) : null}
|
||||
|
||||
{detail ? (
|
||||
<div className="rounded-xl border bg-muted/20 p-3">
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<p className="text-sm font-medium">{t("play.batchSwitchesTitle", { ns: "config" })}</p>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<p className="text-sm font-medium">{t("play.batchSwitchesTitle", { ns: "config" })}</p>
|
||||
{!isDraft ? (
|
||||
<span className="text-xs text-amber-600 dark:text-amber-400">
|
||||
{t("play.readOnlyDraftHint", { ns: "config" })}
|
||||
@@ -438,7 +434,7 @@ export function PlayConfigDocScreen() {
|
||||
{batchSwitchStates.map((group) => (
|
||||
<div
|
||||
key={group.key}
|
||||
className="flex items-center gap-2 rounded-lg border bg-background px-3 py-2"
|
||||
className="flex items-center gap-2 rounded-xl border border-border/60 bg-background/70 px-3 py-2"
|
||||
>
|
||||
<div className="min-w-[92px]">
|
||||
<p className="text-sm font-medium">{group.label}</p>
|
||||
@@ -474,8 +470,7 @@ export function PlayConfigDocScreen() {
|
||||
{loadingDetail ? (
|
||||
<p className="text-sm text-muted-foreground">{t("states.loading", { ns: "common" })}</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto rounded-md border">
|
||||
<Table>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="text-center">{t("play.table.playCode", { ns: "config" })}</TableHead>
|
||||
@@ -606,8 +601,7 @@ export function PlayConfigDocScreen() {
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</Table>
|
||||
)}
|
||||
</CardContent>
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ export function RebateConfigDocScreen() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-3 rounded-lg border bg-muted/30 p-4">
|
||||
<div className="flex items-start gap-3 px-1">
|
||||
<Checkbox
|
||||
id="win-enjoy"
|
||||
checked
|
||||
|
||||
@@ -374,7 +374,7 @@ export function RiskCapDocScreen() {
|
||||
|
||||
{error ? <p className="text-sm text-destructive">{error}</p> : null}
|
||||
|
||||
<section className="space-y-3 rounded-lg border bg-muted/20 p-4">
|
||||
<section className="space-y-3">
|
||||
<h3 className="text-sm font-medium">{t("riskCap.defaultCap.title", { ns: "config" })}</h3>
|
||||
<div className="flex flex-wrap items-end gap-2">
|
||||
<div className="grid gap-1">
|
||||
@@ -422,8 +422,7 @@ export function RiskCapDocScreen() {
|
||||
) : specialRows.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">{t("riskCap.noDetailRows", { ns: "config" })}</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto rounded-md border">
|
||||
<Table>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[110px]">{t("riskCap.table.number", { ns: "config" })}</TableHead>
|
||||
@@ -492,9 +491,8 @@ export function RiskCapDocScreen() {
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</section>
|
||||
|
||||
@@ -522,8 +520,7 @@ export function RiskCapDocScreen() {
|
||||
{t("riskCap.actions.exportCsv", { ns: "config" })}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="overflow-x-auto rounded-md border">
|
||||
<Table>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>{t("riskCap.table.number", { ns: "config" })}</TableHead>
|
||||
@@ -551,7 +548,6 @@ export function RiskCapDocScreen() {
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</section>
|
||||
</CardContent>
|
||||
|
||||
|
||||
@@ -42,7 +42,11 @@ interface Draft {
|
||||
outMax: string;
|
||||
}
|
||||
|
||||
export function WalletConfigDocScreen() {
|
||||
type WalletConfigDocScreenProps = {
|
||||
embedded?: boolean;
|
||||
};
|
||||
|
||||
export function WalletConfigDocScreen({ embedded = false }: WalletConfigDocScreenProps) {
|
||||
const { t } = useTranslation(["config", "adminUsers"]);
|
||||
const [draft, setDraft] = useState<Draft>({
|
||||
inMin: "",
|
||||
@@ -109,83 +113,91 @@ export function WalletConfigDocScreen() {
|
||||
}
|
||||
};
|
||||
|
||||
const content = (
|
||||
<>
|
||||
<div className="grid gap-5 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="in-min">{t("wallet.fields.inMin", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="in-min"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder={t("wallet.placeholders.min", { ns: "config" })}
|
||||
value={draft.inMin}
|
||||
onChange={(e) => handleChange("inMin", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="in-max">{t("wallet.fields.inMax", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="in-max"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder={t("wallet.placeholders.max", { ns: "config" })}
|
||||
value={draft.inMax}
|
||||
onChange={(e) => handleChange("inMax", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="out-min">{t("wallet.fields.outMin", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="out-min"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder={t("wallet.placeholders.min", { ns: "config" })}
|
||||
value={draft.outMin}
|
||||
onChange={(e) => handleChange("outMin", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="out-max">{t("wallet.fields.outMax", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="out-max"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder={t("wallet.placeholders.max", { ns: "config" })}
|
||||
value={draft.outMax}
|
||||
onChange={(e) => handleChange("outMax", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 pt-2">
|
||||
<Button onClick={() => void handleSave()} disabled={!dirty || loading || saving}>
|
||||
{saving ? t("saving", { ns: "adminUsers" }) : t("actions.save", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
{dirty && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setDraft(saved);
|
||||
setDirty(false);
|
||||
}}
|
||||
>
|
||||
{t("wallet.discard", { ns: "config" })}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
if (embedded) {
|
||||
return content;
|
||||
}
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t("wallet.title", { ns: "config" })}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="grid gap-6 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="in-min">{t("wallet.fields.inMin", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="in-min"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder={t("wallet.placeholders.min", { ns: "config" })}
|
||||
value={draft.inMin}
|
||||
onChange={(e) => handleChange("inMin", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="in-max">{t("wallet.fields.inMax", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="in-max"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder={t("wallet.placeholders.max", { ns: "config" })}
|
||||
value={draft.inMax}
|
||||
onChange={(e) => handleChange("inMax", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="out-min">{t("wallet.fields.outMin", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="out-min"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder={t("wallet.placeholders.min", { ns: "config" })}
|
||||
value={draft.outMin}
|
||||
onChange={(e) => handleChange("outMin", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="out-max">{t("wallet.fields.outMax", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="out-max"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder={t("wallet.placeholders.max", { ns: "config" })}
|
||||
value={draft.outMax}
|
||||
onChange={(e) => handleChange("outMax", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<Button onClick={() => void handleSave()} disabled={!dirty || loading || saving}>
|
||||
{saving ? t("saving", { ns: "adminUsers" }) : t("actions.save", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
{dirty && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setDraft(saved);
|
||||
setDirty(false);
|
||||
}}
|
||||
>
|
||||
{t("wallet.discard", { ns: "config" })}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
<CardContent className="space-y-6">{content}</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
ClipboardList,
|
||||
Diamond,
|
||||
FileSearch,
|
||||
FileSpreadsheet,
|
||||
Gift,
|
||||
RefreshCw,
|
||||
ScrollText,
|
||||
@@ -25,6 +24,8 @@ import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { formatAdminMinorUnits, getAdminCurrencyDecimalPlaces } from "@/lib/money";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type { AdminDrawFinanceSummaryData } from "@/types/api/admin-draw-finance";
|
||||
@@ -42,20 +43,18 @@ type SoldOutBuckets = {
|
||||
};
|
||||
|
||||
function formatMoneyMinor(minor: number, currencyCode: string | null): string {
|
||||
const major = minor / 100;
|
||||
const code = (currencyCode ?? "CNY").toUpperCase();
|
||||
const code = (currencyCode ?? "NPR").toUpperCase();
|
||||
const decimals = getAdminCurrencyDecimalPlaces(code);
|
||||
const major = minor / 10 ** decimals;
|
||||
try {
|
||||
return new Intl.NumberFormat("zh-CN", {
|
||||
style: "currency",
|
||||
currency: code,
|
||||
maximumFractionDigits: 2,
|
||||
minimumFractionDigits: decimals,
|
||||
maximumFractionDigits: decimals,
|
||||
}).format(major);
|
||||
} catch {
|
||||
return new Intl.NumberFormat("zh-CN", {
|
||||
style: "currency",
|
||||
currency: "CNY",
|
||||
maximumFractionDigits: 2,
|
||||
}).format(major);
|
||||
return formatAdminMinorUnits(minor, code, decimals);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,6 +250,7 @@ function SoldOutDonut({ buckets }: { buckets: SoldOutBuckets }): ReactElement {
|
||||
|
||||
export function DashboardConsole(): ReactElement {
|
||||
const { t } = useTranslation(["dashboard", "common"]);
|
||||
useAdminCurrencyCatalog();
|
||||
const [todayLabel] = useState(() => format(new Date(), "yyyy-MM-dd EEEE", { locale: zhCN }));
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
@@ -352,7 +352,6 @@ export function DashboardConsole(): ReactElement {
|
||||
},
|
||||
{ href: "/admin/tickets", label: t("quickLinks.tickets"), icon: <Shield className="size-5" /> },
|
||||
{ href: "/admin/wallet/transactions", label: t("quickLinks.walletTransactions"), icon: <Wallet className="size-5" /> },
|
||||
{ href: "/admin/reports", label: t("quickLinks.reports"), icon: <FileSpreadsheet className="size-5" /> },
|
||||
{ href: "/admin/audit-logs", label: t("quickLinks.auditLogs"), icon: <ScrollText className="size-5" /> },
|
||||
];
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ export function DrawsIndexConsole() {
|
||||
const [appliedDrawNo, setAppliedDrawNo] = useState("");
|
||||
const [appliedStatus, setAppliedStatus] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState<number>(20);
|
||||
const [perPage, setPerPage] = useState<number>(10);
|
||||
const [generating, setGenerating] = useState(false);
|
||||
|
||||
const drawStatusTriggerLabel = useMemo(
|
||||
|
||||
@@ -35,11 +35,11 @@ export function JackpotRecordsConsole() {
|
||||
|
||||
const [payouts, setPayouts] = useState<AdminJackpotPayoutLogsData | null>(null);
|
||||
const [pPage, setPPage] = useState(1);
|
||||
const [pPer, setPPer] = useState(15);
|
||||
const [pPer, setPPer] = useState(10);
|
||||
|
||||
const [contribs, setContribs] = useState<AdminJackpotContributionsData | null>(null);
|
||||
const [cPage, setCPage] = useState(1);
|
||||
const [cPer, setCPer] = useState(15);
|
||||
const [cPer, setCPer] = useState(10);
|
||||
|
||||
const [loadingP, setLoadingP] = useState(true);
|
||||
const [loadingC, setLoadingC] = useState(true);
|
||||
|
||||
@@ -41,6 +41,8 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { formatAdminMinorUnits } from "@/lib/money";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type { AdminPlayerRow } from "@/types/api/admin-player";
|
||||
|
||||
@@ -60,11 +62,6 @@ function playerStatusVariant(
|
||||
return "default";
|
||||
}
|
||||
|
||||
function formatMinorUnits(minor: number, currencyCode: string): string {
|
||||
const major = minor / 100;
|
||||
return `${major.toFixed(2)} ${currencyCode}`;
|
||||
}
|
||||
|
||||
const PLAYER_STATUS_OPTIONS = [
|
||||
{ value: 0, label: "statusNormal" },
|
||||
{ value: 1, label: "statusFrozen" },
|
||||
@@ -74,9 +71,10 @@ const PLAYER_STATUS_OPTIONS = [
|
||||
export function PlayersConsole(): React.ReactElement {
|
||||
const { t } = useTranslation(["players", "common"]);
|
||||
const profile = useAdminProfile();
|
||||
useAdminCurrencyCatalog();
|
||||
const canManagePlayers = adminHasAnyPermission(profile?.permissions, ["prd.users.manage"]);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [keyword, setKeyword] = useState("");
|
||||
const [query, setQuery] = useState("");
|
||||
|
||||
@@ -206,6 +204,9 @@ export function PlayersConsole(): React.ReactElement {
|
||||
if (formNickname !== editingPlayer?.nickname) {
|
||||
body.nickname = formNickname.trim() || null;
|
||||
}
|
||||
if (formDefaultCurrency !== editingPlayer?.default_currency) {
|
||||
body.default_currency = formDefaultCurrency.trim().toUpperCase();
|
||||
}
|
||||
if (formStatus !== editingPlayer?.status) {
|
||||
body.status = formStatus;
|
||||
}
|
||||
@@ -344,12 +345,12 @@ export function PlayersConsole(): React.ReactElement {
|
||||
<TableCell>{row.default_currency}</TableCell>
|
||||
<TableCell className="whitespace-nowrap text-right tabular-nums text-xs">
|
||||
{row.wallets.length > 0
|
||||
? formatMinorUnits(row.wallets[0].balance, row.wallets[0].currency_code)
|
||||
? formatAdminMinorUnits(row.wallets[0].balance, row.wallets[0].currency_code)
|
||||
: "—"}
|
||||
</TableCell>
|
||||
<TableCell className="whitespace-nowrap text-right tabular-nums text-xs">
|
||||
{row.wallets.length > 0
|
||||
? formatMinorUnits(row.wallets[0].available_balance, row.wallets[0].currency_code)
|
||||
? formatAdminMinorUnits(row.wallets[0].available_balance, row.wallets[0].currency_code)
|
||||
: "—"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
|
||||
@@ -9,19 +9,15 @@ import {
|
||||
getAdminReconcileJobs,
|
||||
postAdminReconcileJob,
|
||||
} from "@/api/admin-reconcile";
|
||||
import { getAdminPlayers } from "@/api/admin-player";
|
||||
import { AdminDateRangeField } from "@/components/admin/admin-date-range-field";
|
||||
import { AdminListPaginationFooter } from "@/components/admin/admin-list-pagination-footer";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -30,11 +26,12 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type { AdminPlayerRow } from "@/types/api/admin-player";
|
||||
import type {
|
||||
AdminReconcileItemsData,
|
||||
AdminReconcileJobListData,
|
||||
@@ -43,12 +40,7 @@ import type {
|
||||
const MANAGE = ["prd.wallet_reconcile.manage"] as const;
|
||||
|
||||
/** 与后端 reconcile_type 对齐;扩展时在 API 与下拉同步增加 */
|
||||
const RECONCILE_TYPE_OPTIONS = [{ value: "wallet_transfer", label: "walletTransfer" }] as const;
|
||||
|
||||
function reconcileTypeLabel(slug: string, t: (key: string) => string): string {
|
||||
const hit = RECONCILE_TYPE_OPTIONS.find((o) => o.value === slug);
|
||||
return hit ? t(hit.label) : slug;
|
||||
}
|
||||
const RECONCILE_TYPE = "wallet_transfer" as const;
|
||||
|
||||
function jobStatusLabel(status: string, t: (key: string) => string): string {
|
||||
switch (status) {
|
||||
@@ -76,34 +68,13 @@ function itemStatusLabel(status: string, t: (key: string) => string): string {
|
||||
}
|
||||
}
|
||||
|
||||
function toIsoFromDatetimeLocal(local: string): string | null {
|
||||
const t = local.trim();
|
||||
if (t === "") {
|
||||
return null;
|
||||
function reconcileTypeLabel(type: string, t: (key: string) => string): string {
|
||||
switch (type) {
|
||||
case "wallet_transfer":
|
||||
return t("reconcileTypeWalletTransfer");
|
||||
default:
|
||||
return type;
|
||||
}
|
||||
const d = new Date(t);
|
||||
if (Number.isNaN(d.getTime())) {
|
||||
return null;
|
||||
}
|
||||
return d.toISOString();
|
||||
}
|
||||
|
||||
function scopeLinesToItems(
|
||||
raw: string,
|
||||
): NonNullable<Parameters<typeof postAdminReconcileJob>[0]["items"]> | undefined {
|
||||
const lines = raw
|
||||
.split(/\r?\n/)
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
if (lines.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return lines.map((side_a_ref) => ({
|
||||
side_a_ref,
|
||||
side_b_ref: null,
|
||||
difference_amount: 0,
|
||||
status: "pending_check",
|
||||
}));
|
||||
}
|
||||
|
||||
export function ReconcileConsole(): React.ReactElement {
|
||||
@@ -116,18 +87,21 @@ export function ReconcileConsole(): React.ReactElement {
|
||||
const [jobsLoading, setJobsLoading] = useState(true);
|
||||
const [jobsErr, setJobsErr] = useState<string | null>(null);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
|
||||
const [selectedId, setSelectedId] = useState<number | null>(null);
|
||||
const [detailOpen, setDetailOpen] = useState(false);
|
||||
const [items, setItems] = useState<AdminReconcileItemsData | null>(null);
|
||||
const [itemsPage, setItemsPage] = useState(1);
|
||||
const [itemsPerPage, setItemsPerPage] = useState(50);
|
||||
const [itemsPerPage, setItemsPerPage] = useState(10);
|
||||
const [itemsLoading, setItemsLoading] = useState(false);
|
||||
|
||||
const [reconcileType, setReconcileType] = useState<string>(RECONCILE_TYPE_OPTIONS[0].value);
|
||||
const [periodStartLocal, setPeriodStartLocal] = useState("");
|
||||
const [periodEndLocal, setPeriodEndLocal] = useState("");
|
||||
const [scopeLines, setScopeLines] = useState("");
|
||||
const [dateFrom, setDateFrom] = useState("");
|
||||
const [dateTo, setDateTo] = useState("");
|
||||
const [playerSearch, setPlayerSearch] = useState("");
|
||||
const [playerResults, setPlayerResults] = useState<AdminPlayerRow[]>([]);
|
||||
const [playerLoading, setPlayerLoading] = useState(false);
|
||||
const [selectedPlayer, setSelectedPlayer] = useState<AdminPlayerRow | null>(null);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
const loadJobs = useCallback(async () => {
|
||||
@@ -176,35 +150,59 @@ export function ReconcileConsole(): React.ReactElement {
|
||||
});
|
||||
}, [loadItems]);
|
||||
|
||||
const loadPlayers = useCallback(async (keyword: string) => {
|
||||
const q = keyword.trim();
|
||||
if (q === "") {
|
||||
setPlayerResults([]);
|
||||
return;
|
||||
}
|
||||
setPlayerLoading(true);
|
||||
try {
|
||||
const data = await getAdminPlayers({ page: 1, per_page: 8, keyword: q });
|
||||
setPlayerResults(data.items);
|
||||
} catch {
|
||||
setPlayerResults([]);
|
||||
} finally {
|
||||
setPlayerLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const q = playerSearch.trim();
|
||||
if (q === "") {
|
||||
return;
|
||||
}
|
||||
const timer = window.setTimeout(() => {
|
||||
void loadPlayers(q);
|
||||
}, 250);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [loadPlayers, playerSearch]);
|
||||
|
||||
async function onCreate(): Promise<void> {
|
||||
if (!periodStartLocal.trim() || !periodEndLocal.trim()) {
|
||||
if (!dateFrom.trim() || !dateTo.trim()) {
|
||||
toast.error(t("periodRequired"));
|
||||
return;
|
||||
}
|
||||
const periodStartIso = toIsoFromDatetimeLocal(periodStartLocal);
|
||||
const periodEndIso = toIsoFromDatetimeLocal(periodEndLocal);
|
||||
if (periodStartIso == null || periodEndIso == null) {
|
||||
toast.error(t("periodInvalid"));
|
||||
return;
|
||||
}
|
||||
if (new Date(periodStartIso).getTime() > new Date(periodEndIso).getTime()) {
|
||||
if (dateFrom > dateTo) {
|
||||
toast.error(t("periodOrderInvalid"));
|
||||
return;
|
||||
}
|
||||
|
||||
const itemsPayload = scopeLinesToItems(scopeLines);
|
||||
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await postAdminReconcileJob({
|
||||
reconcile_type: reconcileType,
|
||||
period_start: periodStartIso,
|
||||
period_end: periodEndIso,
|
||||
items: itemsPayload,
|
||||
reconcile_type: RECONCILE_TYPE,
|
||||
date_from: dateFrom,
|
||||
date_to: dateTo,
|
||||
player_id: selectedPlayer ? selectedPlayer.id : null,
|
||||
});
|
||||
toast.success(t("createSuccess"));
|
||||
setPage(1);
|
||||
setScopeLines("");
|
||||
setDateFrom("");
|
||||
setDateTo("");
|
||||
setPlayerSearch("");
|
||||
setSelectedPlayer(null);
|
||||
setPlayerResults([]);
|
||||
await loadJobs();
|
||||
} catch (e) {
|
||||
toast.error(e instanceof LotteryApiBizError ? e.message : t("createFailed"));
|
||||
@@ -215,6 +213,7 @@ export function ReconcileConsole(): React.ReactElement {
|
||||
|
||||
const jm = jobs?.meta;
|
||||
const im = items?.meta;
|
||||
const selectedJob = jobs?.items.find((job) => job.id === selectedId) ?? null;
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-none flex-col gap-6">
|
||||
@@ -222,65 +221,104 @@ export function ReconcileConsole(): React.ReactElement {
|
||||
<Card className="admin-list-card">
|
||||
<CardHeader className="admin-list-header">
|
||||
<CardTitle className="admin-list-title">{t("createTitle")}</CardTitle>
|
||||
<CardDescription className="mt-1">{t("createDesc")}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="admin-list-content pt-4">
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(220px,0.9fr)_minmax(180px,0.7fr)_minmax(180px,0.7fr)_auto] lg:items-end">
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(220px,0.9fr)_minmax(220px,0.95fr)_auto] lg:items-end">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="rc-type">{t("reconcileType")}</Label>
|
||||
<Select
|
||||
modal={false}
|
||||
value={reconcileType}
|
||||
onValueChange={(v) => {
|
||||
if (v != null && v !== "") {
|
||||
setReconcileType(v);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SelectTrigger id="rc-type" className="w-full">
|
||||
<SelectValue>{reconcileTypeLabel(reconcileType, t)}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent align="start">
|
||||
{RECONCILE_TYPE_OPTIONS.map((o) => (
|
||||
<SelectItem key={o.value} value={o.value}>
|
||||
{t(o.label)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Label htmlFor="rc-type">{t("reconcileType")}</Label>
|
||||
<Input id="rc-type" value={t("reconcileTypeFixed")} readOnly className="bg-muted/30" />
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="rc-start">{t("startTime")}</Label>
|
||||
<Input
|
||||
id="rc-start"
|
||||
type="datetime-local"
|
||||
value={periodStartLocal}
|
||||
onChange={(e) => setPeriodStartLocal(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="rc-end">{t("endTime")}</Label>
|
||||
<Input
|
||||
id="rc-end"
|
||||
type="datetime-local"
|
||||
value={periodEndLocal}
|
||||
onChange={(e) => setPeriodEndLocal(e.target.value)}
|
||||
<AdminDateRangeField
|
||||
id="rc-date-range"
|
||||
label={t("dateRange")}
|
||||
from={dateFrom}
|
||||
to={dateTo}
|
||||
onRangeChange={({ from, to }) => {
|
||||
setDateFrom(from);
|
||||
setDateTo(to);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<Button type="button" className="w-full lg:w-auto" onClick={() => void onCreate()} disabled={submitting}>
|
||||
{submitting ? t("submitting") : t("createTask")}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="rc-scope">{t("scope")}</Label>
|
||||
<Textarea
|
||||
id="rc-scope"
|
||||
value={scopeLines}
|
||||
onChange={(e) => setScopeLines(e.target.value)}
|
||||
rows={3}
|
||||
placeholder={t("scopePlaceholder")}
|
||||
className="min-h-20 text-sm"
|
||||
<div className="grid gap-1.5 pt-4">
|
||||
<Label htmlFor="rc-player-search">{t("playerSearch")}</Label>
|
||||
<Input
|
||||
id="rc-player-search"
|
||||
value={playerSearch}
|
||||
onChange={(e) => setPlayerSearch(e.target.value)}
|
||||
placeholder={t("playerSearchPlaceholder")}
|
||||
/>
|
||||
{selectedPlayer ? (
|
||||
<div className="flex items-center justify-between gap-3 rounded-lg border bg-muted/20 px-3 py-2 text-sm">
|
||||
<div className="min-w-0">
|
||||
<div className="truncate font-medium text-foreground">
|
||||
{selectedPlayer.site_player_id}
|
||||
{selectedPlayer.nickname ? ` · ${selectedPlayer.nickname}` : ""}
|
||||
{selectedPlayer.username ? ` · ${selectedPlayer.username}` : ""}
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setSelectedPlayer(null);
|
||||
setPlayerSearch("");
|
||||
setPlayerResults([]);
|
||||
}}
|
||||
>
|
||||
{t("playerClear")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
{playerSearch.trim() !== "" || playerResults.length > 0 || playerLoading ? (
|
||||
<div className="rounded-lg border bg-background">
|
||||
<div className="max-h-56 overflow-y-auto">
|
||||
{playerLoading ? (
|
||||
<div className="px-3 py-2 text-sm text-muted-foreground">{t("loadingPlayers")}</div>
|
||||
) : playerResults.length === 0 ? (
|
||||
<div className="px-3 py-2 text-sm text-muted-foreground">{t("playerNoResults")}</div>
|
||||
) : (
|
||||
<div className="divide-y">
|
||||
{playerResults.map((player) => {
|
||||
const active = selectedPlayer?.id === player.id;
|
||||
return (
|
||||
<button
|
||||
key={player.id}
|
||||
type="button"
|
||||
className={cn(
|
||||
"flex w-full items-start justify-between gap-3 px-3 py-2.5 text-left text-sm transition-colors hover:bg-muted/25",
|
||||
active && "bg-muted/30",
|
||||
)}
|
||||
onClick={() => {
|
||||
setSelectedPlayer(player);
|
||||
setPlayerSearch(player.site_player_id);
|
||||
}}
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="truncate font-medium text-foreground">
|
||||
{player.site_player_id}
|
||||
{player.nickname ? ` · ${player.nickname}` : ""}
|
||||
</div>
|
||||
<div className="truncate text-xs text-muted-foreground">
|
||||
{player.username ?? "—"} · {player.site_code}
|
||||
</div>
|
||||
</div>
|
||||
<span className="shrink-0 text-xs text-muted-foreground">
|
||||
{active ? t("playerSelectedShort") : t("playerChoose")}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -292,7 +330,6 @@ export function ReconcileConsole(): React.ReactElement {
|
||||
<CardHeader className="admin-list-header flex flex-row flex-wrap items-end justify-between gap-4">
|
||||
<div>
|
||||
<CardTitle className="admin-list-title">{t("jobsTitle")}</CardTitle>
|
||||
<CardDescription className="mt-1.5">{t("jobsDesc")}</CardDescription>
|
||||
</div>
|
||||
<Button type="button" variant="secondary" size="sm" onClick={() => void loadJobs()}>
|
||||
{t("refresh")}
|
||||
@@ -309,37 +346,37 @@ export function ReconcileConsole(): React.ReactElement {
|
||||
<Table id="reconcile-jobs-table">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-24">{t("table.id", { ns: "common" })}</TableHead>
|
||||
<TableHead>{t("jobNo")}</TableHead>
|
||||
<TableHead className="sticky left-0 z-20 w-24 bg-muted/20 shadow-[1px_0_0_rgba(203,213,225,0.7)]">
|
||||
{t("table.id", { ns: "common" })}
|
||||
</TableHead>
|
||||
<TableHead className="sticky left-24 z-20 min-w-[14rem] bg-muted/20 shadow-[1px_0_0_rgba(203,213,225,0.7)]">
|
||||
{t("jobNo")}
|
||||
</TableHead>
|
||||
<TableHead>{t("type")}</TableHead>
|
||||
<TableHead>{t("status")}</TableHead>
|
||||
<TableHead>{t("period")}</TableHead>
|
||||
<TableHead>{t("createdAt")}</TableHead>
|
||||
<TableHead className="sticky right-0 z-20 w-28 bg-muted/20 text-center shadow-[-1px_0_0_rgba(203,213,225,0.7)]">
|
||||
{t("operate")}
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{jobs.items.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-muted-foreground">
|
||||
<TableCell colSpan={7} className="text-muted-foreground">
|
||||
{t("states.noData", { ns: "common" })}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
jobs.items.map((row) => (
|
||||
<TableRow
|
||||
key={row.id}
|
||||
className={
|
||||
selectedId === row.id
|
||||
? "bg-muted/60 cursor-pointer"
|
||||
: "cursor-pointer hover:bg-muted/40"
|
||||
}
|
||||
onClick={() => {
|
||||
setSelectedId(row.id);
|
||||
setItemsPage(1);
|
||||
}}
|
||||
>
|
||||
<TableCell className="tabular-nums">{row.id}</TableCell>
|
||||
<TableCell className="font-mono text-xs">{row.job_no}</TableCell>
|
||||
<TableRow key={row.id}>
|
||||
<TableCell className="sticky left-0 z-10 bg-card tabular-nums shadow-[1px_0_0_rgba(226,232,240,0.9)]">
|
||||
{row.id}
|
||||
</TableCell>
|
||||
<TableCell className="sticky left-24 z-10 min-w-[14rem] bg-card font-mono text-xs shadow-[1px_0_0_rgba(226,232,240,0.9)]">
|
||||
{row.job_no}
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">{reconcileTypeLabel(row.reconcile_type, t)}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="secondary">{jobStatusLabel(row.status, t)}</Badge>
|
||||
@@ -353,6 +390,20 @@ export function ReconcileConsole(): React.ReactElement {
|
||||
<TableCell className="whitespace-nowrap font-mono text-[11px] text-muted-foreground">
|
||||
{formatTs(row.created_at)}
|
||||
</TableCell>
|
||||
<TableCell className="sticky right-0 z-10 bg-card text-center shadow-[-1px_0_0_rgba(226,232,240,0.9)]">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setSelectedId(row.id);
|
||||
setItemsPage(1);
|
||||
setDetailOpen(true);
|
||||
}}
|
||||
>
|
||||
{t("view")}
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
@@ -379,23 +430,41 @@ export function ReconcileConsole(): React.ReactElement {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{selectedId != null ? (
|
||||
<Card className="admin-list-card">
|
||||
<CardHeader className="admin-list-header">
|
||||
<CardTitle className="admin-list-title">{t("detailsTitle")}</CardTitle>
|
||||
<CardDescription className="font-mono text-xs">#{selectedId}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="admin-list-content pt-4">
|
||||
<Dialog
|
||||
open={detailOpen}
|
||||
onOpenChange={(open) => {
|
||||
setDetailOpen(open);
|
||||
if (!open) {
|
||||
setSelectedId(null);
|
||||
setItems(null);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogContent
|
||||
showCloseButton
|
||||
className="flex h-[min(86vh,780px)] !max-w-[min(920px,calc(100vw-2rem))] flex-col gap-0 overflow-hidden p-0"
|
||||
>
|
||||
<DialogHeader className="shrink-0 space-y-1 border-b bg-background px-5 py-4 pr-12">
|
||||
<DialogTitle className="text-base">{t("detailsTitle")}</DialogTitle>
|
||||
<DialogDescription className="font-mono text-xs">
|
||||
{selectedJob ? `${selectedJob.job_no} · #${selectedJob.id}` : selectedId != null ? `#${selectedId}` : ""}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain bg-muted/15 px-5 py-4">
|
||||
{itemsLoading && !items ? (
|
||||
<p className="text-sm text-muted-foreground">{t("states.loading", { ns: "common" })}</p>
|
||||
) : null}
|
||||
{items ? (
|
||||
<>
|
||||
{items.job_no ? (
|
||||
<p className="font-mono text-sm text-muted-foreground">{t("jobNo")} {items.job_no}</p>
|
||||
) : null}
|
||||
<div className="admin-table-shell">
|
||||
<Table id={`reconcile-items-table-${selectedId ?? "none"}`}>
|
||||
<div className="mb-3 flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
|
||||
<span>{t("jobNo")} {items.job_no}</span>
|
||||
<span>·</span>
|
||||
<span>{t("status")} {selectedJob ? jobStatusLabel(selectedJob.status, t) : "—"}</span>
|
||||
<span>·</span>
|
||||
<span>{t("period")} {selectedJob ? `${selectedJob.period_start ? formatTs(selectedJob.period_start) : "—"} ~ ${selectedJob.period_end ? formatTs(selectedJob.period_end) : "—"}` : "—"}</span>
|
||||
</div>
|
||||
<div className="rounded-lg border bg-background">
|
||||
<Table id={`reconcile-items-table-${selectedId ?? "none"}`}>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-20">{t("table.id", { ns: "common" })}</TableHead>
|
||||
@@ -427,25 +496,27 @@ export function ReconcileConsole(): React.ReactElement {
|
||||
</Table>
|
||||
</div>
|
||||
{im ? (
|
||||
<AdminListPaginationFooter
|
||||
selectId="reconcile-items-per-page"
|
||||
total={im.total}
|
||||
page={im.current_page}
|
||||
lastPage={Math.max(1, im.last_page)}
|
||||
perPage={im.per_page}
|
||||
loading={itemsLoading}
|
||||
onPerPageChange={(n) => {
|
||||
setItemsPerPage(n);
|
||||
setItemsPage(1);
|
||||
}}
|
||||
onPageChange={setItemsPage}
|
||||
/>
|
||||
<div className="pt-4">
|
||||
<AdminListPaginationFooter
|
||||
selectId="reconcile-items-per-page"
|
||||
total={im.total}
|
||||
page={im.current_page}
|
||||
lastPage={Math.max(1, im.last_page)}
|
||||
perPage={im.per_page}
|
||||
loading={itemsLoading}
|
||||
onPerPageChange={(n) => {
|
||||
setItemsPerPage(n);
|
||||
setItemsPage(1);
|
||||
}}
|
||||
onPageChange={setItemsPage}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
export const reportsModuleMeta = {
|
||||
segment: "reports",
|
||||
title: "报表导出",
|
||||
description: "",
|
||||
} as const;
|
||||
@@ -1,298 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import {
|
||||
downloadAdminReportJob,
|
||||
getAdminReportJobs,
|
||||
postAdminReportJob,
|
||||
} from "@/api/admin-reports";
|
||||
import { AdminListPaginationFooter } from "@/components/admin/admin-list-pagination-footer";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type { AdminReportJobListData } from "@/types/api/admin-reports";
|
||||
|
||||
const REPORT_TYPES = [
|
||||
{ value: "draw_profit_summary" },
|
||||
{ value: "daily_profit_summary" },
|
||||
{ value: "player_win_loss" },
|
||||
{ value: "wallet_transfer_report" },
|
||||
{ value: "hot_number_risk_report" },
|
||||
{ value: "play_dimension_report" },
|
||||
{ value: "sold_out_number_report" },
|
||||
{ value: "rebate_commission_report" },
|
||||
{ value: "audit_operation_report" },
|
||||
{ value: "wallet_txns_daily" },
|
||||
{ value: "transfer_orders_daily" },
|
||||
] as const;
|
||||
|
||||
export function ReportsConsole(): React.ReactElement {
|
||||
const { t } = useTranslation(["reports", "common"]);
|
||||
const formatTs = useAdminDateTimeFormatter();
|
||||
const [data, setData] = useState<AdminReportJobListData | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
|
||||
const [reportType, setReportType] = useState<string>(REPORT_TYPES[0].value);
|
||||
const [exportFormat, setExportFormat] = useState<"csv" | "xlsx">("csv");
|
||||
const [filterJsonText, setFilterJsonText] = useState('{\n "currency_code": "NPR"\n}');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setErr(null);
|
||||
try {
|
||||
const d = await getAdminReportJobs({ page, per_page: perPage });
|
||||
setData(d);
|
||||
} catch (e) {
|
||||
setErr(e instanceof LotteryApiBizError ? e.message : t("errors.loadFailed", { ns: "common" }));
|
||||
setData(null);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [page, perPage, t]);
|
||||
|
||||
useEffect(() => {
|
||||
queueMicrotask(() => {
|
||||
void load();
|
||||
});
|
||||
}, [load]);
|
||||
|
||||
async function onCreate(): Promise<void> {
|
||||
let filter_json: Record<string, unknown> | null = null;
|
||||
const trimmed = filterJsonText.trim();
|
||||
if (trimmed !== "") {
|
||||
try {
|
||||
filter_json = JSON.parse(trimmed) as Record<string, unknown>;
|
||||
} catch {
|
||||
toast.error(t("parseFilterFailed"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await postAdminReportJob({
|
||||
report_type: reportType,
|
||||
export_format: exportFormat,
|
||||
parameters: filter_json,
|
||||
filter_json,
|
||||
});
|
||||
toast.success(t("createSuccess"));
|
||||
setPage(1);
|
||||
await load();
|
||||
} catch (e) {
|
||||
toast.error(e instanceof LotteryApiBizError ? e.message : t("createFailed"));
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function onDownload(rowId: number): Promise<void> {
|
||||
try {
|
||||
const blob = await downloadAdminReportJob(rowId);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "";
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
} catch {
|
||||
toast.error(t("downloadFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
const meta = data?.meta;
|
||||
const lastPage = meta
|
||||
? Math.max(1, meta.last_page)
|
||||
: 1;
|
||||
const reportFormatLabel = (value: string) =>
|
||||
t(`formatOptions.${value}`, { defaultValue: value.toUpperCase() });
|
||||
const reportStatusLabel = (value: string) => t(`statusOptions.${value}`, { defaultValue: value });
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-none flex-col gap-8">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t("createExport")}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label>{t("reportType")}</Label>
|
||||
<Select
|
||||
modal={false}
|
||||
value={reportType}
|
||||
onValueChange={(v) => {
|
||||
if (v) {
|
||||
setReportType(v);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{REPORT_TYPES.map((o) => (
|
||||
<SelectItem key={o.value} value={o.value}>
|
||||
{t(`reportTypes.${o.value}`)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label>{t("exportFormat")}</Label>
|
||||
<Select
|
||||
modal={false}
|
||||
value={exportFormat}
|
||||
onValueChange={(v) => {
|
||||
if (v === "csv" || v === "xlsx") {
|
||||
setExportFormat(v);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="csv">{t("formatOptions.csv")}</SelectItem>
|
||||
<SelectItem value="xlsx">{t("formatOptions.xlsx")}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="sm:col-span-2 lg:col-span-3 grid gap-1.5">
|
||||
<Label htmlFor="report-filter-json">{t("filterJson")}</Label>
|
||||
<Textarea
|
||||
id="report-filter-json"
|
||||
value={filterJsonText}
|
||||
onChange={(e) => setFilterJsonText(e.target.value)}
|
||||
rows={5}
|
||||
className="font-mono text-xs"
|
||||
/>
|
||||
</div>
|
||||
<div className="sm:col-span-2 lg:col-span-3">
|
||||
<Button type="button" onClick={() => void onCreate()} disabled={submitting}>
|
||||
{submitting ? t("actions.submitting", { ns: "common" }) : t("actions.createTask", { ns: "common" })}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row flex-wrap items-end justify-between gap-4">
|
||||
<div>
|
||||
<CardTitle>{t("taskList")}</CardTitle>
|
||||
</div>
|
||||
<Button type="button" variant="secondary" size="sm" onClick={() => void load()}>
|
||||
{t("actions.refresh", { ns: "common" })}
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{err ? <p className="text-sm text-red-600 dark:text-red-400">{err}</p> : null}
|
||||
{loading && !data ? (
|
||||
<p className="text-muted-foreground text-sm">{t("states.loading", { ns: "common" })}</p>
|
||||
) : null}
|
||||
{data ? (
|
||||
<>
|
||||
<div className="rounded-md border">
|
||||
<Table id="reports-table">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-24">{t("id")}</TableHead>
|
||||
<TableHead>{t("jobId")}</TableHead>
|
||||
<TableHead>{t("type")}</TableHead>
|
||||
<TableHead>{t("format")}</TableHead>
|
||||
<TableHead>{t("status")}</TableHead>
|
||||
<TableHead>{t("output")}</TableHead>
|
||||
<TableHead>{t("download")}</TableHead>
|
||||
<TableHead>{t("createdAt")}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{data.items.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={8} className="text-muted-foreground">
|
||||
{t("empty")}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
data.items.map((row) => (
|
||||
<TableRow key={row.id}>
|
||||
<TableCell className="tabular-nums">{row.id}</TableCell>
|
||||
<TableCell className="font-mono text-xs">{row.job_no}</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
{t(`reportTypes.${row.report_type}`, {
|
||||
defaultValue: row.report_type,
|
||||
})}
|
||||
</TableCell>
|
||||
<TableCell>{reportFormatLabel(row.export_format)}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="secondary">{reportStatusLabel(row.status)}</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="max-w-[12rem] truncate text-xs text-muted-foreground">
|
||||
{row.output_path ?? "—"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={() => void onDownload(row.id)}
|
||||
>
|
||||
{t("actions.download", { ns: "common" })}
|
||||
</Button>
|
||||
</TableCell>
|
||||
<TableCell className="whitespace-nowrap font-mono text-[11px] text-muted-foreground">
|
||||
{formatTs(row.created_at)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
{meta ? (
|
||||
<AdminListPaginationFooter
|
||||
selectId="report-jobs-per-page"
|
||||
total={meta.total}
|
||||
page={meta.current_page}
|
||||
lastPage={lastPage}
|
||||
perPage={meta.per_page}
|
||||
loading={loading}
|
||||
onPerPageChange={(n) => {
|
||||
setPerPage(n);
|
||||
setPage(1);
|
||||
}}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ export function RiskIndexConsole() {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [drawNoInput, setDrawNoInput] = useState("");
|
||||
const [drawNoQuery, setDrawNoQuery] = useState("");
|
||||
const [statusFilter, setStatusFilter] = useState("");
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { formatAdminMinorUnits } from "@/lib/money";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
@@ -50,9 +51,10 @@ function riskActionLabel(
|
||||
|
||||
export function RiskLockLogsConsole({ drawId }: { drawId: number }) {
|
||||
const { t } = useTranslation(["risk", "common"]);
|
||||
useAdminCurrencyCatalog();
|
||||
const formatDt = useAdminDateTimeFormatter();
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [data, setData] = useState<AdminRiskLockLogListData | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -184,7 +186,7 @@ export function RiskLockLogsConsole({ drawId }: { drawId: number }) {
|
||||
{riskActionLabel(row.action_type, t)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">
|
||||
{formatAdminMinorUnits(row.amount)}
|
||||
{formatAdminMinorUnits(row.amount, data?.currency_code ?? "NPR")}
|
||||
</TableCell>
|
||||
<TableCell className="text-xs text-muted-foreground">
|
||||
{row.source_reason ?? "—"}
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { formatAdminMinorUnits } from "@/lib/money";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -31,9 +32,10 @@ export function RiskPoolDetailConsole({
|
||||
number4d: string;
|
||||
}) {
|
||||
const { t } = useTranslation(["risk", "common"]);
|
||||
useAdminCurrencyCatalog();
|
||||
const formatDt = useAdminDateTimeFormatter();
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(20);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [data, setData] = useState<AdminRiskPoolShowData | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -88,6 +90,7 @@ export function RiskPoolDetailConsole({
|
||||
}
|
||||
|
||||
const { pool, logs } = data;
|
||||
const currencyCode = data.currency_code ?? "NPR";
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -111,19 +114,19 @@ export function RiskPoolDetailConsole({
|
||||
<div className="rounded-lg border bg-muted/40 p-3">
|
||||
<p className="text-xs text-muted-foreground">{t("totalCap")}</p>
|
||||
<p className="mt-1 font-mono text-sm font-medium tabular-nums">
|
||||
{formatAdminMinorUnits(pool.total_cap_amount)}
|
||||
{formatAdminMinorUnits(pool.total_cap_amount, currencyCode)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rounded-lg border bg-muted/40 p-3">
|
||||
<p className="text-xs text-muted-foreground">{t("lockedWorstCase")}</p>
|
||||
<p className="mt-1 font-mono text-sm font-medium tabular-nums">
|
||||
{formatAdminMinorUnits(pool.locked_amount)}
|
||||
{formatAdminMinorUnits(pool.locked_amount, currencyCode)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rounded-lg border bg-muted/40 p-3">
|
||||
<p className="text-xs text-muted-foreground">{t("remainingSellable")}</p>
|
||||
<p className="mt-1 font-mono text-sm font-medium tabular-nums">
|
||||
{formatAdminMinorUnits(pool.remaining_amount)}
|
||||
{formatAdminMinorUnits(pool.remaining_amount, currencyCode)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rounded-lg border bg-muted/40 p-3">
|
||||
@@ -169,7 +172,7 @@ export function RiskPoolDetailConsole({
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">{row.action_type}</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">
|
||||
{formatAdminMinorUnits(row.amount)}
|
||||
{formatAdminMinorUnits(row.amount, currencyCode)}
|
||||
</TableCell>
|
||||
<TableCell className="text-xs text-muted-foreground">
|
||||
{row.source_reason ?? "—"}
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { formatAdminMinorUnits } from "@/lib/money";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
@@ -71,11 +72,12 @@ export function RiskPoolsConsole({
|
||||
allowSortChange = false,
|
||||
}: RiskPoolsConsoleProps) {
|
||||
const { t } = useTranslation(["risk", "common"]);
|
||||
useAdminCurrencyCatalog();
|
||||
const [sort, setSort] = useState(defaultSort);
|
||||
const [filter, setFilter] = useState<RiskFilter>(soldOutOnly ? "sold_out" : "all");
|
||||
const [number, setNumber] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [data, setData] = useState<AdminRiskPoolListData | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [actingNumber, setActingNumber] = useState<string | null>(null);
|
||||
@@ -241,6 +243,7 @@ export function RiskPoolsConsole({
|
||||
{(data?.items ?? []).map((row: AdminRiskPoolRow) => {
|
||||
const highRisk = (row.usage_ratio ?? 0) >= 0.8;
|
||||
const acting = actingNumber === row.normalized_number;
|
||||
const currencyCode = data?.currency_code ?? "NPR";
|
||||
|
||||
return (
|
||||
<TableRow
|
||||
@@ -255,13 +258,13 @@ export function RiskPoolsConsole({
|
||||
>
|
||||
<TableCell className="font-mono font-medium">{row.normalized_number}</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">
|
||||
{formatAdminMinorUnits(row.total_cap_amount)}
|
||||
{formatAdminMinorUnits(row.total_cap_amount, currencyCode)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">
|
||||
{formatAdminMinorUnits(row.locked_amount)}
|
||||
{formatAdminMinorUnits(row.locked_amount, currencyCode)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">
|
||||
{formatAdminMinorUnits(row.remaining_amount)}
|
||||
{formatAdminMinorUnits(row.remaining_amount, currencyCode)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">
|
||||
{row.usage_ratio != null ? `${(row.usage_ratio * 100).toFixed(2)}%` : "—"}
|
||||
|
||||
11
src/modules/settings/currency-management-screen.tsx
Normal file
11
src/modules/settings/currency-management-screen.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { CurrencySettingsPanel } from "@/modules/settings/currency-settings-panel";
|
||||
|
||||
export function CurrencyManagementScreen() {
|
||||
return (
|
||||
<div className="flex w-full max-w-none flex-col gap-6">
|
||||
<CurrencySettingsPanel />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
377
src/modules/settings/currency-settings-panel.tsx
Normal file
377
src/modules/settings/currency-settings-panel.tsx
Normal file
@@ -0,0 +1,377 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import {
|
||||
deleteAdminCurrency,
|
||||
getAdminCurrencies,
|
||||
postAdminCurrency,
|
||||
putAdminCurrency,
|
||||
} from "@/api/admin-currencies";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { AdminTableExportButton } from "@/components/admin/admin-table-export-button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type { AdminCurrencyRow } from "@/types/api/admin-currency";
|
||||
|
||||
type CurrencyFormState = {
|
||||
code: string;
|
||||
name: string;
|
||||
decimal_places: string;
|
||||
is_enabled: boolean;
|
||||
is_bettable: boolean;
|
||||
};
|
||||
|
||||
const EMPTY_FORM: CurrencyFormState = {
|
||||
code: "",
|
||||
name: "",
|
||||
decimal_places: "2",
|
||||
is_enabled: true,
|
||||
is_bettable: false,
|
||||
};
|
||||
|
||||
function toFormState(row: AdminCurrencyRow): CurrencyFormState {
|
||||
return {
|
||||
code: row.code,
|
||||
name: row.name,
|
||||
decimal_places: String(row.decimal_places),
|
||||
is_enabled: row.is_enabled,
|
||||
is_bettable: row.is_enabled && row.is_bettable,
|
||||
};
|
||||
}
|
||||
|
||||
export function CurrencySettingsPanel() {
|
||||
const { t } = useTranslation(["config", "adminUsers"]);
|
||||
const profile = useAdminProfile();
|
||||
const canManage = adminHasAnyPermission(profile?.permissions, ["prd.currency.manage"]);
|
||||
const [items, setItems] = useState<AdminCurrencyRow[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
const [mode, setMode] = useState<"create" | "edit">("create");
|
||||
const [editingCode, setEditingCode] = useState<string | null>(null);
|
||||
const [form, setForm] = useState<CurrencyFormState>(EMPTY_FORM);
|
||||
const [deleteTarget, setDeleteTarget] = useState<AdminCurrencyRow | null>(null);
|
||||
const [deleteBusy, setDeleteBusy] = useState(false);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
if (!canManage) {
|
||||
setItems([]);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await getAdminCurrencies();
|
||||
setItems(data.items);
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof LotteryApiBizError
|
||||
? error.message
|
||||
: t("currencies.loadFailed", { ns: "config" }),
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [canManage, t]);
|
||||
|
||||
useEffect(() => {
|
||||
queueMicrotask(() => {
|
||||
void load();
|
||||
});
|
||||
}, [load]);
|
||||
|
||||
function openCreate(): void {
|
||||
setMode("create");
|
||||
setEditingCode(null);
|
||||
setForm(EMPTY_FORM);
|
||||
setDialogOpen(true);
|
||||
}
|
||||
|
||||
function openEdit(row: AdminCurrencyRow): void {
|
||||
setMode("edit");
|
||||
setEditingCode(row.code);
|
||||
setForm(toFormState(row));
|
||||
setDialogOpen(true);
|
||||
}
|
||||
|
||||
function updateForm<K extends keyof CurrencyFormState>(key: K, value: CurrencyFormState[K]): void {
|
||||
setForm((prev) => {
|
||||
const next = { ...prev, [key]: value };
|
||||
if (key === "is_enabled" && value === false) {
|
||||
next.is_bettable = false;
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
async function handleSubmit(): Promise<void> {
|
||||
const payload = {
|
||||
name: form.name.trim(),
|
||||
decimal_places: Number.parseInt(form.decimal_places || "0", 10),
|
||||
is_enabled: form.is_enabled,
|
||||
is_bettable: form.is_enabled && form.is_bettable,
|
||||
};
|
||||
|
||||
if (mode === "create") {
|
||||
if (form.code.trim() === "" || payload.name === "") {
|
||||
toast.error(t("currencies.form.required", { ns: "config" }));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Number.isFinite(payload.decimal_places) || payload.decimal_places < 0) {
|
||||
toast.error(t("currencies.form.decimalInvalid", { ns: "config" }));
|
||||
return;
|
||||
}
|
||||
|
||||
setSaving(true);
|
||||
try {
|
||||
if (mode === "create") {
|
||||
await postAdminCurrency({
|
||||
code: form.code.trim().toUpperCase(),
|
||||
...payload,
|
||||
});
|
||||
toast.success(t("currencies.createSuccess", { ns: "config" }));
|
||||
} else if (editingCode !== null) {
|
||||
await putAdminCurrency(editingCode, payload);
|
||||
toast.success(t("currencies.updateSuccess", { ns: "config" }));
|
||||
}
|
||||
|
||||
setDialogOpen(false);
|
||||
await load();
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof LotteryApiBizError
|
||||
? error.message
|
||||
: t(mode === "create" ? "currencies.createFailed" : "currencies.updateFailed", { ns: "config" }),
|
||||
);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmDelete(): Promise<void> {
|
||||
if (deleteTarget === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDeleteBusy(true);
|
||||
try {
|
||||
await deleteAdminCurrency(deleteTarget.code);
|
||||
toast.success(t("currencies.deleteSuccess", { ns: "config", code: deleteTarget.code }));
|
||||
setDeleteTarget(null);
|
||||
await load();
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
error instanceof LotteryApiBizError
|
||||
? error.message
|
||||
: t("currencies.deleteFailed", { ns: "config" }),
|
||||
);
|
||||
} finally {
|
||||
setDeleteBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!canManage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="admin-list-card">
|
||||
<CardHeader className="admin-list-header flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="space-y-1">
|
||||
<CardTitle className="admin-list-title">{t("currencies.title", { ns: "config" })}</CardTitle>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t("currencies.description", { ns: "config" })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<AdminTableExportButton tableId="admin-currencies-table" filename="币种管理" sheetName="币种管理" />
|
||||
<Button onClick={openCreate}>{t("currencies.actions.create", { ns: "config" })}</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="admin-list-content">
|
||||
<div className="admin-table-shell">
|
||||
<Table id="admin-currencies-table">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="whitespace-nowrap">{t("currencies.table.code", { ns: "config" })}</TableHead>
|
||||
<TableHead>{t("currencies.table.name", { ns: "config" })}</TableHead>
|
||||
<TableHead className="whitespace-nowrap">{t("currencies.table.decimals", { ns: "config" })}</TableHead>
|
||||
<TableHead className="whitespace-nowrap">{t("currencies.table.enabled", { ns: "config" })}</TableHead>
|
||||
<TableHead className="whitespace-nowrap">{t("currencies.table.bettable", { ns: "config" })}</TableHead>
|
||||
<TableHead className="whitespace-nowrap text-center">{t("currencies.table.actions", { ns: "config" })}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{loading ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-center text-sm text-muted-foreground">
|
||||
{t("currencies.loading", { ns: "config" })}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : items.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-center text-sm text-muted-foreground">
|
||||
{t("currencies.empty", { ns: "config" })}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
items.map((row) => (
|
||||
<TableRow key={row.code}>
|
||||
<TableCell className="font-mono">{row.code}</TableCell>
|
||||
<TableCell>{row.name}</TableCell>
|
||||
<TableCell>{row.decimal_places}</TableCell>
|
||||
<TableCell>{row.is_enabled ? t("system.states.enabled", { ns: "config" }) : t("system.states.disabled", { ns: "config" })}</TableCell>
|
||||
<TableCell>{row.is_bettable ? t("system.states.enabled", { ns: "config" }) : t("system.states.disabled", { ns: "config" })}</TableCell>
|
||||
<TableCell className="text-center">
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<Button variant="outline" size="sm" onClick={() => openEdit(row)}>
|
||||
{t("currencies.actions.edit", { ns: "config" })}
|
||||
</Button>
|
||||
<Button variant="destructive" size="sm" onClick={() => setDeleteTarget(row)}>
|
||||
{t("currencies.actions.delete", { ns: "config" })}
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
|
||||
<DialogContent showCloseButton className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{t(mode === "create" ? "currencies.dialog.createTitle" : "currencies.dialog.editTitle", {
|
||||
ns: "config",
|
||||
})}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{t("currencies.dialog.description", { ns: "config" })}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="currency-code">{t("currencies.form.code", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="currency-code"
|
||||
value={form.code}
|
||||
onChange={(e) => updateForm("code", e.target.value.toUpperCase())}
|
||||
disabled={saving || mode === "edit"}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="currency-name">{t("currencies.form.name", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="currency-name"
|
||||
value={form.name}
|
||||
onChange={(e) => updateForm("name", e.target.value)}
|
||||
disabled={saving}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="currency-decimals">{t("currencies.form.decimals", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="currency-decimals"
|
||||
type="number"
|
||||
min="0"
|
||||
max="12"
|
||||
step="1"
|
||||
value={form.decimal_places}
|
||||
onChange={(e) => updateForm("decimal_places", e.target.value)}
|
||||
disabled={saving}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between rounded-xl border border-border/70 p-3">
|
||||
<div className="space-y-1">
|
||||
<p className="text-sm font-medium">{t("currencies.form.enabled", { ns: "config" })}</p>
|
||||
<p className="text-xs text-muted-foreground">{t("currencies.form.enabledHint", { ns: "config" })}</p>
|
||||
</div>
|
||||
<Checkbox
|
||||
checked={form.is_enabled}
|
||||
onCheckedChange={(checked) => updateForm("is_enabled", checked === true)}
|
||||
disabled={saving}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between rounded-xl border border-border/70 p-3">
|
||||
<div className="space-y-1">
|
||||
<p className="text-sm font-medium">{t("currencies.form.bettable", { ns: "config" })}</p>
|
||||
<p className="text-xs text-muted-foreground">{t("currencies.form.bettableHint", { ns: "config" })}</p>
|
||||
</div>
|
||||
<Checkbox
|
||||
checked={form.is_enabled && form.is_bettable}
|
||||
onCheckedChange={(checked) => updateForm("is_bettable", checked === true)}
|
||||
disabled={saving || !form.is_enabled}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-3">
|
||||
<Button variant="outline" onClick={() => setDialogOpen(false)} disabled={saving}>
|
||||
{t("actions.cancel", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
<Button onClick={() => void handleSubmit()} disabled={saving}>
|
||||
{saving ? t("saving", { ns: "adminUsers" }) : t("actions.save", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={deleteTarget !== null} onOpenChange={(open) => !open && setDeleteTarget(null)}>
|
||||
<DialogContent showCloseButton className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("currencies.deleteDialog.title", { ns: "config" })}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{t("currencies.deleteDialog.description", {
|
||||
ns: "config",
|
||||
code: deleteTarget?.code ?? "",
|
||||
})}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex justify-end gap-3">
|
||||
<Button variant="outline" onClick={() => setDeleteTarget(null)} disabled={deleteBusy}>
|
||||
{t("actions.cancel", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
<Button variant="destructive" onClick={() => void confirmDelete()} disabled={deleteBusy}>
|
||||
{deleteBusy ? t("deleting", { ns: "adminUsers" }) : t("currencies.actions.delete", { ns: "config" })}
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
import { WalletConfigDocScreen } from "@/modules/config/doc/wallet-config-doc-screen";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
@@ -31,6 +30,45 @@ interface RuntimeDraft {
|
||||
autoSettlement: boolean;
|
||||
}
|
||||
|
||||
function BinaryChoice({
|
||||
active,
|
||||
disabled,
|
||||
onChange,
|
||||
leftLabel,
|
||||
rightLabel,
|
||||
}: {
|
||||
active: boolean;
|
||||
disabled: boolean;
|
||||
onChange: (value: boolean) => void;
|
||||
leftLabel: string;
|
||||
rightLabel: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="inline-flex rounded-full border border-border/60 bg-background p-1">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant={!active ? "default" : "ghost"}
|
||||
className={!active ? "h-8 rounded-full px-3" : "h-8 rounded-full px-3 text-muted-foreground"}
|
||||
disabled={disabled}
|
||||
onClick={() => onChange(false)}
|
||||
>
|
||||
{leftLabel}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant={active ? "default" : "ghost"}
|
||||
className={active ? "h-8 rounded-full px-3" : "h-8 rounded-full px-3 text-muted-foreground"}
|
||||
disabled={disabled}
|
||||
onClick={() => onChange(true)}
|
||||
>
|
||||
{rightLabel}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SystemSettingsScreen() {
|
||||
const { t } = useTranslation(["common", "config", "adminUsers"]);
|
||||
const [draft, setDraft] = useState<RuntimeDraft>({
|
||||
@@ -120,82 +158,89 @@ export function SystemSettingsScreen() {
|
||||
</CardTitle>
|
||||
</div>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t("system.title", { ns: "config" })}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
<div className="space-y-3 rounded-xl border border-border/70 p-4">
|
||||
<Label htmlFor="manual-review">{t("system.fields.manualReview", { ns: "config" })}</Label>
|
||||
<div className="flex items-center gap-3">
|
||||
<Checkbox
|
||||
id="manual-review"
|
||||
checked={draft.requireManualReview}
|
||||
onCheckedChange={(checked) => updateDraft("requireManualReview", checked === true)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
<Label htmlFor="manual-review" className="text-sm font-medium">
|
||||
{draft.requireManualReview
|
||||
? t("system.states.enabled", { ns: "config" })
|
||||
: t("system.states.disabled", { ns: "config" })}
|
||||
</Label>
|
||||
<CardContent className="space-y-8">
|
||||
<section className="space-y-4">
|
||||
<div className="flex flex-wrap items-end justify-between gap-3">
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-base font-semibold">{t("system.title", { ns: "config" })}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3 rounded-xl border border-border/70 p-4">
|
||||
<Label htmlFor="auto-settlement">{t("system.fields.autoSettlement", { ns: "config" })}</Label>
|
||||
<div className="flex items-center gap-3">
|
||||
<Checkbox
|
||||
id="auto-settlement"
|
||||
checked={draft.autoSettlement}
|
||||
onCheckedChange={(checked) => updateDraft("autoSettlement", checked === true)}
|
||||
<div className="space-y-5 rounded-2xl border border-border/60 bg-muted/10 px-4 py-4">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="space-y-1">
|
||||
<Label className="text-sm font-medium">{t("system.fields.manualReview", { ns: "config" })}</Label>
|
||||
</div>
|
||||
<BinaryChoice
|
||||
active={draft.requireManualReview}
|
||||
disabled={loading || saving}
|
||||
onChange={(value) => updateDraft("requireManualReview", value)}
|
||||
leftLabel={t("system.states.disabled", { ns: "config" })}
|
||||
rightLabel={t("system.states.enabled", { ns: "config" })}
|
||||
/>
|
||||
<Label htmlFor="auto-settlement" className="text-sm font-medium">
|
||||
{draft.autoSettlement
|
||||
? t("system.states.enabled", { ns: "config" })
|
||||
: t("system.states.disabled", { ns: "config" })}
|
||||
</div>
|
||||
|
||||
<div className="h-px bg-border/60" />
|
||||
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="space-y-1">
|
||||
<Label className="text-sm font-medium">{t("system.fields.autoSettlement", { ns: "config" })}</Label>
|
||||
</div>
|
||||
<BinaryChoice
|
||||
active={draft.autoSettlement}
|
||||
disabled={loading || saving}
|
||||
onChange={(value) => updateDraft("autoSettlement", value)}
|
||||
leftLabel={t("system.states.disabled", { ns: "config" })}
|
||||
rightLabel={t("system.states.enabled", { ns: "config" })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="h-px bg-border/60" />
|
||||
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="cooldown-minutes" className="text-sm font-medium">
|
||||
{t("system.fields.cooldownMinutes", { ns: "config" })}
|
||||
</Label>
|
||||
<Input
|
||||
id="cooldown-minutes"
|
||||
type="number"
|
||||
min="0"
|
||||
step="1"
|
||||
value={draft.cooldownMinutes}
|
||||
onChange={(e) => updateDraft("cooldownMinutes", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
className="max-w-[240px]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-4 pt-2">
|
||||
<Button onClick={() => void handleSave()} disabled={!dirty || loading || saving}>
|
||||
{saving ? t("saving", { ns: "adminUsers" }) : t("actions.save", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
{dirty && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setDraft(saved);
|
||||
setDirty(false);
|
||||
}}
|
||||
>
|
||||
{t("system.discard", { ns: "config" })}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="cooldown-minutes">{t("system.fields.cooldownMinutes", { ns: "config" })}</Label>
|
||||
<Input
|
||||
id="cooldown-minutes"
|
||||
type="number"
|
||||
min="0"
|
||||
step="1"
|
||||
value={draft.cooldownMinutes}
|
||||
onChange={(e) => updateDraft("cooldownMinutes", e.target.value)}
|
||||
disabled={loading || saving}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<Button onClick={() => void handleSave()} disabled={!dirty || loading || saving}>
|
||||
{saving ? t("saving", { ns: "adminUsers" }) : t("actions.save", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
{dirty && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setDraft(saved);
|
||||
setDirty(false);
|
||||
}}
|
||||
>
|
||||
{t("system.discard", { ns: "config" })}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<section className="space-y-4 border-t border-border/60 pt-6">
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-base font-semibold">{t("wallet.title", { ns: "config" })}</h3>
|
||||
</div>
|
||||
<WalletConfigDocScreen embedded />
|
||||
</section>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<WalletConfigDocScreen />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { formatAdminMinorUnits } from "@/lib/money";
|
||||
@@ -69,6 +70,7 @@ function settlementReviewStatusText(value: string | null, t: (key: string) => st
|
||||
export function SettlementBatchDetailsConsole({ batchId }: Props) {
|
||||
const { t } = useTranslation(["settlement", "common"]);
|
||||
const profile = useAdminProfile();
|
||||
useAdminCurrencyCatalog();
|
||||
const canReviewSettlement = adminHasAnyPermission(profile?.permissions, [PRD_PAYOUT_REVIEW]);
|
||||
const canManagePayout = adminHasAnyPermission(profile?.permissions, [PRD_PAYOUT_MANAGE]);
|
||||
const formatDt = useAdminDateTimeFormatter();
|
||||
@@ -77,7 +79,7 @@ export function SettlementBatchDetailsConsole({ batchId }: Props) {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [acting, setActing] = useState<string | null>(null);
|
||||
const [pendingAction, setPendingAction] = useState<SettlementAction | null>(null);
|
||||
const [reviewRemark, setReviewRemark] = useState("");
|
||||
@@ -224,20 +226,26 @@ export function SettlementBatchDetailsConsole({ batchId }: Props) {
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-muted-foreground">{t("totalBet")}</span>{" "}
|
||||
<span className="font-mono tabular-nums">{formatAdminMinorUnits(summary.total_bet_amount)}</span>
|
||||
<span className="font-mono tabular-nums">
|
||||
{formatAdminMinorUnits(summary.total_bet_amount, summary.currency_code ?? "NPR")}
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-muted-foreground">{t("actualDeduct")}</span>{" "}
|
||||
<span className="font-mono tabular-nums">{formatAdminMinorUnits(summary.total_actual_deduct)}</span>
|
||||
<span className="font-mono tabular-nums">
|
||||
{formatAdminMinorUnits(summary.total_actual_deduct, summary.currency_code ?? "NPR")}
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-muted-foreground">{t("payoutAmount")}</span>{" "}
|
||||
<span className="font-mono tabular-nums">{formatAdminMinorUnits(summary.total_payout_amount)}</span>
|
||||
<span className="font-mono tabular-nums">
|
||||
{formatAdminMinorUnits(summary.total_payout_amount, summary.currency_code ?? "NPR")}
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
<span className="text-muted-foreground">{t("jackpotPayout")}</span>{" "}
|
||||
<span className="font-mono tabular-nums">
|
||||
{formatAdminMinorUnits(summary.total_jackpot_payout_amount)}
|
||||
{formatAdminMinorUnits(summary.total_jackpot_payout_amount, summary.currency_code ?? "NPR")}
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
@@ -248,7 +256,7 @@ export function SettlementBatchDetailsConsole({ batchId }: Props) {
|
||||
summary.platform_profit < 0 ? "text-destructive" : "text-emerald-700",
|
||||
)}
|
||||
>
|
||||
{formatAdminMinorUnits(summary.platform_profit)}
|
||||
{formatAdminMinorUnits(summary.platform_profit, summary.currency_code ?? "NPR")}
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
@@ -322,10 +330,13 @@ export function SettlementBatchDetailsConsole({ batchId }: Props) {
|
||||
</TableCell>
|
||||
<TableCell className="text-xs">{r.matched_prize_tier ?? "—"}</TableCell>
|
||||
<TableCell className="text-right font-mono text-xs tabular-nums">
|
||||
{formatAdminMinorUnits(r.win_amount)}
|
||||
{formatAdminMinorUnits(r.win_amount, r.currency_code ?? summary.currency_code ?? "NPR")}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-xs tabular-nums">
|
||||
{formatAdminMinorUnits(r.jackpot_allocation_amount)}
|
||||
{formatAdminMinorUnits(
|
||||
r.jackpot_allocation_amount,
|
||||
r.currency_code ?? summary.currency_code ?? "NPR",
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
@@ -375,9 +386,9 @@ export function SettlementBatchDetailsConsole({ batchId }: Props) {
|
||||
<div className="space-y-3">
|
||||
<p className="rounded-md border bg-muted/30 p-3 text-sm">
|
||||
{t("confirmAmountLine", {
|
||||
actual: formatAdminMinorUnits(summary.total_actual_deduct),
|
||||
payout: formatAdminMinorUnits(summary.total_payout_amount),
|
||||
profit: formatAdminMinorUnits(summary.platform_profit),
|
||||
actual: formatAdminMinorUnits(summary.total_actual_deduct, summary.currency_code ?? "NPR"),
|
||||
payout: formatAdminMinorUnits(summary.total_payout_amount, summary.currency_code ?? "NPR"),
|
||||
profit: formatAdminMinorUnits(summary.platform_profit, summary.currency_code ?? "NPR"),
|
||||
})}
|
||||
</p>
|
||||
{pendingAction !== "payout" ? (
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { formatAdminMinorUnits } from "@/lib/money";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -84,6 +85,7 @@ function settlementReviewStatusText(value: string | null, t: (key: string) => st
|
||||
export function SettlementBatchesConsole() {
|
||||
const { t } = useTranslation(["settlement", "common"]);
|
||||
const profile = useAdminProfile();
|
||||
useAdminCurrencyCatalog();
|
||||
const canReviewSettlement = adminHasAnyPermission(profile?.permissions, [PRD_PAYOUT_REVIEW]);
|
||||
const canManagePayout = adminHasAnyPermission(profile?.permissions, [PRD_PAYOUT_MANAGE]);
|
||||
const [data, setData] = useState<AdminSettlementBatchListData | null>(null);
|
||||
@@ -94,7 +96,7 @@ export function SettlementBatchesConsole() {
|
||||
const [draftStatus, setDraftStatus] = useState(STATUS_ALL);
|
||||
const [appliedStatus, setAppliedStatus] = useState(STATUS_ALL);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(20);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [actingId, setActingId] = useState<number | null>(null);
|
||||
const [pendingAction, setPendingAction] = useState<PendingAction | null>(null);
|
||||
const [reviewRemark, setReviewRemark] = useState("");
|
||||
@@ -252,13 +254,13 @@ export function SettlementBatchesConsole() {
|
||||
<TableCell className="font-mono text-xs">{row.id}</TableCell>
|
||||
<TableCell className="font-mono text-sm">{row.draw_no ?? "—"}</TableCell>
|
||||
<TableCell className="text-right font-mono text-xs tabular-nums">
|
||||
{formatAdminMinorUnits(row.total_bet_amount)}
|
||||
{formatAdminMinorUnits(row.total_bet_amount, row.currency_code ?? "NPR")}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-xs tabular-nums">
|
||||
{formatAdminMinorUnits(row.total_actual_deduct)}
|
||||
{formatAdminMinorUnits(row.total_actual_deduct, row.currency_code ?? "NPR")}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-xs tabular-nums">
|
||||
{formatAdminMinorUnits(row.total_payout_amount)}
|
||||
{formatAdminMinorUnits(row.total_payout_amount, row.currency_code ?? "NPR")}
|
||||
</TableCell>
|
||||
<TableCell
|
||||
className={cn(
|
||||
@@ -266,7 +268,7 @@ export function SettlementBatchesConsole() {
|
||||
row.platform_profit < 0 ? "text-destructive" : "text-emerald-700",
|
||||
)}
|
||||
>
|
||||
{formatAdminMinorUnits(row.platform_profit)}
|
||||
{formatAdminMinorUnits(row.platform_profit, row.currency_code ?? "NPR")}
|
||||
</TableCell>
|
||||
<TableCell className="text-xs text-muted-foreground">
|
||||
{settlementReviewStatusText(row.review_status, t)}
|
||||
@@ -368,9 +370,18 @@ export function SettlementBatchesConsole() {
|
||||
<div className="space-y-3">
|
||||
<p className="rounded-md border bg-muted/30 p-3 text-sm">
|
||||
{t("confirmAmountLine", {
|
||||
actual: formatAdminMinorUnits(pendingAction.row.total_actual_deduct),
|
||||
payout: formatAdminMinorUnits(pendingAction.row.total_payout_amount),
|
||||
profit: formatAdminMinorUnits(pendingAction.row.platform_profit),
|
||||
actual: formatAdminMinorUnits(
|
||||
pendingAction.row.total_actual_deduct,
|
||||
pendingAction.row.currency_code ?? "NPR",
|
||||
),
|
||||
payout: formatAdminMinorUnits(
|
||||
pendingAction.row.total_payout_amount,
|
||||
pendingAction.row.currency_code ?? "NPR",
|
||||
),
|
||||
profit: formatAdminMinorUnits(
|
||||
pendingAction.row.platform_profit,
|
||||
pendingAction.row.currency_code ?? "NPR",
|
||||
),
|
||||
})}
|
||||
</p>
|
||||
{pendingAction.action !== "payout" ? (
|
||||
|
||||
@@ -95,7 +95,7 @@ export function PlayerTicketsConsole(): React.ReactElement {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(20);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
|
||||
@@ -36,7 +36,9 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { useAdminCurrencyCatalog } from "@/hooks/use-admin-currency-catalog";
|
||||
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
|
||||
import { formatAdminMinorUnits } from "@/lib/money";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
import type {
|
||||
AdminPlayerWalletsData,
|
||||
@@ -44,11 +46,6 @@ import type {
|
||||
AdminWalletTxnListData,
|
||||
} from "@/types/api/admin-wallet";
|
||||
|
||||
function formatMinorUnits(minor: number, currencyCode: string): string {
|
||||
const major = minor / 100;
|
||||
return `${major.toFixed(2)} ${currencyCode}`;
|
||||
}
|
||||
|
||||
/** 长单号/流水号:单行截断;点击复制全文,悬停可看全文 */
|
||||
function CellMonoId({
|
||||
value,
|
||||
@@ -227,12 +224,13 @@ function canManuallyProcessTransferOrder(row: {
|
||||
|
||||
export function TransferOrdersPanel(): React.ReactElement {
|
||||
const { t } = useTranslation(["wallet", "common"]);
|
||||
useAdminCurrencyCatalog();
|
||||
const formatTs = useAdminDateTimeFormatter();
|
||||
const [data, setData] = useState<AdminTransferOrderListData | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(20);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [draft, setDraft] = useState<TransferFilters>(emptyTransferFilters);
|
||||
const [applied, setApplied] = useState<TransferFilters>(emptyTransferFilters);
|
||||
const [actionLoading, setActionLoading] = useState<Set<string>>(new Set());
|
||||
@@ -475,7 +473,7 @@ export function TransferOrdersPanel(): React.ReactElement {
|
||||
</TableCell>
|
||||
<TableCell>{row.direction}</TableCell>
|
||||
<TableCell className="tabular-nums">
|
||||
{formatMinorUnits(row.amount, row.currency_code)}
|
||||
{formatAdminMinorUnits(row.amount, row.currency_code)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={statusBadgeVariant(row.status)}>{statusLabelT(row.status, t)}</Badge>
|
||||
@@ -552,7 +550,7 @@ export function WalletTxnsPanel(): React.ReactElement {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(20);
|
||||
const [perPage, setPerPage] = useState(10);
|
||||
const [draft, setDraft] = useState<TxnFilters>(emptyTxnFilters);
|
||||
const [applied, setApplied] = useState<TxnFilters>(emptyTxnFilters);
|
||||
|
||||
@@ -836,6 +834,7 @@ export function WalletTxnsPanel(): React.ReactElement {
|
||||
|
||||
export function PlayerWalletPanel(): React.ReactElement {
|
||||
const { t } = useTranslation(["wallet", "common"]);
|
||||
useAdminCurrencyCatalog();
|
||||
const [playerId, setPlayerId] = useState("");
|
||||
const [result, setResult] = useState<AdminPlayerWalletsData | null>(null);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
@@ -918,7 +917,7 @@ export function PlayerWalletPanel(): React.ReactElement {
|
||||
<TableCell>{w.currency_code}</TableCell>
|
||||
<TableCell className="font-mono tabular-nums">{w.balance}</TableCell>
|
||||
<TableCell className="tabular-nums">
|
||||
{formatMinorUnits(w.available_balance, w.currency_code)}
|
||||
{formatAdminMinorUnits(w.available_balance, w.currency_code)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
|
||||
@@ -4,8 +4,8 @@ import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { adminHasAnyPermission } from "@/lib/admin-permissions";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useAdminProfile } from "@/stores/admin-session";
|
||||
|
||||
const RECONCILE_PERMS = [
|
||||
@@ -28,27 +28,38 @@ export function WalletSubnav(): React.ReactElement {
|
||||
return (
|
||||
<nav
|
||||
aria-label={t("subnavLabel")}
|
||||
className="mb-6 flex flex-wrap gap-2 border-b border-border pb-3"
|
||||
className="flex w-full flex-wrap items-end gap-1 border-b border-border/60 px-1"
|
||||
>
|
||||
{tabs.map((tab) => {
|
||||
const allowed = adminHasAnyPermission(perms, [...tab.requiredAny]);
|
||||
const active = pathname === tab.href || pathname.startsWith(`${tab.href}/`);
|
||||
const className = cn(
|
||||
"rounded-lg px-3 py-1.5 text-sm font-medium transition-colors",
|
||||
active
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "bg-muted/60 text-foreground hover:bg-muted",
|
||||
!allowed && "cursor-not-allowed opacity-45",
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return (
|
||||
<span key={tab.href} className={className} title={t("noPermission")}>
|
||||
<span
|
||||
key={tab.href}
|
||||
className={cn(
|
||||
"border-b-2 border-transparent px-4 py-3 text-sm font-medium text-muted-foreground/45",
|
||||
"cursor-not-allowed",
|
||||
)}
|
||||
title={t("noPermission")}
|
||||
>
|
||||
{t(tab.label)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Link key={tab.href} href={tab.href} className={className}>
|
||||
<Link
|
||||
key={tab.href}
|
||||
href={tab.href}
|
||||
className={cn(
|
||||
"border-b-2 px-4 py-3 text-sm font-medium transition-colors",
|
||||
active
|
||||
? "border-primary text-primary"
|
||||
: "border-transparent text-muted-foreground hover:border-border/80 hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{t(tab.label)}
|
||||
</Link>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user