From ba12d0a2bdffac696c3dbff3d21b57bc460124ef Mon Sep 17 00:00:00 2001
From: Bastien DUMONT <bdumont@grandlyon.com>
Date: Wed, 9 Oct 2024 14:12:38 +0200
Subject: [PATCH] Revert "change to lowercase"

This reverts commit 5c293bbfac2f905e07c6f91bf97da60145b3a3a6.
---
 .../Connection/SGEConnect/SgeConnectView.tsx  | 12 ++++-----
 .../SGEConnect/StepIdentityAndPdl.spec.tsx    |  4 +--
 .../SGEConnect/StepIdentityAndPdl.tsx         |  4 +--
 src/components/Connection/useForm.tsx         |  4 +--
 src/components/Hooks/useKonnectorAuth.tsx     |  4 +--
 .../ConnectionResult/ConnectionResult.tsx     | 27 +++++++++++++++++--
 src/models/sgeStore.model.ts                  |  4 +--
 tests/__mocks__/forms.mock.ts                 |  4 +--
 8 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/src/components/Connection/SGEConnect/SgeConnectView.tsx b/src/components/Connection/SGEConnect/SgeConnectView.tsx
index 2b72a3a21..e6290bd54 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 16aa31199..db0bb7e1d 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 936855740..e9ef1c8ec 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 4f01f587d..1bf3be720 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 85ef5133e..6755f9ed4 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 03db452ff..d0e41143b 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 947ef39f9..59b30d9f4 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 481cfea04..9f3f43e67 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: '',
-- 
GitLab