Skip to content

Commit 9184b9b

Browse files
author
haitaoo
committed
fix(Question): Handle unexpected state handling issues when CAPTCHA and draft functions are mixed together.
1 parent 601721a commit 9184b9b

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

ui/src/components/Comment/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ const Comment = ({ objectId, mode, commentId }) => {
192192
if (ex.isError) {
193193
const captchaErr = addCaptcha.handleCaptchaError(ex.list);
194194
// If it is not a CAPTCHA error, leave it to the subsequent error handling logic to continue processing.
195-
if (!captchaErr || captchaErr.error_msg !== ex.msg) {
195+
if (!(captchaErr && ex.list.length === 1)) {
196196
return Promise.reject(ex);
197197
}
198198
}

ui/src/pages/Questions/Ask/index.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ const Ask = () => {
244244
};
245245

246246
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
247-
contentChangedRef.current = false;
248247
event.preventDefault();
249248
event.stopPropagation();
250249

@@ -256,6 +255,7 @@ const Ask = () => {
256255

257256
if (isEdit) {
258257
editCaptcha.check(() => {
258+
contentChangedRef.current = false;
259259
const ep = {
260260
...params,
261261
id: qid,
@@ -283,6 +283,7 @@ const Ask = () => {
283283
});
284284
} else {
285285
saveCaptcha.check(async () => {
286+
contentChangedRef.current = false;
286287
const imgCode = saveCaptcha.getCaptcha();
287288
if (imgCode.verify) {
288289
params.captcha_code = imgCode.captcha_code;
@@ -295,25 +296,21 @@ const Ask = () => {
295296
answer_content: formData.answer_content.value,
296297
}).catch((err) => {
297298
if (err.isError) {
298-
saveCaptcha.handleCaptchaError(err.list);
299-
const data = handleFormError(err, formData);
300-
if (data.keys.includes('captcha')) {
301-
delete data.captcha_code;
302-
delete data.captcha_id;
299+
const captchaErr = saveCaptcha.handleCaptchaError(err.list);
300+
if (!(captchaErr && err.list.length === 1)) {
301+
const data = handleFormError(err, formData);
302+
setFormData({ ...data });
303303
}
304-
setFormData({ ...data });
305304
}
306305
});
307306
} else {
308307
res = await saveQuestion(params).catch((err) => {
309308
if (err.isError) {
310-
saveCaptcha.handleCaptchaError(err.list);
311-
const data = handleFormError(err, formData);
312-
if (data.keys.includes('captcha')) {
313-
delete data.captcha_code;
314-
delete data.captcha_id;
309+
const captchaErr = saveCaptcha.handleCaptchaError(err.list);
310+
if (!(captchaErr && err.list.length === 1)) {
311+
const data = handleFormError(err, formData);
312+
setFormData({ ...data });
315313
}
316-
setFormData({ ...data });
317314
}
318315
});
319316
}

0 commit comments

Comments
 (0)