diff --git a/src/components/Connection/ConnectionResult.tsx b/src/components/Connection/ConnectionResult.tsx index b8e082d1f44dc075835ca53d5d45efde72562869..4d7f10a65c6572c545e8def657d2bc992c4e1bfd 100644 --- a/src/components/Connection/ConnectionResult.tsx +++ b/src/components/Connection/ConnectionResult.tsx @@ -5,9 +5,16 @@ import { useDispatch } from 'react-redux' import { setShouldRefreshConsent, updatedFluidConnection, + updateSgeStore, } from 'store/global/global.actions' -import { Account, FluidConnection, FluidStatus, Trigger } from 'models' +import { + Account, + AccountSgeData, + FluidConnection, + FluidStatus, + Trigger, +} from 'models' import AccountService from 'services/account.service' import { getKonnectorUpdateError } from 'utils/utils' @@ -111,10 +118,33 @@ const ConnectionResult: React.FC<ConnectionResultProps> = ({ } }, [lastExecutionDate]) - const handleRefreshConsent = useCallback(() => { - deleteAccountsAndTriggers() - dispatch(setShouldRefreshConsent(true)) - }, [deleteAccountsAndTriggers, dispatch]) + const handleRefreshConsent = useCallback( + (fluidType: FluidType) => { + if (fluidType == FluidType.ELECTRICITY) { + const accountData = fluidStatus.connection.account + ?.auth as AccountSgeData + //store the previous account data since the onDelete will remove account from DB + dispatch( + updateSgeStore({ + currentStep: 0, + firstName: accountData.firstname, + lastName: accountData.lastname, + pdl: parseInt(accountData.pointId), + address: accountData.address, + zipCode: parseInt(accountData.postalCode), + city: accountData.city, + dataConsent: true, + pdlConfirm: true, + shouldLaunchAccount: true, + }) + ) + } else { + deleteAccountsAndTriggers() + } + dispatch(setShouldRefreshConsent(true)) + }, + [deleteAccountsAndTriggers, dispatch] + ) useEffect(() => { if (fluidStatus.connection.triggerState?.last_success) { @@ -274,7 +304,7 @@ const ConnectionResult: React.FC<ConnectionResultProps> = ({ aria-label={t('konnector_form.accessibility.button_update')} onClick={ konnectorError === 'error_update_oauth' - ? handleRefreshConsent + ? () => handleRefreshConsent(fluidType) : updateKonnector } disabled={updating || deleting}