From 8b94deb854f61ada46c60d9c1d4564231e62f3ba Mon Sep 17 00:00:00 2001 From: abhi patel Date: Fri, 2 Feb 2024 21:34:18 +0530 Subject: [PATCH 1/4] added cursor and closehandler --- .../TwoFactorModal/TwoFactorEmailModal.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx index 19074f7f6b34..12526fdd6c66 100644 --- a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx +++ b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx @@ -45,6 +45,17 @@ const TwoFactorEmailModal = ({ onConfirm, onClose, emailOrUsername, invalidAttem }; const id = useUniqueId(); + const onCloseHandler = () => { + try { + if (typeof onClose === 'function') { + onClose(); + // Change the URL without triggering a full page reload + window.location.href = 'http://localhost:3000'; + } + } catch (error) { + console.error('Error in onClose function:', error); + } + }; return ( {t('Invalid_password')}} - + {t('Cloud_resend_email')} From 93c79bfba98a2c1729f6c663ab3d3d117379c587 Mon Sep 17 00:00:00 2001 From: abhi patel Date: Sat, 3 Feb 2024 00:37:53 +0530 Subject: [PATCH 2/4] close button fix --- .../components/TwoFactorModal/TwoFactorEmailModal.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx index 12526fdd6c66..5b2a83ed8cea 100644 --- a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx +++ b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx @@ -49,7 +49,6 @@ const TwoFactorEmailModal = ({ onConfirm, onClose, emailOrUsername, invalidAttem try { if (typeof onClose === 'function') { onClose(); - // Change the URL without triggering a full page reload window.location.href = 'http://localhost:3000'; } } catch (error) { @@ -60,11 +59,10 @@ const TwoFactorEmailModal = ({ onConfirm, onClose, emailOrUsername, invalidAttem return ( } - onCancel={onClose} + onCancel={onCloseHandler} confirmText={t('Verify')} title={t('Two-factor_authentication_email')} - onClose={onClose} - onClick={onCloseHandler} + onClose={onCloseHandler} variant='warning' icon='info' confirmDisabled={!code} From fbc9a6f4c73053ac238065f140818dd06e658bb1 Mon Sep 17 00:00:00 2001 From: rique223 Date: Fri, 2 Feb 2024 18:50:58 -0300 Subject: [PATCH 3/4] fix: :bug: GUI crash when 2fa is canceled/closed Fixed a bug in which the LoginForm would crash upon the cancellation or closure of the 2FA modal. This issue occurred because the "totp-canceled" error was not mapped to the list of errors that could occur with this component. --- .../TwoFactorModal/TwoFactorEmailModal.tsx | 16 +++------------- packages/web-ui-registration/src/LoginForm.tsx | 7 ++++++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx index 5b2a83ed8cea..19074f7f6b34 100644 --- a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx +++ b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx @@ -45,24 +45,14 @@ const TwoFactorEmailModal = ({ onConfirm, onClose, emailOrUsername, invalidAttem }; const id = useUniqueId(); - const onCloseHandler = () => { - try { - if (typeof onClose === 'function') { - onClose(); - window.location.href = 'http://localhost:3000'; - } - } catch (error) { - console.error('Error in onClose function:', error); - } - }; return ( } - onCancel={onCloseHandler} + onCancel={onClose} confirmText={t('Verify')} title={t('Two-factor_authentication_email')} - onClose={onCloseHandler} + onClose={onClose} variant='warning' icon='info' confirmDisabled={!code} @@ -78,7 +68,7 @@ const TwoFactorEmailModal = ({ onConfirm, onClose, emailOrUsername, invalidAttem {invalidAttempt && {t('Invalid_password')}} - + {t('Cloud_resend_email')} diff --git a/packages/web-ui-registration/src/LoginForm.tsx b/packages/web-ui-registration/src/LoginForm.tsx index 55c638df6707..3290b9f16191 100644 --- a/packages/web-ui-registration/src/LoginForm.tsx +++ b/packages/web-ui-registration/src/LoginForm.tsx @@ -56,7 +56,7 @@ const LOGIN_SUBMIT_ERRORS = { }, } as const; -export type LoginErrors = keyof typeof LOGIN_SUBMIT_ERRORS; +export type LoginErrors = keyof typeof LOGIN_SUBMIT_ERRORS | 'totp-canceled'; export const LoginForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRouter }): ReactElement => { const { @@ -111,7 +111,12 @@ export const LoginForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRoute }, [errorOnSubmit]); const renderErrorOnSubmit = (error: LoginErrors) => { + if (error === 'totp-canceled') { + return null; + } + const { type, i18n } = LOGIN_SUBMIT_ERRORS[error]; + return ( {t(i18n)} From 98098c1f4b9f278b4f0304d03baed8f807d1d93b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Guimar=C3=A3es=20Ribeiro?= Date: Fri, 2 Feb 2024 20:54:49 -0300 Subject: [PATCH 4/4] Create tall-bears-compete.md --- .changeset/tall-bears-compete.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tall-bears-compete.md diff --git a/.changeset/tall-bears-compete.md b/.changeset/tall-bears-compete.md new file mode 100644 index 000000000000..6929ba4d0afd --- /dev/null +++ b/.changeset/tall-bears-compete.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/web-ui-registration": patch +--- + +Fixed a bug that caused the Login page to crash when closing the Two-Factor Authentication modal using the Cancel button or the X button.