/* 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, assertUnreachable } from "@gnu-taler/taler-util"; import { Button, LocalNotificationBanner, RenderAllFieldsByUiConfig, useExchangeApiContext, useLocalNotificationHandler, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { privatePages } from "../Routing.js"; import { BaseForm, uiForms } from "../forms/declaration.js"; import { useFormState } from "../hooks/form.js"; import { useOfficer } from "../hooks/officer.js"; import { HandleAccountNotReady } from "./HandleAccountNotReady.js"; import { Justification } from "./CaseDetails.js"; export function CaseUpdate({ account, type: formId, }: { account: string; type: string; }): VNode { const { i18n } = useTranslationContext(); const officer = useOfficer(); const { lib: { exchange: api }, } = useExchangeApiContext(); // const [notification, notify, handleError] = useLocalNotification(); const [notification, withErrorHandler] = useLocalNotificationHandler(); const { config } = useExchangeApiContext(); const initial = { when: AbsoluteTime.now(), state: TalerExchangeApi.AmlState.pending, threshold: Amounts.zeroOfCurrency(config.currency), }; if (officer.state !== "ready") { return ; } const theForm = uiForms.forms(i18n).find((v) => v.id === formId); if (!theForm) { return
form with id {formId} not found
; } const [form, state] = useFormState(initial, (st) => { return { status: "ok", result: st as any, errors: undefined, }; }); const ff = theForm.impl(state.result as any); const validatedForm = state.status === "fail" ? undefined : state.result; const submitHandler = validatedForm === undefined ? undefined : withErrorHandler( () => { const justification: Justification = { id: theForm.id, label: theForm.label, version: theForm.version, value: validatedForm, }; const decision: Omit = { justification: JSON.stringify(justification), decision_time: TalerProtocolTimestamp.now(), h_payto: account, new_state: justification.value.state, new_threshold: Amounts.stringify(justification.value.threshold), kyc_requirements: undefined, }; return api.addDecisionDetails(officer.account, decision); }, () => { window.location.href = privatePages.cases.url({}); }, (fail) => { switch (fail.case) { case HttpStatusCode.Forbidden: case HttpStatusCode.Unauthorized: return i18n.str`Wrong credentials for "${officer.account}"`; case HttpStatusCode.NotFound: return i18n.str`Officer or account not found`; case HttpStatusCode.Conflict: return i18n.str`Officer disabled or more recent decision was already submitted.`; default: assertUnreachable(fail); } }, ); // const asd = ff.design[0]?.fields[0]?.props return (
{ff.design.map((section, i) => { if (!section) return ; return (

{section.title}

{section.description && (

{section.description}

)}
); })}
Cancel
); } 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} ); })}
); }