From b3c747151bb3f50d28bf6205cafa4b7dd6ae2b1c Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Thu, 21 Sep 2023 09:41:07 -0300
Subject: more ui

---
 packages/demobank-ui/src/components/Routing.tsx | 66 +++++++++++++++++++++----
 1 file changed, 56 insertions(+), 10 deletions(-)

(limited to 'packages/demobank-ui/src/components/Routing.tsx')

diff --git a/packages/demobank-ui/src/components/Routing.tsx b/packages/demobank-ui/src/components/Routing.tsx
index 2c532e863..890058a9b 100644
--- a/packages/demobank-ui/src/components/Routing.tsx
+++ b/packages/demobank-ui/src/components/Routing.tsx
@@ -24,12 +24,50 @@ import { HomePage, WithdrawalOperationPage } from "../pages/HomePage.js";
 import { PublicHistoriesPage } from "../pages/PublicHistoriesPage.js";
 import { RegistrationPage } from "../pages/RegistrationPage.js";
 import { Test } from "../pages/Test.js";
+import { useBackendContext } from "../context/backend.js";
+import { LoginForm } from "../pages/LoginForm.js";
+import { AdminPage } from "../pages/AdminPage.js";
 
 export function Routing(): VNode {
   const history = createHashHistory();
+  const backend = useBackendContext();
+
+  if (backend.state.status === "loggedOut") {
+    return <BankFrame
+      goToBusinessAccount={() => {
+        route("/business");
+      }}
+    >
+      <Router history={history}>
+        <Route
+          path="/login"
+          component={() => (
+            <LoginForm
+              onRegister={() => {
+                route("/register");
+              }}
+            />
+          )}
+        />
+        <Route
+          path="/register"
+          component={() => (
+            <RegistrationPage
+              onComplete={() => {
+                route("/account");
+              }}
+            />
+          )}
+        />
+        <Route default component={Redirect} to="/login" />
+      </Router>
+    </BankFrame>
+  }
+  const isAdmin = backend.state.isUserAdministrator
 
   return (
     <BankFrame
+      account={backend.state.username}
       goToBusinessAccount={() => {
         route("/business");
       }}
@@ -69,16 +107,24 @@ export function Routing(): VNode {
         />
         <Route
           path="/account"
-          component={() => (
-            <HomePage
-              onPendingOperationFound={(wopid) => {
-                route(`/operation/${wopid}`);
-              }}
-              onRegister={() => {
-                route("/register");
-              }}
-            />
-          )}
+          component={() => {
+            if (isAdmin) {
+              return <AdminPage
+                onRegister={() => {
+                  route("/register");
+                }}
+              />;
+            } else {
+              return <HomePage
+                onPendingOperationFound={(wopid) => {
+                  route(`/operation/${wopid}`);
+                }}
+                onRegister={() => {
+                  route("/register");
+                }}
+              />
+            }
+          }}
         />
         <Route
           path="/business"
-- 
cgit v1.2.3

