81 lines
4.7 KiB
TypeScript
81 lines
4.7 KiB
TypeScript
import Link from "next/link";
|
||
import { ArrowRight, MessagesSquare } from "lucide-react";
|
||
import { chatOverview, syncChats } from "@peppa/core";
|
||
import { LiveRefresh } from "@/components/LiveRefresh";
|
||
import { AgentBadge } from "@/components/AgentBadge";
|
||
import { QuestionCard } from "@/components/cards";
|
||
import { ago, Empty, Flash, PageHeader, Section } from "@/components/common";
|
||
import { Workspace } from "@/components/Workspace";
|
||
import { requireUser } from "@/lib/auth";
|
||
import { db } from "@/lib/db";
|
||
import { inbox } from "@/lib/queries";
|
||
|
||
export const metadata = { title: "Чаты — Peppa FACTORY" };
|
||
|
||
/**
|
||
* «Чаты» (PEP-117): the overview a product manager lands on — what waits for their answer and
|
||
* where to write to the analyst of each project. The raw feed of events lives at /chats/master.
|
||
*/
|
||
export default async function Chats({ searchParams }: { searchParams: Promise<{ error?: string }> }) {
|
||
const user = await requireUser();
|
||
const { error } = await searchParams;
|
||
await syncChats(db).catch((e) => console.error("syncChats", e));
|
||
const [cards, waiting] = await Promise.all([chatOverview(db, user), inbox(user.id)]);
|
||
return (
|
||
<Workspace>
|
||
<LiveRefresh scope="chats" />
|
||
<Flash error={error} />
|
||
<PageHeader title="Чаты">Здесь вы разговариваете с фабрикой: отвечаете агентам и пишете аналитику своего проекта — что узнать или что сделать.</PageHeader>
|
||
|
||
<Section title="Ждут вашего ответа" count={waiting.length}>
|
||
{waiting.length === 0 ? (
|
||
<Empty>Сейчас от вас ничего не нужно — агенты работают сами.</Empty>
|
||
) : (
|
||
waiting.map((q) => <QuestionCard key={q.id} q={q} taskKey={q.taskKey} taskStatus={q.taskStatus} back="/chats" />)
|
||
)}
|
||
</Section>
|
||
|
||
<Section title="Ваши проекты" count={cards.length}>
|
||
{cards.length === 0 ? (
|
||
<Empty>
|
||
Проектов пока нет. <Link href="/projects/new">Создайте проект</Link> — и у него появится чат с аналитиком.
|
||
</Empty>
|
||
) : (
|
||
<ul className="m-0 grid list-none gap-3 p-0 md:grid-cols-2">
|
||
{cards.map((c) => (
|
||
<li key={c.chatId}>
|
||
<Link href={`/chats/${c.key}`} className="flex h-full flex-col gap-2 rounded-xl border bg-card p-4 text-foreground hover:border-primary/60 hover:no-underline">
|
||
<span className="flex items-center gap-2">
|
||
<span className="rounded bg-muted px-1.5 font-mono text-xs text-primary">{c.key}</span>
|
||
<span className="min-w-0 flex-1 truncate font-medium">{c.name}</span>
|
||
{c.unread > 0 && <span className="rounded-full bg-info px-2 text-xs font-semibold text-background" title="новые сообщения">{c.unread} нов.</span>}
|
||
{c.open > 0 && <span className="rounded-full bg-primary px-2 text-xs font-semibold text-primary-foreground" title="агенты ждут вашего ответа">ждут ответа: {c.open}</span>}
|
||
</span>
|
||
{c.last ? (
|
||
<span className="flex min-w-0 flex-col gap-0.5 text-sm">
|
||
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||
{c.last.who === "Аналитик" ? <AgentBadge name="Аналитик" /> : <span>{c.last.mine ? "вы" : c.last.who}</span>}
|
||
<span>· {ago(c.last.at)}</span>
|
||
</span>
|
||
<span className="line-clamp-2 text-muted-foreground">{c.last.text}</span>
|
||
</span>
|
||
) : (
|
||
<span className="text-sm text-muted-foreground">Здесь пока тихо. Спросите аналитика, что с проектом, или опишите новую задачу.</span>
|
||
)}
|
||
<span className="mt-auto inline-flex items-center gap-1.5 text-sm font-medium text-primary">
|
||
<MessagesSquare className="size-4" /> Написать аналитику <ArrowRight className="size-3.5" />
|
||
</span>
|
||
</Link>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
)}
|
||
</Section>
|
||
|
||
<p className="mt-6 text-sm text-muted-foreground">
|
||
Нужна история? <Link href="/chats/master">Все события по вашим проектам</Link> — что делали агенты, обновления продукта и сбои, справочно.
|
||
</p>
|
||
</Workspace>
|
||
);
|
||
}
|