diff options
author | Christian Blättler <blatc2@bfh.ch> | 2024-05-22 20:24:27 +0200 |
---|---|---|
committer | Christian Blättler <blatc2@bfh.ch> | 2024-05-22 20:24:27 +0200 |
commit | 631027a807138ed9125befc7a2a7c0d8219e17c6 (patch) | |
tree | f088a606d4852b524e1f62fe549f68df367ff2ca /packages/merchant-backoffice-ui/src/paths/instance | |
parent | 349cd9a1f46a2ea8e8d9e502577196c7ed1847eb (diff) | |
parent | 027b26d1ac9d88a4cfc901cc2465e45bfe13e812 (diff) | |
download | wallet-core-631027a807138ed9125befc7a2a7c0d8219e17c6.tar.xz |
Merge branch 'master' into feature/tokens
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance')
6 files changed, 74 insertions, 56 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx b/packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx index 9d5701fa7..39e2fd0c7 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/products/list/Table.tsx @@ -506,6 +506,7 @@ function difference(price: string, tax: number) { ps[1] = `${p - tax}`; return ps.join(":"); } -function sum(taxes: TalerMerchantApi.Tax[]) { +function sum(taxes: TalerMerchantApi.Tax[] | undefined) { + if (taxes === undefined) return 0; return taxes.reduce((p, c) => p + parseInt(c.tax.split(":")[1], 10), 0); } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx index 78d7c83ac..50262be17 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx @@ -70,7 +70,7 @@ interface Props { export function CreatePage({ onCreate, onBack }: Props): VNode { const { i18n } = useTranslationContext(); const { config } = useSessionContext(); - const {state:session} = useSessionContext(); + const { state: session } = useSessionContext(); const devices = useInstanceOtpDevices(); const [state, setState] = useState<Partial<Entity>>({ @@ -100,11 +100,11 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { : undefined, description: !state.description ? i18n.str`should not be empty` : undefined, amount: !state.amount - ? undefined + ? state.amount_editable ? undefined : i18n.str`required` : !parsedPrice ? i18n.str`not valid` : Amounts.isZero(parsedPrice) - ? i18n.str`must be greater than 0` + ? state.amount_editable ? undefined : i18n.str`must be greater than 0` : undefined, minimum_age: state.minimum_age && state.minimum_age < 0 @@ -125,24 +125,30 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { (k) => (errors as Record<string, unknown>)[k] !== undefined, ); + const zero = Amounts.stringify(Amounts.zeroOfCurrency(config.currency)) + const submitForm = () => { if (hasErrors) return Promise.reject(); + const contract_amount = state.amount_editable ? undefined : state.amount as AmountString + const contract_summary = state.summary_editable ? undefined : state.summary + const template_contract: TalerMerchantApi.TemplateContractDetails = { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + amount: contract_amount, + summary: contract_summary, + currency: + cList.length > 1 && state.currency_editable + ? undefined + : config.currency, + } return onCreate({ template_id: state.id!, template_description: state.description!, - template_contract: { - minimum_age: state.minimum_age!, - pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), - amount: state.amount_editable ? undefined : state.amount, - summary: state.summary_editable ? undefined : state.summary, - currency: - cList.length > 1 && state.currency_editable - ? undefined - : config.currency, - }, + template_contract, + required_currency: contract_amount !== undefined ? undefined : config.currency, editable_defaults: { - amount: !state.amount_editable ? undefined : state.amount, - summary: !state.summary_editable ? undefined : state.summary, + amount: !state.amount_editable ? undefined : (state.amount ?? zero), + summary: !state.summary_editable ? undefined : (state.summary ?? ""), currency: cList.length === 1 || !state.currency_editable ? undefined diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx index 9e59609c7..fce14dcc3 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx @@ -93,11 +93,16 @@ export default function ListTemplates({ /> <ListPage - templates={result.body} - onLoadMoreBefore={ - result.isFirstPage ? undefined: result.loadFirst - } - onLoadMoreAfter={result.isLastPage ? undefined : result.loadNext} + // templates={result.body} + // onLoadMoreBefore={ + // result.isFirstPage ? undefined: result.loadFirst + // } + // onLoadMoreAfter={result.isLastPage ? undefined : result.loadNext} + + templates={result.body.templates} + onLoadMoreBefore={undefined} + onLoadMoreAfter={undefined} + onCreate={onCreate} onSelect={(e) => { onSelect(e.template_id); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx index 7322ca169..547996ea1 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx @@ -70,7 +70,8 @@ export function QrPage({ id: templateId, onBack }: Props): VNode { const payTemplateUri = stringifyPayTemplateUri({ merchantBaseUrl, templateId, - templateParams: {}, + // FIXME! + //templateParams: {}, }); return ( @@ -78,7 +79,7 @@ export function QrPage({ id: templateId, onBack }: Props): VNode { <section id="printThis"> <QR text={payTemplateUri} /> <pre style={{ textAlign: "center" }}> - <a href={payTemplateUri}>{payTemplateUri}</a> + <a target="_blank" rel="noreferrer" href={payTemplateUri}>{payTemplateUri}</a> </pre> </section> diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx index eedb77f28..32c5637aa 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/UpdatePage.tsx @@ -51,7 +51,7 @@ type Entity = { description?: string; otpId?: string | null; summary?: string; - amount?: AmountString; + amount?: string; minimum_age?: number; pay_duration?: Duration; summary_editable?: boolean; @@ -68,7 +68,7 @@ interface Props { export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { const { i18n } = useTranslationContext(); const { config } = useSessionContext(); - const {state:session} = useSessionContext(); + const { state: session } = useSessionContext(); const [state, setState] = useState<Partial<Entity>>({ description: template.template_description, @@ -76,8 +76,8 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { otpId: template.otp_id, pay_duration: template.template_contract.pay_duration ? Duration.fromTalerProtocolDuration( - template.template_contract.pay_duration, - ) + template.template_contract.pay_duration, + ) : undefined, summary: template.editable_defaults?.summary ?? template.template_contract.summary, @@ -85,8 +85,8 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { template.editable_defaults?.amount ?? (template.template_contract.amount as AmountString | undefined), currency_editable: !!template.editable_defaults?.currency, - summary_editable: !!template.editable_defaults?.summary, - amount_editable: !!template.editable_defaults?.amount, + summary_editable: template.editable_defaults?.summary !== undefined, + amount_editable: template.editable_defaults?.amount !== undefined, }); function updateState(up: (s: Partial<Entity>) => Partial<Entity>) { @@ -117,11 +117,11 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { const errors: FormErrors<Entity> = { description: !state.description ? i18n.str`should not be empty` : undefined, amount: !state.amount - ? undefined + ? state.amount_editable ? undefined : i18n.str`required` : !parsedPrice ? i18n.str`not valid` : Amounts.isZero(parsedPrice) - ? i18n.str`must be greater than 0` + ? state.amount_editable ? undefined : i18n.str`must be greater than 0` : undefined, minimum_age: state.minimum_age && state.minimum_age < 0 @@ -142,23 +142,29 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { (k) => (errors as Record<string, unknown>)[k] !== undefined, ); + const zero = Amounts.stringify(Amounts.zeroOfCurrency(config.currency)) + const submitForm = () => { if (hasErrors) return Promise.reject(); + const contract_amount = state.amount_editable ? undefined : state.amount as AmountString + const contract_summary = state.summary_editable ? undefined : state.summary + const template_contract: TalerMerchantApi.TemplateContractDetails = { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + amount: contract_amount, + summary: contract_summary, + currency: + cList.length > 1 && state.currency_editable + ? undefined + : config.currency, + } return onUpdate({ template_description: state.description!, - template_contract: { - minimum_age: state.minimum_age!, - pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), - amount: state.amount_editable ? undefined : state.amount, - summary: state.summary_editable ? undefined : state.summary, - currency: - cList.length > 1 && state.currency_editable - ? undefined - : config.currency, - }, + template_contract, + required_currency: contract_amount !== undefined ? undefined : config.currency, editable_defaults: { - amount: !state.amount_editable ? undefined : state.amount, - summary: !state.summary_editable ? undefined : state.summary, + amount: !state.amount_editable ? undefined : (state.amount ?? zero), + summary: !state.summary_editable ? undefined : (state.summary ?? ""), currency: cList.length === 1 || !state.currency_editable ? undefined diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/use/UsePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/UsePage.tsx index 360c9d373..5b1404b55 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/use/UsePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/UsePage.tsx @@ -19,9 +19,9 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { TalerMerchantApi } from "@gnu-taler/taler-util"; +import { AmountString, TalerMerchantApi } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { h, VNode } from "preact"; +import { VNode, h } from "preact"; import { useState } from "preact/hooks"; import { AsyncButton } from "../../../../components/exception/AsyncButton.js"; import { @@ -44,20 +44,19 @@ export function UsePage({ id, template, onCreateOrder, onBack }: Props): VNode { const { i18n } = useTranslationContext(); const [state, setState] = useState<Partial<Entity>>({ - currency: template.editable_defaults?.currency ?? template.template_contract.currency, - amount: template.editable_defaults?.amount ?? template.template_contract.amount, - summary: template.editable_defaults?.summary ?? template.template_contract.summary, + currency: + template.editable_defaults?.currency ?? + template.template_contract.currency, + // FIXME: Add additional check here, editable default might be a plain string! + amount: (template.editable_defaults?.amount ?? + template.template_contract.amount) as AmountString, + summary: + template.editable_defaults?.summary ?? template.template_contract.summary, }); const errors: FormErrors<Entity> = { - amount: - !state.amount - ? i18n.str`Amount is required` - : undefined, - summary: - !state.summary - ? i18n.str`Order summary is required` - : undefined, + amount: !state.amount ? i18n.str`Amount is required` : undefined, + summary: !state.summary ? i18n.str`Order summary is required` : undefined, }; const hasErrors = Object.keys(errors).some( |