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

---
 .../src/ApplicationReadyRoutes.tsx                 | 42 +++++++++++-----------
 1 file changed, 20 insertions(+), 22 deletions(-)

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

diff --git a/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx b/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx
index 46dea98e3..8bfbdb076 100644
--- a/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx
+++ b/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx
@@ -18,22 +18,23 @@
  *
  * @author Sebastian Javier Marchano (sebasjm)
  */
+import { HttpStatusCode } from "@gnu-taler/taler-util";
 import { ErrorType, useTranslationContext } from "@gnu-taler/web-util/browser";
 import { createHashHistory } from "history";
-import { Fragment, h, VNode } from "preact";
-import { Router, Route, route } from "preact-router";
-import { useEffect, useState } from "preact/hooks";
+import { Fragment, VNode, h } from "preact";
+import { Route, Router, route } from "preact-router";
+import { useState } from "preact/hooks";
+import { InstanceRoutes } from "./InstanceRoutes.js";
 import {
-  NotificationCard,
   NotYetReadyAppMenu,
+  NotificationCard,
 } from "./components/menu/index.js";
 import { useBackendContext } from "./context/backend.js";
+import { LoginToken } from "./declaration.js";
 import { useBackendInstancesTestForAdmin } from "./hooks/backend.js";
-import { InstanceRoutes } from "./InstanceRoutes.js";
-import LoginPage from "./paths/login/index.js";
-import { INSTANCE_ID_LOOKUP } from "./utils/constants.js";
-import { HttpStatusCode } from "@gnu-taler/taler-util";
+import { ConnectionPage, LoginPage } from "./paths/login/index.js";
 import { Settings } from "./paths/settings/index.js";
+import { INSTANCE_ID_LOOKUP } from "./utils/constants.js";
 
 /**
  * Check if admin against /management/instances
@@ -41,15 +42,14 @@ import { Settings } from "./paths/settings/index.js";
  */
 export function ApplicationReadyRoutes(): VNode {
   const { i18n } = useTranslationContext();
+  const { url: backendURL, changeBackend } = useBackendContext()
   const [unauthorized, setUnauthorized] = useState(false)
   const {
-    url: backendURL,
-    updateLoginStatus: updateLoginStatus2,
+    updateToken,
   } = useBackendContext();
 
-  function updateLoginStatus(url: string, token: string | undefined) {
-    console.log("updateing", url, token)
-    updateLoginStatus2(url, token)
+  function updateLoginStatus(token: LoginToken | undefined) {
+    updateToken(token)
     setUnauthorized(false)
   }
 
@@ -59,15 +59,15 @@ export function ApplicationReadyRoutes(): VNode {
     route("/");
   };
   const [showSettings, setShowSettings] = useState(false)
-  // useEffect(() => {
-  //   setUnauthorized(FF)
-  // }, [FF])
-  const unauthorizedAdmin = !result.loading && !result.ok && result.type === ErrorType.CLIENT && result.status === HttpStatusCode.Unauthorized
+  const unauthorizedAdmin = !result.loading
+    && !result.ok
+    && result.type === ErrorType.CLIENT
+    && result.status === HttpStatusCode.Unauthorized;
 
   if (showSettings) {
     return <Fragment>
       <NotYetReadyAppMenu onShowSettings={() => setShowSettings(true)} title="UI Settings" onLogout={clearTokenAndGoToRoot} isPasswordOk={false} />
-      <Settings />
+      <Settings onClose={() => setShowSettings(false)} />
     </Fragment>
   }
 
@@ -100,7 +100,7 @@ export function ApplicationReadyRoutes(): VNode {
               type: "ERROR",
             }}
           />
-          <LoginPage onConfirm={updateLoginStatus} />
+          <ConnectionPage onConfirm={changeBackend} />
         </Fragment>
       );
     }
@@ -108,14 +108,13 @@ export function ApplicationReadyRoutes(): VNode {
     instanceNameByBackendURL = match[1];
   }
 
-  console.log(unauthorized, unauthorizedAdmin)
   if (unauthorized || unauthorizedAdmin) {
     return <Fragment>
       <NotYetReadyAppMenu onShowSettings={() => setShowSettings(true)} title="Login" onLogout={clearTokenAndGoToRoot} isPasswordOk={false} />
       <NotificationCard
         notification={{
           message: i18n.str`Access denied`,
-          description: i18n.str`Check your token is valid`,
+          description: i18n.str`Check your token is valid 1`,
           type: "ERROR",
         }}
       />
@@ -132,7 +131,6 @@ export function ApplicationReadyRoutes(): VNode {
         admin={admin}
         onUnauthorized={() => setUnauthorized(true)}
         onLoginPass={() => {
-          console.log("ahora si")
           setUnauthorized(false)
         }}
         instanceNameByBackendURL={instanceNameByBackendURL}
-- 
cgit v1.2.3

