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,4 +1,5 @@
|
||||
import { MessageSquare, Shield, Terminal, Users } from "lucide-react";
|
||||
import { getLocale, getTranslations } from "next-intl/server";
|
||||
import { redirect } from "next/navigation";
|
||||
import { StatsCard } from "@/components/admin/stats-card";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
@@ -39,7 +40,7 @@ async function safeRawCount(sql: Promise<{ count: bigint }[]>): Promise<number>
|
||||
}
|
||||
}
|
||||
|
||||
async function getActivityData(): Promise<ActivityData> {
|
||||
async function getActivityData(locale: string): Promise<ActivityData> {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const todayStart = now - (now % 86400);
|
||||
const weekAgo = now - 7 * 86400;
|
||||
@@ -50,7 +51,7 @@ async function getActivityData(): Promise<ActivityData> {
|
||||
const dayStart = todayStart - i * 86400;
|
||||
const date = new Date(dayStart * 1000);
|
||||
emptyDays.push({
|
||||
label: date.toLocaleDateString("en", {
|
||||
label: date.toLocaleDateString(locale, {
|
||||
weekday: "short",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
@@ -153,7 +154,7 @@ async function getActivityData(): Promise<ActivityData> {
|
||||
const userId = Number(c.userId);
|
||||
return {
|
||||
userId,
|
||||
username: userMap.get(userId) ?? `User #${userId}`,
|
||||
username: userMap.get(userId) ?? "",
|
||||
messages: Number(c.messages),
|
||||
};
|
||||
});
|
||||
@@ -177,33 +178,35 @@ export default async function ActivityPage() {
|
||||
redirect("/admin");
|
||||
}
|
||||
|
||||
const data = await getActivityData();
|
||||
const locale = await getLocale();
|
||||
const t = await getTranslations("pages.admin.analytics.activity");
|
||||
const data = await getActivityData(locale);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
<StatsCard
|
||||
title="Chat Messages"
|
||||
value={data.weekChats.toLocaleString()}
|
||||
description="Last 7 days"
|
||||
title={t("chatMessages")}
|
||||
value={data.weekChats.toLocaleString(locale)}
|
||||
description={t("last7Days")}
|
||||
icon={<MessageSquare className="h-4 w-4" />}
|
||||
/>
|
||||
<StatsCard
|
||||
title="Commands"
|
||||
value={data.weekCommands.toLocaleString()}
|
||||
description="Last 7 days"
|
||||
title={t("commands")}
|
||||
value={data.weekCommands.toLocaleString(locale)}
|
||||
description={t("last7Days")}
|
||||
icon={<Terminal className="h-4 w-4" />}
|
||||
/>
|
||||
<StatsCard
|
||||
title="Bans"
|
||||
value={data.weekBans.toLocaleString()}
|
||||
description="Last 7 days"
|
||||
title={t("bans")}
|
||||
value={data.weekBans.toLocaleString(locale)}
|
||||
description={t("last7Days")}
|
||||
icon={<Shield className="h-4 w-4" />}
|
||||
/>
|
||||
<StatsCard
|
||||
title="Registrations"
|
||||
value={data.weekRegistrations.toLocaleString()}
|
||||
description="Last 7 days"
|
||||
title={t("registrations")}
|
||||
value={data.weekRegistrations.toLocaleString(locale)}
|
||||
description={t("last7Days")}
|
||||
icon={<Users className="h-4 w-4" />}
|
||||
/>
|
||||
</div>
|
||||
@@ -211,18 +214,26 @@ export default async function ActivityPage() {
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Daily Breakdown (7 days)</CardTitle>
|
||||
<CardTitle>{t("dailyBreakdownTitle")}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b text-muted-foreground">
|
||||
<th className="text-left py-2 font-medium">Day</th>
|
||||
<th className="text-right py-2 font-medium">Chats</th>
|
||||
<th className="text-right py-2 font-medium">Cmds</th>
|
||||
<th className="text-right py-2 font-medium">Bans</th>
|
||||
<th className="text-right py-2 font-medium">Regs</th>
|
||||
<th className="text-left py-2 font-medium">{t("colDay")}</th>
|
||||
<th className="text-right py-2 font-medium">
|
||||
{t("colChats")}
|
||||
</th>
|
||||
<th className="text-right py-2 font-medium">
|
||||
{t("colCmds")}
|
||||
</th>
|
||||
<th className="text-right py-2 font-medium">
|
||||
{t("colBans")}
|
||||
</th>
|
||||
<th className="text-right py-2 font-medium">
|
||||
{t("colRegs")}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -230,10 +241,10 @@ export default async function ActivityPage() {
|
||||
<tr key={day.label} className="border-b last:border-0">
|
||||
<td className="py-2">{day.label}</td>
|
||||
<td className="text-right tabular-nums">
|
||||
{day.chats.toLocaleString()}
|
||||
{day.chats.toLocaleString(locale)}
|
||||
</td>
|
||||
<td className="text-right tabular-nums">
|
||||
{day.commands.toLocaleString()}
|
||||
{day.commands.toLocaleString(locale)}
|
||||
</td>
|
||||
<td className="text-right tabular-nums">{day.bans}</td>
|
||||
<td className="text-right tabular-nums">
|
||||
@@ -249,11 +260,11 @@ export default async function ActivityPage() {
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Most Active Users (7 days)</CardTitle>
|
||||
<CardTitle>{t("mostActiveUsersTitle")}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{data.topChatters.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No chat activity</p>
|
||||
<div className="admin-empty">{t("noChatActivity")}</div>
|
||||
) : (
|
||||
<div className="divide-y">
|
||||
{data.topChatters.map((user, i) => (
|
||||
@@ -265,10 +276,13 @@ export default async function ActivityPage() {
|
||||
{i + 1}
|
||||
</span>
|
||||
<span className="flex-1 text-sm font-medium">
|
||||
{user.username}
|
||||
{user.username ||
|
||||
t("userFallback", { id: user.userId })}
|
||||
</span>
|
||||
<span className="text-sm tabular-nums text-muted-foreground">
|
||||
{user.messages.toLocaleString()} msgs
|
||||
{t("msgCount", {
|
||||
count: user.messages.toLocaleString(locale),
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
|
||||
Reference in new issue
Block a user