From 27b16ef34d122d0b8952cdddb770aee6b44fab67 Mon Sep 17 00:00:00 2001 From: Sachin-Mamoru Date: Mon, 2 Sep 2024 00:11:21 +0530 Subject: [PATCH 1/3] remove the implementation of showing the old qr code --- .../authenticators/totp-authenticator.tsx | 145 +++++++----------- 1 file changed, 57 insertions(+), 88 deletions(-) diff --git a/apps/myaccount/src/components/multi-factor-authentication/authenticators/totp-authenticator.tsx b/apps/myaccount/src/components/multi-factor-authentication/authenticators/totp-authenticator.tsx index 0f387cc779c..e7c631bf5b1 100644 --- a/apps/myaccount/src/components/multi-factor-authentication/authenticators/totp-authenticator.tsx +++ b/apps/myaccount/src/components/multi-factor-authentication/authenticators/totp-authenticator.tsx @@ -19,7 +19,7 @@ import { TestableComponentInterface } from "@wso2is/core/models"; import { GenericIcon, LinkButton, Popup } from "@wso2is/react-components"; import QRCode from "qrcode.react"; -import React, { FormEvent, PropsWithChildren, SyntheticEvent, useEffect, useRef, useState } from "react"; +import React, { PropsWithChildren, ReactElement, SyntheticEvent, useEffect, useRef, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useSelector } from "react-redux"; import { @@ -41,11 +41,9 @@ import { initTOTPCode, refreshTOTPCode, updateEnabledAuthenticators, - validateTOTPCode, - viewTOTPCode + validateTOTPCode } from "../../../api"; import { getMFAIcons } from "../../../configs"; -import { commonConfig } from "../../../extensions"; import { AlertInterface, AlertLevels, @@ -103,8 +101,8 @@ export const TOTPAuthenticator: React.FunctionComponent = ( const [ isTOTPError, setIsTOTPError ] = useState(false); const [ isRevokeTOTPModalOpen, setIsRevokeTOTPModalOpen ] = useState(false); const [ isViewTOTPModalOpen, setIsViewTOTPModalOpen ] = useState(false); + const [ isConfirmRegenerationModalOpen, setIsConfirmRegenerationModalOpen ] = useState(false); const [ viewTOTPModalCurrentStep, setViewTOTPModalCurrentStep ] = useState(0); - const [ isConfirmRegenerate, setIsConfirmRegenerate ] = useState(false); const pinCode1: React.MutableRefObject = useRef(); const pinCode2: React.MutableRefObject = useRef(); @@ -654,39 +652,6 @@ export const TOTPAuthenticator: React.FunctionComponent = ( ); }; - /** - * Handle view TOTP event. - */ - const handleViewTOTP = (): void => { - setIsLoading(true); - viewTOTPCode() - .then((response: any) => { - const qrCodeUrl: string = window.atob(response?.data?.qrCodeUrl); - - setQrCode(qrCodeUrl); - setIsViewTOTPModalOpen(true); - }) - .catch((error: any) => { - onAlertFired({ - description: t(translateKey + "notifications.initError.error.description", { - error - }), - level: AlertLevels.ERROR, - message: t(translateKey + "notifications.initError.error.message") - }); - }) - .finally(() => { - setIsLoading(false); - }); - }; - - /** - * Handle confirm QR code regeneration checkbox event. - */ - const handleConfirmRegenerateQRCode = (_: FormEvent, data: CheckboxProps): void => { - setIsConfirmRegenerate(data.checked ?? false); - }; - /** * Handle regenerate QR code event. */ @@ -697,6 +662,8 @@ export const TOTPAuthenticator: React.FunctionComponent = ( const qrCodeUrl: string = window.atob(response?.data?.qrCodeUrl); setQrCode(qrCodeUrl); + setIsViewTOTPModalOpen(true); + setIsConfirmRegenerationModalOpen(false); setViewTOTPModalCurrentStep(1); }) .catch((errorMessage: any) => { @@ -713,6 +680,49 @@ export const TOTPAuthenticator: React.FunctionComponent = ( }); }; + /** + * Render the totp QR code regenerate confirmation modal + */ + const renderConfirmRegenerateModal = (): ReactElement => { + return ( + + + +

{ t(translateKey + "modals.scan.regenerateConfirmLabel") }

+
+ + + + { t(translateKey + "modals.scan.regenerateWarning.generic") } + + +
+ + setIsConfirmRegenerationModalOpen(false) } + data-testid={ `${testId}-regenerate-confirm-modal-actions-cancel-button` } + > + { t("common:cancel") } + + + +
+ ); + }; + /** * Renders modal content. * @@ -724,59 +734,15 @@ export const TOTPAuthenticator: React.FunctionComponent = ( return (
{ t(translateKey + "modals.scan.heading") }
- - { qrCode - ? - : null - } -
- - - - { t(commonConfig.accountSecurityPage.mfa.totp.regenerateWarning) } - - - { - commonConfig.accountSecurityPage.mfa.totp.showRegenerateConfirmation - ? ( - - ) : null - } -
- - - - - -