From e05a6a3de164028641a99d8e21d60ac309bc493d Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 4 Dec 2024 17:47:50 +0100 Subject: [PATCH] fix: [IOCOM-1994,IOCOM-1995] Fix for back behaviours on FIMS Auth (#6481) ## Short description This PR fixes some anomalies on the back behaviour for the FIMS' Auth flow ## List of changes proposed in this pull request - When going back from an error screen, proper deallocation of FIMS resources was not triggered (using navigation.back instead of back saga) - On Android, physical back button event is not handled by the assistance modal and is propagated to the underlying screen. If this happens on the FIMS' consents screen, the flow is interrupted. Since this anomaly affects the entire app, the back capturing has been disabled and the user has to rely on the UI back buttons ## How to test Using the io-dev-api-server, check that: - the FIMS flow can be successfully retried after an error - the Android back button does nothing on the FIMS' Auth flow Co-authored-by: Martino Cesari Tomba <60693085+forrest57@users.noreply.github.com> --- .../components/FimsFullScreenErrors.tsx | 19 +++++++++++++------ .../screens/FimsFlowHandlerScreen.tsx | 12 +++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ts/features/fims/singleSignOn/components/FimsFullScreenErrors.tsx b/ts/features/fims/singleSignOn/components/FimsFullScreenErrors.tsx index b6015928a18..4aeca1ab908 100644 --- a/ts/features/fims/singleSignOn/components/FimsFullScreenErrors.tsx +++ b/ts/features/fims/singleSignOn/components/FimsFullScreenErrors.tsx @@ -1,21 +1,22 @@ -import { useNavigation } from "@react-navigation/native"; import * as React from "react"; import { OperationResultScreenContent, OperationResultScreenContentProps } from "../../../../components/screens/OperationResultScreenContent"; import I18n from "../../../../i18n"; -import { useIOSelector } from "../../../../store/hooks"; +import { useIODispatch, useIOSelector } from "../../../../store/hooks"; import { fimsAuthenticationErrorTagSelector, fimsDebugDataSelector } from "../store/selectors"; import { useDebugInfo } from "../../../../hooks/useDebugInfo"; +import { fimsCancelOrAbortAction } from "../store/actions"; export const FimsSSOFullScreenError = () => { - const navigation = useNavigation(); + const dispatch = useIODispatch(); const errorTag = useIOSelector(fimsAuthenticationErrorTagSelector); const debugData = useIOSelector(fimsDebugDataSelector); + const debugInfo = React.useMemo( () => ({ fimsFailure: `${errorTag}: ${debugData}` @@ -23,6 +24,12 @@ export const FimsSSOFullScreenError = () => { [debugData, errorTag] ); useDebugInfo(debugInfo); + + const handleClose = React.useCallback( + () => dispatch(fimsCancelOrAbortAction()), + [dispatch] + ); + const getErrorComponentProps = (): OperationResultScreenContentProps => { switch (errorTag) { case "AUTHENTICATION": @@ -35,7 +42,7 @@ export const FimsSSOFullScreenError = () => { pictogram: "umbrellaNew", action: { label: I18n.t("global.buttons.close"), - onPress: navigation.goBack + onPress: handleClose } }; case "MISSING_INAPP_BROWSER": @@ -50,7 +57,7 @@ export const FimsSSOFullScreenError = () => { pictogram: "updateOS", action: { label: I18n.t("global.buttons.close"), - onPress: navigation.goBack + onPress: handleClose } }; default: @@ -61,7 +68,7 @@ export const FimsSSOFullScreenError = () => { pictogram: "umbrellaNew", action: { label: I18n.t("global.buttons.close"), - onPress: navigation.goBack + onPress: handleClose } }; } diff --git a/ts/features/fims/singleSignOn/screens/FimsFlowHandlerScreen.tsx b/ts/features/fims/singleSignOn/screens/FimsFlowHandlerScreen.tsx index 81629f1c4f5..d6ca4ad1067 100644 --- a/ts/features/fims/singleSignOn/screens/FimsFlowHandlerScreen.tsx +++ b/ts/features/fims/singleSignOn/screens/FimsFlowHandlerScreen.tsx @@ -1,6 +1,6 @@ import { Body, IOStyles } from "@pagopa/io-app-design-system"; import * as pot from "@pagopa/ts-commons/lib/pot"; -import { pipe } from "fp-ts/lib/function"; +import { constTrue, pipe } from "fp-ts/lib/function"; import * as O from "fp-ts/Option"; import * as React from "react"; import { View } from "react-native"; @@ -64,10 +64,12 @@ export const FimsFlowHandlerScreen = ( goBack: handleCancelOrAbort }); - useHardwareBackButton(() => { - handleCancelOrAbort(); - return true; - }); + // Force users on Android to use UI buttons to go back, since + // there are cases where a modal may be displayed on top of + // the screen (like the assistance one) and the hardware back + // button event is not stopped by such screen but is instead + // propagated to this UI, causing a back loop + useHardwareBackButton(constTrue); React.useEffect(() => { if (ctaUrl && !requiresAppUpdate) {