Skip to content

Commit 1d51f23

Browse files
author
haitaoo
committed
fix(useCaptchaModal): CAPTCHA popup closes with all intermediate states cleaned up.
1 parent 9184b9b commit 1d51f23

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

ui/src/hooks/useCaptchaModal/index.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ const Index = (captchaKey: CaptchaKey) => {
6464
});
6565
};
6666

67+
const resetImgCode = () => {
68+
setImgCode({
69+
value: '',
70+
isInvalid: false,
71+
errorMsg: '',
72+
});
73+
};
74+
const resetCallback = () => {
75+
refCallback.current = undefined;
76+
};
77+
6778
const show = () => {
6879
if (!stateShow) {
6980
setStateShow(true);
@@ -76,11 +87,12 @@ const Index = (captchaKey: CaptchaKey) => {
7687
* and the `captchaModal.close()` call is inside the child component.
7788
* In this case, call `await captchaModal.close()` and wait for the close action to complete.
7889
*/
79-
const close = (reset = true) => {
90+
const close = () => {
8091
setStateShow(false);
81-
if (reset) {
82-
resetCapture();
83-
}
92+
resetCapture();
93+
resetImgCode();
94+
resetCallback();
95+
8496
const p = new Promise<void>((resolve) => {
8597
setTimeout(resolve, 50);
8698
});
@@ -109,11 +121,6 @@ const Index = (captchaKey: CaptchaKey) => {
109121
fetchCaptchaData();
110122
show();
111123
} else {
112-
setImgCode({
113-
...ri,
114-
isInvalid: false,
115-
errorMsg: '',
116-
});
117124
close();
118125
}
119126
// Assist business logic in filtering CAPTCHA error messages when necessary
@@ -178,7 +185,7 @@ const Index = (captchaKey: CaptchaKey) => {
178185
size="sm"
179186
title="Captcha"
180187
show={stateShow}
181-
onHide={() => close(false)}
188+
onHide={() => close()}
182189
centered>
183190
<Modal.Header closeButton>
184191
<Modal.Title as="h5">{t('title')}</Modal.Title>

0 commit comments

Comments
 (0)