Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/entities/report/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ export interface ReportResponse {
discoveryRoute?: string;
damageType?: string;
description?: string;
/** AI가 원문을 요약한 사건 개요. 원문이 짧거나 요약을 만들지 못하면 없다. */
summary?: string | null;
sourceUrls?: string[];
evidenceIds?: number[];
targetAgencyType?: string;
additionalNotes?: string;
/** 신고 문서(PDF)를 받는 API 경로. 로그인이 필요해 링크로 열 수 없고 downloadReportDocument로 받는다. */
documentUrl?: string;
documentSimulated?: boolean;
timeline: ReportTimelineEntry[];
createdAt: string;
}
Expand Down Expand Up @@ -74,6 +76,13 @@ export async function updateReport(
return data;
}

export async function downloadReportDocument(reportId: number): Promise<Blob> {
const { data } = await api.get<Blob>(`/api/v1/reports/${reportId}/document`, {
responseType: "blob",
});
return data;
}

export async function finalizeReport(reportId: number): Promise<ReportStatusResponse> {
const { data } = await api.post<ReportStatusResponse>(`/api/v1/reports/${reportId}/finalize`);
return data;
Expand Down
23 changes: 6 additions & 17 deletions src/views/ReportHistoryDetailPage/ReportHistoryDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import Button from "@/shared/ui/Button";
import ConfirmModal from "@/shared/ui/ConfirmModal";
import NoticeBanner from "@/shared/ui/NoticeBanner";
import PageHeading from "@/shared/ui/PageHeading";
import { resolveFileUrl } from "@/shared/lib/resolveFileUrl";
import ReportDocumentDownloadButton from "@/views/ReportPage/ReportDocumentDownloadButton";
import ReportSummary from "@/views/ReportPage/ReportSummary";
import Footer from "@/widgets/Footer";
import SiteHeader from "@/widgets/SiteHeader";
import { useLocale, useT } from "@/shared/i18n/I18nProvider";
Expand Down Expand Up @@ -265,22 +266,10 @@ export default function ReportHistoryDetailPage({ id }: ReportHistoryDetailPageP

<NoticeBanner className="w-full max-w-[960px]">{t.aiNotice}</NoticeBanner>

{report.documentSimulated ? (
<p className="text-small md:text-body-2 w-full max-w-[960px] text-gray-700">
{t.fileSimulated}
</p>
) : (
report.documentUrl && (
<a
href={resolveFileUrl(report.documentUrl)}
target="_blank"
rel="noreferrer"
className="text-secondary-600 text-body-2 w-full max-w-[960px] underline"
>
{t.viewFile}
</a>
)
)}
<div className="flex w-full max-w-[960px] flex-col gap-3">
<ReportDocumentDownloadButton reportId={reportId} className="w-full md:w-fit" />
Comment thread
ryusuye0n marked this conversation as resolved.
Resolved
{!isEditing && <ReportSummary summary={report.summary} />}
</div>

<div className="flex w-full max-w-[960px] flex-col gap-2">
<p className="text-body-2 md:text-body-1 text-black">{t.content}</p>
Expand Down
50 changes: 50 additions & 0 deletions src/views/ReportPage/ReportDocumentDownloadButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use client";

import { useMutation } from "@tanstack/react-query";
import { toast } from "sonner";
import { downloadReportDocument } from "@/entities/report/api";
import { useT } from "@/shared/i18n/I18nProvider";
import Button, { type ButtonVariant } from "@/shared/ui/Button";
import { reportDocumentMessages } from "./reportDocumentMessages";

interface ReportDocumentDownloadButtonProps {
reportId: number;
variant?: ButtonVariant;
className?: string;
}

/** 신고 문서(PDF)는 로그인이 필요한 API라 링크가 아니라 blob으로 받아 저장한다. */
export default function ReportDocumentDownloadButton({
reportId,
variant = "outline",
className = "",
}: ReportDocumentDownloadButtonProps) {
const t = useT(reportDocumentMessages);

const downloadMutation = useMutation({
mutationFn: () => downloadReportDocument(reportId),
onSuccess: (blob) => {
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `signal-report-${reportId}.pdf`;
link.click();
URL.revokeObjectURL(url);
Comment thread
ryusuye0n marked this conversation as resolved.
Resolved
},
onError: () => {
toast.error(t.downloadFailed);
},
});

return (
<Button
type="button"
variant={variant}
className={className}
disabled={downloadMutation.isPending}
onClick={() => downloadMutation.mutate()}
>
{downloadMutation.isPending ? t.downloading : t.download}
</Button>
);
}
27 changes: 27 additions & 0 deletions src/views/ReportPage/ReportSummary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use client";

import { useT } from "@/shared/i18n/I18nProvider";
import { reportDocumentMessages } from "./reportDocumentMessages";

interface ReportSummaryProps {
summary: string | null | undefined;
className?: string;
}

/** AI가 만든 사건 개요. 요약이 없으면(원문이 짧거나 만들지 못함) 아무것도 그리지 않는다. */
export default function ReportSummary({ summary, className = "" }: ReportSummaryProps) {
const t = useT(reportDocumentMessages);
if (!summary?.trim()) return null;

return (
<div
className={`flex flex-col gap-1.5 rounded-lg border border-gray-300 p-3 md:p-4 ${className}`}
>
<p className="text-body-2 md:text-body-1 font-semibold text-black">{t.summaryTitle}</p>
<p className="text-body-2 md:text-body-1 w-full break-words whitespace-pre-wrap text-black">
{summary}
</p>
<p className="text-small text-gray-650">{t.summaryNotice}</p>
</div>
);
}
12 changes: 12 additions & 0 deletions src/views/ReportPage/Step4Generated.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use client";

import { useQuery } from "@tanstack/react-query";
import Link from "next/link";
import { getReport } from "@/entities/report/api";
import Button, { buttonStyle } from "@/shared/ui/Button";
import DraftCardHeader from "./DraftCardHeader";
import StepNavigation from "./StepNavigation";
Expand All @@ -9,6 +11,8 @@ import type { ReportDraft } from "./reportDraft";
import { useLocale, useT } from "@/shared/i18n/I18nProvider";
import { formatDateLong } from "@/shared/i18n/format";
import { reportMessages } from "./messages";
import ReportDocumentDownloadButton from "./ReportDocumentDownloadButton";
import ReportSummary from "./ReportSummary";

interface Step4GeneratedProps {
draft: ReportDraft;
Expand All @@ -31,6 +35,11 @@ export default function Step4Generated({
}: Step4GeneratedProps) {
const { draft: d } = useT(reportMessages);
const { locale } = useLocale();
// 요약은 서버가 저장한 뒤에 생기므로 저장된 신고서에서 가져온다. 못 가져와도 화면은 그대로 보여준다.
const { data: report } = useQuery({
Comment thread
ryusuye0n marked this conversation as resolved.
Resolved
queryKey: ["reports", reportId],
queryFn: () => getReport(reportId),
});
const sourceUrl = draft.sourceUrl.trim();
const rows: { title: string; body: string }[] = [
{ title: d.overview, body: d.overviewText(draft.damageType.trim()) },
Expand Down Expand Up @@ -58,6 +67,8 @@ export default function Step4Generated({
status={d.generated}
/>

<ReportSummary summary={report?.summary} />

<div className="flex flex-col gap-2">
<p className="text-body-2 md:text-body-1 px-1 text-black">{d.content}</p>
<div className="w-full divide-y divide-gray-200 overflow-y-auto rounded-lg border border-gray-300 md:max-h-[427px]">
Expand Down Expand Up @@ -86,6 +97,7 @@ export default function Step4Generated({

<StepNavigation onBack={onBack}>
<div className="flex w-full flex-col gap-2 md:w-auto md:flex-row">
<ReportDocumentDownloadButton reportId={reportId} className="w-full md:w-auto" />
<Link
href={`/mypage/reports/${reportId}`}
className={buttonStyle("outline", "w-full md:w-auto")}
Expand Down
38 changes: 38 additions & 0 deletions src/views/ReportPage/reportDocumentMessages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { defineMessages } from "@/shared/i18n/defineMessages";

export const reportDocumentMessages = defineMessages(
{
download: "신고 문서(PDF) 내려받기",
downloading: "문서 만드는 중...",
downloadFailed: "신고 문서를 내려받지 못했어요. 잠시 후 다시 시도해 주세요.",
summaryTitle: "사건 개요 (AI 요약)",
summaryNotice:
"AI가 입력하신 피해 내용을 요약한 것으로 원문과 다를 수 있어요. 제출 전에 꼭 확인해 주세요.",
},
{
en: {
download: "Download report (PDF)",
downloading: "Preparing the file...",
downloadFailed: "Couldn't download the report. Please try again in a moment.",
summaryTitle: "Case summary (AI)",
summaryNotice:
"AI summarized what you wrote and it may differ from the original. Please check it before submitting.",
},
ja: {
download: "通報書類(PDF)をダウンロード",
downloading: "ファイルを作成中...",
downloadFailed:
"通報書類をダウンロードできませんでした。しばらくしてからもう一度お試しください。",
summaryTitle: "事件の概要(AI要約)",
summaryNotice:
"入力された被害内容をAIが要約したもので、原文と異なる場合があります。提出前に必ずご確認ください。",
},
zh: {
download: "下载举报文件(PDF)",
downloading: "正在生成文件...",
downloadFailed: "无法下载举报文件。请稍后再试。",
summaryTitle: "事件概要(AI摘要)",
summaryNotice: "这是AI对你填写的伤害内容的摘要,可能与原文不同。提交前请务必确认。",
},
},
);
11 changes: 0 additions & 11 deletions src/views/mypageMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ export const mypageMessages = defineMessages(
reviewDescription: "아래 내용은 자유롭게 수정할 수 있습니다.",
aiNotice:
"AI가 입력 내용을 정리한 문서입니다. 실제 제출 전 날짜, URL, 피해 내용을 한 번 더 확인해 주세요.",
fileSimulated:
"신고 문서 파일(PDF) 생성은 준비 중입니다. 아래 내용을 확인해 기관에 제출해 주세요.",
viewFile: "생성된 신고 문서 파일 보기",
content: "신고 내용",
overview: "피해 개요",
overviewText: (damageType: string) => `${damageType} 피해가 발생한 것으로 보여 신고합니다.`,
Expand Down Expand Up @@ -131,9 +128,6 @@ export const mypageMessages = defineMessages(
reviewDescription: "You can freely edit the content below.",
aiNotice:
"AI organized what you entered. Double-check the date, URL, and details before submitting.",
fileSimulated:
"PDF generation is coming soon. Please review the content below and submit it to an agency.",
viewFile: "View the generated report file",
content: "Report content",
overview: "Summary",
overviewText: (damageType) => `I am reporting harm that appears to be ${damageType}.`,
Expand Down Expand Up @@ -217,9 +211,6 @@ export const mypageMessages = defineMessages(
reviewDescription: "以下の内容は自由に修正できます。",
aiNotice:
"AIが入力内容を整理した書類です。提出前に日付、URL、被害内容をもう一度確認してください。",
fileSimulated:
"通報書類ファイル(PDF)の作成は準備中です。以下の内容を確認して機関に提出してください。",
viewFile: "作成された通報書類ファイルを見る",
content: "通報内容",
overview: "被害の概要",
overviewText: (damageType) => `${damageType}の被害が発生したと考えられるため通報します。`,
Expand Down Expand Up @@ -300,8 +291,6 @@ export const mypageMessages = defineMessages(
reviewTitle: "请确认举报文件内容",
reviewDescription: "以下内容可以自由修改。",
aiNotice: "这是AI整理你输入内容后生成的文件。提交前请再次确认日期、URL和伤害内容。",
fileSimulated: "举报文件(PDF)生成功能即将推出。请确认以下内容后提交给机构。",
viewFile: "查看生成的举报文件",
content: "举报内容",
overview: "伤害概要",
overviewText: (damageType) => `发生了疑似${damageType}的伤害,特此举报。`,
Expand Down
Loading