@@ -4,11 +4,7 @@ import Markdown from 'react-markdown';
44
55import { useModalContext } from '@/features/modal' ;
66import { useSessionStore } from '@/features/session' ;
7- import {
8- patchQuestionBody ,
9- postQuestion ,
10- Question ,
11- } from '@/features/session/qna' ;
7+ import { patchQuestionBody , postQuestion , Question } from '@/features/session/qna' ;
128import { useToastStore } from '@/features/toast' ;
139
1410import { Button } from '@/components' ;
@@ -22,58 +18,45 @@ function CreateQuestionModal({ question }: CreateQuestionModalProps) {
2218
2319 const { closeModal } = useModalContext ( ) ;
2420
25- const { sessionId, sessionToken, expired, addQuestion, updateQuestion } =
26- useSessionStore ( ) ;
21+ const { sessionId, sessionToken, expired, addQuestion, updateQuestion } = useSessionStore ( ) ;
2722
2823 const [ body , setBody ] = useState ( '' ) ;
2924
30- const { mutate : postQuestionQuery , isPending : isPostInProgress } =
31- useMutation ( {
32- mutationFn : postQuestion ,
33- onSuccess : ( response ) => {
34- addQuestion ( response . question ) ;
35- addToast ( {
36- type : 'SUCCESS' ,
37- message : '질문이 성공적으로 등록되었습니다.' ,
38- duration : 3000 ,
39- } ) ;
40- closeModal ( ) ;
41- } ,
42- onError : console . error ,
43- } ) ;
25+ const { mutate : postQuestionQuery , isPending : isPostInProgress } = useMutation ( {
26+ mutationFn : postQuestion ,
27+ onSuccess : ( response ) => {
28+ addQuestion ( response . question ) ;
29+ addToast ( {
30+ type : 'SUCCESS' ,
31+ message : '질문이 성공적으로 등록되었습니다.' ,
32+ duration : 3000 ,
33+ } ) ;
34+ closeModal ( ) ;
35+ } ,
36+ onError : console . error ,
37+ } ) ;
4438
45- const { mutate : patchQuestionBodyQuery , isPending : isPatchInProgress } =
46- useMutation ( {
47- mutationFn : ( params : {
48- questionId : number ;
49- token : string ;
50- sessionId : string ;
51- body : string ;
52- } ) =>
53- patchQuestionBody ( params . questionId , {
54- token : params . token ,
55- sessionId : params . sessionId ,
56- body : params . body ,
57- } ) ,
58- onSuccess : ( response ) => {
59- updateQuestion ( response . question ) ;
60- addToast ( {
61- type : 'SUCCESS' ,
62- message : '질문이 성공적으로 수정되었습니다.' ,
63- duration : 3000 ,
64- } ) ;
65- closeModal ( ) ;
66- } ,
67- onError : console . error ,
68- } ) ;
39+ const { mutate : patchQuestionBodyQuery , isPending : isPatchInProgress } = useMutation ( {
40+ mutationFn : ( params : { questionId : number ; token : string ; sessionId : string ; body : string } ) =>
41+ patchQuestionBody ( params . questionId , {
42+ token : params . token ,
43+ sessionId : params . sessionId ,
44+ body : params . body ,
45+ } ) ,
46+ onSuccess : ( response ) => {
47+ updateQuestion ( response . question ) ;
48+ addToast ( {
49+ type : 'SUCCESS' ,
50+ message : '질문이 성공적으로 수정되었습니다.' ,
51+ duration : 3000 ,
52+ } ) ;
53+ closeModal ( ) ;
54+ } ,
55+ onError : console . error ,
56+ } ) ;
6957
7058 const submitDisabled =
71- expired ||
72- body . trim ( ) . length === 0 ||
73- ! sessionId ||
74- ! sessionToken ||
75- isPostInProgress ||
76- isPatchInProgress ;
59+ expired || body . trim ( ) . length === 0 || ! sessionId || ! sessionToken || isPostInProgress || isPatchInProgress ;
7760
7861 const handleSubmit = ( ) => {
7962 if ( submitDisabled ) return ;
@@ -113,9 +96,7 @@ function CreateQuestionModal({ question }: CreateQuestionModalProps) {
11396 />
11497 < div className = 'inline-flex shrink grow basis-0 flex-col items-start justify-start gap-2 self-stretch overflow-y-auto rounded border border-gray-200 bg-white p-4' >
11598 < Markdown className = 'prose prose-stone flex w-full flex-col gap-3 prose-img:rounded-md' >
116- { body . length === 0
117- ? `**질문을 남겨주세요**\n\n**(마크다운 지원)**`
118- : body }
99+ { body . length === 0 ? `**질문을 남겨주세요**\n\n**(마크다운 지원)**` : body }
119100 </ Markdown >
120101 </ div >
121102 </ div >
@@ -128,9 +109,7 @@ function CreateQuestionModal({ question }: CreateQuestionModalProps) {
128109 className = { `${ ! submitDisabled ? 'bg-indigo-600' : 'cursor-not-allowed bg-indigo-300' } ` }
129110 onClick = { handleSubmit }
130111 >
131- < div className = 'text-sm font-bold text-white' >
132- { question ? '수정하기' : '생성하기' }
133- </ div >
112+ < div className = 'text-sm font-bold text-white' > { question ? '수정하기' : '생성하기' } </ div >
134113 </ Button >
135114 </ div >
136115 </ div >
0 commit comments