diff --git a/src/components/Connection/ConnectionResult.tsx b/src/components/Connection/ConnectionResult.tsx index c3560ac13c6d4128400fe0df8daa087362691340..755e9bf6fadcfb431bbb21466ab5dd139ff1e37e 100644 --- a/src/components/Connection/ConnectionResult.tsx +++ b/src/components/Connection/ConnectionResult.tsx @@ -132,6 +132,7 @@ const ConnectionResult: React.FC<ConnectionResultProps> = ({ dataConsent: true, pdlConfirm: true, shouldLaunchAccount: true, + openSGEForm: false, }) ) dispatch(setShouldRefreshConsent(true)) diff --git a/src/components/Connection/SGEConnect/SgeConnectView.tsx b/src/components/Connection/SGEConnect/SgeConnectView.tsx index 7c9c17f7fef45037d45f17ec147cf1dd225de6d0..9ae0721c9d21c9d7044e4c6594a31e8cb8f9483d 100644 --- a/src/components/Connection/SGEConnect/SgeConnectView.tsx +++ b/src/components/Connection/SGEConnect/SgeConnectView.tsx @@ -82,18 +82,6 @@ const SgeConnectView: React.FC = () => { } setCurrentSgeState(updatedState) dispatch(updateSgeStore(updatedState)) - // Timeout to let konnectorAuth load before we dismiss SGE form - setTimeout(() => { - dispatch( - updateSgeStore({ - ...currentSgeState, - openSGEForm: false, - // switch to false in case the form fails and the user have to give its consent again - dataConsent: false, - pdlConfirm: false, - }) - ) - }, 500) } }, [currentSgeState, currentStep, dispatch, isNextValid]) diff --git a/src/components/FormGlobal/FormNavigation.tsx b/src/components/FormGlobal/FormNavigation.tsx index d2711c30bb04c4f18c8360ea7e55836d582aa1fc..81f63c06cd39805b4897bec9e0226a595cc7c9f2 100644 --- a/src/components/FormGlobal/FormNavigation.tsx +++ b/src/components/FormGlobal/FormNavigation.tsx @@ -1,11 +1,11 @@ -import React from 'react' -import 'components/FormGlobal/formNavigation.scss' +import Button from '@material-ui/core/Button' import classNames from 'classnames' +import 'components/FormGlobal/formNavigation.scss' import { useI18n } from 'cozy-ui/transpiled/react/I18n' -import Button from '@material-ui/core/Button' -import { ProfileTypeStepForm } from 'enum/profileType.enum' import { EcogestureStepForm } from 'enum/ecogestureForm.enum' +import { ProfileTypeStepForm } from 'enum/profileType.enum' import { SgeStep } from 'enum/sgeStep.enum' +import React from 'react' import { useHistory } from 'react-router-dom' interface FormNavigationProps { diff --git a/src/components/Konnector/KonnectorViewerCard.tsx b/src/components/Konnector/KonnectorViewerCard.tsx index 5ae78e9e6daf6ddb5ee680271bdaba8b3280682e..91b264255c929628af449483c95d56afad76f9d9 100644 --- a/src/components/Konnector/KonnectorViewerCard.tsx +++ b/src/components/Konnector/KonnectorViewerCard.tsx @@ -54,6 +54,7 @@ import { setFluidStatus, toggleChallengeDuelNotification, updatedFluidConnection, + updateSgeStore, } from 'store/global/global.actions' import { getAddPicto, getParamPicto } from 'utils/picto' import './konnectorViewerCard.scss' @@ -84,9 +85,11 @@ const KonnectorViewerCard: React.FC<KonnectorViewerCardProps> = ({ const konnector: Konnector | null = fluidStatus.connection.konnector const account: Account | null = fluidStatus.connection.account const trigger: Trigger | null = fluidStatus.connection.trigger - const { fluidStatus: statusArray, shouldRefreshConsent } = useSelector( - (state: AppStore) => state.ecolyo.global - ) + const { + fluidStatus: statusArray, + shouldRefreshConsent, + sgeConnect, + } = useSelector((state: AppStore) => state.ecolyo.global) const [openModal, setOpenModal] = useState(false) const [isUpdating, setIsUpdating] = useState(false) @@ -419,6 +422,21 @@ const KonnectorViewerCard: React.FC<KonnectorViewerCardProps> = ({ deleteAccountForConsentRefresh() }, [account, client, handleAccountDeletion, shouldRefreshConsent]) + /** Closes SGE form if opened */ + const closeSGEForm = () => { + if (sgeConnect.openSGEForm) { + dispatch( + updateSgeStore({ + ...sgeConnect, + openSGEForm: false, + // switch to false in case the form fails and the user have to give its consent again + dataConsent: false, + pdlConfirm: false, + }) + ) + } + } + useEffect(() => { let subscribed = true async function getData() { @@ -434,6 +452,7 @@ const KonnectorViewerCard: React.FC<KonnectorViewerCardProps> = ({ const connectionFlow = new ConnectionFlow(client, trigger, konnector) await connectionFlow.launch() + closeSGEForm() connectionFlow.jobWatcher.on(ERROR_EVENT, () => { sendUsageEventError(fluidSlug, fluidStatus.lastDataDate === null) setKonnectorErrorDescription(connectionFlow.jobWatcher.on()._error)