140 lines
8.5 KiB
TypeScript
140 lines
8.5 KiB
TypeScript
import Link from "next/link";
|
||
import { FEEDBACK_ADMIN_STATUS, FEEDBACK_KIND, FEEDBACK_SIZE, FEEDBACK_USER_STATUS, feedbackTitle, type FeedbackView } from "@peppa/core";
|
||
import { Hidden } from "@/components/cards";
|
||
import { ago, Disclosure } from "@/components/common";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Badge } from "@/components/ui/badge";
|
||
import { Card } from "@/components/ui/card";
|
||
import { Input } from "@/components/ui/input";
|
||
import { getT } from "@/lib/i18n";
|
||
import { fixFeedbackAction, linkFeedbackAction, rejectFeedbackAction } from "@/app/(app)/actions";
|
||
|
||
const TONE = { received: "muted", analyzed: "info", planned: "info", fixed: "ok", rejected: "warn" } as const;
|
||
|
||
function Shots({ f, label }: { f: FeedbackView; label: (n: number) => string }) {
|
||
if (!f.screenshots.length) return null;
|
||
return (
|
||
<div className="flex flex-wrap gap-2">
|
||
{f.screenshots.map((s, i) => (
|
||
<a key={s.file} href={`/api/feedback/${f.id}/shots/${i}`} target="_blank" rel="noreferrer">
|
||
<img src={`/api/feedback/${f.id}/shots/${i}`} alt={label(i + 1)} loading="lazy" className="h-24 max-w-40 rounded-md border object-cover" />
|
||
</a>
|
||
))}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/** PEP-143: the author's own report — what they wrote, where it stands, what they were answered. */
|
||
export async function MyFeedbackCard({ f }: { f: FeedbackView }) {
|
||
const t = await getT();
|
||
return (
|
||
<Card className="gap-3" data-feedback={f.id}>
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<span className="min-w-0 flex-1 font-medium break-words">{feedbackTitle(f)}</span>
|
||
<Badge variant={TONE[f.status]}>{t.text(FEEDBACK_USER_STATUS[f.status])}</Badge>
|
||
<span className="text-xs text-muted-foreground">{ago(f.createdAt, t)}</span>
|
||
</div>
|
||
{f.text.includes("\n") && <p className="m-0 text-sm whitespace-pre-wrap text-muted-foreground">{f.text}</p>}
|
||
<Shots f={f} label={(n) => t("Скриншот {n}", { n })} />
|
||
{f.status === "fixed" && <p className="m-0 text-sm">{t("Исправили. Спасибо, что сообщили.")}</p>}
|
||
{f.status === "rejected" && <p className="m-0 text-sm">{f.rejectReason ? t("Решили пока не исправлять. Причина: {reason}", { reason: f.rejectReason }) : t("Решили пока не исправлять.")}</p>}
|
||
</Card>
|
||
);
|
||
}
|
||
|
||
/** PEP-143: a report for the superadmin — who, where, what, the agent's analysis and the decision. */
|
||
export async function AdminFeedbackCard({ f, back }: { f: FeedbackView; back: string }) {
|
||
const t = await getT();
|
||
const a = f.analysis;
|
||
const c = f.context;
|
||
const open = f.status === "received" || f.status === "analyzed";
|
||
const fields = { feedbackId: f.id, back };
|
||
return (
|
||
<Card className="gap-3" data-feedback={f.id} id={`feedback-${f.id}`}>
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<span className="font-mono text-sm text-muted-foreground">№{f.id}</span>
|
||
<span className="font-medium">{f.authorName && f.authorName.toLowerCase() !== f.authorLogin.toLowerCase() ? `${f.authorName} (${f.authorLogin})` : f.authorLogin}</span>
|
||
<Badge variant="muted">{f.via === "telegram" ? "Telegram" : t("веб")}</Badge>
|
||
{a && <Badge variant={a.kind === "bug" ? "danger" : "info"}>{t.text(FEEDBACK_KIND[a.kind])}</Badge>}
|
||
<Badge variant={TONE[f.status]}>{t.text(FEEDBACK_ADMIN_STATUS[f.status])}</Badge>
|
||
<span className="ml-auto text-xs text-muted-foreground">{ago(f.createdAt, t)}</span>
|
||
</div>
|
||
{f.text ? <p className="m-0 text-sm whitespace-pre-wrap break-words">{f.text}</p> : <p className="m-0 text-sm text-muted-foreground">{t("Скриншот без подписи")}</p>}
|
||
<Shots f={f} label={(n) => t("Скриншот {n}", { n })} />
|
||
{(c.url || c.userAgent || c.errors?.length) && (
|
||
<Disclosure summary={c.url ? t("Страница: {url}", { url: c.url }) : t("Подробнее")}>
|
||
<dl className="m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs text-muted-foreground">
|
||
{c.projectKey && (<><dt>{t("Проект")}</dt><dd className="m-0">{c.taskKey ?? c.projectKey}</dd></>)}
|
||
{c.mode && (<><dt>{t("Вид")}</dt><dd className="m-0">{c.mode === "engineer" ? t("Инженер") : t("Продакт")}</dd></>)}
|
||
{c.locale && (<><dt>{t("Язык")}</dt><dd className="m-0">{c.locale}</dd></>)}
|
||
{c.viewport && (<><dt>{t("Окно")}</dt><dd className="m-0">{c.viewport}</dd></>)}
|
||
{c.userAgent && (<><dt>{t("Браузер")}</dt><dd className="m-0 break-words">{c.userAgent}</dd></>)}
|
||
{c.errors?.map((e, i) => (
|
||
<div key={i} className="contents">
|
||
<dt>{t("Ошибка")}</dt>
|
||
<dd className="m-0 font-mono break-words">{e.type}: {e.message}</dd>
|
||
</div>
|
||
))}
|
||
</dl>
|
||
</Disclosure>
|
||
)}
|
||
{a ? (
|
||
<div className="flex flex-col gap-2 rounded-lg border bg-background/40 p-3 text-sm">
|
||
<p className="m-0"><b>{t("Суть")}:</b> {a.summary}</p>
|
||
{a.cause && <p className="m-0"><b>{t("Вероятная причина")}:</b> {a.cause}</p>}
|
||
{!a.confident && <p className="m-0 text-warn">{t("Агент не уверен в разборе — проверьте сами.")}</p>}
|
||
{a.options.map((o, i) => (
|
||
<div key={i} className="flex flex-col gap-1 border-t pt-2">
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<b>{t("Вариант {n}", { n: i + 1 })}</b>
|
||
<span>{o.title}</span>
|
||
{a.recommended === i + 1 && <Badge variant="primary">{t("рекомендуем")}</Badge>}
|
||
<Badge variant="muted">{t.text(FEEDBACK_SIZE[o.size])}</Badge>
|
||
{f.optionIndex === i + 1 && <Badge variant="ok">{t("выбран")}</Badge>}
|
||
</div>
|
||
<p className="m-0">{o.what}</p>
|
||
{o.pros && <p className="m-0 text-muted-foreground">➕ {o.pros}</p>}
|
||
{o.cons && <p className="m-0 text-muted-foreground">➖ {o.cons}</p>}
|
||
{open && (
|
||
<form action={fixFeedbackAction}>
|
||
<Hidden fields={{ ...fields, option: i + 1 }} />
|
||
<Button type="submit" size="sm" variant={a.recommended === i + 1 ? "default" : "outline"}>{t("Исправить: вариант {n}", { n: i + 1 })}</Button>
|
||
</form>
|
||
)}
|
||
</div>
|
||
))}
|
||
</div>
|
||
) : (
|
||
f.status !== "received" && <p className="m-0 text-sm text-muted-foreground">{f.analysisError ? t("Разбора нет: агент не смог ответить.") : t("Разбора нет.")}</p>
|
||
)}
|
||
{f.status === "received" && <p className="m-0 text-sm text-muted-foreground">{t("Агент обратной связи разбирает обращение…")}</p>}
|
||
{f.taskKey && (
|
||
<p className="m-0 text-sm">
|
||
{t("Задача")}: <Link href={`/t/${f.taskKey}`}>{f.taskKey}</Link> {f.taskTitle}
|
||
</p>
|
||
)}
|
||
{f.status === "rejected" && <p className="m-0 text-sm">{f.rejectReason ? t("Не исправляем. Причина: {reason}", { reason: f.rejectReason }) : t("Не исправляем.")}</p>}
|
||
{open && (
|
||
<div className="flex flex-col gap-2 border-t pt-3">
|
||
{!a?.options.length && (
|
||
<form action={fixFeedbackAction}>
|
||
<Hidden fields={{ ...fields, option: 0 }} />
|
||
<Button type="submit" size="sm" variant="default">{t("Завести задачу")}</Button>
|
||
</form>
|
||
)}
|
||
<form action={linkFeedbackAction} className="flex flex-wrap items-center gap-2">
|
||
<Hidden fields={fields} />
|
||
<Input name="task" defaultValue={a?.duplicateOf ?? ""} placeholder={t("Номер задачи, например PEP-12")} aria-label={t("Номер задачи")} className="h-8 w-52" />
|
||
<Button type="submit" size="sm">{t("Уже есть задача")}</Button>
|
||
</form>
|
||
<form action={rejectFeedbackAction} className="flex flex-wrap items-center gap-2">
|
||
<Hidden fields={fields} />
|
||
<Input name="reason" placeholder={t("Причина — её увидит автор")} aria-label={t("Причина")} className="h-8 min-w-52 flex-1" />
|
||
<Button type="submit" size="sm" variant="destructive">{t("Не исправлять")}</Button>
|
||
</form>
|
||
</div>
|
||
)}
|
||
</Card>
|
||
);
|
||
}
|