Skip to content

Commit

Permalink
fix: 제목이 5자 미만이여도 질문이 등록되는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
asaei623 committed Sep 25, 2023
1 parent 79497f0 commit 17dee17
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/components/common/WriteConfirmBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '답변이 등록되었습니다.';
}

Expand All @@ -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();
}
}
};
Expand Down

0 comments on commit 17dee17

Please sign in to comment.