From 17dee17e2c4178b90ad11ea2c7548ab59a35e698 Mon Sep 17 00:00:00 2001 From: asaei623 <86418308+asaei623@users.noreply.github.com> Date: Mon, 25 Sep 2023 17:14:29 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A0=9C=EB=AA=A9=EC=9D=B4=205=EC=9E=90?= =?UTF-8?q?=20=EB=AF=B8=EB=A7=8C=EC=9D=B4=EC=97=AC=EB=8F=84=20=EC=A7=88?= =?UTF-8?q?=EB=AC=B8=EC=9D=B4=20=EB=93=B1=EB=A1=9D=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/WriteConfirmBar.tsx | 36 ++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/components/common/WriteConfirmBar.tsx b/src/components/common/WriteConfirmBar.tsx index 350377d..7156219 100644 --- a/src/components/common/WriteConfirmBar.tsx +++ b/src/components/common/WriteConfirmBar.tsx @@ -18,16 +18,34 @@ const WriteConfirmBar = ({ postIdx }: { postIdx?: number }) => { //onClick const onClickWrite = () => { let message, destination: string, api: any, successMsg: string; - + const questionApi = async () => { + try { + let res = await postQuestionApi({ title, category, content }); + if (res.isSuccess) { + alert(successMsg); + navigate(destination); + } + } catch (err) {} + }; + const answerApi = async () => { + try { + let res = await postAnswerApi({ + postIdx: postIdx ? postIdx : -1, + answer: content, + }); + if (res.isSuccess) { + alert(successMsg); + navigate(destination); + } + } catch (err) {} + }; if (currentURI === '/ask/write') { message = '질문을 등록하시겠습니까?'; destination = '/ask'; - api = postQuestionApi({ title, category, content }); successMsg = '질문이 등록되었습니다.'; } else { message = '답변을 등록하시겠습니까?'; destination = '/answer'; - api = postIdx ? postAnswerApi({ postIdx, answer: content }) : ''; successMsg = '답변이 등록되었습니다.'; } @@ -38,17 +56,7 @@ const WriteConfirmBar = ({ postIdx }: { postIdx?: number }) => { } else if (content.length < 10) { alert('내용을 10자 이상 입력해주세요.'); } else { - const postApi = async () => { - try { - let res = await api; - if (res.isSuccess) { - alert(successMsg); - navigate(destination); - } - } catch (err) {} - }; - - postApi(); + currentURI === '/ask/write' ? questionApi() : answerApi(); } } };