From c59f9a2556731ad95ab8bd7eefe7fa8a41629834 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 20 Dec 2022 17:45:24 -0300 Subject: use translation context from web-utils, don't use match react-router since is broken --- .../paths/instance/templates/create/CreatePage.tsx | 44 +++++++++++----------- .../src/paths/instance/templates/create/index.tsx | 8 ++-- .../src/paths/instance/templates/list/ListPage.tsx | 4 +- .../src/paths/instance/templates/list/Table.tsx | 32 +++++++++------- .../src/paths/instance/templates/list/index.tsx | 8 ++-- .../paths/instance/templates/update/UpdatePage.tsx | 44 +++++++++++----------- .../src/paths/instance/templates/update/index.tsx | 7 ++-- 7 files changed, 73 insertions(+), 74 deletions(-) (limited to 'packages/merchant-backoffice-ui/src/paths/instance/templates') 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 dba4b5d14..2a47c22a0 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 @@ -19,6 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { AsyncButton } from "../../../../components/exception/AsyncButton.js"; @@ -33,7 +34,6 @@ import { InputNumber } from "../../../../components/form/InputNumber.js"; import { InputWithAddon } from "../../../../components/form/InputWithAddon.js"; import { useBackendContext } from "../../../../context/backend.js"; import { MerchantBackend } from "../../../../declaration.js"; -import { Translate, useTranslator } from "../../../../i18n/index.js"; import { undefinedIfEmpty } from "../../../../utils/table.js"; type Entity = MerchantBackend.Template.TemplateAddDetails; @@ -44,7 +44,7 @@ interface Props { } export function CreatePage({ onCreate, onBack }: Props): VNode { - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); const backend = useBackendContext(); const [state, setState] = useState>({ @@ -57,23 +57,23 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { }); const errors: FormErrors = { - template_id: !state.template_id ? i18n`should not be empty` : undefined, + template_id: !state.template_id ? i18n.str`should not be empty` : undefined, template_description: !state.template_description - ? i18n`should not be empty` + ? i18n.str`should not be empty` : undefined, template_contract: !state.template_contract ? undefined : undefinedIfEmpty({ minimum_age: state.template_contract.minimum_age < 0 - ? i18n`should be greater that 0` + ? i18n.str`should be greater that 0` : undefined, pay_duration: !state.template_contract.pay_duration - ? i18n`can't be empty` + ? i18n.str`can't be empty` : state.template_contract.pay_duration.d_us === "forever" ? undefined : state.template_contract.pay_duration.d_us < 1000 - ? i18n`to short` + ? i18n.str`to short` : undefined, }), }; @@ -101,57 +101,57 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { name="template_id" addonBefore={`${backend.url}/instances/templates/`} - label={i18n`Identifier`} - tooltip={i18n`Name of the template in URLs.`} + label={i18n.str`Identifier`} + tooltip={i18n.str`Name of the template in URLs.`} /> name="template_description" - label={i18n`Description`} + label={i18n.str`Description`} help="" - tooltip={i18n`Describe what this template stands for`} + tooltip={i18n.str`Describe what this template stands for`} />
{onBack && ( )} - Confirm + Confirm
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/create/index.tsx index bfedb7369..dcbf70106 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/create/index.tsx @@ -19,14 +19,12 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { NotificationCard } from "../../../../components/menu/index.js"; import { MerchantBackend } from "../../../../declaration.js"; -import { useInstanceDetails } from "../../../../hooks/instance.js"; import { useTemplateAPI } from "../../../../hooks/templates.js"; -import { useTransferAPI } from "../../../../hooks/transfer.js"; -import { useTranslator } from "../../../../i18n/index.js"; import { Notification } from "../../../../utils/types.js"; import { CreatePage } from "./CreatePage.js"; @@ -39,7 +37,7 @@ interface Props { export default function CreateTransfer({ onConfirm, onBack }: Props): VNode { const { createTemplate } = useTemplateAPI(); const [notif, setNotif] = useState(undefined); - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); return ( <> @@ -51,7 +49,7 @@ export default function CreateTransfer({ onConfirm, onBack }: Props): VNode { .then(() => onConfirm()) .catch((error) => { setNotif({ - message: i18n`could not inform template`, + message: i18n.str`could not inform template`, type: "ERROR", description: error.message, }); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/ListPage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/ListPage.tsx index dd983918f..9d289e957 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/ListPage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/ListPage.tsx @@ -21,7 +21,7 @@ import { h, VNode } from "preact"; import { MerchantBackend } from "../../../../declaration.js"; -import { useTranslator } from "../../../../i18n/index.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { CardTable } from "./Table.js"; export interface Props { @@ -43,7 +43,7 @@ export function ListPage({ }: Props): VNode { const form = { payto_uri: "" }; - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); return (
([]); - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); return (
@@ -58,10 +58,13 @@ export function CardTable({ - Templates + Templates

- + )} @@ -164,7 +167,7 @@ function Table({
- ID + ID - Description + Description
)} @@ -190,6 +193,7 @@ function Table({ } function EmptyTable(): VNode { + const { i18n } = useTranslationContext(); return (

@@ -198,9 +202,9 @@ function EmptyTable(): VNode {

- + There is no templates yet, add more pressing the + sign - +

); 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 0d58093d3..dcac23983 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 @@ -19,6 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { Loading } from "../../../../components/exception/loading.js"; @@ -29,7 +30,6 @@ import { useInstanceTemplates, useTemplateAPI, } from "../../../../hooks/templates.js"; -import { useTranslator } from "../../../../i18n/index.js"; import { Notification } from "../../../../utils/types.js"; import { ListPage } from "./ListPage.js"; @@ -49,7 +49,7 @@ export default function ListTemplates({ onNotFound, }: Props): VNode { const [position, setPosition] = useState(undefined); - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); const [notif, setNotif] = useState(undefined); const { deleteTemplate } = useTemplateAPI(); const result = useInstanceTemplates({ position }, (id) => setPosition(id)); @@ -77,13 +77,13 @@ export default function ListTemplates({ deleteTemplate(e.template_id) .then(() => setNotif({ - message: i18n`template delete successfully`, + message: i18n.str`template delete successfully`, type: "SUCCESS", }), ) .catch((error) => setNotif({ - message: i18n`could not delete the template`, + message: i18n.str`could not delete the template`, type: "ERROR", description: error.message, }), 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 42d9e5825..a49e8000b 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 @@ -19,6 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { AsyncButton } from "../../../../components/exception/AsyncButton.js"; @@ -31,11 +32,8 @@ import { InputCurrency } from "../../../../components/form/InputCurrency.js"; import { InputDuration } from "../../../../components/form/InputDuration.js"; import { InputNumber } from "../../../../components/form/InputNumber.js"; import { InputWithAddon } from "../../../../components/form/InputWithAddon.js"; -import { ProductForm } from "../../../../components/product/ProductForm.js"; import { useBackendContext } from "../../../../context/backend.js"; import { MerchantBackend, WithId } from "../../../../declaration.js"; -import { useListener } from "../../../../hooks/listener.js"; -import { Translate, useTranslator } from "../../../../i18n/index.js"; import { undefinedIfEmpty } from "../../../../utils/table.js"; type Entity = MerchantBackend.Template.TemplatePatchDetails & WithId; @@ -47,28 +45,28 @@ interface Props { } export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); const backend = useBackendContext(); const [state, setState] = useState>(template); const errors: FormErrors = { template_description: !state.template_description - ? i18n`should not be empty` + ? i18n.str`should not be empty` : undefined, template_contract: !state.template_contract ? undefined : undefinedIfEmpty({ minimum_age: state.template_contract.minimum_age < 0 - ? i18n`should be greater that 0` + ? i18n.str`should be greater that 0` : undefined, pay_duration: !state.template_contract.pay_duration - ? i18n`can't be empty` + ? i18n.str`can't be empty` : state.template_contract.pay_duration.d_us === "forever" ? undefined : state.template_contract.pay_duration.d_us < 1000 - ? i18n`to short` + ? i18n.str`to short` : undefined, }), }; @@ -112,57 +110,57 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { name="id" addonBefore={`templates/`} readonly - label={i18n`Identifier`} - tooltip={i18n`Name of the template in URLs.`} + label={i18n.str`Identifier`} + tooltip={i18n.str`Name of the template in URLs.`} /> name="template_description" - label={i18n`Description`} + label={i18n.str`Description`} help="" - tooltip={i18n`Describe what this template stands for`} + tooltip={i18n.str`Describe what this template stands for`} />
{onBack && ( )} - Confirm + Confirm
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx index 25dc9abdc..4a4cc4274 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx @@ -19,18 +19,17 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { Loading } from "../../../../components/exception/loading.js"; import { NotificationCard } from "../../../../components/menu/index.js"; import { MerchantBackend, WithId } from "../../../../declaration.js"; import { HttpError } from "../../../../hooks/backend.js"; -import { useProductAPI, useProductDetails } from "../../../../hooks/product.js"; import { useTemplateAPI, useTemplateDetails, } from "../../../../hooks/templates.js"; -import { useTranslator } from "../../../../i18n/index.js"; import { Notification } from "../../../../utils/types.js"; import { UpdatePage } from "./UpdatePage.js"; @@ -56,7 +55,7 @@ export default function UpdateTemplate({ const result = useTemplateDetails(tid); const [notif, setNotif] = useState(undefined); - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); if (result.clientError && result.isUnauthorized) return onUnauthorized(); if (result.clientError && result.isNotfound) return onNotFound(); @@ -74,7 +73,7 @@ export default function UpdateTemplate({ .then(onConfirm) .catch((error) => { setNotif({ - message: i18n`could not update template`, + message: i18n.str`could not update template`, type: "ERROR", description: error.message, }); -- cgit v1.2.3