feat: add web app pages for org portal, thread viewer, and admin org management
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import Link from 'next/link';
|
||||
import { apiFetch } from '../../_lib/api';
|
||||
|
||||
interface ThreadMessage {
|
||||
id: string;
|
||||
content: string;
|
||||
senderJid: string;
|
||||
senderName: string | null;
|
||||
tags: string[];
|
||||
status: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
interface ThreadDetail {
|
||||
id: string;
|
||||
topic: string | null;
|
||||
sourceGroupName: string;
|
||||
messageCount: number;
|
||||
lastActivityAt: string;
|
||||
createdAt: string;
|
||||
messages: ThreadMessage[];
|
||||
}
|
||||
|
||||
const STATUS_COLORS: Record<string, string> = {
|
||||
APPROVED: 'text-green-600',
|
||||
PENDING: 'text-amber-600',
|
||||
REJECTED: 'text-red-600',
|
||||
RAW: 'text-gray-400',
|
||||
DNC: 'text-gray-400',
|
||||
DISTRIBUTED: 'text-blue-600',
|
||||
};
|
||||
|
||||
export default async function ThreadDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
}) {
|
||||
const { id } = await params;
|
||||
|
||||
let thread: ThreadDetail | null = null;
|
||||
let error: string | null = null;
|
||||
|
||||
try {
|
||||
const res = await apiFetch(`/admin/threads/${id}`);
|
||||
if (res.ok) {
|
||||
thread = await res.json();
|
||||
} else {
|
||||
error = `API returned ${res.status}`;
|
||||
}
|
||||
} catch {
|
||||
error = 'Failed to load thread';
|
||||
}
|
||||
|
||||
if (error || !thread) {
|
||||
return (
|
||||
<div className="max-w-2xl">
|
||||
<Link href="/threads" className="text-sm text-blue-600 hover:underline mb-4 inline-block">← Back to threads</Link>
|
||||
<p className="text-red-600 text-sm">{error ?? 'Thread not found'}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-2xl">
|
||||
<Link href="/threads" className="text-sm text-blue-600 hover:underline mb-4 inline-block">← Back to threads</Link>
|
||||
|
||||
<div className="mb-6">
|
||||
<h1 className="text-xl font-semibold">
|
||||
{thread.topic ?? `Thread ${thread.id.slice(0, 8)}`}
|
||||
</h1>
|
||||
<p className="text-sm text-gray-500 mt-1">
|
||||
{thread.sourceGroupName} · {thread.messageCount} messages · last activity {new Date(thread.lastActivityAt).toLocaleDateString()}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-3">
|
||||
{thread.messages.map((msg) => (
|
||||
<div key={msg.id} className="border border-gray-200 rounded-lg p-4">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<div className="text-xs text-gray-500">
|
||||
<span className="font-medium text-gray-700">{msg.senderName ?? msg.senderJid}</span>
|
||||
<span className="mx-1">·</span>
|
||||
<span>{new Date(msg.createdAt).toLocaleString()}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={`text-xs font-medium ${STATUS_COLORS[msg.status] ?? 'text-gray-500'}`}>
|
||||
{msg.status}
|
||||
</span>
|
||||
<Link href={`/messages/${msg.id}`} className="text-xs text-blue-600 hover:underline">
|
||||
View
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-sm text-gray-900 whitespace-pre-wrap">{msg.content}</p>
|
||||
{msg.tags.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1 mt-2">
|
||||
{msg.tags.map((tag) => (
|
||||
<span key={tag} className="rounded-full bg-blue-50 px-2 py-0.5 text-xs text-blue-600">{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import Link from 'next/link';
|
||||
import { apiFetch } from '../_lib/api';
|
||||
|
||||
interface ThreadSummary {
|
||||
id: string;
|
||||
topic: string | null;
|
||||
sourceGroupName: string;
|
||||
messageCount: number;
|
||||
lastActivityAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export default async function ThreadsPage() {
|
||||
let threads: ThreadSummary[] = [];
|
||||
let error: string | null = null;
|
||||
|
||||
try {
|
||||
const res = await apiFetch('/admin/threads');
|
||||
if (res.ok) {
|
||||
threads = await res.json();
|
||||
} else {
|
||||
error = `API returned ${res.status}`;
|
||||
}
|
||||
} catch {
|
||||
error = 'Failed to load threads';
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl">
|
||||
<h1 className="text-xl font-semibold mb-6">Threads</h1>
|
||||
|
||||
{error && (
|
||||
<p className="text-red-600 text-sm mb-4">{error}</p>
|
||||
)}
|
||||
|
||||
{!error && threads.length === 0 && (
|
||||
<p className="text-gray-500 text-sm">No threads yet. Threads are created automatically when members reply to messages.</p>
|
||||
)}
|
||||
|
||||
{threads.length > 0 && (
|
||||
<div className="border border-gray-200 rounded-lg divide-y divide-gray-100">
|
||||
{threads.map((thread) => (
|
||||
<Link
|
||||
key={thread.id}
|
||||
href={`/threads/${thread.id}`}
|
||||
className="flex items-start justify-between p-4 hover:bg-gray-50 transition-colors"
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm font-medium text-gray-900 truncate">
|
||||
{thread.topic ?? `Thread ${thread.id.slice(0, 8)}`}
|
||||
</p>
|
||||
<p className="text-xs text-gray-500 mt-0.5">{thread.sourceGroupName}</p>
|
||||
</div>
|
||||
<div className="ml-4 shrink-0 text-right">
|
||||
<span className="inline-flex items-center rounded-full bg-blue-50 px-2.5 py-0.5 text-xs font-medium text-blue-700">
|
||||
{thread.messageCount} {thread.messageCount === 1 ? 'message' : 'messages'}
|
||||
</span>
|
||||
<p className="text-xs text-gray-400 mt-1">
|
||||
{new Date(thread.lastActivityAt).toLocaleDateString()}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user