aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-10-31 13:10:33 +0100
committerFlorian Dold <florian@dold.me>2022-10-31 13:11:40 +0100
commit6e7928062f5bb93769d2960c77af95d5959a64a4 (patch)
treefc5284127f4b342a0266960d0ab0aba24ee8df21
parent234ee55882da7759591730be72f0940f82c52a05 (diff)
demobank-ui: handle per-deployment customization
-rw-r--r--packages/demobank-ui/README.md28
-rw-r--r--packages/demobank-ui/src/pages/home/index.tsx70
-rw-r--r--packages/demobank-ui/static/index.html3
3 files changed, 67 insertions, 34 deletions
diff --git a/packages/demobank-ui/README.md b/packages/demobank-ui/README.md
index 5c68d127e..7f582c5ba 100644
--- a/packages/demobank-ui/README.md
+++ b/packages/demobank-ui/README.md
@@ -19,3 +19,31 @@ This can be changed for testing by setting the URL via local storage (via your b
```
localStorage.setItem("bank-base-url", OTHER_URL);
```
+
+## Customizing Per-Deployment Settings
+
+To customize per-deployment settings, make sure that the
+`demobank-ui-settings.js` file is served alongside the UI.
+
+This file is loaded before the SPA and can do customizations by
+changing `globalThis.`.
+
+For example, the following settings would correspond
+to the default settings:
+
+```
+globalThis.talerDemobankSettings = {
+ allowRegistrations: true,
+ bankName: "Taler Bank",
+ // Show explainer text and navbar to other demo sites
+ showDemoNav: true,
+ // Names and links for other demo sites to show in the navbar
+ demoSites: [
+ ["Landing", "https://demo.taler.net/"],
+ ["Bank", "https://bank.demo.taler.net/"],
+ ["Essay Shop", "https://shop.demo.taler.net/"],
+ ["Donations", "https://donations.demo.taler.net/"],
+ ["Survey", "https://donations.demo.taler.net/"],
+ ],
+};
+```
diff --git a/packages/demobank-ui/src/pages/home/index.tsx b/packages/demobank-ui/src/pages/home/index.tsx
index 0ee2aa20d..0eb7e389d 100644
--- a/packages/demobank-ui/src/pages/home/index.tsx
+++ b/packages/demobank-ui/src/pages/home/index.tsx
@@ -33,27 +33,33 @@ import { Translate, useTranslator } from "../../i18n/index.js";
import "../../scss/main.scss";
import { Amounts, parsePaytoUri } from "@gnu-taler/taler-util";
+interface BankUiSettings {
+ allowRegistrations: boolean;
+ showDemoNav: boolean;
+ bankName: string;
+ demoSites: [string, string][];
+}
+
/**
- * If the first argument does not look like a placeholder, return it.
- * Otherwise, return the default.
- *
- * Useful for placeholder string replacements optionally
- * done as part of the build system.
+ * Global settings for the demobank UI.
*/
-const replacementOrDefault = (x: string, defaultVal: string): string => {
- if (x.startsWith("__")) {
- return defaultVal;
- }
- return x;
+const defaultSettings: BankUiSettings = {
+ allowRegistrations: true,
+ bankName: "Taler Bank",
+ showDemoNav: true,
+ demoSites: [
+ ["Landing", "https://demo.taler.net/"],
+ ["Bank", "https://bank.demo.taler.net/"],
+ ["Essay Shop", "https://shop.demo.taler.net/"],
+ ["Donations", "https://donations.demo.taler.net/"],
+ ["Survey", "https://donations.demo.taler.net/"],
+ ],
};
-const UI_ALLOW_REGISTRATIONS =
- replacementOrDefault("__LIBEUFIN_UI_ALLOW_REGISTRATIONS__", "1") == "1";
-const UI_IS_DEMO = replacementOrDefault("__LIBEUFIN_UI_IS_DEMO__", "0") == "1";
-const UI_BANK_NAME = replacementOrDefault(
- "__LIBEUFIN_UI_BANK_NAME__",
- "Taler Bank",
-);
+const bankUiSettings: BankUiSettings =
+ "talerDemobankSettings" in globalThis
+ ? (globalThis as any).talerDemobankSettings
+ : defaultSettings;
/**
* FIXME:
@@ -185,7 +191,7 @@ interface PageStateType {
***********/
function maybeDemoContent(content: VNode): VNode {
- if (UI_IS_DEMO) {
+ if (bankUiSettings.showDemoNav) {
return content;
}
return <Fragment />;
@@ -1023,17 +1029,13 @@ function BankFrame(Props: any): VNode {
</div>
);
- // Prepare demo sites links.
- const DEMO_SITES = [
- ["Landing", "__DEMO_SITE_LANDING_URL__"],
- ["Bank", "__DEMO_SITE_BANK_URL__"],
- ["Essay Shop", "__DEMO_SITE_BLOG_URL__"],
- ["Donations", "__DEMO_SITE_DONATIONS_URL__"],
- ["Survey", "__DEMO_SITE_SURVEY_URL__"],
- ];
const demo_sites = [];
- for (const i in DEMO_SITES)
- demo_sites.push(<a href={DEMO_SITES[i][1]}>{DEMO_SITES[i][0]}</a>);
+ for (const i in bankUiSettings.demoSites)
+ demo_sites.push(
+ <a href={bankUiSettings.demoSites[i][1]}>
+ {bankUiSettings.demoSites[i][0]}
+ </a>,
+ );
return (
<Fragment>
@@ -1045,7 +1047,7 @@ function BankFrame(Props: any): VNode {
<div style="max-width: 50em; margin-left: 2em;">
<h1>
<span class="it">
- <a href="/">{UI_BANK_NAME}</a>
+ <a href="/">{bankUiSettings.bankName}</a>
</span>
</h1>
{maybeDemoContent(
@@ -1754,7 +1756,7 @@ function PaymentOptions(Props: any): VNode {
function RegistrationButton(Props: any): VNode {
const { backendStateSetter, pageStateSetter } = Props;
const i18n = useTranslator();
- if (UI_ALLOW_REGISTRATIONS)
+ if (bankUiSettings.allowRegistrations)
return (
<button
class="pure-button pure-button-secondary btn-cancel"
@@ -1898,7 +1900,7 @@ function RegistrationForm(Props: any): VNode {
return (
<Fragment>
- <h1 class="nav">{i18n`Welcome to ${UI_BANK_NAME}!`}</h1>
+ <h1 class="nav">{i18n`Welcome to ${bankUiSettings.bankName}!`}</h1>
<article>
<div class="register-div">
<form action="javascript:void(0);" class="register-form">
@@ -2435,8 +2437,8 @@ export function BankHome(): VNode {
);
if (pageState.tryRegister) {
- console.log("allow registrations?", UI_ALLOW_REGISTRATIONS);
- if (UI_ALLOW_REGISTRATIONS)
+ console.log("allow registrations?", bankUiSettings.allowRegistrations);
+ if (bankUiSettings.allowRegistrations)
return (
<PageContext.Provider value={[pageState, pageStateSetter]}>
<BankFrame>
@@ -2485,7 +2487,7 @@ export function BankHome(): VNode {
return (
<PageContext.Provider value={[pageState, pageStateSetter]}>
<BankFrame>
- <h1 class="nav">{i18n`Welcome to ${UI_BANK_NAME}!`}</h1>
+ <h1 class="nav">{i18n`Welcome to ${bankUiSettings.bankName}!`}</h1>
<LoginForm
pageStateSetter={pageStateSetter}
backendStateSetter={backendStateSetter}
diff --git a/packages/demobank-ui/static/index.html b/packages/demobank-ui/static/index.html
index 6597eb26f..0fa5215d3 100644
--- a/packages/demobank-ui/static/index.html
+++ b/packages/demobank-ui/static/index.html
@@ -3,6 +3,9 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Demobank</title>
+ <!-- Optional customization script. -->
+ <script src="demobank-ui-settings.js"></script>
+ <!-- Entry point for the demobank SPA. -->
<script type="module" src="index.js"></script>
<link rel="stylesheet" href="index.css" />
</head>