feat(admin): marketplace console + analytics degraded banners
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
f150aea8b9
commit
025af147cd
9 files changed
+355
-39
No files matched your search
@@ -0,0 +1,36 @@
|
|||||||
|
"use server";
|
||||||
|
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
import { requirePermissionRateLimited } from "@/lib/admin/guard";
|
||||||
|
import { PERMS } from "@/lib/permissions";
|
||||||
|
import { prisma } from "@/lib/prisma";
|
||||||
|
import { logStaffActivity } from "@/lib/services/staff-activity";
|
||||||
|
|
||||||
|
/** Cancel an active marketplace listing (state 1 → 0). */
|
||||||
|
export async function cancelMarketplaceListing(
|
||||||
|
formData: FormData,
|
||||||
|
): Promise<void> {
|
||||||
|
const staff = await requirePermissionRateLimited(PERMS.SHOP_EDIT);
|
||||||
|
const id = Number(formData.get("id"));
|
||||||
|
if (!(id > 0)) return;
|
||||||
|
|
||||||
|
const listing = await prisma.marketplaceItems.findUnique({
|
||||||
|
where: { id },
|
||||||
|
select: { id: true, state: true, userId: true, itemId: true, price: true },
|
||||||
|
});
|
||||||
|
if (listing?.state !== 1) return;
|
||||||
|
|
||||||
|
await prisma.marketplaceItems.update({
|
||||||
|
where: { id },
|
||||||
|
data: { state: 0 },
|
||||||
|
});
|
||||||
|
|
||||||
|
await logStaffActivity({
|
||||||
|
staffId: staff.id,
|
||||||
|
action: "marketplace_cancel",
|
||||||
|
description: `Cancelled marketplace listing #${id} (item ${listing.itemId}, user ${listing.userId}, price ${listing.price})`,
|
||||||
|
targetType: "marketplace",
|
||||||
|
targetId: id,
|
||||||
|
});
|
||||||
|
revalidatePath("/admin/marketplace");
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MessageSquare, Shield, Terminal, Users } from "lucide-react";
|
import { MessageSquare, Shield, Terminal, Users } from "lucide-react";
|
||||||
import { getLocale, getTranslations } from "next-intl/server";
|
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { getLocale, getTranslations } from "next-intl/server";
|
||||||
import { StatsCard } from "@/components/admin/stats-card";
|
import { StatsCard } from "@/components/admin/stats-card";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
@@ -23,28 +23,35 @@ type ActivityData = {
|
|||||||
topChatters: { userId: number; username: string; messages: number }[];
|
topChatters: { userId: number; username: string; messages: number }[];
|
||||||
};
|
};
|
||||||
|
|
||||||
async function safeCount(fn: () => Promise<number>): Promise<number> {
|
async function safeCount(
|
||||||
|
fn: () => Promise<number>,
|
||||||
|
): Promise<{ value: number; ok: boolean }> {
|
||||||
try {
|
try {
|
||||||
return await fn();
|
return { value: await fn(), ok: true };
|
||||||
} catch {
|
} catch {
|
||||||
return 0;
|
return { value: 0, ok: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function safeRawCount(sql: Promise<{ count: bigint }[]>): Promise<number> {
|
async function safeRawCount(
|
||||||
|
sql: Promise<{ count: bigint }[]>,
|
||||||
|
): Promise<{ value: number; ok: boolean }> {
|
||||||
try {
|
try {
|
||||||
const rows = await sql;
|
const rows = await sql;
|
||||||
return Number(rows[0]?.count ?? 0);
|
return { value: Number(rows[0]?.count ?? 0), ok: true };
|
||||||
} catch {
|
} catch {
|
||||||
return 0;
|
return { value: 0, ok: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getActivityData(locale: string): Promise<ActivityData> {
|
async function getActivityData(
|
||||||
|
locale: string,
|
||||||
|
): Promise<ActivityData & { degraded: boolean }> {
|
||||||
const now = Math.floor(Date.now() / 1000);
|
const now = Math.floor(Date.now() / 1000);
|
||||||
const todayStart = now - (now % 86400);
|
const todayStart = now - (now % 86400);
|
||||||
const weekAgo = now - 7 * 86400;
|
const weekAgo = now - 7 * 86400;
|
||||||
const rangeStart = todayStart - 6 * 86400;
|
const rangeStart = todayStart - 6 * 86400;
|
||||||
|
let degraded = false;
|
||||||
|
|
||||||
const emptyDays: DayRow[] = [];
|
const emptyDays: DayRow[] = [];
|
||||||
for (let i = 6; i >= 0; i--) {
|
for (let i = 6; i >= 0; i--) {
|
||||||
@@ -99,7 +106,7 @@ async function getActivityData(locale: string): Promise<ActivityData> {
|
|||||||
banMap = toMap(banRows);
|
banMap = toMap(banRows);
|
||||||
regMap = toMap(regRows);
|
regMap = toMap(regRows);
|
||||||
} catch {
|
} catch {
|
||||||
/* keep empty maps */
|
degraded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dailyData = emptyDays.map((day, idx) => {
|
const dailyData = emptyDays.map((day, idx) => {
|
||||||
@@ -132,11 +139,13 @@ async function getActivityData(locale: string): Promise<ActivityData> {
|
|||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
for (const r of [weekChats, weekCommands, weekBans, weekRegistrations]) {
|
||||||
|
if (!r.ok) degraded = true;
|
||||||
|
}
|
||||||
|
|
||||||
let topChatters: ActivityData["topChatters"] = [];
|
let topChatters: ActivityData["topChatters"] = [];
|
||||||
try {
|
try {
|
||||||
const rows = await prisma.$queryRaw<
|
const rows = await prisma.$queryRaw<{ userId: number; messages: bigint }[]>`
|
||||||
{ userId: number; messages: bigint }[]
|
|
||||||
>`
|
|
||||||
SELECT user_from_id AS userId, COUNT(*) AS messages
|
SELECT user_from_id AS userId, COUNT(*) AS messages
|
||||||
FROM chatlogs_room WHERE timestamp >= ${weekAgo}
|
FROM chatlogs_room WHERE timestamp >= ${weekAgo}
|
||||||
GROUP BY user_from_id ORDER BY messages DESC LIMIT 10
|
GROUP BY user_from_id ORDER BY messages DESC LIMIT 10
|
||||||
@@ -160,15 +169,17 @@ async function getActivityData(locale: string): Promise<ActivityData> {
|
|||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
topChatters = [];
|
topChatters = [];
|
||||||
|
degraded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dailyData,
|
dailyData,
|
||||||
weekChats,
|
weekChats: weekChats.value,
|
||||||
weekCommands,
|
weekCommands: weekCommands.value,
|
||||||
weekBans,
|
weekBans: weekBans.value,
|
||||||
weekRegistrations,
|
weekRegistrations: weekRegistrations.value,
|
||||||
topChatters,
|
topChatters,
|
||||||
|
degraded,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,10 +191,16 @@ export default async function ActivityPage() {
|
|||||||
|
|
||||||
const locale = await getLocale();
|
const locale = await getLocale();
|
||||||
const t = await getTranslations("pages.admin.analytics.activity");
|
const t = await getTranslations("pages.admin.analytics.activity");
|
||||||
|
const tRoot = await getTranslations("pages.admin.analytics");
|
||||||
const data = await getActivityData(locale);
|
const data = await getActivityData(locale);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
{data.degraded ? (
|
||||||
|
<div className="rounded-lg bg-[var(--admin-error-subtle)] p-3 text-xs text-[var(--admin-error)]">
|
||||||
|
{tRoot("loadError")}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||||
<StatsCard
|
<StatsCard
|
||||||
title={t("chatMessages")}
|
title={t("chatMessages")}
|
||||||
@@ -221,7 +238,9 @@ export default async function ActivityPage() {
|
|||||||
<table className="w-full text-sm">
|
<table className="w-full text-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="border-b text-muted-foreground">
|
<tr className="border-b text-muted-foreground">
|
||||||
<th className="text-left py-2 font-medium">{t("colDay")}</th>
|
<th className="text-left py-2 font-medium">
|
||||||
|
{t("colDay")}
|
||||||
|
</th>
|
||||||
<th className="text-right py-2 font-medium">
|
<th className="text-right py-2 font-medium">
|
||||||
{t("colChats")}
|
{t("colChats")}
|
||||||
</th>
|
</th>
|
||||||
@@ -276,8 +295,7 @@ export default async function ActivityPage() {
|
|||||||
{i + 1}
|
{i + 1}
|
||||||
</span>
|
</span>
|
||||||
<span className="flex-1 text-sm font-medium">
|
<span className="flex-1 text-sm font-medium">
|
||||||
{user.username ||
|
{user.username || t("userFallback", { id: user.userId })}
|
||||||
t("userFallback", { id: user.userId })}
|
|
||||||
</span>
|
</span>
|
||||||
<span className="text-sm tabular-nums text-muted-foreground">
|
<span className="text-sm tabular-nums text-muted-foreground">
|
||||||
{t("msgCount", {
|
{t("msgCount", {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ArrowLeftRight } from "lucide-react";
|
import { ArrowLeftRight } from "lucide-react";
|
||||||
import { getLocale, getTranslations } from "next-intl/server";
|
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { getLocale, getTranslations } from "next-intl/server";
|
||||||
import { RevenueChart } from "@/components/admin/revenue-chart";
|
import { RevenueChart } from "@/components/admin/revenue-chart";
|
||||||
import { StatsCard } from "@/components/admin/stats-card";
|
import { StatsCard } from "@/components/admin/stats-card";
|
||||||
import { CurrencyIcon } from "@/components/shared/currency-icon";
|
import { CurrencyIcon } from "@/components/shared/currency-icon";
|
||||||
@@ -42,17 +42,29 @@ async function safeCount(fn: () => Promise<number>): Promise<number> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getEconomyData(locale: string): Promise<EconomyData> {
|
async function getEconomyData(
|
||||||
|
locale: string,
|
||||||
|
): Promise<{ data: EconomyData; degraded: boolean }> {
|
||||||
const now = Math.floor(Date.now() / 1000);
|
const now = Math.floor(Date.now() / 1000);
|
||||||
const todayStart = now - (now % 86400);
|
const todayStart = now - (now % 86400);
|
||||||
const weekAgo = now - 7 * 86400;
|
const weekAgo = now - 7 * 86400;
|
||||||
const rangeStart = todayStart - 6 * 86400;
|
const rangeStart = todayStart - 6 * 86400;
|
||||||
|
let degraded = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [creditsAgg, pixelsAgg, pointsAgg] = await Promise.all([
|
const [creditsAgg, pixelsAgg, pointsAgg] = await Promise.all([
|
||||||
prisma.user.aggregate({ _sum: { credits: true } }).catch(() => null),
|
prisma.user.aggregate({ _sum: { credits: true } }).catch(() => {
|
||||||
prisma.user.aggregate({ _sum: { pixels: true } }).catch(() => null),
|
degraded = true;
|
||||||
prisma.user.aggregate({ _sum: { points: true } }).catch(() => null),
|
return null;
|
||||||
|
}),
|
||||||
|
prisma.user.aggregate({ _sum: { pixels: true } }).catch(() => {
|
||||||
|
degraded = true;
|
||||||
|
return null;
|
||||||
|
}),
|
||||||
|
prisma.user.aggregate({ _sum: { points: true } }).catch(() => {
|
||||||
|
degraded = true;
|
||||||
|
return null;
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
const totalCredits = creditsAgg?._sum.credits ?? 0;
|
const totalCredits = creditsAgg?._sum.credits ?? 0;
|
||||||
const totalPixels = pixelsAgg?._sum.pixels ?? 0;
|
const totalPixels = pixelsAgg?._sum.pixels ?? 0;
|
||||||
@@ -72,14 +84,11 @@ async function getEconomyData(locale: string): Promise<EconomyData> {
|
|||||||
shopCreditsSpent = shopRevenue._sum?.costCredits ?? 0;
|
shopCreditsSpent = shopRevenue._sum?.costCredits ?? 0;
|
||||||
shopPointsSpent = shopRevenue._sum?.costPoints ?? 0;
|
shopPointsSpent = shopRevenue._sum?.costPoints ?? 0;
|
||||||
} catch {
|
} catch {
|
||||||
/* shop logs table/columns may be missing */
|
degraded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [marketplaceActive, marketplaceSold, weekTrades] = await Promise.all(
|
const [marketplaceActive, marketplaceSold, weekTrades] = await Promise.all([
|
||||||
[
|
safeCount(() => prisma.marketplaceItems.count({ where: { state: 1 } })),
|
||||||
safeCount(() =>
|
|
||||||
prisma.marketplaceItems.count({ where: { state: 1 } }),
|
|
||||||
),
|
|
||||||
safeCount(() =>
|
safeCount(() =>
|
||||||
prisma.marketplaceItems.count({
|
prisma.marketplaceItems.count({
|
||||||
where: { state: 2, soldTimestamp: { gte: weekAgo } },
|
where: { state: 2, soldTimestamp: { gte: weekAgo } },
|
||||||
@@ -88,8 +97,7 @@ async function getEconomyData(locale: string): Promise<EconomyData> {
|
|||||||
safeCount(() =>
|
safeCount(() =>
|
||||||
prisma.roomTradeLog.count({ where: { timestamp: { gte: weekAgo } } }),
|
prisma.roomTradeLog.count({ where: { timestamp: { gte: weekAgo } } }),
|
||||||
),
|
),
|
||||||
],
|
]);
|
||||||
);
|
|
||||||
|
|
||||||
const revenueData: EconomyData["revenueData"] = [];
|
const revenueData: EconomyData["revenueData"] = [];
|
||||||
for (let i = 6; i >= 0; i--) {
|
for (let i = 6; i >= 0; i--) {
|
||||||
@@ -104,7 +112,11 @@ async function getEconomyData(locale: string): Promise<EconomyData> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const revRows = await prisma.$queryRaw<
|
const revRows = await prisma.$queryRaw<
|
||||||
{ day_bucket: bigint; credits: number | bigint; points: number | bigint }[]
|
{
|
||||||
|
day_bucket: bigint;
|
||||||
|
credits: number | bigint;
|
||||||
|
points: number | bigint;
|
||||||
|
}[]
|
||||||
>`
|
>`
|
||||||
SELECT FLOOR(timestamp / 86400) AS day_bucket,
|
SELECT FLOOR(timestamp / 86400) AS day_bucket,
|
||||||
COALESCE(SUM(cost_credits), 0) AS credits,
|
COALESCE(SUM(cost_credits), 0) AS credits,
|
||||||
@@ -128,10 +140,12 @@ async function getEconomyData(locale: string): Promise<EconomyData> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
/* keep zero revenue series */
|
degraded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
degraded,
|
||||||
|
data: {
|
||||||
totalCredits,
|
totalCredits,
|
||||||
totalPixels,
|
totalPixels,
|
||||||
totalPoints,
|
totalPoints,
|
||||||
@@ -142,9 +156,10 @@ async function getEconomyData(locale: string): Promise<EconomyData> {
|
|||||||
marketplaceSold,
|
marketplaceSold,
|
||||||
weekTrades,
|
weekTrades,
|
||||||
revenueData,
|
revenueData,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
return EMPTY;
|
return { data: EMPTY, degraded: true };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,10 +171,16 @@ export default async function EconomyPage() {
|
|||||||
|
|
||||||
const locale = await getLocale();
|
const locale = await getLocale();
|
||||||
const t = await getTranslations("pages.admin.analytics.economy");
|
const t = await getTranslations("pages.admin.analytics.economy");
|
||||||
const data = await getEconomyData(locale);
|
const tRoot = await getTranslations("pages.admin.analytics");
|
||||||
|
const { data, degraded } = await getEconomyData(locale);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
{degraded ? (
|
||||||
|
<div className="rounded-lg bg-[var(--admin-error-subtle)] p-3 text-xs text-[var(--admin-error)]">
|
||||||
|
{tRoot("loadError")}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||||
<StatsCard
|
<StatsCard
|
||||||
title={t("creditsInCirculation")}
|
title={t("creditsInCirculation")}
|
||||||
@@ -203,13 +224,17 @@ export default async function EconomyPage() {
|
|||||||
<span className="font-medium">{data.shopPurchases}</span>
|
<span className="font-medium">{data.shopPurchases}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<span className="text-muted-foreground">{t("creditsSpent")}</span>
|
<span className="text-muted-foreground">
|
||||||
|
{t("creditsSpent")}
|
||||||
|
</span>
|
||||||
<span className="font-medium">
|
<span className="font-medium">
|
||||||
{data.shopCreditsSpent.toLocaleString(locale)}
|
{data.shopCreditsSpent.toLocaleString(locale)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<span className="text-muted-foreground">{t("pointsSpent")}</span>
|
<span className="text-muted-foreground">
|
||||||
|
{t("pointsSpent")}
|
||||||
|
</span>
|
||||||
<span className="font-medium">
|
<span className="font-medium">
|
||||||
{data.shopPointsSpent.toLocaleString(locale)}
|
{data.shopPointsSpent.toLocaleString(locale)}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getTranslations } from "next-intl/server";
|
||||||
|
import { cancelMarketplaceListing } from "@/actions/admin-marketplace";
|
||||||
|
import { AdminSimplePager } from "@/components/admin/admin-simple-pager";
|
||||||
|
import { StatusCard } from "@/components/admin/dashboard";
|
||||||
|
import { calcPagination, parseListParams } from "@/lib/admin-helpers";
|
||||||
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
|
import { prisma } from "@/lib/prisma";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
function fmt(ts: number): string {
|
||||||
|
if (!ts) return "—";
|
||||||
|
return new Date(ts * 1000).toISOString().slice(0, 16).replace("T", " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function AdminMarketplacePage({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: Promise<Record<string, string>>;
|
||||||
|
}) {
|
||||||
|
const { session, permissions } = await getAdminContext();
|
||||||
|
if (!canAccess(permissions, PERMS.SHOP_VIEW, session.user.rank)) {
|
||||||
|
redirect("/admin");
|
||||||
|
}
|
||||||
|
|
||||||
|
const t = await getTranslations("pages.admin.marketplace");
|
||||||
|
const canEdit = canAccess(permissions, PERMS.SHOP_EDIT, session.user.rank);
|
||||||
|
const raw = await searchParams;
|
||||||
|
const parsed = parseListParams(new URLSearchParams(raw));
|
||||||
|
const filter = raw.filter === "sold" ? "sold" : "active";
|
||||||
|
|
||||||
|
const where = filter === "sold" ? { state: 2 } : { state: 1 };
|
||||||
|
|
||||||
|
let total = 0;
|
||||||
|
let rows: Awaited<ReturnType<typeof prisma.marketplaceItems.findMany>> = [];
|
||||||
|
let activeCount = 0;
|
||||||
|
let soldCount = 0;
|
||||||
|
let loadError = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
[total, activeCount, soldCount] = await Promise.all([
|
||||||
|
prisma.marketplaceItems.count({ where }),
|
||||||
|
prisma.marketplaceItems.count({ where: { state: 1 } }),
|
||||||
|
prisma.marketplaceItems.count({ where: { state: 2 } }),
|
||||||
|
]);
|
||||||
|
const pagination = calcPagination(total, parsed.page, parsed.perPage);
|
||||||
|
rows = await prisma.marketplaceItems.findMany({
|
||||||
|
where,
|
||||||
|
orderBy: { timestamp: "desc" },
|
||||||
|
skip: pagination.offset,
|
||||||
|
take: pagination.perPage,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
loadError = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pagination = calcPagination(total, parsed.page, parsed.perPage);
|
||||||
|
const userIds = [
|
||||||
|
...new Set(rows.map((r) => r.userId).filter((id) => id > 0)),
|
||||||
|
];
|
||||||
|
const users =
|
||||||
|
userIds.length > 0
|
||||||
|
? await prisma.user
|
||||||
|
.findMany({
|
||||||
|
where: { id: { in: userIds } },
|
||||||
|
select: { id: true, username: true },
|
||||||
|
})
|
||||||
|
.catch(() => [])
|
||||||
|
: [];
|
||||||
|
const usernameById = new Map(users.map((u) => [u.id, u.username]));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main>
|
||||||
|
{loadError ? (
|
||||||
|
<div className="mb-4 rounded-lg bg-[var(--admin-error-subtle)] p-3 text-xs text-[var(--admin-error)]">
|
||||||
|
{t("loadError")}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<div className="mb-4 flex flex-wrap gap-2">
|
||||||
|
<Link
|
||||||
|
href="/admin/marketplace?filter=active"
|
||||||
|
className={`btn btn-sm ${filter === "active" ? "btn-primary" : "btn-ghost"}`}
|
||||||
|
>
|
||||||
|
{t("filterActive")}
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/admin/marketplace?filter=sold"
|
||||||
|
className={`btn btn-sm ${filter === "sold" ? "btn-primary" : "btn-ghost"}`}
|
||||||
|
>
|
||||||
|
{t("filterSold")}
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
|
||||||
|
<StatusCard label={t("activeListings")} value={activeCount} icon="🏪" />
|
||||||
|
<StatusCard label={t("soldListings")} value={soldCount} icon="✅" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h2 className="admin-section-title">
|
||||||
|
{filter === "sold" ? t("soldListings") : t("activeListings")} ({total}
|
||||||
|
)
|
||||||
|
</h2>
|
||||||
|
{rows.length === 0 ? (
|
||||||
|
<div className="admin-empty">{t("empty")}</div>
|
||||||
|
) : (
|
||||||
|
<div className="admin-card overflow-x-auto" style={{ padding: 0 }}>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{t("colId")}</th>
|
||||||
|
<th>{t("colItem")}</th>
|
||||||
|
<th>{t("colSeller")}</th>
|
||||||
|
<th>{t("colPrice")}</th>
|
||||||
|
<th>{t("colListed")}</th>
|
||||||
|
{filter === "sold" ? <th>{t("colSold")}</th> : null}
|
||||||
|
{canEdit && filter === "active" ? (
|
||||||
|
<th>{t("colActions")}</th>
|
||||||
|
) : null}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{rows.map((row) => (
|
||||||
|
<tr key={row.id}>
|
||||||
|
<td className="muted">{row.id}</td>
|
||||||
|
<td>
|
||||||
|
<code>{row.itemId}</code>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<Link href={`/admin/users/show/${row.userId}`}>
|
||||||
|
{usernameById.get(row.userId) ?? `#${row.userId}`}
|
||||||
|
</Link>
|
||||||
|
</td>
|
||||||
|
<td>{row.price}</td>
|
||||||
|
<td className="muted">{fmt(row.timestamp)}</td>
|
||||||
|
{filter === "sold" ? (
|
||||||
|
<td className="muted">{fmt(row.soldTimestamp)}</td>
|
||||||
|
) : null}
|
||||||
|
{canEdit && filter === "active" ? (
|
||||||
|
<td>
|
||||||
|
<form action={cancelMarketplaceListing}>
|
||||||
|
<input type="hidden" name="id" value={row.id} />
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-ghost btn-sm"
|
||||||
|
>
|
||||||
|
{t("cancel")}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
) : null}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<AdminSimplePager
|
||||||
|
page={pagination.page}
|
||||||
|
lastPage={pagination.lastPage}
|
||||||
|
total={total}
|
||||||
|
basePath="/admin/marketplace"
|
||||||
|
params={filter === "sold" ? { filter: "sold" } : undefined}
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -6,18 +6,21 @@ export function AdminSimplePager({
|
|||||||
lastPage,
|
lastPage,
|
||||||
total,
|
total,
|
||||||
basePath,
|
basePath,
|
||||||
|
params,
|
||||||
label,
|
label,
|
||||||
}: {
|
}: {
|
||||||
page: number;
|
page: number;
|
||||||
lastPage: number;
|
lastPage: number;
|
||||||
total: number;
|
total: number;
|
||||||
basePath: string;
|
basePath: string;
|
||||||
|
/** Extra query params preserved across pages (e.g. filter=sold). */
|
||||||
|
params?: Record<string, string>;
|
||||||
label?: string;
|
label?: string;
|
||||||
}) {
|
}) {
|
||||||
if (lastPage <= 1) return null;
|
if (lastPage <= 1) return null;
|
||||||
|
|
||||||
const href = (p: number) => {
|
const href = (p: number) => {
|
||||||
const u = new URLSearchParams();
|
const u = new URLSearchParams(params);
|
||||||
u.set("page", String(p));
|
u.set("page", String(p));
|
||||||
return `${basePath}?${u.toString()}`;
|
return `${basePath}?${u.toString()}`;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -457,6 +457,12 @@ export const ADMIN_NAV_GROUPS: AdminNavGroup[] = [
|
|||||||
icon: ShoppingCart,
|
icon: ShoppingCart,
|
||||||
permission: PERMS.SHOP_VIEW,
|
permission: PERMS.SHOP_VIEW,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
href: "/admin/marketplace",
|
||||||
|
labelKey: "marketplace",
|
||||||
|
icon: Store,
|
||||||
|
permission: PERMS.SHOP_VIEW,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
href: "/admin/transactions",
|
href: "/admin/transactions",
|
||||||
labelKey: "transactions",
|
labelKey: "transactions",
|
||||||
|
|||||||
@@ -1041,6 +1041,7 @@
|
|||||||
"hubShop": "Shop & payments",
|
"hubShop": "Shop & payments",
|
||||||
"catalog": "Catalog",
|
"catalog": "Catalog",
|
||||||
"shop": "Shop",
|
"shop": "Shop",
|
||||||
|
"marketplace": "Marketplace",
|
||||||
"transactions": "Transactions",
|
"transactions": "Transactions",
|
||||||
"vouchers": "Vouchers",
|
"vouchers": "Vouchers",
|
||||||
"subscriptions": "Subscriptions",
|
"subscriptions": "Subscriptions",
|
||||||
@@ -1796,6 +1797,24 @@
|
|||||||
"cancel": "Cancel"
|
"cancel": "Cancel"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"marketplace": {
|
||||||
|
"title": "Marketplace",
|
||||||
|
"subtitle": "Hotel marketplace listings",
|
||||||
|
"activeListings": "Active listings",
|
||||||
|
"soldListings": "Sold",
|
||||||
|
"filterActive": "Active",
|
||||||
|
"filterSold": "Sold",
|
||||||
|
"empty": "No marketplace listings to show.",
|
||||||
|
"loadError": "Could not load marketplace data (database unavailable).",
|
||||||
|
"cancel": "Cancel listing",
|
||||||
|
"colId": "ID",
|
||||||
|
"colItem": "Item ID",
|
||||||
|
"colSeller": "Seller",
|
||||||
|
"colPrice": "Price",
|
||||||
|
"colListed": "Listed",
|
||||||
|
"colSold": "Sold at",
|
||||||
|
"colActions": "Actions"
|
||||||
|
},
|
||||||
"transactions": {
|
"transactions": {
|
||||||
"title": "Transactions",
|
"title": "Transactions",
|
||||||
"subtitle": "PayPal payment log",
|
"subtitle": "PayPal payment log",
|
||||||
|
|||||||
@@ -971,6 +971,7 @@
|
|||||||
"economy": "Economia",
|
"economy": "Economia",
|
||||||
"catalog": "Catalogo",
|
"catalog": "Catalogo",
|
||||||
"shop": "Negozio",
|
"shop": "Negozio",
|
||||||
|
"marketplace": "Marketplace",
|
||||||
"transactions": "Transazioni",
|
"transactions": "Transazioni",
|
||||||
"vouchers": "Buoni",
|
"vouchers": "Buoni",
|
||||||
"subscriptions": "Abbonamenti",
|
"subscriptions": "Abbonamenti",
|
||||||
@@ -1734,6 +1735,24 @@
|
|||||||
"cancel": "Annulla"
|
"cancel": "Annulla"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"marketplace": {
|
||||||
|
"title": "Marketplace",
|
||||||
|
"subtitle": "Annunci marketplace hotel",
|
||||||
|
"activeListings": "Annunci attivi",
|
||||||
|
"soldListings": "Venduti",
|
||||||
|
"filterActive": "Attivi",
|
||||||
|
"filterSold": "Venduti",
|
||||||
|
"empty": "Nessun annuncio marketplace da mostrare.",
|
||||||
|
"loadError": "Impossibile caricare i dati marketplace (database non disponibile).",
|
||||||
|
"cancel": "Annulla annuncio",
|
||||||
|
"colId": "ID",
|
||||||
|
"colItem": "Item ID",
|
||||||
|
"colSeller": "Venditore",
|
||||||
|
"colPrice": "Prezzo",
|
||||||
|
"colListed": "Pubblicato",
|
||||||
|
"colSold": "Venduto il",
|
||||||
|
"colActions": "Azioni"
|
||||||
|
},
|
||||||
"transactions": {
|
"transactions": {
|
||||||
"title": "Transazioni",
|
"title": "Transazioni",
|
||||||
"subtitle": "Registro pagamenti PayPal",
|
"subtitle": "Registro pagamenti PayPal",
|
||||||
|
|||||||
@@ -1016,6 +1016,7 @@
|
|||||||
"economy": "Economie",
|
"economy": "Economie",
|
||||||
"catalog": "Catalogus",
|
"catalog": "Catalogus",
|
||||||
"shop": "Winkel",
|
"shop": "Winkel",
|
||||||
|
"marketplace": "Marketplace",
|
||||||
"transactions": "Transacties",
|
"transactions": "Transacties",
|
||||||
"vouchers": "Vouchers",
|
"vouchers": "Vouchers",
|
||||||
"subscriptions": "Abonnementen",
|
"subscriptions": "Abonnementen",
|
||||||
@@ -1710,6 +1711,24 @@
|
|||||||
"cancel": "Annuleren"
|
"cancel": "Annuleren"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"marketplace": {
|
||||||
|
"title": "Marketplace",
|
||||||
|
"subtitle": "Hotel marketplace-aanbiedingen",
|
||||||
|
"activeListings": "Actieve listings",
|
||||||
|
"soldListings": "Verkocht",
|
||||||
|
"filterActive": "Actief",
|
||||||
|
"filterSold": "Verkocht",
|
||||||
|
"empty": "Geen marketplace-listings om te tonen.",
|
||||||
|
"loadError": "Kon marketplace-gegevens niet laden (database niet beschikbaar).",
|
||||||
|
"cancel": "Listing annuleren",
|
||||||
|
"colId": "ID",
|
||||||
|
"colItem": "Item-ID",
|
||||||
|
"colSeller": "Verkoper",
|
||||||
|
"colPrice": "Prijs",
|
||||||
|
"colListed": "Geplaatst",
|
||||||
|
"colSold": "Verkocht op",
|
||||||
|
"colActions": "Acties"
|
||||||
|
},
|
||||||
"transactions": {
|
"transactions": {
|
||||||
"title": "Transacties",
|
"title": "Transacties",
|
||||||
"subtitle": "PayPal betalingslogboek",
|
"subtitle": "PayPal betalingslogboek",
|
||||||
|
|||||||
Reference in new issue
Block a user