From e1d86816a7c07cb8ca2d54676d5cdbbe513f2ba7 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Mon, 4 Sep 2023 14:17:55 -0300
Subject: backoffcie new version, lot of changes

---
 .../merchant-backoffice-ui/src/Application.tsx     | 60 +++++++++++++---------
 1 file changed, 36 insertions(+), 24 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 f6a81ff8d..5e82821ae 100644
--- a/packages/merchant-backoffice-ui/src/Application.tsx
+++ b/packages/merchant-backoffice-ui/src/Application.tsx
@@ -19,19 +19,20 @@
  * @author Sebastian Javier Marchano (sebasjm)
  */
 
+import { HttpStatusCode, LibtoolVersion } from "@gnu-taler/taler-util";
 import {
   ErrorType,
   TranslationProvider,
   useTranslationContext,
 } from "@gnu-taler/web-util/browser";
-import { Fragment, h, VNode } from "preact";
+import { Fragment, VNode, h } from "preact";
 import { route } from "preact-router";
-import { useMemo, useState } from "preact/hooks";
+import { useMemo } from "preact/hooks";
 import { ApplicationReadyRoutes } from "./ApplicationReadyRoutes.js";
 import { Loading } from "./components/exception/loading.js";
 import {
-  NotificationCard,
-  NotYetReadyAppMenu,
+  NotConnectedAppMenu,
+  NotificationCard
 } from "./components/menu/index.js";
 import {
   BackendContextProvider,
@@ -41,23 +42,24 @@ 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 { HttpStatusCode } from "@gnu-taler/taler-util";
-import { Settings } from "./paths/settings/index.js";
 
 export function Application(): VNode {
   return (
-    // <FetchContextProvider>
     <BackendContextProvider>
       <TranslationProvider source={strings}>
         <ApplicationStatusRoutes />
       </TranslationProvider>
     </BackendContextProvider>
-    // </FetchContextProvider>
   );
 }
 
+/**
+ * Check connection testing against /config
+ * 
+ * @returns 
+ */
 function ApplicationStatusRoutes(): VNode {
-  const { updateLoginStatus, triedToLog } = useBackendContext();
+  const { url, updateLoginStatus, triedToLog } = useBackendContext();
   const result = useBackendConfig();
   const { i18n } = useTranslationContext();
 
@@ -71,19 +73,10 @@ function ApplicationStatusRoutes(): VNode {
     : { currency: "unknown", version: "unknown" };
   const ctx = useMemo(() => ({ currency, version }), [currency, version]);
 
-  const [showSettings, setShowSettings] = useState(false)
-
-  if (showSettings) {
-    return <Fragment>
-      <NotYetReadyAppMenu onShowSettings={() => setShowSettings(true)} title="UI Settings" />
-      <Settings />
-    </Fragment>
-  }
-
   if (!triedToLog) {
     return (
       <Fragment>
-        <NotYetReadyAppMenu title="Welcome!" onShowSettings={() => setShowSettings(true)} />
+        <NotConnectedAppMenu title="Welcome!" />
         <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
       </Fragment>
     );
@@ -97,7 +90,7 @@ function ApplicationStatusRoutes(): VNode {
     ) {
       return (
         <Fragment>
-          <NotYetReadyAppMenu title="Login" onShowSettings={() => setShowSettings(true)} />
+          <NotConnectedAppMenu title="Login" />
           <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
         </Fragment>
       );
@@ -108,7 +101,7 @@ function ApplicationStatusRoutes(): VNode {
     ) {
       return (
         <Fragment>
-          <NotYetReadyAppMenu title="Error" onShowSettings={() => setShowSettings(true)} />
+          <NotConnectedAppMenu title="Error" />
           <NotificationCard
             notification={{
               message: i18n.str`Server not found`,
@@ -122,7 +115,7 @@ function ApplicationStatusRoutes(): VNode {
     }
     if (result.type === ErrorType.SERVER) {
       <Fragment>
-        <NotYetReadyAppMenu title="Error" onShowSettings={() => setShowSettings(true)} />
+        <NotConnectedAppMenu title="Error" />
         <NotificationCard
           notification={{
             message: i18n.str`Server response with an error code`,
@@ -135,7 +128,7 @@ function ApplicationStatusRoutes(): VNode {
     }
     if (result.type === ErrorType.UNREADABLE) {
       <Fragment>
-        <NotYetReadyAppMenu title="Error" onShowSettings={() => setShowSettings(true)} />
+        <NotConnectedAppMenu title="Error" />
         <NotificationCard
           notification={{
             message: i18n.str`Response from server is unreadable, http status: ${result.status}`,
@@ -148,7 +141,7 @@ function ApplicationStatusRoutes(): VNode {
     }
     return (
       <Fragment>
-        <NotYetReadyAppMenu title="Error" onShowSettings={() => setShowSettings(true)} />
+        <NotConnectedAppMenu title="Error" />
         <NotificationCard
           notification={{
             message: i18n.str`Unexpected Error`,
@@ -161,6 +154,25 @@ function ApplicationStatusRoutes(): VNode {
     );
   }
 
+  const SUPPORTED_VERSION = "5:0:1"
+  if (!LibtoolVersion.compare(
+    SUPPORTED_VERSION,
+    result.data.version,
+  )?.compatible) {
+    return <Fragment>
+      <NotConnectedAppMenu title="Error" />
+      <NotificationCard
+        notification={{
+          message: i18n.str`Incompatible version`,
+          type: "ERROR",
+          description: i18n.str`Merchant backend server version ${result.data.version} is not compatible with the supported version ${SUPPORTED_VERSION}`,
+        }}
+      />
+      <LoginPage onConfirm={updateLoginInfoAndGoToRoot} />
+    </Fragment>
+
+  }
+
   return (
     <div class="has-navbar-fixed-top">
       <ConfigContextProvider value={ctx}>
-- 
cgit v1.2.3

