From 8c20f4b27946679267bb44255721a9f14ae1077a Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Mon, 11 Sep 2023 15:07:55 -0300
Subject: new login token

---
 .../merchant-backoffice-ui/src/Application.tsx     | 32 ++++++++++------------
 1 file changed, 14 insertions(+), 18 deletions(-)

(limited to 'packages/merchant-backoffice-ui/src/Application.tsx')

diff --git a/packages/merchant-backoffice-ui/src/Application.tsx b/packages/merchant-backoffice-ui/src/Application.tsx
index 5e82821ae..1a7617643 100644
--- a/packages/merchant-backoffice-ui/src/Application.tsx
+++ b/packages/merchant-backoffice-ui/src/Application.tsx
@@ -41,7 +41,8 @@ import {
 import { ConfigContextProvider } from "./context/config.js";
 import { useBackendConfig } from "./hooks/backend.js";
 import { strings } from "./i18n/strings.js";
-import LoginPage from "./paths/login/index.js";
+import { ConnectionPage, LoginPage } from "./paths/login/index.js";
+import { LoginToken } from "./declaration.js";
 
 export function Application(): VNode {
   return (
@@ -59,25 +60,20 @@ export function Application(): VNode {
  * @returns 
  */
 function ApplicationStatusRoutes(): VNode {
-  const { url, updateLoginStatus, triedToLog } = useBackendContext();
+  const { url: backendURL, updateToken, changeBackend } = useBackendContext();
   const result = useBackendConfig();
   const { i18n } = useTranslationContext();
 
-  const updateLoginInfoAndGoToRoot = (url: string, token?: string) => {
-    updateLoginStatus(url, token);
-    route("/");
-  };
-
   const { currency, version } = result.ok
     ? result.data
     : { currency: "unknown", version: "unknown" };
   const ctx = useMemo(() => ({ currency, version }), [currency, version]);
 
-  if (!triedToLog) {
+  if (!backendURL) {
     return (
       <Fragment>
         <NotConnectedAppMenu title="Welcome!" />
-        <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+        <ConnectionPage onConfirm={changeBackend} />
       </Fragment>
     );
   }
@@ -91,7 +87,7 @@ function ApplicationStatusRoutes(): VNode {
       return (
         <Fragment>
           <NotConnectedAppMenu title="Login" />
-          <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+          <ConnectionPage onConfirm={changeBackend} />
         </Fragment>
       );
     }
@@ -109,7 +105,7 @@ function ApplicationStatusRoutes(): VNode {
               description: `Check your url`,
             }}
           />
-          <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+          <ConnectionPage onConfirm={changeBackend} />
         </Fragment>
       );
     }
@@ -120,10 +116,10 @@ function ApplicationStatusRoutes(): VNode {
           notification={{
             message: i18n.str`Server response with an error code`,
             type: "ERROR",
-            description: i18n.str`Got message ${result.message} from ${result.info?.url}`,
+            description: i18n.str`Got message "${result.message}" from ${result.info?.url}`,
           }}
         />
-        <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+        <ConnectionPage onConfirm={changeBackend} />
       </Fragment>;
     }
     if (result.type === ErrorType.UNREADABLE) {
@@ -133,10 +129,10 @@ function ApplicationStatusRoutes(): VNode {
           notification={{
             message: i18n.str`Response from server is unreadable, http status: ${result.status}`,
             type: "ERROR",
-            description: i18n.str`Got message ${result.message} from ${result.info?.url}`,
+            description: i18n.str`Got message "${result.message}" from ${result.info?.url}`,
           }}
         />
-        <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+        <ConnectionPage onConfirm={changeBackend} />
       </Fragment>;
     }
     return (
@@ -146,10 +142,10 @@ function ApplicationStatusRoutes(): VNode {
           notification={{
             message: i18n.str`Unexpected Error`,
             type: "ERROR",
-            description: i18n.str`Got message ${result.message} from ${result.info?.url}`,
+            description: i18n.str`Got message "${result.message}" from ${result.info?.url}`,
           }}
         />
-        <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+        <ConnectionPage onConfirm={changeBackend} />
       </Fragment>
     );
   }
@@ -168,7 +164,7 @@ function ApplicationStatusRoutes(): VNode {
           description: i18n.str`Merchant backend server version ${result.data.version} is not compatible with the supported version ${SUPPORTED_VERSION}`,
         }}
       />
-      <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+      <ConnectionPage onConfirm={changeBackend} />
     </Fragment>
 
   }
-- 
cgit v1.2.3

