fix: resolve critical bugs and improve admin panel reliability
- Fix missing await in pets API route causing empty responses - Fix updateSetting to use upsert pattern instead of update-only - Create missing /api/admin/sounds/upload route (upload was broken) - Wire bulk delete actions in catalog table - Replace native confirm() with useConfirmDialog() across rooms and clone pages - Add error logging to silent catch blocks in radio actions and audit route - Add graceful degradation to devops health endpoint - Add cache eviction to clone icon route to prevent memory leak - Internationalize hardcoded Italian strings to English - Remove placeholder created_at fields from prefix API responses - Remove dead code and fix type errors in translations and import pages - Standardize PERMS import path in analytics export route
This commit is contained in:
1 parent
6f53ca514d
commit
1b817fe434
19 files changed
+255
-89
No files matched your search
@@ -2,8 +2,8 @@
|
||||
|
||||
import { Pencil } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { toggleCatalogPage } from "@/actions/catalog";
|
||||
import { toggleBcPage } from "@/actions/catalog-bc";
|
||||
import { deleteCatalogPage, toggleCatalogPage } from "@/actions/catalog";
|
||||
import { deleteBcTreePage, toggleBcPage } from "@/actions/catalog-bc";
|
||||
import { DataTable } from "@/components/admin/data-table";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -175,6 +175,20 @@ export function CatalogTable({
|
||||
},
|
||||
];
|
||||
|
||||
async function handleBulkAction(action: string, ids: (number | string)[]) {
|
||||
if (action !== "delete" || ids.length === 0) return;
|
||||
for (const id of ids) {
|
||||
const numId = typeof id === "string" ? Number(id) : id;
|
||||
if (Number.isInteger(numId) && numId > 0) {
|
||||
run(() =>
|
||||
isBc
|
||||
? deleteBcTreePage({ pageId: numId, mode: "reparent" })
|
||||
: deleteCatalogPage({ id: numId }),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
data={data}
|
||||
@@ -191,6 +205,7 @@ export function CatalogTable({
|
||||
]
|
||||
: undefined
|
||||
}
|
||||
onBulkAction={canEdit ? handleBulkAction : undefined}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from "lucide-react";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { useConfirmDialog } from "@/components/admin/confirm-dialog";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -370,6 +371,7 @@ interface FurniGridProps {
|
||||
const PER_PAGE = 50;
|
||||
|
||||
function FurniGrid({ source }: FurniGridProps) {
|
||||
const { confirm, dialog: confirmDialog } = useConfirmDialog();
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [activeSearch, setActiveSearch] = useState("");
|
||||
const [items, setItems] = useState<FurniItem[]>([]);
|
||||
@@ -554,13 +556,12 @@ function FurniGrid({ source }: FurniGridProps) {
|
||||
toast.info("Nothing to clone — everything is already present");
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!window.confirm(
|
||||
`Clone ALL ${names.length} furni from "${source.name}"? This can take a while.`,
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const confirmed = await confirm({
|
||||
title: "Clone All Furni",
|
||||
description: `Clone ALL ${names.length} furni from "${source.name}"? This can take a while.`,
|
||||
confirmLabel: "Clone All",
|
||||
});
|
||||
if (!confirmed) return;
|
||||
batchAbortRef.current?.abort();
|
||||
const abort = new AbortController();
|
||||
batchAbortRef.current = abort;
|
||||
@@ -614,6 +615,7 @@ function FurniGrid({ source }: FurniGridProps) {
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{confirmDialog}
|
||||
{/* Stats bar */}
|
||||
{stats && (
|
||||
<div className="flex items-center gap-3 flex-wrap">
|
||||
|
||||
@@ -396,14 +396,6 @@ export function ImportFurniClient({ source }: { source: FurniImportSource }) {
|
||||
}
|
||||
}, [statusFilter, activeSearch, fetchItems]);
|
||||
|
||||
function _doSearch(e?: React.FormEvent) {
|
||||
e?.preventDefault();
|
||||
setActiveSearch(searchTerm);
|
||||
setPage(1);
|
||||
fetchItems(searchTerm, 1, statusFilter);
|
||||
}
|
||||
void _doSearch;
|
||||
|
||||
function goPage(p: number) {
|
||||
setPage(p);
|
||||
fetchItems(activeSearch, p, statusFilter);
|
||||
|
||||
@@ -215,7 +215,7 @@ export function NitroEditorDialog({
|
||||
return;
|
||||
}
|
||||
|
||||
toast.success("Nitro metadata salvato");
|
||||
toast.success("Nitro metadata saved");
|
||||
setMetadata(metadataToSave);
|
||||
setOriginalMetadata(JSON.parse(JSON.stringify(metadataToSave)));
|
||||
setOriginalFlags({ ...flags });
|
||||
@@ -392,7 +392,7 @@ export function NitroEditorDialog({
|
||||
<section className="rounded-lg border bg-card p-4">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Ruler className="w-4 h-4 text-muted-foreground" />
|
||||
<h3 className="text-sm font-medium">Dimensioni</h3>
|
||||
<h3 className="text-sm font-medium">Dimensions</h3>
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<div>
|
||||
@@ -400,7 +400,7 @@ export function NitroEditorDialog({
|
||||
htmlFor="dim-x"
|
||||
className="text-xs text-muted-foreground"
|
||||
>
|
||||
X (larghezza)
|
||||
X (width)
|
||||
</Label>
|
||||
<Input
|
||||
id="dim-x"
|
||||
@@ -432,7 +432,7 @@ export function NitroEditorDialog({
|
||||
htmlFor="dim-z"
|
||||
className="text-xs text-muted-foreground"
|
||||
>
|
||||
Z (altezza)
|
||||
Z (height)
|
||||
</Label>
|
||||
<Input
|
||||
id="dim-z"
|
||||
@@ -451,7 +451,7 @@ export function NitroEditorDialog({
|
||||
<section className="rounded-lg border bg-card p-4">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<MousePointerClick className="w-4 h-4 text-muted-foreground" />
|
||||
<h3 className="text-sm font-medium">Interazione</h3>
|
||||
<h3 className="text-sm font-medium">Interaction</h3>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center justify-between rounded-md border px-3 py-2 hover:bg-muted/50 transition-colors">
|
||||
@@ -489,7 +489,7 @@ export function NitroEditorDialog({
|
||||
<section className="rounded-lg border bg-card p-4">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Compass className="w-4 h-4 text-muted-foreground" />
|
||||
<h3 className="text-sm font-medium">Direzioni</h3>
|
||||
<h3 className="text-sm font-medium">Directions</h3>
|
||||
<span className="text-xs text-muted-foreground ml-auto">
|
||||
{directions.length} attive
|
||||
</span>
|
||||
@@ -784,7 +784,7 @@ export function NitroEditorDialog({
|
||||
variant="secondary"
|
||||
className="text-[10px] gap-1 animate-[pulse_1s_ease-in-out_1]"
|
||||
>
|
||||
Modifiche non salvate
|
||||
Unsaved changes
|
||||
</Badge>
|
||||
)}
|
||||
<div className="flex-1" />
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
deleteRoomItem,
|
||||
roomRconAction,
|
||||
} from "@/actions/rooms";
|
||||
import { useConfirmDialog } from "@/components/admin/confirm-dialog";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
@@ -91,6 +92,7 @@ function isWallType(t: string) {
|
||||
|
||||
export function FurniClient({ room, items = [], canEdit }: Props) {
|
||||
const { run, isPending } = useServerAction();
|
||||
const { confirm, dialog: confirmDialog } = useConfirmDialog();
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [view, setView] = useState<View>("flat");
|
||||
@@ -231,29 +233,44 @@ export function FurniClient({ room, items = [], canEdit }: Props) {
|
||||
setSelected(next);
|
||||
}
|
||||
|
||||
function handleRcon(action: "reload" | "kick") {
|
||||
if (action === "kick" && !confirm("Kick all users from this room?")) return;
|
||||
async function handleRcon(action: "reload" | "kick") {
|
||||
if (action === "kick") {
|
||||
const ok = await confirm({
|
||||
title: "Kick Users",
|
||||
description: "Kick all users from this room?",
|
||||
confirmLabel: "Kick",
|
||||
variant: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
}
|
||||
run(() => roomRconAction({ roomId: room.id, action }), {
|
||||
successMessage:
|
||||
action === "reload" ? "Room reloaded" : "All users kicked",
|
||||
});
|
||||
}
|
||||
|
||||
function handleDelete(itemId: number, name: string) {
|
||||
if (!confirm(`Delete "${name}" (#${itemId}) from this room?`)) return;
|
||||
async function handleDelete(itemId: number, name: string) {
|
||||
const ok = await confirm({
|
||||
title: "Delete Item",
|
||||
description: `Delete "${name}" (#${itemId}) from this room?`,
|
||||
confirmLabel: "Delete",
|
||||
variant: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(() => deleteRoomItem({ roomId: room.id, itemId }), {
|
||||
successMessage: "Item deleted",
|
||||
});
|
||||
}
|
||||
|
||||
function handleBulkDelete() {
|
||||
async function handleBulkDelete() {
|
||||
if (selected.size === 0) return;
|
||||
if (
|
||||
!confirm(
|
||||
`Delete ${selected.size} selected item${selected.size > 1 ? "s" : ""}?`,
|
||||
)
|
||||
)
|
||||
return;
|
||||
const ok = await confirm({
|
||||
title: "Delete Items",
|
||||
description: `Delete ${selected.size} selected item${selected.size > 1 ? "s" : ""}?`,
|
||||
confirmLabel: "Delete",
|
||||
variant: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(
|
||||
() =>
|
||||
bulkDeleteRoomItems({ roomId: room.id, itemIds: Array.from(selected) }),
|
||||
@@ -264,8 +281,18 @@ export function FurniClient({ room, items = [], canEdit }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
function handleDeleteGroup(_baseId: number, ids: number[], name: string) {
|
||||
if (!confirm(`Delete all ${ids.length} "${name}" from this room?`)) return;
|
||||
async function handleDeleteGroup(
|
||||
_baseId: number,
|
||||
ids: number[],
|
||||
name: string,
|
||||
) {
|
||||
const ok = await confirm({
|
||||
title: "Delete Items",
|
||||
description: `Delete all ${ids.length} "${name}" from this room?`,
|
||||
confirmLabel: "Delete",
|
||||
variant: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(() => bulkDeleteRoomItems({ roomId: room.id, itemIds: ids }), {
|
||||
successMessage: `${ids.length} item(s) deleted`,
|
||||
});
|
||||
@@ -276,6 +303,7 @@ export function FurniClient({ room, items = [], canEdit }: Props) {
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{confirmDialog}
|
||||
{/* ── Header ─────────────────────────────────────────── */}
|
||||
<div className="flex flex-wrap items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-4">
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from "lucide-react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { deleteRoom, roomRconAction, updateRoom } from "@/actions/rooms";
|
||||
import { useConfirmDialog } from "@/components/admin/confirm-dialog";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
@@ -63,13 +64,17 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
|
||||
});
|
||||
}
|
||||
|
||||
function handleDelete() {
|
||||
if (
|
||||
!confirm(
|
||||
const { confirm, dialog: confirmDialog } = useConfirmDialog();
|
||||
|
||||
async function handleDelete() {
|
||||
const ok = await confirm({
|
||||
title: "Delete Room",
|
||||
description:
|
||||
"Are you sure you want to delete this room? This cannot be undone.",
|
||||
)
|
||||
)
|
||||
return;
|
||||
confirmLabel: "Delete",
|
||||
variant: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(() => deleteRoom({ id: room.id }), { redirectTo: "/admin/rooms" });
|
||||
}
|
||||
|
||||
@@ -82,6 +87,7 @@ export function RoomEditForm({ room }: RoomEditFormProps) {
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{confirmDialog}
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
{/* Edit Form */}
|
||||
<Card>
|
||||
|
||||
@@ -271,7 +271,7 @@ export function SoundsClient({
|
||||
onEnded={() => setPlayingId(null)}
|
||||
onError={() =>
|
||||
toast.error(
|
||||
`Impossibile riprodurre "${s.code}.mp3" da ${baseUrl}.`,
|
||||
`Failed to play "${s.code}.mp3" from ${baseUrl}.`,
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -100,7 +100,7 @@ export function TraxPlayer({
|
||||
|
||||
const AudioCtor = window.AudioContext;
|
||||
if (!AudioCtor) {
|
||||
toast.error("Web Audio API non supportata da questo browser.");
|
||||
toast.error("Web Audio API is not supported by this browser.");
|
||||
setStatus("error");
|
||||
return;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ export function TraxPlayer({
|
||||
|
||||
if (failed > 0) {
|
||||
toast.warning(
|
||||
`${failed}/${uniqueIds.length} sample non caricati — la riproduzione potrebbe avere buchi.`,
|
||||
`${failed}/${uniqueIds.length} samples failed to load — playback may have gaps.`,
|
||||
);
|
||||
}
|
||||
if (failed === uniqueIds.length) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { and, asc, count, like, or, type SQL } from "drizzle-orm";
|
||||
import { and, asc, count, like, or, type SQL, sql } from "drizzle-orm";
|
||||
import { ExternalLink } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
@@ -34,10 +34,12 @@ export default async function EmulatorTranslationsPage({
|
||||
const perPage = Math.min(Math.max(parseInt(sp.perPage || "50", 10), 10), 200);
|
||||
const page = Math.max(parseInt(sp.page || "1", 10), 1);
|
||||
|
||||
const patternFilters = or(
|
||||
...TRANSLATION_KEY_PATTERNS.map((p) => like(EmulatorSettings.key, `${p}%`)),
|
||||
);
|
||||
if (!patternFilters) throw new Error("No emulator translation key patterns");
|
||||
const patternFilters =
|
||||
or(
|
||||
...TRANSLATION_KEY_PATTERNS.map((p) =>
|
||||
like(EmulatorSettings.key, `${p}%`),
|
||||
),
|
||||
) ?? sql`1=0`;
|
||||
|
||||
const conditions: SQL[] = [patternFilters];
|
||||
if (group) conditions.push(like(EmulatorSettings.key, `${group}.%`));
|
||||
|
||||
Reference in new issue
Block a user