diff --git a/src/apis/summary.ts b/src/apis/summary.ts new file mode 100644 index 00000000..af789684 --- /dev/null +++ b/src/apis/summary.ts @@ -0,0 +1,36 @@ +import { safeFetch } from '@/hooks/util/server/safeFetch'; +import { SummaryData, SummaryRes } from '@/types/api/summaryApi'; + +const API_URL = process.env.NEXT_PUBLIC_BASE_API_URL; +const API_TOKEN = process.env.NEXT_PUBLIC_API_TOKEN; + +if (!API_URL) throw new Error('Missing environment variable: NEXT_PUBLIC_BASE_API_URL'); +if (!API_TOKEN) throw new Error('Missing environment variable: NEXT_PUBLIC_API_TOKEN'); + +const SUMMARY_ENDPOINT = `${API_URL}/v1/links`; + +type Params = { + id: number; + format?: 'CONCISE' | 'DETAILED'; +}; + +export const fetchNewSummary = async (params: Params): Promise => { + const url = new URL(`${SUMMARY_ENDPOINT}/${params.id}/summary`); + if (params.format) { + url.searchParams.set('format', params.format); + } + + const body = await safeFetch(url.toString(), { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${API_TOKEN}`, + }, + timeout: 15_000, + jsonContentTypeCheck: true, + }); + if (!body?.data || !body.success) { + throw new Error(body?.message ?? 'Invalid response structure'); + } + return body.data; +}; diff --git a/src/components/wrappers/ReSummaryModal/NewSummary.tsx b/src/components/wrappers/ReSummaryModal/NewSummary.tsx new file mode 100644 index 00000000..9fbf8322 --- /dev/null +++ b/src/components/wrappers/ReSummaryModal/NewSummary.tsx @@ -0,0 +1,10 @@ +export default function NewSummary({ content }: { content: string }) { + return ( +
+ 재생성 요약 +
+
{content}
+
+
+ ); +} diff --git a/src/components/wrappers/ReSummaryModal/PostReSummaryButton.tsx b/src/components/wrappers/ReSummaryModal/PostReSummaryButton.tsx index 1e7d72a2..d2596271 100644 --- a/src/components/wrappers/ReSummaryModal/PostReSummaryButton.tsx +++ b/src/components/wrappers/ReSummaryModal/PostReSummaryButton.tsx @@ -1,45 +1,46 @@ import Button from '@/components/basics/Button/Button'; // import Toast from '@/components/basics/Toast/Toast'; import { useModalStore } from '@/stores/modalStore'; +import { showToast } from '@/stores/toastStore'; interface Props { + disabled: boolean; type: 'prev' | 'new'; - isWriting?: boolean; - // content: string; + onClick: () => void; } -export default function PostReSummaryButton({ type, isWriting }: Props) { +export default function PostReSummaryButton({ type, disabled, onClick }: Props) { const { close } = useModalStore(); // const [toastVisible, setToastVisible] = useState(false); - const onClick = () => { - close(); - // setToastVisible(true); + const handleClick = () => { + onClick(); + if (type === 'prev') { + close(); + showToast({ + id: 'save-prev', + message: '기존 요약을 유지했습니다.', + variant: 'success', + }); + } else if (type === 'new') { + close(); + showToast({ + id: 'save-new', + message: '새로운 요약을 저장했습니다.', + variant: 'success', + }); + } }; - // const handleToastClose = () => { - // setToastVisible(false); - // }; - return ( <>