diff options
Diffstat (limited to 'packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx')
-rw-r--r-- | packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx | 100 |
1 files changed, 66 insertions, 34 deletions
diff --git a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx index df97cc3a4..7c10132fa 100644 --- a/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx +++ b/packages/aml-backoffice-ui/src/pages/NewFormEntry.tsx @@ -1,12 +1,38 @@ -import { AbsoluteTime, Amounts, HttpStatusCode, TalerExchangeApi, TalerProtocolTimestamp, TranslatedString } from "@gnu-taler/taler-util"; -import { LocalNotificationBanner, useLocalNotification, useTranslationContext } from "@gnu-taler/web-util/browser"; +/* + 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 { + 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"; -import { uiForms } from "../forms/declaration.js"; export function NewFormEntry({ account, @@ -15,10 +41,10 @@ export function NewFormEntry({ account?: string; type?: string; }): VNode { - const { i18n } = useTranslationContext() + const { i18n } = useTranslationContext(); const officer = useOfficer(); - const { api } = useExchangeApiContext() - const [notification, notify, handleError] = useLocalNotification() + const { api } = useExchangeApiContext(); + const [notification, notify, handleError] = useLocalNotification(); if (!account) { return <div>no account</div>; @@ -38,46 +64,51 @@ export function NewFormEntry({ account={account} formId={type} onSubmit={async (justification, new_state, new_threshold) => { - const decision: Omit<TalerExchangeApi.AmlDecision, "officer_sig"> = { justification: JSON.stringify(justification), decision_time: TalerProtocolTimestamp.now(), h_payto: account, new_state, new_threshold: Amounts.stringify(new_threshold), - kyc_requirements: undefined - } + kyc_requirements: undefined, + }; await handleError(async () => { - const resp = await api.addDecisionDetails(officer.account, decision); + 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(), - }) + 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(), + }); } - }) + }); }} /> </Fragment> @@ -85,13 +116,14 @@ export function NewFormEntry({ } function SelectForm({ account }: { account: string }) { - const { i18n } = useTranslationContext() + const { i18n } = useTranslationContext(); return ( <div> <pre>New form for account: {account.substring(0, 16)}...</pre> - {uiForms.forms(i18n).map((form, idx) => { + {uiForms.forms(i18n).map((form) => { return ( <a + key={form.id} href={Pages.newFormEntry.url({ account, type: form.id })} class="m-4 block rounded-md w-fit border-0 p-3 py-2 text-center text-sm bg-indigo-700 text-white shadow-sm hover:bg-indigo-600" > |