Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
25 changes: 15 additions & 10 deletions src/features/chat/ChatEntryScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useQuery } from "@tanstack/react-query";
import { TopNavigationButton, Typography } from "@wanteddev/wds";
import { IconChevronLeft } from "@wanteddev/wds-icon";
import { useCallback, useEffect, useRef, useState } from "react";
Expand All @@ -14,14 +15,14 @@ import ChatLoadingDots from "@/features/chat/components/ChatLoadingDots";
import ChatMessageBubble from "@/features/chat/components/ChatMessageBubble";
import SuggestedQuestion from "@/features/chat/components/SuggestedQuestion";
import { CHAT_SEND_FAILURE_MESSAGE } from "@/features/chat/constants/chat";
import { CHAT_SUGGESTED_QUESTIONS } from "@/features/chat/constants/chatSuggestedQuestions";
import { useChatStream } from "@/features/chat/hooks/useChatStream";
import {
clearChatSnapshot,
readChatSnapshot,
saveChatSnapshot,
} from "@/features/chat/utils/chatSnapshot";
import { useBackNavigation } from "@/hooks/useBackNavigation";
import { chatQueries } from "@/shared/entities/chat/chatQueries";

// Figma: 챗봇 진입 화면(nodeId 1887:91534)과 챗봇 대화창(1770:63314) — 메시지를 하나라도
// 보내면 진입 화면의 웰컴 문구·그라데이션·추천 질문이 페이드아웃되고 대화창(말풍선 + 응답
Expand All @@ -32,6 +33,8 @@ function ChatEntryScreen() {
const location = useLocation();
// 출처 링크로 공지·행사에 갔다가 뒤로 돌아왔으면 떠날 때의 대화를 이어 간다(utils/chatSnapshot)
const [restored] = useState(() => readChatSnapshot(location.key));
// 추천 질문은 보조 기능이라 받는 중·실패·0개면 영역을 그리지 않는다 — 입력창은 기다리지 않는다
const { data: faqs = [] } = useQuery(chatQueries.faqs());
const [inputValue, setInputValue] = useState("");
const [isLeaveOpen, setIsLeaveOpen] = useState(false);
const [isFailureToastOpen, setIsFailureToastOpen] = useState(false);
Expand Down Expand Up @@ -163,15 +166,17 @@ function ChatEntryScreen() {
</Typography>
</div>
</div>
<div className="flex flex-col items-start gap-2">
{CHAT_SUGGESTED_QUESTIONS.map((question) => (
<SuggestedQuestion
key={question.id}
onClick={() => sendMessage(question.text)}
question={question.text}
/>
))}
</div>
{faqs.length > 0 && (
<div className="flex flex-col items-start gap-2">
{faqs.map((faq) => (
<SuggestedQuestion
key={faq.faqId}
onClick={() => sendMessage(faq.question)}
question={faq.question}
/>
))}
</div>
)}
</div>
<div
className={`absolute inset-0 flex flex-col gap-3 overflow-y-auto pt-4 pb-4 transition-opacity duration-300 ${
Expand Down
10 changes: 0 additions & 10 deletions src/features/chat/constants/chatSuggestedQuestions.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/shared/entities/chat/chatKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// 챗봇 조회 캐시 key. 답변은 스트리밍이라 캐시하지 않고, 추천 질문(FAQ) 목록만 받아 둔다.
export const chatKeys = {
root: () => ["chat"] as const,
faqs: () => [...chatKeys.root(), "faqs"] as const,
};
24 changes: 24 additions & 0 deletions src/shared/entities/chat/chatQueries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { queryOptions } from "@tanstack/react-query";
import { z } from "zod";

import { api } from "@/shared/api";
import { chatKeys } from "@/shared/entities/chat/chatKeys";

// 운영진이 등록한 추천 질문 — 등록 순서대로 최대 5개, 없으면 빈 배열이다.
// 질문은 100자 이하라 그대로 챗봇 질문(1~500자)으로 보낼 수 있다.
export const chatFaqsResponseSchema = z.array(
z.looseObject({ faqId: z.number(), question: z.string() }),
);

// 화면은 이 queryOptions로만 데이터를 받는다
export const chatQueries = {
// 챗봇 진입 화면 추천 질문(GET /v1/app/chat/faqs)
faqs: () =>
queryOptions({
queryKey: chatKeys.faqs(),
queryFn: async ({ signal }) =>
chatFaqsResponseSchema.parse(
await api.get<unknown>("/v1/app/chat/faqs", { signal }),
),
}),
};
Loading