mirror of https://gitee.com/answerdev/answer.git
fix(Question): Handle unexpected state handling issues when CAPTCHA and draft functions are mixed together.
This commit is contained in:
parent
601721a921
commit
9184b9b416
|
@ -192,7 +192,7 @@ const Comment = ({ objectId, mode, commentId }) => {
|
||||||
if (ex.isError) {
|
if (ex.isError) {
|
||||||
const captchaErr = addCaptcha.handleCaptchaError(ex.list);
|
const captchaErr = addCaptcha.handleCaptchaError(ex.list);
|
||||||
// If it is not a CAPTCHA error, leave it to the subsequent error handling logic to continue processing.
|
// If it is not a CAPTCHA error, leave it to the subsequent error handling logic to continue processing.
|
||||||
if (!captchaErr || captchaErr.error_msg !== ex.msg) {
|
if (!(captchaErr && ex.list.length === 1)) {
|
||||||
return Promise.reject(ex);
|
return Promise.reject(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,6 @@ const Ask = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
contentChangedRef.current = false;
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
|
@ -256,6 +255,7 @@ const Ask = () => {
|
||||||
|
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
editCaptcha.check(() => {
|
editCaptcha.check(() => {
|
||||||
|
contentChangedRef.current = false;
|
||||||
const ep = {
|
const ep = {
|
||||||
...params,
|
...params,
|
||||||
id: qid,
|
id: qid,
|
||||||
|
@ -283,6 +283,7 @@ const Ask = () => {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
saveCaptcha.check(async () => {
|
saveCaptcha.check(async () => {
|
||||||
|
contentChangedRef.current = false;
|
||||||
const imgCode = saveCaptcha.getCaptcha();
|
const imgCode = saveCaptcha.getCaptcha();
|
||||||
if (imgCode.verify) {
|
if (imgCode.verify) {
|
||||||
params.captcha_code = imgCode.captcha_code;
|
params.captcha_code = imgCode.captcha_code;
|
||||||
|
@ -295,26 +296,22 @@ const Ask = () => {
|
||||||
answer_content: formData.answer_content.value,
|
answer_content: formData.answer_content.value,
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
if (err.isError) {
|
if (err.isError) {
|
||||||
saveCaptcha.handleCaptchaError(err.list);
|
const captchaErr = saveCaptcha.handleCaptchaError(err.list);
|
||||||
|
if (!(captchaErr && err.list.length === 1)) {
|
||||||
const data = handleFormError(err, formData);
|
const data = handleFormError(err, formData);
|
||||||
if (data.keys.includes('captcha')) {
|
|
||||||
delete data.captcha_code;
|
|
||||||
delete data.captcha_id;
|
|
||||||
}
|
|
||||||
setFormData({ ...data });
|
setFormData({ ...data });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res = await saveQuestion(params).catch((err) => {
|
res = await saveQuestion(params).catch((err) => {
|
||||||
if (err.isError) {
|
if (err.isError) {
|
||||||
saveCaptcha.handleCaptchaError(err.list);
|
const captchaErr = saveCaptcha.handleCaptchaError(err.list);
|
||||||
|
if (!(captchaErr && err.list.length === 1)) {
|
||||||
const data = handleFormError(err, formData);
|
const data = handleFormError(err, formData);
|
||||||
if (data.keys.includes('captcha')) {
|
|
||||||
delete data.captcha_code;
|
|
||||||
delete data.captcha_id;
|
|
||||||
}
|
|
||||||
setFormData({ ...data });
|
setFormData({ ...data });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue