@@ -30,29 +30,31 @@ function ChatSection() {
3030 } > ( { } ) ;
3131
3232 const handleSendMessage = async ( payload : stepPayload | { message : string ; userId : string } ) => {
33- const typingTimer = setTimeout ( ( ) => setIsBotTyping ( true ) , 300 ) ;
33+ // Typing 임시메시지
34+ setMessages ( ( prev ) => [
35+ ...prev ,
36+ {
37+ id : 'typing' ,
38+ sender : 'CHATBOT' ,
39+ type : 'TYPING' ,
40+ message : '' ,
41+ createdAt : new Date ( ) . toISOString ( ) ,
42+ } ,
43+ ] ) ;
3444
3545 try {
36- if ( ! ( 'currentStep' in payload ) ) {
37- const botMessage = await fetchSendTextMessage ( payload ) ;
38- clearTimeout ( typingTimer ) ;
39- setIsBotTyping ( false ) ;
40-
41- if ( ! botMessage ) return ;
42- setTimeout ( ( ) => setMessages ( ( prev ) => [ ...prev , botMessage ] ) , 500 ) ;
43- return ;
44- }
45-
46- const botMessage = await fetchSendStepMessage ( payload ) ;
47- clearTimeout ( typingTimer ) ;
48- setIsBotTyping ( false ) ;
46+ const botMessage =
47+ 'currentStep' in payload
48+ ? await fetchSendStepMessage ( payload )
49+ : await fetchSendTextMessage ( payload ) ;
4950
5051 if ( ! botMessage ) return ;
51- setTimeout ( ( ) => setMessages ( ( prev ) => [ ...prev , botMessage ] ) , 500 ) ;
52+
53+ // Typing 임시메시지 제거 후 실제 메시지 추가
54+ setMessages ( ( prev ) => [ ...prev . filter ( ( m ) => m . type !== 'TYPING' ) , botMessage ] ) ;
5255 } catch ( err ) {
53- clearTimeout ( typingTimer ) ;
54- setIsBotTyping ( false ) ;
5556 console . error ( err ) ;
57+ setMessages ( ( prev ) => prev . filter ( ( m ) => m . type !== 'TYPING' ) ) ;
5658 }
5759 } ;
5860
@@ -70,7 +72,16 @@ function ChatSection() {
7072 { id : tempId , userId, message, sender : 'USER' , type : 'text' , createdAt : tempCreatedAt } ,
7173 ] ) ;
7274
73- await handleSendMessage ( { message, userId } ) ;
75+ const nextStep = userCurrentStep === 3 ? userCurrentStep + 1 : userCurrentStep ;
76+
77+ const payload : stepPayload = {
78+ currentStep : nextStep ,
79+ message,
80+ userId,
81+ ...selectedOptions . current ,
82+ } ;
83+
84+ await handleSendMessage ( payload ) ;
7485 } ;
7586
7687 // 옵션 클릭 시
0 commit comments