diff --git a/src/hooks/use-html-file-submit.hooks.ts b/src/hooks/use-html-file-submit.hooks.ts index eeb1afe..4829cba 100644 --- a/src/hooks/use-html-file-submit.hooks.ts +++ b/src/hooks/use-html-file-submit.hooks.ts @@ -11,7 +11,7 @@ export const useHtmlFileSubmit = (type: string, category: string, html_file: Fil console.log(formdata.get('category')); console.log(formdata.get('html_file')); try { - const response = await llm_axiosInstance.post('/upload_html/', formdata, { + const response = await llm_axiosInstance.post('/upload_pdf/', formdata, { headers: { 'Content-Type': 'multipart/form-data', }, diff --git a/src/store/admin/check-question-answer-store.ts b/src/store/admin/check-question-answer-store.ts new file mode 100644 index 0000000..b66ec8a --- /dev/null +++ b/src/store/admin/check-question-answer-store.ts @@ -0,0 +1,40 @@ +import { create } from 'zustand'; + +export interface QuestionAnswerState { + id: number; + content: string; + viewCount: string; + isChecked: boolean; + answer: { + id: number; + content: string; + }; +} + +interface CheckQuestionAnswerState { + questionData: QuestionAnswerState[]; + updateQuestionData: (firstData: QuestionAnswerState[]) => void; //처음 데이터를 삽입할 때 사용하는 거 + inputQuestionData: (data: QuestionAnswerState) => void; //커스텀 질문 생성시 사용하는거 + updateCheck: (id: number, isChecked: boolean) => void; //질문-답변 상태 확인할 때 사용 + updateAnswer: (answerId: number, answerContent: string) => void; //답변 내용 변경할 때 사용 +} + +const useCheckQuestionAnswerStore = create((set) => ({ + questionData: [], + updateQuestionData: (firstData) => set({ questionData: firstData }), + inputQuestionData: (data) => set((state) => ({ questionData: [...state.questionData, data] })), + updateCheck: (id, isChecked) => + set((state) => ({ + questionData: state.questionData.map((question) => (question.id === id ? { ...question, isChecked } : question)), + })), + updateAnswer: (answerId, answerContent) => + set((state) => ({ + questionData: state.questionData.map((question) => + question.answer.id === answerId + ? { ...question, answer: { ...question.answer, content: answerContent } } + : question, + ), + })), +})); + +export default useCheckQuestionAnswerStore; diff --git a/src/store/chat-store.ts b/src/store/chat-store.ts index 78b0f48..2303cbb 100644 --- a/src/store/chat-store.ts +++ b/src/store/chat-store.ts @@ -1,11 +1,11 @@ import { create } from 'zustand'; interface ChatState { - messages: { content: string; role: 'user' | 'system' }[]; - loading: boolean; - addMessage: (message: { content: string; role: 'user' | 'system' }) => void; + messages: { content: string; role: 'user' | 'system' }[]; //사용자와 시스템 메시지가 저장되는 배열 + loading: boolean; //답변이 오는 기간동안 로딩상태 파악 위한 것으로, 스피너에 적용 + addMessage: (message: { content: string; role: 'user' | 'system' }) => void; //새로운 메시지가 들어올때 사용 setLoading: (loading: boolean) => void; - updateLastMessage: (content: string) => void; + updateLastMessage: (content: string) => void; //유저가 새로운 질문을 할 때 화면에 보여지기 위해 사용되는 함수 } const useChatStore = create((set) => ({ diff --git a/src/ui/components/admin/modal/edit-modal.tsx b/src/ui/components/admin/modal/edit-modal.tsx index c4b27b7..ab11af0 100644 --- a/src/ui/components/admin/modal/edit-modal.tsx +++ b/src/ui/components/admin/modal/edit-modal.tsx @@ -3,29 +3,26 @@ import TextArea from 'antd/es/input/TextArea'; import React, { useState } from 'react'; import { AdminEditAnswer } from '../../../../api/admin-edit-answer'; import { AdminCheckQuestionAnswer } from '../../../../api/admin-check-question-answer'; +import useCheckQuestionAnswerStore from '../../../../store/admin/check-question-answer-store'; interface CustomModalProps { open: boolean; setOpen: React.Dispatch>; - modalTitle: string; - modalContent: string; - modalContentId: number; questionId: number; - isChecked: boolean; } -const EditModal = ({ - open, - setOpen, - modalTitle, - modalContent, - modalContentId, - questionId, - isChecked, -}: CustomModalProps) => { +const EditModal = ({ open, setOpen, questionId }: CustomModalProps) => { + const { questionData, updateCheck, updateAnswer } = useCheckQuestionAnswerStore(); + const question = questionData.find((question) => question.id === questionId); + + if (!question) { + return null; + } + + const { content: modalTitle, answer, isChecked } = question; const [editStatus, setEditStatus] = useState(false); const [loading, setLoading] = useState(false); - const [content, setContent] = useState(modalContent); + const [content, setContent] = useState(answer.content); const executeWithLoading = async (action: () => Promise) => { setLoading(true); @@ -41,8 +38,12 @@ const EditModal = ({ const handleEditSubmit = async () => { try { await executeWithLoading(async () => { - await AdminEditAnswer(modalContentId, content); - await AdminCheckQuestionAnswer({ questionId, check: true }); + await AdminEditAnswer(answer.id, content); + updateAnswer(answer.id, content); + if (!isChecked) { + await AdminCheckQuestionAnswer({ questionId, check: true }); + updateCheck(questionId, true); + } }); } catch (err) { setEditStatus(false); @@ -51,8 +52,10 @@ const EditModal = ({ }; const handleCheckToggle = async () => { + const newCheckStatus = !isChecked; await executeWithLoading(async () => { - await AdminCheckQuestionAnswer({ questionId, check: !isChecked }); + await AdminCheckQuestionAnswer({ questionId, check: newCheckStatus }); + updateCheck(questionId, newCheckStatus); }); }; @@ -86,7 +89,6 @@ const EditModal = ({ 질문-답변 미확인 상태 변경 ), - editStatus ? (