diff --git a/src/components/Connection/SGEConnect/SgeConnectView.tsx b/src/components/Connection/SGEConnect/SgeConnectView.tsx index 2b72a3a21b0f0f46ad3043fa260ca02216e2f9be..e6290bd5472d2f9427a8064270d6d896510eb102 100644 --- a/src/components/Connection/SGEConnect/SgeConnectView.tsx +++ b/src/components/Connection/SGEConnect/SgeConnectView.tsx @@ -86,8 +86,8 @@ const SgeConnectView = () => { switch (currentStep) { case SgeStep.IdentityAndPDL: return ( - sgeState.firstname !== '' && - sgeState.lastname !== '' && + sgeState.firstName !== '' && + sgeState.lastName !== '' && sgeState.pdl !== null && sgeState.pdl.toString().length === 14 ) @@ -107,8 +107,8 @@ const SgeConnectView = () => { sgeState.address, sgeState.city, sgeState.dataConsent, - sgeState.firstname, - sgeState.lastname, + sgeState.firstName, + sgeState.lastName, sgeState.pdl, sgeState.pdlConfirm, sgeState.zipCode, @@ -122,8 +122,8 @@ const SgeConnectView = () => { client.save({ ...formData, _type: FORM_DOCTYPE, - firstName: sgeState.firstname, - lastName: sgeState.lastname, + firstName: sgeState.firstName, + lastName: sgeState.lastName, pdl: sgeState.pdl, address: sgeState.address, city: sgeState.city, diff --git a/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx b/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx index 16aa31199eac4c94d4cb409fbfb0886e4a80d2ee..db0bb7e1d6909e0773a57d14d1a092b7840fb256 100644 --- a/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx +++ b/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx @@ -61,8 +61,8 @@ describe('StepIdentityAndPdl component', () => { sgeState={{ ...mockSgeState, pdl: 11111111111111, - firstname: 'Zack', - lastname: 'Ichan', + firstName: 'Zack', + lastName: 'Ichan', zipCode: 69003, }} onChange={mockHandleChange} diff --git a/src/components/Connection/SGEConnect/StepIdentityAndPdl.tsx b/src/components/Connection/SGEConnect/StepIdentityAndPdl.tsx index 936855740e81d48d2d28bd92e81ab34dc536bcf9..e9ef1c8ecaa6d880c75d9018b22d292e9c8ce4a6 100644 --- a/src/components/Connection/SGEConnect/StepIdentityAndPdl.tsx +++ b/src/components/Connection/SGEConnect/StepIdentityAndPdl.tsx @@ -31,7 +31,7 @@ const StepIdentityAndPdl = ({ variant="outlined" type="text" id="firstName" - value={sgeState.firstname} + value={sgeState.firstName} onChange={e => onChange('firstName', e.target.value)} required autoComplete="given-name" @@ -41,7 +41,7 @@ const StepIdentityAndPdl = ({ variant="outlined" type="text" id="lastName" - value={sgeState.lastname} + value={sgeState.lastName} onChange={e => onChange('lastName', e.target.value)} required autoComplete="family-name" diff --git a/src/components/Connection/useForm.tsx b/src/components/Connection/useForm.tsx index 4f01f587d45fff4b463c5418e9f90f760bd66a56..1bf3be72089103ee22d8a0d8ac7efc1e38370a88 100644 --- a/src/components/Connection/useForm.tsx +++ b/src/components/Connection/useForm.tsx @@ -45,8 +45,8 @@ export const useFormData = () => { export const createInitialSgeState = (formData?: FormData): SgeStore => ({ address: formData?.address ?? '', - lastname: formData?.lastName ?? '', - firstname: formData?.firstName ?? '', + lastName: formData?.lastName ?? '', + firstName: formData?.firstName ?? '', pdl: formData?.pdl ? parseInt(formData.pdl) : null, zipCode: formData?.zipCode ? parseInt(formData.zipCode) : null, city: formData?.city ?? '', diff --git a/src/components/Hooks/useKonnectorAuth.tsx b/src/components/Hooks/useKonnectorAuth.tsx index 85ef5133e41b3f88933e4f83b2934e59ca4fda5b..6755f9ed4dcffe90ac611bfbe61df92ba11bbe7c 100644 --- a/src/components/Hooks/useKonnectorAuth.tsx +++ b/src/components/Hooks/useKonnectorAuth.tsx @@ -47,8 +47,8 @@ const formatAuthData = ({ } else if (sgeAuthData) { const konnectorFields: AccountSgeData = { pointId: sgeAuthData?.pdl?.toString() ?? '', - firstname: sgeAuthData?.firstname ?? '', - lastname: sgeAuthData?.lastname ?? '', + firstname: sgeAuthData?.firstName ?? '', + lastname: sgeAuthData?.lastName ?? '', address: sgeAuthData?.address ?? '', postalCode: sgeAuthData?.zipCode?.toString() ?? '', city: sgeAuthData?.city ?? '', diff --git a/src/components/Konnector/ConnectionResult/ConnectionResult.tsx b/src/components/Konnector/ConnectionResult/ConnectionResult.tsx index 03db452ffbe8995d3f6954df16efebd6e72468e9..d0e41143ba1b7f1640def054212e3426b726b157 100644 --- a/src/components/Konnector/ConnectionResult/ConnectionResult.tsx +++ b/src/components/Konnector/ConnectionResult/ConnectionResult.tsx @@ -6,7 +6,7 @@ import { useClient } from 'cozy-client' import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' import { FluidType, KonnectorUpdate } from 'enums' import { DateTime } from 'luxon' -import { FluidConnection, FluidStatus } from 'models' +import { AccountSgeData, FluidConnection, FluidStatus } from 'models' import React, { useCallback, useEffect, useState } from 'react' import AccountService from 'services/account.service' import DateChartService from 'services/dateChart.service' @@ -14,6 +14,7 @@ import TriggerService from 'services/triggers.service' import { setShouldRefreshConsent, updateFluidConnection, + updateSgeStore, } from 'store/global/global.slice' import { useAppDispatch, useAppSelector } from 'store/hooks' import { getKonnectorUpdateError } from 'utils/utils' @@ -107,11 +108,33 @@ const ConnectionResult = ({ const handleRefreshConsent = useCallback(() => { if (fluidType == FluidType.ELECTRICITY) { + const accountData = currentFluidStatus.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, + }) + ) dispatch(setShouldRefreshConsent(true)) } else { deleteAccountsAndTriggers() } - }, [fluidType, dispatch, deleteAccountsAndTriggers]) + }, [ + fluidType, + currentFluidStatus.connection.account?.auth, + dispatch, + deleteAccountsAndTriggers, + ]) useEffect(() => { if (currentFluidStatus.connection.triggerState?.last_success) { diff --git a/src/models/sgeStore.model.ts b/src/models/sgeStore.model.ts index 947ef39f992520ccdefd027d2a5e1eb97cfe300d..59b30d9f42f3b5e912b4ad5b43838ce240e8f84e 100644 --- a/src/models/sgeStore.model.ts +++ b/src/models/sgeStore.model.ts @@ -1,7 +1,7 @@ export interface SgeStore { currentStep: number - firstname: string - lastname: string + firstName: string + lastName: string pdl: number | null address: string zipCode: number | null diff --git a/tests/__mocks__/forms.mock.ts b/tests/__mocks__/forms.mock.ts index 481cfea041f986b80565ff2b78eb6f275a85b308..9f3f43e67924305e8024b8d7505bb8b084e8b833 100644 --- a/tests/__mocks__/forms.mock.ts +++ b/tests/__mocks__/forms.mock.ts @@ -2,8 +2,8 @@ import { SgeStore } from 'models' export const mockSgeState: SgeStore = { address: '', - lastname: '', - firstname: '', + lastName: '', + firstName: '', pdl: 0, zipCode: 0, city: '',