diff --git a/src/features/chat/ChatEntryScreen.tsx b/src/features/chat/ChatEntryScreen.tsx index e044df09..5051da89 100644 --- a/src/features/chat/ChatEntryScreen.tsx +++ b/src/features/chat/ChatEntryScreen.tsx @@ -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"; @@ -14,7 +15,6 @@ 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, @@ -22,6 +22,7 @@ import { saveChatSnapshot, } from "@/features/chat/utils/chatSnapshot"; import { useBackNavigation } from "@/hooks/useBackNavigation"; +import { chatQueries } from "@/shared/entities/chat/chatQueries"; // Figma: 챗봇 진입 화면(nodeId 1887:91534)과 챗봇 대화창(1770:63314) — 메시지를 하나라도 // 보내면 진입 화면의 웰컴 문구·그라데이션·추천 질문이 페이드아웃되고 대화창(말풍선 + 응답 @@ -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); @@ -163,15 +166,17 @@ function ChatEntryScreen() { -
- {CHAT_SUGGESTED_QUESTIONS.map((question) => ( - sendMessage(question.text)} - question={question.text} - /> - ))} -
+ {faqs.length > 0 && ( +
+ {faqs.map((faq) => ( + sendMessage(faq.question)} + question={faq.question} + /> + ))} +
+ )}
["chat"] as const, + faqs: () => [...chatKeys.root(), "faqs"] as const, +}; diff --git a/src/shared/entities/chat/chatQueries.ts b/src/shared/entities/chat/chatQueries.ts new file mode 100644 index 00000000..590e0ece --- /dev/null +++ b/src/shared/entities/chat/chatQueries.ts @@ -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("/v1/app/chat/faqs", { signal }), + ), + }), +};