From 8a62cbd4ef2fafdf596c58a3a244eb0451f3a035 Mon Sep 17 00:00:00 2001 From: asaei623 <86418308+asaei623@users.noreply.github.com> Date: Mon, 25 Sep 2023 15:20:45 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=B5=9C=EC=86=8C,=20=EC=B5=9C=EB=8C=80?= =?UTF-8?q?=20=EA=B8=80=EC=9E=90=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PostDetail/CommentInputBox.tsx | 43 +++++++++++-------- src/components/common/WriteConfirmBar.tsx | 13 ++++-- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/components/PostDetail/CommentInputBox.tsx b/src/components/PostDetail/CommentInputBox.tsx index b958dd7..bd580ea 100644 --- a/src/components/PostDetail/CommentInputBox.tsx +++ b/src/components/PostDetail/CommentInputBox.tsx @@ -18,28 +18,37 @@ const CommentInputBox = ({ idx }: { idx: number }) => { const [text, setText] = useState(''); const handleChange = (event: React.ChangeEvent) => { const newText = event.target.value; - setText(newText); + //최대 글자 500자 + if (newText.length > 500) { + setText(text); + } else { + setText(newText); + } }; const handleClickSend = async () => { //수정하기 버튼을 누른 경우, 댓글 수정 기능을 수행하도록 변함 - if (editState.editClicked) { - const [content, commentIdx] = [text, editState.commentIdx]; - let res = await editCommentApi({ content, commentIdx }); - - if (res.isSuccess) { - alert('댓글이 수정되었습니다.'); - //새로고침 - resetEditComment(); //recoil atom 리셋 - window.location.reload(); - } + if (text.length < 2) { + alert('내용을 2자 이상 입력해주세요.'); } else { - const [content, postIdx] = [text, idx]; - let res = await postCommentApi({ content, postIdx }); + if (editState.editClicked) { + const [content, commentIdx] = [text, editState.commentIdx]; + let res = await editCommentApi({ content, commentIdx }); + + if (res.isSuccess) { + alert('댓글이 수정되었습니다.'); + //새로고침 + resetEditComment(); //recoil atom 리셋 + window.location.reload(); + } + } else { + const [content, postIdx] = [text, idx]; + let res = await postCommentApi({ content, postIdx }); - if (res.isSuccess) { - alert('댓글이 등록되었습니다.'); - //새로고침 - window.location.reload(); + if (res.isSuccess) { + alert('댓글이 등록되었습니다.'); + //새로고침 + window.location.reload(); + } } } }; diff --git a/src/components/common/WriteConfirmBar.tsx b/src/components/common/WriteConfirmBar.tsx index a83ecfd..350377d 100644 --- a/src/components/common/WriteConfirmBar.tsx +++ b/src/components/common/WriteConfirmBar.tsx @@ -17,29 +17,34 @@ const WriteConfirmBar = ({ postIdx }: { postIdx?: number }) => { //onClick const onClickWrite = () => { - let message, destination: string, api: any; + let message, destination: string, api: any, successMsg: string; if (currentURI === '/ask/write') { message = '질문을 등록하시겠습니까?'; destination = '/ask'; api = postQuestionApi({ title, category, content }); + successMsg = '질문이 등록되었습니다.'; } else { message = '답변을 등록하시겠습니까?'; destination = '/answer'; api = postIdx ? postAnswerApi({ postIdx, answer: content }) : ''; + successMsg = '답변이 등록되었습니다.'; } const result = window.confirm(message); if (result) { - if (title && title.length < 10) { - alert('제목을 10자 이상 입력해주세요.'); + if (title && title.length < 5) { + alert('제목을 5자 이상 입력해주세요.'); } else if (content.length < 10) { alert('내용을 10자 이상 입력해주세요.'); } else { const postApi = async () => { try { let res = await api; - res.isSuccess && navigate(destination); + if (res.isSuccess) { + alert(successMsg); + navigate(destination); + } } catch (err) {} };