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/InstanceRoutes.tsx  | 35 +++++++++++-----------
 1 file changed, 18 insertions(+), 17 deletions(-)

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

diff --git a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx
index ee8db9a9f..c2a9d3b18 100644
--- a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx
+++ b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx
@@ -35,7 +35,7 @@ import { InstanceContextProvider } from "./context/instance.js";
 import {
   useBackendDefaultToken,
   useBackendInstanceToken,
-  useLocalStorage,
+  useSimpleLocalStorage,
 } from "./hooks/index.js";
 import { useInstanceKYCDetails } from "./hooks/instance.js";
 import InstanceCreatePage from "./paths/admin/create/index.js";
@@ -71,10 +71,10 @@ import InstanceUpdatePage, {
   AdminUpdate as InstanceAdminUpdatePage,
   Props as InstanceUpdatePageProps,
 } from "./paths/instance/update/index.js";
-import LoginPage from "./paths/login/index.js";
+import { LoginPage } from "./paths/login/index.js";
 import NotFoundPage from "./paths/notfound/index.js";
 import { Notification } from "./utils/types.js";
-import { MerchantBackend } from "./declaration.js";
+import { LoginToken, MerchantBackend } from "./declaration.js";
 import { Settings } from "./paths/settings/index.js";
 import { dateFormatForSettings, useSettings } from "./hooks/useSettings.js";
 
@@ -143,7 +143,7 @@ export function InstanceRoutes({
   id,
   admin,
   path,
-  onUnauthorized,
+  // onUnauthorized,
   onLoginPass,
   setInstanceName,
 }: Props): VNode {
@@ -155,7 +155,7 @@ export function InstanceRoutes({
   const [globalNotification, setGlobalNotification] =
     useState<GlobalNotifState>(undefined);
 
-  const changeToken = (token?: string) => {
+  const changeToken = (token?: LoginToken) => {
     if (admin) {
       updateToken(token);
     } else {
@@ -201,14 +201,17 @@ export function InstanceRoutes({
 
   // const LoginPageAccessDeniend = onUnauthorized
   const LoginPageAccessDenied = () => {
-    onUnauthorized()
-    return <NotificationCard
-      notification={{
-        message: i18n.str`Access denied`,
-        description: i18n.str`Redirecting to login page.`,
-        type: "ERROR",
-      }}
-    />
+    return <Fragment>
+      <NotificationCard
+        notification={{
+          message: i18n.str`Access denied`,
+          description: i18n.str`Redirecting to login page.`,
+          type: "ERROR",
+        }}
+      />
+      <LoginPage onConfirm={changeToken} />
+    </Fragment>
+
   }
 
   function IfAdminCreateDefaultOr<T>(Next: FunctionComponent<any>) {
@@ -687,9 +690,7 @@ function AdminInstanceUpdatePage({
   ...rest
 }: { id: string } & InstanceUpdatePageProps): VNode {
   const [token, changeToken] = useBackendInstanceToken(id);
-  const { updateLoginStatus: changeBackend } = useBackendContext();
-  const updateLoginStatus = (url: string, token?: string): void => {
-    changeBackend(url);
+  const updateLoginStatus = (token?: LoginToken): void => {
     changeToken(token);
   };
   const value = useMemo(
@@ -752,7 +753,7 @@ function KycBanner(): VNode {
   const { i18n } = useTranslationContext();
   const [settings] = useSettings();
   const today = format(new Date(), dateFormatForSettings(settings));
-  const [lastHide, setLastHide] = useLocalStorage("kyc-last-hide");
+  const [lastHide, setLastHide] = useSimpleLocalStorage("kyc-last-hide");
   const hasBeenHidden = today === lastHide;
   const needsToBeShown = kycStatus.ok && kycStatus.data.type === "redirect";
   if (hasBeenHidden || !needsToBeShown) return <Fragment />;
-- 
cgit v1.2.3

