Merge pull request #457 from answerdev/feat/1.1.1/ui

fix(useCaptchaModal): CAPTCHA popup closes with all intermediate stat…
This commit is contained in:
haitao.jarvis 2023-08-02 10:37:27 +08:00 committed by GitHub
commit 2dc23c7f15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 10 deletions

View File

@ -64,6 +64,17 @@ const Index = (captchaKey: CaptchaKey) => {
});
};
const resetImgCode = () => {
setImgCode({
value: '',
isInvalid: false,
errorMsg: '',
});
};
const resetCallback = () => {
refCallback.current = undefined;
};
const show = () => {
if (!stateShow) {
setStateShow(true);
@ -76,11 +87,12 @@ const Index = (captchaKey: CaptchaKey) => {
* and the `captchaModal.close()` call is inside the child component.
* In this case, call `await captchaModal.close()` and wait for the close action to complete.
*/
const close = (reset = true) => {
const close = () => {
setStateShow(false);
if (reset) {
resetCapture();
}
resetCapture();
resetImgCode();
resetCallback();
const p = new Promise<void>((resolve) => {
setTimeout(resolve, 50);
});
@ -109,11 +121,6 @@ const Index = (captchaKey: CaptchaKey) => {
fetchCaptchaData();
show();
} else {
setImgCode({
...ri,
isInvalid: false,
errorMsg: '',
});
close();
}
// Assist business logic in filtering CAPTCHA error messages when necessary
@ -178,7 +185,7 @@ const Index = (captchaKey: CaptchaKey) => {
size="sm"
title="Captcha"
show={stateShow}
onHide={() => close(false)}
onHide={() => close()}
centered>
<Modal.Header closeButton>
<Modal.Title as="h5">{t('title')}</Modal.Title>