From f5fabec23de468232f492a3e11072800aaa895d3 Mon Sep 17 00:00:00 2001 From: s0zzang Date: Mon, 18 Nov 2024 20:32:06 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Feat:=20=EC=8B=AC=EB=A6=AC=EC=83=81?= =?UTF-8?q?=EB=8B=B4=20=ED=94=84=EB=A1=AC=ED=94=84=ED=8A=B8=EC=97=90=20?= =?UTF-8?q?=EC=B5=9C=EA=B7=BC=20=EB=82=9C=EC=9E=84=EC=B2=99=EB=8F=84=20?= =?UTF-8?q?=EC=A0=90=EC=88=98=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/counseling/Counseling.tsx | 33 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/pages/counseling/Counseling.tsx b/src/pages/counseling/Counseling.tsx index a20b7cc..476b4f3 100644 --- a/src/pages/counseling/Counseling.tsx +++ b/src/pages/counseling/Counseling.tsx @@ -25,10 +25,11 @@ interface CounselData { const Counseling = () => { const member_id = Number(localStorage.getItem('MemberId')); + const [scaleData, setScaleData] = useState({ total: 0, belifs: '' }); const userData = { name: localStorage.getItem('userName'), - total: '180점', - faith: '나는 살아갈 가치가 없는 사람이다, 결혼한 부부는 아이가 꼭 있어야 한다.', + total: `${scaleData.total}/230`, + belifs: scaleData.belifs, }; const scrollBoxRef = useRef(null); const [messages, setMessages] = useState([]); @@ -46,7 +47,7 @@ const Counseling = () => { 1. 사용자 특성: - 이름: ${userData.name} - 난임 스트레스 척도 점수: 230점 만점의 ${userData.total} - - 난임 스트레스 척도로 평가된 핵심 신념: ${userData.faith} + - 난임 스트레스 척도로 평가된 핵심 신념: ${userData.belifs} 2. 상담 목표: 인지적 왜곡 및 부정적 자동적 사고를 탐색하여 핵심 신념 반박 3. 대화 횟수: ${dataForPrompt.count} 4. 사례개념화: ${dataForPrompt.caseFoumulation} @@ -87,7 +88,7 @@ const Counseling = () => { setMessages((prev) => [...prev, { sender, message }]); }; - const handleSubmit = async (e: FormEvent) => { + const handleChat = async (e: FormEvent) => { e.preventDefault(); // 사용자 입력란이 공백일 경우 함수 실행 X @@ -128,6 +129,23 @@ const Counseling = () => { const now = new Date(); const toDay = formatDate(now); + const fetchScaleData = async () => { + try { + const { data } = await axios.get('/infertility/tests/', { + params: { memberId: member_id }, + headers: { + 'content-type': 'application/json', + accept: 'application/json', + }, + }); + setScaleData({ total: data.result.totalTests[0].total, belifs: data.result.totalTests[0].belifs }); + return data.result.totalTests[0]; + } catch (err) { + console.error('Failed to POST scaleList: ', err); + return null; + } + }; + const fetchCounselResult = async (body: CounselData) => { try { const response = await axios.post('/counsels/records/', body, { @@ -153,7 +171,6 @@ const Counseling = () => { const response = await fetchGPT(prompt, dataForPrompt.summary); const { summary, tags } = JSON.parse(response.choices[0].message.content); const fetchRes = await fetchCounselResult({ member_id, summary, tags, count: 1 }); - console.log(fetchRes); if (fetchRes && fetchRes.status === 201) setModal(true); }; @@ -187,6 +204,10 @@ const Counseling = () => { moveScrollDown(); }, [messages]); + useEffect(() => { + fetchScaleData(); + }, []); + return ( <> {guideVisible && } @@ -234,7 +255,7 @@ const Counseling = () => { -
handleSubmit(e)}> + handleChat(e)}> setUserInput(e.target.value)} />