feat(api, i18n): add admin report job functionalities and enhance locale support
- Introduced new API functions for managing admin report jobs, including download and post operations. - Updated English, Nepali, and Chinese locale files to include new messages related to report job actions and rollback confirmations. - Enhanced user experience by providing clearer instructions and feedback in the admin interface. - Refactored related components to integrate new functionalities and improve overall usability.
This commit is contained in:
@@ -19,8 +19,16 @@ import {
|
||||
ConfigVersionToolbarMeta,
|
||||
ConfigVersionToolbarMetaEmphasis,
|
||||
} from "@/modules/config/config-version-toolbar-meta";
|
||||
import { AdminStatusBadge } from "@/components/admin/admin-status-badge";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { ConfigReadonlyValue } from "@/modules/config/config-readonly-value";
|
||||
@@ -116,6 +124,8 @@ export function RebateConfigDocScreen({
|
||||
const [p2, setP2] = useState("0");
|
||||
const [p3, setP3] = useState("0");
|
||||
const [p4, setP4] = useState("0");
|
||||
const [rollbackOpen, setRollbackOpen] = useState(false);
|
||||
const [rollbackTarget, setRollbackTarget] = useState<ConfigVersionSummary | null>(null);
|
||||
|
||||
const refreshTypes = useCallback(async () => {
|
||||
try {
|
||||
@@ -328,6 +338,45 @@ export function RebateConfigDocScreen({
|
||||
|
||||
const activeHead = listRows.find((x) => x.status === "active");
|
||||
|
||||
function requestRollback(row: ConfigVersionSummary) {
|
||||
setRollbackTarget(row);
|
||||
setRollbackOpen(true);
|
||||
}
|
||||
|
||||
async function handleRollback() {
|
||||
if (!rollbackTarget) {
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
const d = await postOddsVersion({
|
||||
reason: `rollback from v${rollbackTarget.version_no}`,
|
||||
clone_from_version_id: rollbackTarget.id,
|
||||
});
|
||||
toast.success(
|
||||
t("versionActions.rollbackSuccess", {
|
||||
ns: "config",
|
||||
fromVersion: rollbackTarget.version_no,
|
||||
version: d.version_no,
|
||||
}),
|
||||
);
|
||||
await refreshList();
|
||||
setSelectedId(String(d.id));
|
||||
const rows = d.items.map((it) => ({ ...it }));
|
||||
setDetail(d);
|
||||
setDraftRows(rows);
|
||||
setP2(inferPercentFrom(2, rows, types));
|
||||
setP3(inferPercentFrom(3, rows, types));
|
||||
setP4(inferPercentFrom(4, rows, types));
|
||||
setRollbackOpen(false);
|
||||
setRollbackTarget(null);
|
||||
} catch (e) {
|
||||
toast.error(e instanceof LotteryApiBizError ? e.message : t("versionActions.rollbackFailed", { ns: "config" }));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDeleteVersion(row: ConfigVersionSummary) {
|
||||
try {
|
||||
await deleteOddsVersion(row.id);
|
||||
@@ -350,6 +399,8 @@ export function RebateConfigDocScreen({
|
||||
sheetTitle={`${t("nav.items.rebate", { ns: "config" })} ${t("versionSwitcher.sheetTitle", { ns: "config" })}`}
|
||||
sheetDescription={t("rebate.sheetDescription", { ns: "config" })}
|
||||
onDeleteVersion={handleDeleteVersion}
|
||||
onRollbackVersion={requestRollback}
|
||||
rollbackBusy={saving}
|
||||
/>
|
||||
}
|
||||
actions={
|
||||
@@ -460,12 +511,13 @@ export function RebateConfigDocScreen({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between gap-3 rounded-xl border border-border/60 px-4 py-3">
|
||||
<p className="text-sm font-medium">{t("rebate.winEnjoy.label", { ns: "config" })}</p>
|
||||
<AdminStatusBadge status="enabled">
|
||||
{t("system.states.enabled", { ns: "config" })}
|
||||
</AdminStatusBadge>
|
||||
</div>
|
||||
<Alert className="border-border/80 bg-muted/30">
|
||||
<AlertDescription className="text-sm leading-relaxed">
|
||||
<span className="font-medium text-foreground">{t("rebate.winEnjoy.label", { ns: "config" })}</span>
|
||||
{" — "}
|
||||
{t("rebate.winEnjoy.pendingNote", { ns: "config" })}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
{!embedded ? (
|
||||
<div className="grid gap-1 text-sm">
|
||||
@@ -482,10 +534,35 @@ export function RebateConfigDocScreen({
|
||||
</>
|
||||
);
|
||||
|
||||
const rollbackDialog = (
|
||||
<Dialog open={rollbackOpen} onOpenChange={setRollbackOpen}>
|
||||
<DialogContent showCloseButton className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("versionActions.rollbackDialog.title", { ns: "config" })}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{t("versionActions.rollbackDialog.description", {
|
||||
ns: "config",
|
||||
version: rollbackTarget?.version_no ?? "—",
|
||||
})}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => setRollbackOpen(false)}>
|
||||
{t("actions.cancel", { ns: "adminUsers" })}
|
||||
</Button>
|
||||
<Button type="button" onClick={() => void handleRollback()} disabled={!rollbackTarget || saving}>
|
||||
{t("versionActions.rollbackDialog.confirm", { ns: "config" })}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
if (embedded) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{fieldsBlock}
|
||||
{rollbackDialog}
|
||||
<ConfirmDialog />
|
||||
</div>
|
||||
);
|
||||
@@ -497,6 +574,7 @@ export function RebateConfigDocScreen({
|
||||
toolbar={toolbarBlock}
|
||||
>
|
||||
{fieldsBlock}
|
||||
{rollbackDialog}
|
||||
<ConfirmDialog />
|
||||
</ConfigDocPage>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user