From 79e93451394c66f7f08d25fc578c59cffb807bd0 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 21 Nov 2023 00:40:04 -0300 Subject: sane default for pay deadline and wire transfer and webhook docs --- .../paths/instance/orders/create/CreatePage.tsx | 74 ++++++++++++++++------ .../paths/instance/webhooks/create/CreatePage.tsx | 46 +++++++++++--- 2 files changed, 91 insertions(+), 29 deletions(-) (limited to 'packages/merchant-backoffice-ui/src/paths') diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx index ea2cf849a..52ee9d351 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx @@ -143,7 +143,7 @@ export function CreatePage({ const instance_default = with_defaults(instanceConfig, config.currency) const [value, valueHandler] = useState(instance_default); const zero = Amounts.zeroOfCurrency(config.currency); - const [settings] = useSettings() + const [settings, updateSettings] = useSettings() const inventoryList = Object.values(value.inventoryProducts || {}); const productList = Object.values(value.products || {}); @@ -184,7 +184,7 @@ export function CreatePage({ ? i18n.str`wire transfer deadline cannot be before refund deadline` : undefined, pay_deadline: !value.payments?.pay_deadline - ? undefined + ? i18n.str`required` : !isFuture(value.payments.pay_deadline) ? i18n.str`should be in the future` : value.payments.wire_transfer_deadline && @@ -194,6 +194,11 @@ export function CreatePage({ ) ? i18n.str`wire transfer deadline cannot be before pay deadline` : undefined, + wire_transfer_deadline: !value.payments?.wire_transfer_deadline + ? i18n.str`required` + : !isFuture(value.payments.wire_transfer_deadline) + ? i18n.str`should be in the future` + : undefined, auto_refund_deadline: !value.payments?.auto_refund_deadline ? undefined : !isFuture(value.payments.auto_refund_deadline) @@ -354,9 +359,39 @@ export function CreatePage({ !prev.minimum_age || cur > prev.minimum_age ? cur : prev.minimum_age, 0, ); + + const noDefault_payDeadline = !instance_default.payments || !instance_default.payments.pay_deadline + const noDefault_wireDeadline = !instance_default.payments || !instance_default.payments.wire_transfer_deadline + const requiresSomeTalerOptions = noDefault_payDeadline || noDefault_wireDeadline + return (
+
+
+
    +
  • { + updateSettings({ + ...settings, + advanceOrderMode: false + }) + }}> + + Simple + +
  • +
  • { + updateSettings({ + ...settings, + advanceOrderMode: true + }) + }}> + + Advanced + +
  • +
+
@@ -481,33 +516,34 @@ export function CreatePage({ } - {settings.advanceOrderMode && + {(settings.advanceOrderMode || requiresSomeTalerOptions) && - } - /> - } + {settings.advanceOrderMode && } - /> - } + {(settings.advanceOrderMode || noDefault_wireDeadline) && } - /> - } + {settings.advanceOrderMode && + />} - - } + {settings.advanceOrderMode && - } + {settings.advanceOrderMode && + />} } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/create/CreatePage.tsx index 7b07e689e..434d69412 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/create/CreatePage.tsx @@ -20,7 +20,7 @@ */ import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { h, VNode } from "preact"; +import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { AsyncButton } from "../../../../components/exception/AsyncButton.js"; import { @@ -51,14 +51,14 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { const errors: FormErrors = { webhook_id: !state.webhook_id ? i18n.str`required` : undefined, - event_type: !state.event_type ? i18n.str`required` - : state.event_type !== "pay" && state.event_type !== "refund" ? i18n.str`it should be "pay" or "refund"` - : undefined, + event_type: !state.event_type ? i18n.str`required` + : state.event_type !== "pay" && state.event_type !== "refund" ? i18n.str`it should be "pay" or "refund"` + : undefined, http_method: !state.http_method ? i18n.str`required` : !validMethod.includes(state.http_method) - ? i18n.str`should be one of '${validMethod.join(", ")}'` - : undefined, + ? i18n.str`should be one of '${validMethod.join(", ")}'` + : undefined, url: !state.url ? i18n.str`required` : undefined, }; @@ -116,16 +116,42 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { label={i18n.str`URL`} tooltip={i18n.str`URL of the webhook where the customer will be redirected`} /> - + +

+ The text below support mustache template engine. Any string + between

{{
and
}}
will + be replaced with replaced with the value of the correspoding variable. +

+

+ For example

{{contract_terms.amount}}
will be replaced + with the the order's price +

+

+ The short list of variables are: +

+ + {/* name="header_template" - label={i18n.str`Header`} + label={i18n.str`Http header`} inputType="multiline" tooltip={i18n.str`Header template of the webhook`} - /> + /> */} name="body_template" inputType="multiline" - label={i18n.str`Body`} + label={i18n.str`Http body`} tooltip={i18n.str`Body template by the webhook`} /> -- cgit v1.2.3