1
+ import { isAxiosError } from 'axios' ;
1
2
import { motion } from 'motion/react' ;
2
3
import { useRef , useState } from 'react' ;
3
4
import { GrValidate } from 'react-icons/gr' ;
4
5
import { IoClose , IoShareSocialOutline } from 'react-icons/io5' ;
5
6
6
7
import { useModal } from '@/features/modal' ;
7
- import { useSessionStore } from '@/features/session' ;
8
+ import { postSessionTerminate , useSessionStore } from '@/features/session' ;
8
9
import { useToastStore } from '@/features/toast' ;
9
10
10
11
import {
11
12
Button ,
12
13
CreateQuestionModal ,
13
14
SessionParticipantsModal ,
14
15
} from '@/components' ;
16
+ import SessionTerminateModal from '@/components/modal/SessionTerminateModal' ;
15
17
import QuestionSection from '@/components/qna/QuestionSection' ;
16
18
import SessionSettingsDropdown from '@/components/qna/SessionSettingsDropdown' ;
17
19
@@ -22,6 +24,8 @@ function QuestionList() {
22
24
questions,
23
25
sessionId,
24
26
sessionTitle,
27
+ sessionToken,
28
+ setExpired,
25
29
setSelectedQuestionId,
26
30
} = useSessionStore ( ) ;
27
31
@@ -35,6 +39,36 @@ function QuestionList() {
35
39
openModal : openSessionParticipantsModal ,
36
40
} = useModal ( < SessionParticipantsModal /> ) ;
37
41
42
+ const { Modal : SessionTerminate , openModal : openSessionTerminateModal } =
43
+ useModal (
44
+ < SessionTerminateModal
45
+ onConfirm = { ( ) => {
46
+ if ( ! sessionId || ! sessionToken ) return ;
47
+
48
+ postSessionTerminate ( { sessionId, token : sessionToken } )
49
+ . then ( ( response ) => {
50
+ if ( response . expired ) {
51
+ setExpired ( true ) ;
52
+ addToast ( {
53
+ type : 'SUCCESS' ,
54
+ message : '세션이 종료되었습니다' ,
55
+ duration : 3000 ,
56
+ } ) ;
57
+ }
58
+ } )
59
+ . catch ( ( err ) => {
60
+ if ( isAxiosError ( err ) && err . response ?. status === 403 ) {
61
+ addToast ( {
62
+ type : 'ERROR' ,
63
+ message : '세션 생성자만 세션을 종료할 수 있습니다' ,
64
+ duration : 3000 ,
65
+ } ) ;
66
+ }
67
+ } ) ;
68
+ } }
69
+ /> ,
70
+ ) ;
71
+
38
72
const [ isDropdownOpen , setIsDropdownOpen ] = useState ( false ) ;
39
73
40
74
const buttonRef = useRef < HTMLButtonElement > ( null ) ;
@@ -98,7 +132,7 @@ function QuestionList() {
98
132
{
99
133
icon : < IoClose /> ,
100
134
label : '세션 종료' ,
101
- onClick : ( ) => { } ,
135
+ onClick : ( ) => openSessionTerminateModal ( ) ,
102
136
} ,
103
137
] ;
104
138
@@ -150,6 +184,7 @@ function QuestionList() {
150
184
</ div >
151
185
{ CreateQuestion }
152
186
{ SessionParticipants }
187
+ { SessionTerminate }
153
188
</ >
154
189
) ;
155
190
}
0 commit comments