Remove deprecated ModulePlaceholderPage component for dashboard modules. This file was previously used as a catch-all for remaining modules but is no longer needed due to the introduction of dedicated route folders for Batch A modules.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { CommandOverrideDashboardUpsertSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { resetCommandOverrideDashboard, upsertCommandOverrideDashboard } from '@/lib/module-configs/commands';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ guildId: string; commandName: string }>;
|
||||
}
|
||||
|
||||
export async function PATCH(request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, commandName } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const body = await request.json();
|
||||
const input = CommandOverrideDashboardUpsertSchema.parse({ ...body, commandName });
|
||||
|
||||
const updated = await upsertCommandOverrideDashboard(guildId, input);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'commands.update',
|
||||
path: `/dashboard/${guildId}/commands`,
|
||||
after: updated
|
||||
});
|
||||
|
||||
return NextResponse.json(updated);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(_request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, commandName } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const reset = await resetCommandOverrideDashboard(guildId, commandName);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'commands.reset',
|
||||
path: `/dashboard/${guildId}/commands`,
|
||||
after: reset
|
||||
});
|
||||
|
||||
return NextResponse.json(reset);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
18
apps/webui/src/app/api/guilds/[guildId]/commands/route.ts
Normal file
18
apps/webui/src/app/api/guilds/[guildId]/commands/route.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { listCommandOverridesDashboard } from '@/lib/module-configs/commands';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ guildId: string }>;
|
||||
}
|
||||
|
||||
export async function GET(_request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId } = await params;
|
||||
try {
|
||||
await requireGuildAccess(guildId);
|
||||
const commands = await listCommandOverridesDashboard(guildId);
|
||||
return NextResponse.json({ commands });
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
import { DASHBOARD_MODULES, type DashboardModuleId } from '@nexumi/shared';
|
||||
import { Construction } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { getLocale, t } from '@/lib/i18n';
|
||||
|
||||
/**
|
||||
* Batch A modules (Phase 7) got dedicated route folders (e.g.
|
||||
* `dashboard/[guildId]/moderation/page.tsx`), which Next.js prefers over this
|
||||
* catch-all - so they never reach this component. This placeholder now only
|
||||
* serves the remaining Batch B/C modules until they get dedicated pages too.
|
||||
*/
|
||||
const REMAINING_MODULE_IDS: ReadonlySet<DashboardModuleId> = new Set([
|
||||
'giveaways',
|
||||
'tickets',
|
||||
'selfroles',
|
||||
'tags',
|
||||
'starboard',
|
||||
'suggestions',
|
||||
'birthdays',
|
||||
'tempvoice',
|
||||
'stats',
|
||||
'feeds',
|
||||
'scheduler',
|
||||
'guildbackup'
|
||||
]);
|
||||
|
||||
interface ModulePlaceholderPageProps {
|
||||
params: Promise<{ guildId: string; module: string }>;
|
||||
}
|
||||
|
||||
export default async function ModulePlaceholderPage({ params }: ModulePlaceholderPageProps) {
|
||||
const { guildId, module: moduleHref } = await params;
|
||||
const moduleEntry = DASHBOARD_MODULES.find((entry) => entry.href === moduleHref);
|
||||
|
||||
if (!moduleEntry || !REMAINING_MODULE_IDS.has(moduleEntry.id)) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const locale = await getLocale();
|
||||
const moduleLabel = t(locale, `modules.${moduleEntry.id}.label`);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-center gap-4 py-16 text-center">
|
||||
<div className="flex size-12 items-center justify-center rounded-full bg-muted">
|
||||
<Construction className="size-6 text-muted-foreground" />
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<h1 className="text-xl font-semibold">{t(locale, 'modulePlaceholder.title', { module: moduleLabel })}</h1>
|
||||
<p className="text-sm text-muted-foreground">{t(locale, 'modulePlaceholder.message')}</p>
|
||||
</div>
|
||||
<Link href={`/dashboard/${guildId}/modules`} className="text-sm text-primary hover:underline">
|
||||
{t(locale, 'modulePlaceholder.backToModules')}
|
||||
</Link>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
14
apps/webui/src/app/dashboard/[guildId]/backup/loading.tsx
Normal file
14
apps/webui/src/app/dashboard/[guildId]/backup/loading.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
|
||||
export default function BackupLoading() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-48" />
|
||||
<Skeleton className="h-4 w-80" />
|
||||
</div>
|
||||
<Skeleton className="h-48 rounded-lg" />
|
||||
<Skeleton className="h-64 rounded-lg" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
30
apps/webui/src/app/dashboard/[guildId]/backup/page.tsx
Normal file
30
apps/webui/src/app/dashboard/[guildId]/backup/page.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { GuildBackupManager } from '@/components/modules/guild-backup-manager';
|
||||
import { requireAuthOrRedirect } from '@/lib/auth';
|
||||
import { fetchDiscordUserGuildsCached } from '@/lib/discord-oauth';
|
||||
import { getLocale, t } from '@/lib/i18n';
|
||||
import { listGuildBackupsDashboard } from '@/lib/module-configs/guildbackup';
|
||||
|
||||
interface BackupPageProps {
|
||||
params: Promise<{ guildId: string }>;
|
||||
}
|
||||
|
||||
export default async function BackupPage({ params }: BackupPageProps) {
|
||||
const { guildId } = await params;
|
||||
const session = await requireAuthOrRedirect();
|
||||
const [locale, backups, discordGuilds] = await Promise.all([
|
||||
getLocale(),
|
||||
listGuildBackupsDashboard(guildId),
|
||||
fetchDiscordUserGuildsCached(session.accessToken)
|
||||
]);
|
||||
const isOwner = discordGuilds.find((guild) => guild.id === guildId)?.owner ?? false;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">{t(locale, 'modules.guildbackup.label')}</h1>
|
||||
<p className="text-sm text-muted-foreground">{t(locale, 'modules.guildbackup.description')}</p>
|
||||
</div>
|
||||
<GuildBackupManager guildId={guildId} initialBackups={backups} isOwner={isOwner} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
215
apps/webui/src/components/modules/guild-backup-manager.tsx
Normal file
215
apps/webui/src/components/modules/guild-backup-manager.tsx
Normal file
@@ -0,0 +1,215 @@
|
||||
'use client';
|
||||
|
||||
import type { GuildBackupDashboard } from '@nexumi/shared';
|
||||
import { Download, Info, Plus, RotateCcw, Trash2 } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import { useTranslations } from '@/components/locale-provider';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
|
||||
function formatDate(iso: string): string {
|
||||
return new Date(iso).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' });
|
||||
}
|
||||
|
||||
interface GuildBackupManagerProps {
|
||||
guildId: string;
|
||||
initialBackups: GuildBackupDashboard[];
|
||||
isOwner: boolean;
|
||||
}
|
||||
|
||||
export function GuildBackupManager({ guildId, initialBackups, isOwner }: GuildBackupManagerProps) {
|
||||
const t = useTranslations();
|
||||
const [backups, setBackups] = useState<GuildBackupDashboard[]>(initialBackups);
|
||||
const [name, setName] = useState('');
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [pendingId, setPendingId] = useState<string | null>(null);
|
||||
const [infoId, setInfoId] = useState<string | null>(null);
|
||||
const [infoText, setInfoText] = useState<string | null>(null);
|
||||
|
||||
async function handleCreate() {
|
||||
if (!name.trim()) {
|
||||
toast.error(t('modulePages.guildbackup.nameRequired'));
|
||||
return;
|
||||
}
|
||||
setCreating(true);
|
||||
try {
|
||||
const response = await fetch(`/api/guilds/${guildId}/guildbackup`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: name.trim() })
|
||||
});
|
||||
const body = (await response.json().catch(() => null)) as (GuildBackupDashboard & { error?: string }) | null;
|
||||
if (!response.ok || !body) {
|
||||
toast.error(body?.error ?? t('common.saveError'));
|
||||
return;
|
||||
}
|
||||
setBackups((prev) => [body, ...prev]);
|
||||
setName('');
|
||||
toast.success(t('modulePages.guildbackup.created'));
|
||||
} catch {
|
||||
toast.error(t('common.saveError'));
|
||||
} finally {
|
||||
setCreating(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleInfo(backup: GuildBackupDashboard) {
|
||||
if (infoId === backup.id) {
|
||||
setInfoId(null);
|
||||
setInfoText(null);
|
||||
return;
|
||||
}
|
||||
setInfoId(backup.id);
|
||||
try {
|
||||
const response = await fetch(`/api/guilds/${guildId}/guildbackup/${backup.id}`);
|
||||
const body = (await response.json().catch(() => null)) as {
|
||||
payload?: { guildName: string; roles: unknown[]; channels: unknown[] } | null;
|
||||
error?: string;
|
||||
} | null;
|
||||
if (!response.ok || !body?.payload) {
|
||||
setInfoText(t('modulePages.guildbackup.infoUnavailable'));
|
||||
return;
|
||||
}
|
||||
setInfoText(
|
||||
`${t('modulePages.guildbackup.infoGuildName')}: ${body.payload.guildName} · ${t('modulePages.guildbackup.infoRoles')}: ${body.payload.roles.length} · ${t('modulePages.guildbackup.infoChannels')}: ${body.payload.channels.length}`
|
||||
);
|
||||
} catch {
|
||||
setInfoText(t('modulePages.guildbackup.infoUnavailable'));
|
||||
}
|
||||
}
|
||||
|
||||
function handleDownload(backup: GuildBackupDashboard) {
|
||||
window.open(`/api/guilds/${guildId}/guildbackup/${backup.id}/download`, '_blank');
|
||||
}
|
||||
|
||||
async function handleDelete(backup: GuildBackupDashboard) {
|
||||
if (!window.confirm(t('modulePages.guildbackup.confirmDelete'))) {
|
||||
return;
|
||||
}
|
||||
setPendingId(backup.id);
|
||||
try {
|
||||
const response = await fetch(`/api/guilds/${guildId}/guildbackup/${backup.id}`, { method: 'DELETE' });
|
||||
if (!response.ok) {
|
||||
toast.error(t('common.saveError'));
|
||||
return;
|
||||
}
|
||||
setBackups((prev) => prev.filter((entry) => entry.id !== backup.id));
|
||||
toast.success(t('common.saveSuccess'));
|
||||
} catch {
|
||||
toast.error(t('common.saveError'));
|
||||
} finally {
|
||||
setPendingId(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRestore(backup: GuildBackupDashboard) {
|
||||
if (!window.confirm(t('modulePages.guildbackup.confirmRestoreStep1'))) {
|
||||
return;
|
||||
}
|
||||
if (!window.confirm(t('modulePages.guildbackup.confirmRestoreStep2'))) {
|
||||
return;
|
||||
}
|
||||
setPendingId(backup.id);
|
||||
try {
|
||||
const response = await fetch(`/api/guilds/${guildId}/guildbackup/${backup.id}/restore`, { method: 'POST' });
|
||||
const body = (await response.json().catch(() => null)) as { error?: string } | null;
|
||||
if (!response.ok) {
|
||||
toast.error(body?.error ?? t('common.saveError'));
|
||||
return;
|
||||
}
|
||||
toast.success(t('modulePages.guildbackup.restoreQueued'));
|
||||
} catch {
|
||||
toast.error(t('common.saveError'));
|
||||
} finally {
|
||||
setPendingId(null);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t('modulePages.guildbackup.createTitle')}</CardTitle>
|
||||
<CardDescription>{t('modulePages.guildbackup.createDescription')}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>{t('modulePages.guildbackup.name')}</Label>
|
||||
<Input value={name} onChange={(event) => setName(event.target.value)} placeholder={t('modulePages.guildbackup.namePlaceholder')} />
|
||||
</div>
|
||||
<Button type="button" onClick={handleCreate} disabled={creating}>
|
||||
<Plus className="size-4" />
|
||||
{creating ? t('common.saving') : t('modulePages.guildbackup.create')}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{t('modulePages.guildbackup.listTitle')}</CardTitle>
|
||||
<CardDescription>{t('modulePages.guildbackup.listDescription')}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{backups.length === 0 && (
|
||||
<p className="text-sm text-muted-foreground">{t('modulePages.guildbackup.empty')}</p>
|
||||
)}
|
||||
{backups.map((backup) => (
|
||||
<div key={backup.id} className="space-y-2 rounded-md border border-border p-4">
|
||||
<div className="flex flex-wrap items-start justify-between gap-2">
|
||||
<div>
|
||||
<p className="font-medium">{backup.name}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{formatDate(backup.createdAt)} · {t('modulePages.guildbackup.infoRoles')}: {backup.roleCount} ·{' '}
|
||||
{t('modulePages.guildbackup.infoChannels')}: {backup.channelCount}
|
||||
</p>
|
||||
</div>
|
||||
{!isOwner && (
|
||||
<Badge variant="outline">{t('modulePages.guildbackup.ownerOnlyBadge')}</Badge>
|
||||
)}
|
||||
</div>
|
||||
{infoId === backup.id && infoText && (
|
||||
<p className="rounded-md bg-muted p-2 text-xs text-muted-foreground">{infoText}</p>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="button" size="sm" variant="outline" onClick={() => handleInfo(backup)}>
|
||||
<Info className="size-4" />
|
||||
{t('modulePages.guildbackup.info')}
|
||||
</Button>
|
||||
<Button type="button" size="sm" variant="outline" onClick={() => handleDownload(backup)}>
|
||||
<Download className="size-4" />
|
||||
{t('modulePages.guildbackup.download')}
|
||||
</Button>
|
||||
{isOwner && (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={pendingId === backup.id}
|
||||
onClick={() => handleRestore(backup)}
|
||||
>
|
||||
<RotateCcw className="size-4" />
|
||||
{t('modulePages.guildbackup.restore')}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
disabled={pendingId === backup.id}
|
||||
onClick={() => handleDelete(backup)}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
{t('common.remove')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
75
apps/webui/src/lib/module-configs/commands.ts
Normal file
75
apps/webui/src/lib/module-configs/commands.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { KNOWN_COMMAND_NAMES, type CommandOverrideDashboard, type CommandOverrideDashboardUpsert } from '@nexumi/shared';
|
||||
import type { CommandOverride } from '@prisma/client';
|
||||
import { prisma } from '../prisma';
|
||||
|
||||
function toDashboard(override: CommandOverride): CommandOverrideDashboard {
|
||||
return {
|
||||
commandName: override.commandName,
|
||||
enabled: override.enabled,
|
||||
allowedRoleIds: override.allowedRoleIds,
|
||||
deniedRoleIds: override.deniedRoleIds,
|
||||
allowedChannelIds: override.allowedChannelIds,
|
||||
deniedChannelIds: override.deniedChannelIds,
|
||||
cooldownSeconds: override.cooldownSeconds
|
||||
};
|
||||
}
|
||||
|
||||
function defaultDashboard(commandName: string): CommandOverrideDashboard {
|
||||
return {
|
||||
commandName,
|
||||
enabled: true,
|
||||
allowedRoleIds: [],
|
||||
deniedRoleIds: [],
|
||||
allowedChannelIds: [],
|
||||
deniedChannelIds: [],
|
||||
cooldownSeconds: null
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists every known command with its dashboard override (or sensible
|
||||
* defaults for commands that have never been overridden on this guild),
|
||||
* sorted alphabetically for a stable table.
|
||||
*/
|
||||
export async function listCommandOverridesDashboard(guildId: string): Promise<CommandOverrideDashboard[]> {
|
||||
const overrides = await prisma.commandOverride.findMany({ where: { guildId } });
|
||||
const byName = new Map(overrides.map((entry) => [entry.commandName, entry]));
|
||||
|
||||
return [...KNOWN_COMMAND_NAMES]
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
.map((commandName) => {
|
||||
const existing = byName.get(commandName);
|
||||
return existing ? toDashboard(existing) : defaultDashboard(commandName);
|
||||
});
|
||||
}
|
||||
|
||||
export async function upsertCommandOverrideDashboard(
|
||||
guildId: string,
|
||||
input: CommandOverrideDashboardUpsert
|
||||
): Promise<CommandOverrideDashboard> {
|
||||
await prisma.guild.upsert({ where: { id: guildId }, update: {}, create: { id: guildId } });
|
||||
|
||||
const data = {
|
||||
enabled: input.enabled,
|
||||
allowedRoleIds: input.allowedRoleIds,
|
||||
deniedRoleIds: input.deniedRoleIds,
|
||||
allowedChannelIds: input.allowedChannelIds,
|
||||
deniedChannelIds: input.deniedChannelIds,
|
||||
cooldownSeconds: input.cooldownSeconds ?? null
|
||||
};
|
||||
|
||||
const updated = await prisma.commandOverride.upsert({
|
||||
where: { guildId_commandName: { guildId, commandName: input.commandName } },
|
||||
update: data,
|
||||
create: { guildId, commandName: input.commandName, ...data }
|
||||
});
|
||||
return toDashboard(updated);
|
||||
}
|
||||
|
||||
export async function resetCommandOverrideDashboard(
|
||||
guildId: string,
|
||||
commandName: string
|
||||
): Promise<CommandOverrideDashboard> {
|
||||
await prisma.commandOverride.deleteMany({ where: { guildId, commandName } });
|
||||
return defaultDashboard(commandName);
|
||||
}
|
||||
Reference in New Issue
Block a user