aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/forms
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-01-12 11:25:38 -0300
committerSebastian <sebasjm@gmail.com>2024-01-12 11:25:38 -0300
commit23a075a44e14a7b6e151857aa4c1ba0e298036c2 (patch)
tree2539ed548ca7784e632529165bf5f38df0cc9f72 /packages/aml-backoffice-ui/src/forms
parent82d4ed90caa4a6ea3bdda1fb80ccecf3dc3637f9 (diff)
making test passed
Diffstat (limited to 'packages/aml-backoffice-ui/src/forms')
-rw-r--r--packages/aml-backoffice-ui/src/forms/902_11e.ts2
-rw-r--r--packages/aml-backoffice-ui/src/forms/902_12e.ts2
-rw-r--r--packages/aml-backoffice-ui/src/forms/902_13e.ts2
-rw-r--r--packages/aml-backoffice-ui/src/forms/902_15e.ts2
-rw-r--r--packages/aml-backoffice-ui/src/forms/902_1e.ts4
-rw-r--r--packages/aml-backoffice-ui/src/forms/902_4e.ts2
-rw-r--r--packages/aml-backoffice-ui/src/forms/902_5e.ts4
-rw-r--r--packages/aml-backoffice-ui/src/forms/902_9e.ts2
-rw-r--r--packages/aml-backoffice-ui/src/forms/declaration.ts70
-rw-r--r--packages/aml-backoffice-ui/src/forms/index.ts34
-rw-r--r--packages/aml-backoffice-ui/src/forms/simplest.ts2
11 files changed, 84 insertions, 42 deletions
diff --git a/packages/aml-backoffice-ui/src/forms/902_11e.ts b/packages/aml-backoffice-ui/src/forms/902_11e.ts
index 258f75135..71ca8bcf4 100644
--- a/packages/aml-backoffice-ui/src/forms/902_11e.ts
+++ b/packages/aml-backoffice-ui/src/forms/902_11e.ts
@@ -1,6 +1,6 @@
import type { TranslatedString } from "@gnu-taler/taler-util";
import type { FlexibleForm, FormState, InternationalizationAPI } from "@gnu-taler/web-util/browser";
-import { BaseForm } from "./index.js";
+import { BaseForm } from "./declaration.js";
import { resolutionSection } from "./simplest.js";
export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): FlexibleForm<Form902_11.Form> => ({
diff --git a/packages/aml-backoffice-ui/src/forms/902_12e.ts b/packages/aml-backoffice-ui/src/forms/902_12e.ts
index 5a6b80772..0c08d274c 100644
--- a/packages/aml-backoffice-ui/src/forms/902_12e.ts
+++ b/packages/aml-backoffice-ui/src/forms/902_12e.ts
@@ -1,7 +1,7 @@
import type { AbsoluteTime, TranslatedString } from "@gnu-taler/taler-util";
import type { FlexibleForm, FormState, InternationalizationAPI } from "@gnu-taler/web-util/browser";
import { resolutionSection } from "./simplest.js";
-import { BaseForm } from "./index.js";
+import { BaseForm } from "./declaration.js";
export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): FlexibleForm<Form902_12.Form> => ({
design: [
diff --git a/packages/aml-backoffice-ui/src/forms/902_13e.ts b/packages/aml-backoffice-ui/src/forms/902_13e.ts
index dce81bc5e..f69884e0e 100644
--- a/packages/aml-backoffice-ui/src/forms/902_13e.ts
+++ b/packages/aml-backoffice-ui/src/forms/902_13e.ts
@@ -1,6 +1,6 @@
import type { AbsoluteTime } from "@gnu-taler/taler-util";
import type { FlexibleForm, FormState, InternationalizationAPI } from "@gnu-taler/web-util/browser";
-import { BaseForm } from "./index.js";
+import { BaseForm } from "./declaration.js";
import { resolutionSection } from "./simplest.js";
export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): FlexibleForm<Form902_13.Form> => ({
diff --git a/packages/aml-backoffice-ui/src/forms/902_15e.ts b/packages/aml-backoffice-ui/src/forms/902_15e.ts
index 98609852b..2375de389 100644
--- a/packages/aml-backoffice-ui/src/forms/902_15e.ts
+++ b/packages/aml-backoffice-ui/src/forms/902_15e.ts
@@ -1,6 +1,6 @@
import type { AbsoluteTime } from "@gnu-taler/taler-util";
import type { FlexibleForm, InternationalizationAPI } from "@gnu-taler/web-util/browser";
-import { BaseForm } from "./index.js";
+import { BaseForm } from "./declaration.js";
import { resolutionSection } from "./simplest.js";
export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): FlexibleForm<Form902_15.Form> => ({
diff --git a/packages/aml-backoffice-ui/src/forms/902_1e.ts b/packages/aml-backoffice-ui/src/forms/902_1e.ts
index 2db6f1b7e..2287db369 100644
--- a/packages/aml-backoffice-ui/src/forms/902_1e.ts
+++ b/packages/aml-backoffice-ui/src/forms/902_1e.ts
@@ -1,6 +1,6 @@
import type { AbsoluteTime, TranslatedString } from "@gnu-taler/taler-util";
import type { FlexibleForm, FormState, InternationalizationAPI } from "@gnu-taler/web-util/browser";
-import { BaseForm } from "./index.js";
+import { BaseForm, uiForms } from "./declaration.js";
import { resolutionSection } from "./simplest.js";
export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): FlexibleForm<Form902_1.Form> => ({
@@ -370,7 +370,7 @@ export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): Flexib
props: {
name: "acceptance.language",
label: i18n.str`Languages`,
- choices: window.amlExchangeBackoffice!.currencies(i18n),
+ choices: uiForms.currencies(i18n),
unique: true,
},
},
diff --git a/packages/aml-backoffice-ui/src/forms/902_4e.ts b/packages/aml-backoffice-ui/src/forms/902_4e.ts
index e6d15eae3..b31a8dcba 100644
--- a/packages/aml-backoffice-ui/src/forms/902_4e.ts
+++ b/packages/aml-backoffice-ui/src/forms/902_4e.ts
@@ -2,7 +2,7 @@ import type { AbsoluteTime, TranslatedString } from "@gnu-taler/taler-util";
import type { FlexibleForm, FormState, InternationalizationAPI } from "@gnu-taler/web-util/browser";
import { h as create } from "preact";
import { resolutionSection } from "./simplest.js";
-import { BaseForm } from "./index.js";
+import { BaseForm } from "./declaration.js";
import { ArrowRightIcon, ChevronRightIcon } from "./icons.js";
export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): FlexibleForm<Form902_4.Form> => ({
diff --git a/packages/aml-backoffice-ui/src/forms/902_5e.ts b/packages/aml-backoffice-ui/src/forms/902_5e.ts
index f8dc82b7c..3af03ed22 100644
--- a/packages/aml-backoffice-ui/src/forms/902_5e.ts
+++ b/packages/aml-backoffice-ui/src/forms/902_5e.ts
@@ -1,6 +1,6 @@
import type { TranslatedString } from "@gnu-taler/taler-util";
import type { FlexibleForm, FormState, InternationalizationAPI } from "@gnu-taler/web-util/browser";
-import { BaseForm } from "./index.js";
+import { BaseForm, uiForms } from "./declaration.js";
import { resolutionSection } from "./simplest.js";
export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): FlexibleForm<Form902_5.Form> => ({
@@ -62,7 +62,7 @@ export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): Flexib
props: {
name: "originOfAssets.currency",
label: i18n.str`Currency`,
- choices: window.amlExchangeBackoffice!.currencies(i18n),
+ choices: uiForms.currencies(i18n),
},
},
{
diff --git a/packages/aml-backoffice-ui/src/forms/902_9e.ts b/packages/aml-backoffice-ui/src/forms/902_9e.ts
index 274d76445..e0e7a6d65 100644
--- a/packages/aml-backoffice-ui/src/forms/902_9e.ts
+++ b/packages/aml-backoffice-ui/src/forms/902_9e.ts
@@ -1,7 +1,7 @@
import { AbsoluteTime, TranslatedString } from "@gnu-taler/taler-util";
import { FlexibleForm, FormState, InternationalizationAPI } from "@gnu-taler/web-util/browser";
import { resolutionSection } from "./simplest.js";
-import { BaseForm } from "./index.js";
+import { BaseForm } from "./declaration.js";
export const v1 = (i18n: InternationalizationAPI) => (current: BaseForm): FlexibleForm<Form902_9.Form> => ({
design: [
diff --git a/packages/aml-backoffice-ui/src/forms/declaration.ts b/packages/aml-backoffice-ui/src/forms/declaration.ts
new file mode 100644
index 000000000..6c52a4bfe
--- /dev/null
+++ b/packages/aml-backoffice-ui/src/forms/declaration.ts
@@ -0,0 +1,70 @@
+/*
+ This file is part of GNU Taler
+ (C) 2022 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+import type { AmountJson, TranslatedString } from "@gnu-taler/taler-util";
+import type { FlexibleForm, InternationalizationAPI } from "@gnu-taler/web-util/browser";
+import { AmlExchangeBackend } from "../utils/types.js";
+
+/**
+ * import entry point without hard reference.
+ *
+ * This file just export types and UI Forms
+ * based on what `globalThis` contiain.
+ *
+ * `./index.js` must be imorted first before
+ * so `globaThis` will have the correct value.
+ */
+
+export interface BaseForm {
+ state: AmlExchangeBackend.AmlState;
+ threshold: AmountJson;
+}
+
+export type FormMetadata<T extends BaseForm> = {
+ label: TranslatedString,
+ id: string,
+ version: number,
+ impl: (current: T) => FlexibleForm<T>
+}
+
+interface LabelValue {
+ label: TranslatedString;
+ value: string,
+}
+
+export interface UiForms {
+ currencies: (i18n: InternationalizationAPI) => LabelValue[],
+ languages: (i18n: InternationalizationAPI) => LabelValue[],
+ forms: (i18n: InternationalizationAPI) => Array<FormMetadata<BaseForm>>,
+}
+
+/**
+ * Global settings for the UI.
+ */
+const defaultUIForms: UiForms = {
+ currencies: () => [],
+ languages: () => [],
+ forms: () => [],
+};
+
+declare global {
+ var amlExchangeBackoffice: UiForms;
+}
+
+export const uiForms: UiForms =
+ "amlExchangeBackoffice" in globalThis
+ ? (globalThis as any).amlExchangeBackoffice
+ : defaultUIForms;
diff --git a/packages/aml-backoffice-ui/src/forms/index.ts b/packages/aml-backoffice-ui/src/forms/index.ts
index c449bf467..f41122bc7 100644
--- a/packages/aml-backoffice-ui/src/forms/index.ts
+++ b/packages/aml-backoffice-ui/src/forms/index.ts
@@ -1,6 +1,4 @@
-import type { AmountJson, TranslatedString } from "@gnu-taler/taler-util";
-import type { AmlExchangeBackend } from "../utils/types.js";
-import type { FlexibleForm, InternationalizationAPI } from "@gnu-taler/web-util/browser";
+import type { InternationalizationAPI } from "@gnu-taler/web-util/browser";
import { v1 as form_902_11e_v1 } from "./902_11e.js";
import { v1 as form_902_12e_v1 } from "./902_12e.js";
import { v1 as form_902_13e_v1 } from "./902_13e.js";
@@ -10,20 +8,7 @@ import { v1 as form_902_4e_v1 } from "./902_4e.js";
import { v1 as form_902_5e_v1 } from "./902_5e.js";
import { v1 as form_902_9e_v1 } from "./902_9e.js";
import { v1 as simplest } from "./simplest.js";
-
-export interface BaseForm {
- state: AmlExchangeBackend.AmlState;
- threshold: AmountJson;
-}
-
-
-export type FormMetadata<T extends BaseForm> = {
- label: TranslatedString,
- id: string,
- version: number,
- impl: (current: T) => FlexibleForm<T>
-}
-
+import { BaseForm, FormMetadata } from "./declaration.js";
const languages = (i18n: InternationalizationAPI) => [
{
@@ -214,17 +199,4 @@ const currencies = (i18n: InternationalizationAPI) => [
},
];
-interface AmlExchangeBackoffice {
- currencies: typeof currencies,
- languages: typeof languages,
- forms: typeof forms,
-}
-declare global {
- interface Window {
- amlExchangeBackoffice?: AmlExchangeBackoffice;
- }
-}
-
-if (typeof window !== "undefined" && !window.amlExchangeBackoffice) {
- window.amlExchangeBackoffice = { currencies, languages, forms }
-}
+globalThis.amlExchangeBackoffice = { currencies, languages, forms }
diff --git a/packages/aml-backoffice-ui/src/forms/simplest.ts b/packages/aml-backoffice-ui/src/forms/simplest.ts
index 1561076df..735ca9bfc 100644
--- a/packages/aml-backoffice-ui/src/forms/simplest.ts
+++ b/packages/aml-backoffice-ui/src/forms/simplest.ts
@@ -3,7 +3,7 @@ import type {
} from "@gnu-taler/taler-util";
import type { DoubleColumnFormSection, FlexibleForm, FormState, InternationalizationAPI } from "@gnu-taler/web-util/browser";
-import { BaseForm } from "./index.js";
+import { BaseForm } from "./declaration.js";
import { amlStateConverter } from "../utils/converter.js";
import { AmlExchangeBackend } from "../utils/types.js";