diff --git a/src/components/Connection/EPGLConnect/EpglForm.tsx b/src/components/Connection/EPGLConnect/EpglForm.tsx index 26719ef2e42edd164b70d370b12edec111ed69fc..0ae8fc6a35f01ddadba355bd9d378ed27f144112 100644 --- a/src/components/Connection/EPGLConnect/EpglForm.tsx +++ b/src/components/Connection/EPGLConnect/EpglForm.tsx @@ -29,7 +29,7 @@ const EpglForm = ({ hasCreatedAccount }: { hasCreatedAccount: boolean }) => { const [loading, setLoading] = useState<boolean>(false) const [showPassword, setShowPassword] = useState(false) - const [connect, update] = useKonnectorAuth(FluidType.WATER, { + const [connect, update, connectError] = useKonnectorAuth(FluidType.WATER, { eglAuthData: { login, password }, }) @@ -67,6 +67,10 @@ const EpglForm = ({ hasCreatedAccount }: { hasCreatedAccount: boolean }) => { } } + useEffect(() => { + if (connectError) setError(connectError) + }, [connectError]) + useEffect(() => { if (account?.auth) { const auth = account.auth diff --git a/src/components/Hooks/useKonnectorAuth.tsx b/src/components/Hooks/useKonnectorAuth.tsx index 4aa951e0d5c663b80773269c755217a0ab1695e3..77348935820f289bccd2b9d4fc87a30c9b31ac71 100644 --- a/src/components/Hooks/useKonnectorAuth.tsx +++ b/src/components/Hooks/useKonnectorAuth.tsx @@ -1,5 +1,6 @@ import * as Sentry from '@sentry/react' import { useClient } from 'cozy-client' +import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { FluidType } from 'enums' import { AccountEGLData, @@ -8,6 +9,7 @@ import { FluidConnection, SgeStore, } from 'models' +import { useState } from 'react' import AccountService from 'services/account.service' import ConnectionService from 'services/connection.service' import { updateFluidConnection } from 'store/global/global.slice' @@ -64,12 +66,14 @@ const useKonnectorAuth = ( sgeAuthData?: SgeStore grdfAuthData?: AccountGRDFData } -): [() => Promise<null | undefined>, () => Promise<void>] => { +): [() => Promise<null | undefined>, () => Promise<void>, string] => { const client = useClient() + const { t } = useI18n() const dispatch = useAppDispatch() const { fluidStatus } = useAppSelector(state => state.ecolyo.global) const currentFluidStatus = fluidStatus[fluidType] const konnectorSlug = currentFluidStatus.connection.konnectorConfig.slug + const [connectError, setConnectError] = useState<string>('') const connect = async () => { try { @@ -88,6 +92,7 @@ const useKonnectorAuth = ( ) if (!trigger || !account) { + setConnectError(t('konnector_form.error_account_creation')) return null } const updatedConnection: FluidConnection = { @@ -142,7 +147,7 @@ const useKonnectorAuth = ( Sentry.captureException(error) } } - return [connect, update] + return [connect, update, connectError] } export default useKonnectorAuth diff --git a/src/locales/fr.json b/src/locales/fr.json index ffacd942115fd1c4f636d2e16a41d5616e7e7930..cd4cbbaffcbca9e381a4d79615fc9ac765b69d15 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -760,6 +760,7 @@ "login_failed": "Un problème a lieu lors de la récupération de vos données. Merci de supprimer votre connecteur et vous reconnecter.", "not_installed": "Le connecteur n'est pas installé. Veuillez l'installer en cliquant sur le bouton ci-dessous.", "button_install": "Installer", + "error_account_creation": "Une erreur est survenue, veuillez essayer de nouveau.", "error_no_login_password": "Identifiant et mot de passe requis", "error_login_failed": "Identifiants invalides", "error_update": "Un problème est survenu lors du rapatriement de vos données.",