aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/components/Routing.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/components/Routing.tsx')
-rw-r--r--packages/demobank-ui/src/components/Routing.tsx208
1 files changed, 189 insertions, 19 deletions
diff --git a/packages/demobank-ui/src/components/Routing.tsx b/packages/demobank-ui/src/components/Routing.tsx
index 04cf96190..1d587fe32 100644
--- a/packages/demobank-ui/src/components/Routing.tsx
+++ b/packages/demobank-ui/src/components/Routing.tsx
@@ -19,19 +19,26 @@ import { createHashHistory } from "history";
import { Fragment, VNode, h } from "preact";
import { Route, Router, route } from "preact-router";
import { useEffect } from "preact/hooks";
-import { useBackendContext } from "../context/backend.js";
+import { useBackendState } from "../hooks/backend.js";
import { BankFrame } from "../pages/BankFrame.js";
import { HomePage, WithdrawalOperationPage } from "../pages/HomePage.js";
import { LoginForm } from "../pages/LoginForm.js";
import { PublicHistoriesPage } from "../pages/PublicHistoriesPage.js";
import { RegistrationPage } from "../pages/RegistrationPage.js";
-import { AdminHome } from "../pages/admin/Home.js";
-import { BusinessAccount } from "../pages/business/Home.js";
+import { AdminHome } from "../pages/admin/AdminHome.js";
+import { CreateCashout } from "../pages/business/CreateCashout.js";
import { bankUiSettings } from "../settings.js";
+import { ShowAccountDetails } from "../pages/ShowAccountDetails.js";
+import { UpdateAccountPassword } from "../pages/UpdateAccountPassword.js";
+import { RemoveAccount } from "../pages/admin/RemoveAccount.js";
+import { CreateNewAccount } from "../pages/admin/CreateNewAccount.js";
+import { CashoutListForAccount } from "../pages/admin/CashoutListForAccount.js";
+import { ShowCashoutDetails } from "../pages/business/ShowCashoutDetails.js";
+import { WireTransfer } from "../pages/admin/Account.js";
export function Routing(): VNode {
const history = createHashHistory();
- const backend = useBackendContext();
+ const backend = useBackendState();
const { i18n } = useTranslationContext();
if (backend.state.status === "loggedOut") {
@@ -90,7 +97,7 @@ export function Routing(): VNode {
const { isUserAdministrator, username } = backend.state
return (
- <BankFrame account={backend.state.username}>
+ <BankFrame account={username}>
<Router history={history}>
<Route
path="/operation/:wopid"
@@ -107,6 +114,167 @@ export function Routing(): VNode {
path="/public-accounts"
component={() => <PublicHistoriesPage />}
/>
+
+ <Route
+ path="/new-account"
+ component={() => <CreateNewAccount
+ onCancel={() => {
+ route("/account")
+ }}
+ onCreateSuccess={() => {
+ route("/account")
+ }}
+ />}
+ />
+
+ <Route
+ path="/profile/:account/details"
+ component={({ account }: { account: string }) => (
+ <ShowAccountDetails
+ account={account}
+ onUpdateSuccess={() => {
+ route("/account")
+ }}
+ onClear={() => {
+ route("/account")
+ }}
+ />
+ )}
+ />
+
+ <Route
+ path="/profile/:account/change-password"
+ component={({ account }: { account: string }) => (
+ <UpdateAccountPassword
+ focus
+ account={account}
+ onUpdateSuccess={() => {
+ route("/account")
+ }}
+ onCancel={() => {
+ route("/account")
+ }}
+ />
+ )}
+ />
+ <Route
+ path="/profile/:account/delete"
+ component={({ account }: { account: string }) => (
+ <RemoveAccount
+ account={account}
+ onUpdateSuccess={() => {
+ route("/account")
+ }}
+ onCancel={() => {
+ route("/account")
+ }}
+ />
+ )}
+ />
+
+ <Route
+ path="/profile/:account/cashouts"
+ component={({ account }: { account: string }) => (
+ <CashoutListForAccount
+ account={account}
+ onSelected={(cid) => {
+ route(`/cashout/${cid}`)
+ }}
+ onClose={() => {
+ route("/account")
+ }}
+ />
+ )}
+ />
+
+ <Route
+ path="/my-profile"
+ component={() => (
+ <ShowAccountDetails
+ account={username}
+ onUpdateSuccess={() => {
+ route("/account")
+ }}
+ onClear={() => {
+ route("/account")
+ }}
+ />
+ )}
+ />
+ <Route
+ path="/my-password"
+ component={() => (
+ <UpdateAccountPassword
+ focus
+ account={username}
+ onUpdateSuccess={() => {
+ route("/account")
+ }}
+ onCancel={() => {
+ route("/account")
+ }}
+ />
+ )}
+ />
+
+ <Route
+ path="/my-cashouts"
+ component={() => (
+ <CashoutListForAccount
+ account={username}
+ onSelected={(cid) => {
+ route(`/cashout/${cid}`)
+ }}
+ onClose={() => {
+ route("/account");
+ }}
+ />
+ )}
+ />
+
+ <Route
+ path="/new-cashout"
+ component={() => (
+ <CreateCashout
+ account={username}
+ onComplete={(cid) => {
+ route(`/cashout/${cid}`);
+ }}
+ onCancel={() => {
+ route("/account");
+ }}
+ />
+ )}
+ />
+
+ <Route
+ path="/cashout/:cid"
+ component={({ cid }: { cid: string }) => (
+ <ShowCashoutDetails
+ id={cid}
+ onCancel={() => {
+ route("/account");
+ }}
+ />
+ )}
+ />
+
+
+ <Route
+ path="/wire-transfer/:dest"
+ component={({ dest }: { dest: string }) => (
+ <WireTransfer
+ toAccount={dest}
+ onCancel={() => {
+ route("/account")
+ }}
+ onSuccess={() => {
+ route("/account")
+ }}
+ />
+ )}
+ />
+
<Route
path="/account"
component={() => {
@@ -115,6 +283,22 @@ export function Routing(): VNode {
onRegister={() => {
route("/register");
}}
+ onCreateAccount={() => {
+ route("/new-account")
+ }}
+ onShowAccountDetails={(aid) => {
+ route(`/profile/${aid}/details`)
+ }}
+ onRemoveAccount={(aid) => {
+ route(`/profile/${aid}/delete`)
+ }}
+ onShowCashoutForAccount={(aid) => {
+ route(`/profile/${aid}/cashouts`)
+ }}
+ onUpdateAccountPassword={(aid) => {
+ route(`/profile/${aid}/change-password`)
+
+ }}
/>;
} else {
return <HomePage
@@ -132,20 +316,6 @@ export function Routing(): VNode {
}
}}
/>
- <Route
- path="/business"
- component={() => (
- <BusinessAccount
- account={username}
- onClose={() => {
- route("/account");
- }}
- onRegister={() => {
- route("/register");
- }}
- />
- )}
- />
<Route default component={Redirect} to="/account" />
</Router>
</BankFrame>