i18n observability hub: analytics pages and log tables.
Translate analytics overview/activity/economy plus peak-hours/revenue charts, and audit/chat/commands/trades DataTables (en/nl/it). Includes prior events/polls detail i18n. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
a25008deb5
commit
bcbdca841b
13 files changed
+576
-211
No files matched your search
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useState } from "react";
|
||||
import { DataTable } from "@/components/admin/data-table";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -17,24 +18,25 @@ interface AuditRow {
|
||||
}
|
||||
|
||||
function DiffCell({ diff }: { diff: string | null }) {
|
||||
const t = useTranslations("pages.admin.logs");
|
||||
const [open, setOpen] = useState(false);
|
||||
if (!diff) return <span className="text-muted-foreground">-</span>;
|
||||
if (!diff) return <span className="text-muted-foreground">{t("emptyValue")}</span>;
|
||||
|
||||
let parsed: Record<string, { from: unknown; to: unknown }>;
|
||||
try {
|
||||
parsed = JSON.parse(diff);
|
||||
} catch {
|
||||
return <span className="text-muted-foreground">-</span>;
|
||||
return <span className="text-muted-foreground">{t("emptyValue")}</span>;
|
||||
}
|
||||
|
||||
const keys = Object.keys(parsed);
|
||||
if (keys.length === 0)
|
||||
return <span className="text-muted-foreground">-</span>;
|
||||
return <span className="text-muted-foreground">{t("emptyValue")}</span>;
|
||||
|
||||
const summary =
|
||||
keys.length === 1
|
||||
? `${keys[0]}: ${String(parsed[keys[0]].from ?? "∅")} → ${String(parsed[keys[0]].to ?? "∅")}`
|
||||
: `${keys.length} changes`;
|
||||
: t("audit.changesCount", { count: keys.length });
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -66,51 +68,57 @@ function DiffCell({ diff }: { diff: string | null }) {
|
||||
);
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<AuditRow>[] = [
|
||||
{ key: "id", label: "ID", sortable: true },
|
||||
{ key: "username", label: "User", sortable: true },
|
||||
{
|
||||
key: "action",
|
||||
label: "Action",
|
||||
sortable: true,
|
||||
render: (value) => {
|
||||
const v = String(value);
|
||||
let variant: "default" | "secondary" | "destructive" = "secondary";
|
||||
if (v.includes("create") || v.includes("add")) variant = "default";
|
||||
if (v.includes("delete") || v.includes("remove") || v.includes("ban"))
|
||||
variant = "destructive";
|
||||
return <Badge variant={variant}>{v}</Badge>;
|
||||
},
|
||||
},
|
||||
{ key: "target", label: "Target", sortable: true },
|
||||
{
|
||||
key: "targetId",
|
||||
label: "Target ID",
|
||||
render: (value) => <span>{value != null ? String(value) : "-"}</span>,
|
||||
},
|
||||
{
|
||||
key: "diff",
|
||||
label: "Details",
|
||||
render: (_value, row) => <DiffCell diff={row.diff} />,
|
||||
},
|
||||
{
|
||||
key: "createdAt",
|
||||
label: "Date",
|
||||
sortable: true,
|
||||
render: (value) => <span>{String(value) || "N/A"}</span>,
|
||||
},
|
||||
];
|
||||
|
||||
interface AuditTableProps {
|
||||
data: PaginatedResult<AuditRow>;
|
||||
}
|
||||
|
||||
export function AuditTable({ data }: AuditTableProps) {
|
||||
const t = useTranslations("pages.admin.logs");
|
||||
|
||||
const columns: DataTableColumn<AuditRow>[] = [
|
||||
{ key: "id", label: t("colId"), sortable: true },
|
||||
{ key: "username", label: t("colUser"), sortable: true },
|
||||
{
|
||||
key: "action",
|
||||
label: t("colAction"),
|
||||
sortable: true,
|
||||
render: (value) => {
|
||||
const v = String(value);
|
||||
let variant: "default" | "secondary" | "destructive" = "secondary";
|
||||
if (v.includes("create") || v.includes("add")) variant = "default";
|
||||
if (v.includes("delete") || v.includes("remove") || v.includes("ban"))
|
||||
variant = "destructive";
|
||||
return <Badge variant={variant}>{v}</Badge>;
|
||||
},
|
||||
},
|
||||
{ key: "target", label: t("colTarget"), sortable: true },
|
||||
{
|
||||
key: "targetId",
|
||||
label: t("audit.colTargetId"),
|
||||
render: (value) => (
|
||||
<span>{value != null ? String(value) : t("emptyValue")}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "diff",
|
||||
label: t("audit.colDetails"),
|
||||
render: (_value, row) => <DiffCell diff={row.diff} />,
|
||||
},
|
||||
{
|
||||
key: "createdAt",
|
||||
label: t("audit.colDate"),
|
||||
sortable: true,
|
||||
render: (value) => (
|
||||
<span>{String(value) || t("audit.notAvailable")}</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
searchPlaceholder="Search by action or target..."
|
||||
searchPlaceholder={t("audit.searchPlaceholder")}
|
||||
exportUrl="/api/admin/export?type=audit"
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { DataTable } from "@/components/admin/data-table";
|
||||
import { formatTimestamp } from "@/lib/admin-helpers";
|
||||
import type { DataTableColumn, PaginatedResult } from "@/types";
|
||||
@@ -12,35 +13,37 @@ interface ChatLogRow {
|
||||
roomId: number;
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<ChatLogRow>[] = [
|
||||
{ key: "id", label: "ID", sortable: true },
|
||||
{ key: "username", label: "User" },
|
||||
{
|
||||
key: "message",
|
||||
label: "Message",
|
||||
render: (value) => (
|
||||
<span className="max-w-[300px] truncate block">{String(value)}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "timestamp",
|
||||
label: "Time",
|
||||
sortable: true,
|
||||
render: (value) => <span>{formatTimestamp(Number(value))}</span>,
|
||||
},
|
||||
{ key: "roomId", label: "Room ID", sortable: true },
|
||||
];
|
||||
|
||||
interface ChatTableProps {
|
||||
data: PaginatedResult<ChatLogRow>;
|
||||
}
|
||||
|
||||
export function ChatTable({ data }: ChatTableProps) {
|
||||
const t = useTranslations("pages.admin.logs");
|
||||
|
||||
const columns: DataTableColumn<ChatLogRow>[] = [
|
||||
{ key: "id", label: t("colId"), sortable: true },
|
||||
{ key: "username", label: t("colUser") },
|
||||
{
|
||||
key: "message",
|
||||
label: t("chat.colMessage"),
|
||||
render: (value) => (
|
||||
<span className="max-w-[300px] truncate block">{String(value)}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "timestamp",
|
||||
label: t("colTime"),
|
||||
sortable: true,
|
||||
render: (value) => <span>{formatTimestamp(Number(value))}</span>,
|
||||
},
|
||||
{ key: "roomId", label: t("chat.colRoomId"), sortable: true },
|
||||
];
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
searchPlaceholder="Search by username or message..."
|
||||
searchPlaceholder={t("chat.searchPlaceholder")}
|
||||
exportUrl="/api/admin/export?type=chatlogs"
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { DataTable } from "@/components/admin/data-table";
|
||||
import { formatTimestamp } from "@/lib/admin-helpers";
|
||||
import type { DataTableColumn, PaginatedResult } from "@/types";
|
||||
@@ -12,37 +13,39 @@ interface CommandLogRow {
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<CommandLogRow>[] = [
|
||||
{ key: "id", label: "ID", sortable: true },
|
||||
{ key: "username", label: "User" },
|
||||
{ key: "command", label: "Command", sortable: true },
|
||||
{
|
||||
key: "params",
|
||||
label: "Params",
|
||||
render: (value) => (
|
||||
<span className="max-w-[200px] truncate block font-mono text-sm">
|
||||
{String(value) || "-"}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "timestamp",
|
||||
label: "Time",
|
||||
sortable: true,
|
||||
render: (value) => <span>{formatTimestamp(Number(value))}</span>,
|
||||
},
|
||||
];
|
||||
|
||||
interface CommandsTableProps {
|
||||
data: PaginatedResult<CommandLogRow>;
|
||||
}
|
||||
|
||||
export function CommandsTable({ data }: CommandsTableProps) {
|
||||
const t = useTranslations("pages.admin.logs");
|
||||
|
||||
const columns: DataTableColumn<CommandLogRow>[] = [
|
||||
{ key: "id", label: t("colId"), sortable: true },
|
||||
{ key: "username", label: t("colUser") },
|
||||
{ key: "command", label: t("commands.colCommand"), sortable: true },
|
||||
{
|
||||
key: "params",
|
||||
label: t("commands.colParams"),
|
||||
render: (value) => (
|
||||
<span className="max-w-[200px] truncate block font-mono text-sm">
|
||||
{String(value) || t("emptyValue")}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "timestamp",
|
||||
label: t("colTime"),
|
||||
sortable: true,
|
||||
render: (value) => <span>{formatTimestamp(Number(value))}</span>,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
searchPlaceholder="Search by username, command, or params..."
|
||||
searchPlaceholder={t("commands.searchPlaceholder")}
|
||||
exportUrl="/api/admin/export?type=commands"
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -88,7 +88,7 @@ export default async function AdminStaffActivities({
|
||||
when: fromDate(a.createdAt),
|
||||
staff: t("staffWithId", {
|
||||
id: Number(a.userId),
|
||||
name: nameById.get(Number(a.userId)) ?? "unknown",
|
||||
name: nameById.get(Number(a.userId)) ?? t("unknownUser"),
|
||||
}),
|
||||
action: a.action,
|
||||
description: a.description,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { DataTable } from "@/components/admin/data-table";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { formatTimestamp } from "@/lib/admin-helpers";
|
||||
@@ -13,43 +14,47 @@ interface TradeLogRow {
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<TradeLogRow>[] = [
|
||||
{ key: "id", label: "ID", sortable: true },
|
||||
{ key: "userOneName", label: "User One" },
|
||||
{ key: "userTwoName", label: "User Two" },
|
||||
{
|
||||
key: "status",
|
||||
label: "Status",
|
||||
sortable: true,
|
||||
render: (value) => {
|
||||
const v = String(value);
|
||||
const variant =
|
||||
v === "completed"
|
||||
? "default"
|
||||
: v === "cancelled"
|
||||
? "destructive"
|
||||
: "secondary";
|
||||
return <Badge variant={variant}>{v || "unknown"}</Badge>;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "timestamp",
|
||||
label: "Time",
|
||||
sortable: true,
|
||||
render: (value) => <span>{formatTimestamp(Number(value))}</span>,
|
||||
},
|
||||
];
|
||||
|
||||
interface TradesTableProps {
|
||||
data: PaginatedResult<TradeLogRow>;
|
||||
}
|
||||
|
||||
export function TradesTable({ data }: TradesTableProps) {
|
||||
const t = useTranslations("pages.admin.logs");
|
||||
|
||||
const columns: DataTableColumn<TradeLogRow>[] = [
|
||||
{ key: "id", label: t("colId"), sortable: true },
|
||||
{ key: "userOneName", label: t("trades.colUserOne") },
|
||||
{ key: "userTwoName", label: t("trades.colUserTwo") },
|
||||
{
|
||||
key: "status",
|
||||
label: t("trades.colStatus"),
|
||||
sortable: true,
|
||||
render: (value) => {
|
||||
const v = String(value);
|
||||
const variant =
|
||||
v === "completed"
|
||||
? "default"
|
||||
: v === "cancelled"
|
||||
? "destructive"
|
||||
: "secondary";
|
||||
return (
|
||||
<Badge variant={variant}>{v || t("trades.statusUnknown")}</Badge>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "timestamp",
|
||||
label: t("colTime"),
|
||||
sortable: true,
|
||||
render: (value) => <span>{formatTimestamp(Number(value))}</span>,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
searchPlaceholder="Search by username..."
|
||||
searchPlaceholder={t("trades.searchPlaceholder")}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user