From 2c7384741354e3943968d2f99af5a5ddcebb0667 Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Thu, 4 Jun 2020 14:16:47 +0200
Subject: [PATCH] WIP: add Success and error screen after job run

---
 .../Konnector/KonnectorLaunch.tsx             | 43 +++++++++++++------
 .../Konnector/KonnectorLoginForm.tsx          |  1 -
 2 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/src/components/ContentComponents/Konnector/KonnectorLaunch.tsx b/src/components/ContentComponents/Konnector/KonnectorLaunch.tsx
index 9cf2abb7f..42fa86a68 100644
--- a/src/components/ContentComponents/Konnector/KonnectorLaunch.tsx
+++ b/src/components/ContentComponents/Konnector/KonnectorLaunch.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect } from 'react'
+import React, { useEffect, useState } from 'react'
 import { withClient, Client } from 'cozy-client'
 import { translate } from 'cozy-ui/react/I18n'
 
@@ -36,7 +36,13 @@ const KonnectorLaunch: React.FC<KonnectorLaunchProps> = ({
   client,
   t,
 }: KonnectorLaunchProps) => {
-  const callbackResponse = () => {
+  const [state, setState] = useState<string | null>(null)
+
+  const callbackResponse = (_state: string) => {
+    setState(_state)
+  }
+
+  const handleClick = () => {
     handleKonnectorLaunch()
   }
 
@@ -47,13 +53,13 @@ const KonnectorLaunch: React.FC<KonnectorLaunchProps> = ({
         const konnectorJob = new KonnectorJob(client, trigger)
         await konnectorJob.launch()
         konnectorJob.jobWatcher.on(ERROR_EVENT, () => {
-          callbackResponse()
+          callbackResponse(ERROR_EVENT)
         })
         konnectorJob.jobWatcher.on(LOGIN_SUCCESS_EVENT, () => {
-          callbackResponse()
+          callbackResponse(LOGIN_SUCCESS_EVENT)
         })
         konnectorJob.jobWatcher.on(SUCCESS_EVENT, () => {
-          callbackResponse()
+          callbackResponse(SUCCESS_EVENT)
         })
       }
     }
@@ -63,16 +69,27 @@ const KonnectorLaunch: React.FC<KonnectorLaunchProps> = ({
     }
   }, [])
 
-  // TODO - SUCCESS SCREEN
+  // TODO - SUCCESS SCREEN + rename of class
   return (
     <div className="kload-content">
-      <Lottie options={loadingOptions} height={50} width={50} />
-      <div className="kload-content-text kload-content-text-center text-16-normal">
-        <div>{t('KONNECTORCONFIG.PLZ_WAIT')}</div>
-      </div>
-      <div className="kload-content-text text-16-normal">
-        <div>{t('KONNECTORCONFIG.LOADING_DATA')}</div>
-      </div>
+      {!state ? (
+        <>
+          <Lottie options={loadingOptions} height={50} width={50} />
+          <div className="kload-content-text kload-content-text-center text-16-normal">
+            <div>{t('KONNECTORCONFIG.PLZ_WAIT')}</div>
+          </div>
+          <div className="kload-content-text text-16-normal">
+            <div>{t('KONNECTORCONFIG.LOADING_DATA')}</div>
+          </div>
+        </>
+      ) : (
+        <>
+          <div>
+            {/* // Add success when state <> ERROR_EVENT 
+            // Add Error when state = ERROR_EVENT */}
+          </div>
+        </>
+      )}
     </div>
   )
 }
diff --git a/src/components/ContentComponents/Konnector/KonnectorLoginForm.tsx b/src/components/ContentComponents/Konnector/KonnectorLoginForm.tsx
index 84156b9b9..13fa9e3ff 100644
--- a/src/components/ContentComponents/Konnector/KonnectorLoginForm.tsx
+++ b/src/components/ContentComponents/Konnector/KonnectorLoginForm.tsx
@@ -107,7 +107,6 @@ const KonnectorLoginForm: React.FC<KonnectorLoginFormProps> = ({
     }
   }, [])
 
-  // TODO - if received account from props = display error login failed
   return (
     <form
       className="form"
-- 
GitLab