From a1c5917e626856f2abd9dbe6ddaa71c1458334c6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 26 Apr 2024 14:31:48 -0300 Subject: update code to match others --- .../src/pages/AntiMoneyLaunderingForm.stories.tsx | 2 +- .../src/pages/AntiMoneyLaunderingForm.tsx | 20 +-- .../aml-backoffice-ui/src/pages/CaseDetails.tsx | 6 +- .../aml-backoffice-ui/src/pages/CaseUpdate.tsx | 132 ++++++++++++++++++++ .../aml-backoffice-ui/src/pages/Cases.stories.tsx | 2 +- packages/aml-backoffice-ui/src/pages/Cases.tsx | 6 +- .../aml-backoffice-ui/src/pages/CreateAccount.tsx | 8 +- .../src/pages/HandleAccountNotReady.tsx | 4 +- .../aml-backoffice-ui/src/pages/NewFormEntry.tsx | 136 --------------------- packages/aml-backoffice-ui/src/pages/Officer.tsx | 27 ++-- .../src/pages/ShowConsolidated.stories.tsx | 2 +- .../src/pages/ShowConsolidated.tsx | 2 +- .../aml-backoffice-ui/src/pages/UnlockAccount.tsx | 2 +- .../aml-backoffice-ui/src/pages/index.stories.ts | 2 +- 14 files changed, 181 insertions(+), 170 deletions(-) create mode 100644 packages/aml-backoffice-ui/src/pages/CaseUpdate.tsx delete mode 100644 packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx (limited to 'packages/aml-backoffice-ui/src/pages') diff --git a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.stories.tsx b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.stories.tsx index 0b055f682..0c82a4a0e 100644 --- a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.stories.tsx +++ b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.stories.tsx @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2022 Taler Systems S.A. + (C) 2022-2024 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 diff --git a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx index 77d4b8167..db034c996 100644 --- a/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx +++ b/packages/aml-backoffice-ui/src/pages/AntiMoneyLaunderingForm.tsx @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2022 Taler Systems S.A. + (C) 2022-2024 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 @@ -24,17 +24,17 @@ import { buildCodecForObject, codecForNumber, codecForString, - codecOptional + codecOptional, } from "@gnu-taler/taler-util"; import { DefaultForm, + useExchangeApiContext, useTranslationContext, } from "@gnu-taler/web-util/browser"; import { h } from "preact"; -import { useExchangeApiContext } from "../context/config.js"; import { BaseForm, FormMetadata, uiForms } from "../forms/declaration.js"; -import { Pages } from "../pages.js"; import { AmlExchangeBackend } from "../utils/types.js"; +import { privatePages } from "../Routing.js"; export function AntiMoneyLaunderingForm({ account, @@ -68,7 +68,10 @@ export function AntiMoneyLaunderingForm({ form={theForm.impl(initial)} onUpdate={() => {}} onSubmit={(formValue) => { - if (formValue.state === undefined || formValue.threshold === undefined) { + if ( + formValue.state === undefined || + formValue.threshold === undefined + ) { return; } const validatedForm = formValue as BaseForm; @@ -87,7 +90,7 @@ export function AntiMoneyLaunderingForm({ >
Cancel @@ -133,7 +136,10 @@ export function parseJustification( s: string, listOfAllKnownForms: FormMetadata[], ): - | OperationOk<{ justification: Justification; metadata: FormMetadata }> + | OperationOk<{ + justification: Justification; + metadata: FormMetadata; + }> | OperationFail { try { const justification = JSON.parse(s); diff --git a/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx b/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx index a91f3d107..576cdbbb9 100644 --- a/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx +++ b/packages/aml-backoffice-ui/src/pages/CaseDetails.tsx @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2022 Taler Systems S.A. + (C) 2022-2024 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 @@ -34,13 +34,13 @@ import { VNode, h } from "preact"; import { useState } from "preact/hooks"; import { BaseForm, FormMetadata, uiForms } from "../forms/declaration.js"; import { useCaseDetails } from "../hooks/useCaseDetails.js"; -import { Pages } from "../pages.js"; import { AmlExchangeBackend } from "../utils/types.js"; import { Justification, parseJustification, } from "./AntiMoneyLaunderingForm.js"; import { ShowConsolidated } from "./ShowConsolidated.js"; +import { privatePages } from "../Routing.js"; export type AmlEvent = | AmlFormEvent @@ -201,7 +201,7 @@ export function CaseDetails({ account }: { account: string }) { return (
New AML form diff --git a/packages/aml-backoffice-ui/src/pages/CaseUpdate.tsx b/packages/aml-backoffice-ui/src/pages/CaseUpdate.tsx new file mode 100644 index 000000000..c4bff1f9f --- /dev/null +++ b/packages/aml-backoffice-ui/src/pages/CaseUpdate.tsx @@ -0,0 +1,132 @@ +/* + This file is part of GNU Taler + (C) 2022-2024 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 + */ +import { + AbsoluteTime, + Amounts, + HttpStatusCode, + TalerExchangeApi, + TalerProtocolTimestamp, + TranslatedString, +} from "@gnu-taler/taler-util"; +import { + LocalNotificationBanner, + useExchangeApiContext, + useLocalNotification, + useTranslationContext, +} from "@gnu-taler/web-util/browser"; +import { Fragment, VNode, h } from "preact"; +import { privatePages } from "../Routing.js"; +import { uiForms } from "../forms/declaration.js"; +import { useOfficer } from "../hooks/officer.js"; +import { AntiMoneyLaunderingForm } from "./AntiMoneyLaunderingForm.js"; +import { HandleAccountNotReady } from "./HandleAccountNotReady.js"; + +export function CaseUpdate({ + account, + type, +}: { + account: string; + type: string; +}): VNode { + const { i18n } = useTranslationContext(); + const officer = useOfficer(); + const { + lib: { exchange: api }, + } = useExchangeApiContext(); + const [notification, notify, handleError] = useLocalNotification(); + + if (officer.state !== "ready") { + return ; + } + + return ( + + + + { + const decision: Omit = { + justification: JSON.stringify(justification), + decision_time: TalerProtocolTimestamp.now(), + h_payto: account, + new_state, + new_threshold: Amounts.stringify(new_threshold), + kyc_requirements: undefined, + }; + await handleError(async () => { + const resp = await api.addDecisionDetails( + officer.account, + decision, + ); + if (resp.type === "ok") { + window.location.href = privatePages.cases.url({}); + return; + } + switch (resp.case) { + case HttpStatusCode.Forbidden: + case HttpStatusCode.Unauthorized: + return notify({ + type: "error", + title: i18n.str`Wrong credentials for "${officer.account}"`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + when: AbsoluteTime.now(), + }); + case HttpStatusCode.NotFound: + return notify({ + type: "error", + title: i18n.str`Officer or account not found`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + when: AbsoluteTime.now(), + }); + case HttpStatusCode.Conflict: + return notify({ + type: "error", + title: i18n.str`Officer disabled or more recent decision was already submitted.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + when: AbsoluteTime.now(), + }); + } + }); + }} + /> + + ); +} + +export function SelectForm({ account }: { account: string }) { + const { i18n } = useTranslationContext(); + return ( +
+
New form for account: {account.substring(0, 16)}...
+ {uiForms.forms(i18n).map((form) => { + return ( +
+ {form.label} + + ); + })} +
+ ); +} diff --git a/packages/aml-backoffice-ui/src/pages/Cases.stories.tsx b/packages/aml-backoffice-ui/src/pages/Cases.stories.tsx index 223cbbb84..dcbd366a4 100644 --- a/packages/aml-backoffice-ui/src/pages/Cases.stories.tsx +++ b/packages/aml-backoffice-ui/src/pages/Cases.stories.tsx @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2022 Taler Systems S.A. + (C) 2022-2024 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 diff --git a/packages/aml-backoffice-ui/src/pages/Cases.tsx b/packages/aml-backoffice-ui/src/pages/Cases.tsx index 7ecc85e44..e928b831f 100644 --- a/packages/aml-backoffice-ui/src/pages/Cases.tsx +++ b/packages/aml-backoffice-ui/src/pages/Cases.tsx @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2022 Taler Systems S.A. + (C) 2022-2024 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 @@ -28,11 +28,11 @@ import { import { VNode, h } from "preact"; import { useState } from "preact/hooks"; import { useCases } from "../hooks/useCases.js"; -import { Pages } from "../pages.js"; import { amlStateConverter } from "../utils/converter.js"; import { AmlExchangeBackend } from "../utils/types.js"; import { Officer } from "./Officer.js"; +import { privatePages } from "../Routing.js"; export function CasesUI({ records, @@ -130,7 +130,7 @@ export function CasesUI({
{r.h_payto.substring(0, 16)}... diff --git a/packages/aml-backoffice-ui/src/pages/CreateAccount.tsx b/packages/aml-backoffice-ui/src/pages/CreateAccount.tsx index 568ec81fa..9afd0d212 100644 --- a/packages/aml-backoffice-ui/src/pages/CreateAccount.tsx +++ b/packages/aml-backoffice-ui/src/pages/CreateAccount.tsx @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2022 Taler Systems S.A. + (C) 2022-2024 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 @@ -20,7 +20,7 @@ import { useTranslationContext, } from "@gnu-taler/web-util/browser"; import { VNode, h } from "preact"; -import { useSettings } from "../hooks/useSettings.js"; +import { usePreferences } from "../hooks/preferences.js"; export function CreateAccount({ onNewAccount, @@ -32,8 +32,8 @@ export function CreateAccount({ password: string; repeat: string; }>(); - const [settings] = useSettings(); - + const [settings] = usePreferences(); + return (
diff --git a/packages/aml-backoffice-ui/src/pages/HandleAccountNotReady.tsx b/packages/aml-backoffice-ui/src/pages/HandleAccountNotReady.tsx index c86906929..b23798172 100644 --- a/packages/aml-backoffice-ui/src/pages/HandleAccountNotReady.tsx +++ b/packages/aml-backoffice-ui/src/pages/HandleAccountNotReady.tsx @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2022 Taler Systems S.A. + (C) 2022-2024 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 @@ -15,7 +15,7 @@ */ import { assertUnreachable } from "@gnu-taler/taler-util"; import { VNode, h } from "preact"; -import { OfficerNotReady } from "../hooks/useOfficer.js"; +import { OfficerNotReady } from "../hooks/officer.js"; import { CreateAccount } from "./CreateAccount.js"; import { UnlockAccount } from "./UnlockAccount.js"; diff --git a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx deleted file mode 100644 index 7c10132fa..000000000 --- a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx +++ /dev/null @@ -1,136 +0,0 @@ -/* - 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 - */ -import { - AbsoluteTime, - Amounts, - HttpStatusCode, - TalerExchangeApi, - TalerProtocolTimestamp, - TranslatedString, -} from "@gnu-taler/taler-util"; -import { - LocalNotificationBanner, - useLocalNotification, - useTranslationContext, -} from "@gnu-taler/web-util/browser"; -import { Fragment, VNode, h } from "preact"; -import { useExchangeApiContext } from "../context/config.js"; -import { uiForms } from "../forms/declaration.js"; -import { useOfficer } from "../hooks/useOfficer.js"; -import { Pages } from "../pages.js"; -import { AntiMoneyLaunderingForm } from "./AntiMoneyLaunderingForm.js"; -import { HandleAccountNotReady } from "./HandleAccountNotReady.js"; - -export function NewFormEntry({ - account, - type, -}: { - account?: string; - type?: string; -}): VNode { - const { i18n } = useTranslationContext(); - const officer = useOfficer(); - const { api } = useExchangeApiContext(); - const [notification, notify, handleError] = useLocalNotification(); - - if (!account) { - return
no account
; - } - if (!type) { - return ; - } - if (officer.state !== "ready") { - return ; - } - - return ( - - - - { - const decision: Omit = { - justification: JSON.stringify(justification), - decision_time: TalerProtocolTimestamp.now(), - h_payto: account, - new_state, - new_threshold: Amounts.stringify(new_threshold), - kyc_requirements: undefined, - }; - await handleError(async () => { - const resp = await api.addDecisionDetails( - officer.account, - decision, - ); - if (resp.type === "ok") { - window.location.href = Pages.cases.url; - return; - } - switch (resp.case) { - case HttpStatusCode.Forbidden: - case HttpStatusCode.Unauthorized: - return notify({ - type: "error", - title: i18n.str`Wrong credentials for "${officer.account}"`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - when: AbsoluteTime.now(), - }); - case HttpStatusCode.NotFound: - return notify({ - type: "error", - title: i18n.str`Officer or account not found`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - when: AbsoluteTime.now(), - }); - case HttpStatusCode.Conflict: - return notify({ - type: "error", - title: i18n.str`Officer disabled or more recent decision was already submitted.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - when: AbsoluteTime.now(), - }); - } - }); - }} - /> - - ); -} - -function SelectForm({ account }: { account: string }) { - const { i18n } = useTranslationContext(); - return ( -
- ); -} diff --git a/packages/aml-backoffice-ui/src/pages/Officer.tsx b/packages/aml-backoffice-ui/src/pages/Officer.tsx index eaa961b90..ad8ae1ed3 100644 --- a/packages/aml-backoffice-ui/src/pages/Officer.tsx +++ b/packages/aml-backoffice-ui/src/pages/Officer.tsx @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2022 Taler Systems S.A. + (C) 2022-2024 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 @@ -13,22 +13,27 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ -import { useTranslationContext } from "@gnu-taler/web-util/browser"; +import { + useExchangeApiContext, + useTranslationContext, +} from "@gnu-taler/web-util/browser"; import { h } from "preact"; -import { getInitialBackendBaseURL } from "../hooks/useBackend.js"; -import { useOfficer } from "../hooks/useOfficer.js"; -import { uiSettings } from "../settings.js"; +import { useOfficer } from "../hooks/officer.js"; import { HandleAccountNotReady } from "./HandleAccountNotReady.js"; +import { useSettingsContext } from "../context/settings.js"; export function Officer() { const officer = useOfficer(); - const { i18n } = useTranslationContext() + const settings = useSettingsContext(); + const { lib } = useExchangeApiContext(); + + const { i18n } = useTranslationContext(); if (officer.state !== "ready") { return ; } - const url = new URL(getInitialBackendBaseURL()) - const signupEmail = uiSettings.signupEmail ?? `aml-signup@${url.hostname}` + const url = new URL("./", lib.exchange.baseUrl); + const signupEmail = settings.signupEmail ?? `aml-signup@${url.hostname}`; return (
@@ -40,7 +45,11 @@ export function Officer() {