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/reserves/create/CreatePage.tsx | 55 +++++++++++-----------
.../reserves/create/CreatedSuccessfully.tsx | 14 +++---
.../src/paths/instance/reserves/create/index.tsx | 6 +--
.../paths/instance/reserves/details/DetailPage.tsx | 53 +++++++++++----------
.../instance/reserves/list/AutorizeTipModal.tsx | 18 +++----
.../src/paths/instance/reserves/list/Table.tsx | 44 +++++++++--------
.../src/paths/instance/reserves/list/index.tsx | 8 ++--
7 files changed, 102 insertions(+), 96 deletions(-)
(limited to 'packages/merchant-backoffice-ui/src/paths/instance/reserves')
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx
index 2c3e963b8..de2319636 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx
@@ -19,24 +19,23 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
+import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser";
import { Fragment, h, VNode } from "preact";
import { StateUpdater, useEffect, useState } from "preact/hooks";
+import { AsyncButton } from "../../../../components/exception/AsyncButton.js";
import {
FormErrors,
FormProvider,
} from "../../../../components/form/FormProvider.js";
import { Input } from "../../../../components/form/Input.js";
import { InputCurrency } from "../../../../components/form/InputCurrency.js";
+import { InputSelector } from "../../../../components/form/InputSelector.js";
import { ExchangeBackend, MerchantBackend } from "../../../../declaration.js";
-import { Translate, useTranslator } from "../../../../i18n/index.js";
-import { AsyncButton } from "../../../../components/exception/AsyncButton.js";
-import { canonicalizeBaseUrl, ExchangeKeysJson } from "@gnu-taler/taler-util";
+import { request } from "../../../../hooks/backend.js";
import {
PAYTO_WIRE_METHOD_LOOKUP,
URL_REGEX,
} from "../../../../utils/constants.js";
-import { request } from "../../../../hooks/backend.js";
-import { InputSelector } from "../../../../components/form/InputSelector.js";
type Entity = MerchantBackend.Tips.ReserveCreateRequest;
@@ -66,7 +65,7 @@ function ViewStep({
submitForm,
setReserve,
}: ViewProps): VNode {
- const i18n = useTranslator();
+ const { i18n } = useTranslationContext();
const [wireMethods, setWireMethods] = useState>([]);
const [exchangeQueryError, setExchangeQueryError] = useState<
string | undefined
@@ -82,12 +81,12 @@ function ViewStep({
initial_balance: !reserve.initial_balance
? "cannot be empty"
: !(parseInt(reserve.initial_balance.split(":")[1], 10) > 0)
- ? i18n`it should be greater than 0`
+ ? i18n.str`it should be greater than 0`
: undefined,
exchange_url: !reserve.exchange_url
- ? i18n`cannot be empty`
+ ? i18n.str`cannot be empty`
: !URL_REGEX.test(reserve.exchange_url)
- ? i18n`must be a valid URL`
+ ? i18n.str`must be a valid URL`
: !exchangeQueryError
? undefined
: exchangeQueryError,
@@ -106,20 +105,20 @@ function ViewStep({
>
name="initial_balance"
- label={i18n`Initial balance`}
- tooltip={i18n`balance prior to deposit`}
+ label={i18n.str`Initial balance`}
+ tooltip={i18n.str`balance prior to deposit`}
/>
name="exchange_url"
- label={i18n`Exchange URL`}
- tooltip={i18n`URL of exchange`}
+ label={i18n.str`Exchange URL`}
+ tooltip={i18n.str`URL of exchange`}
/>
@@ -157,7 +156,9 @@ function ViewStep({
case Steps.WIRE_METHOD: {
const errors: FormErrors = {
- wire_method: !reserve.wire_method ? i18n`cannot be empty` : undefined,
+ wire_method: !reserve.wire_method
+ ? i18n.str`cannot be empty`
+ : undefined,
};
const hasErrors = Object.keys(errors).some(
@@ -172,22 +173,22 @@ function ViewStep({
>
name="initial_balance"
- label={i18n`Initial balance`}
- tooltip={i18n`balance prior to deposit`}
+ label={i18n.str`Initial balance`}
+ tooltip={i18n.str`balance prior to deposit`}
readonly
/>
name="exchange_url"
- label={i18n`Exchange URL`}
- tooltip={i18n`URL of exchange`}
+ label={i18n.str`Exchange URL`}
+ tooltip={i18n.str`URL of exchange`}
readonly
/>
name="wire_method"
- label={i18n`Wire method`}
- tooltip={i18n`method to use for wire transfer`}
+ label={i18n.str`Wire method`}
+ tooltip={i18n.str`method to use for wire transfer`}
values={wireMethods}
- placeholder={i18n`Select one wire method`}
+ placeholder={i18n.str`Select one wire method`}
/>
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx
index 9bb228e1f..92427f3dc 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx
@@ -14,11 +14,11 @@
GNU Taler; see the file COPYING. If not, see
*/
+import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser";
import { h, VNode } from "preact";
+import { QR } from "../../../../components/exception/QR.js";
import { CreatedSuccessfully as Template } from "../../../../components/notifications/CreatedSuccessfully.js";
import { MerchantBackend } from "../../../../declaration.js";
-import { Translate } from "../../../../i18n/index.js";
-import { QR } from "../../../../components/exception/QR.js";
type Entity = {
request: MerchantBackend.Tips.ReserveCreateRequest;
@@ -37,7 +37,7 @@ export function CreatedSuccessfully({
onCreateAnother,
}: Props): VNode {
const link = `${entity.response.payto_uri}?message=${entity.response.reserve_pub}&amount=${entity.request.initial_balance}`;
-
+ const { i18n } = useTranslationContext();
return (
@@ -85,16 +85,16 @@ export function CreatedSuccessfully({
-
+
To complete the setup of the reserve, you must now initiate a wire
transfer using the given wire transfer subject and crediting the
specified amount to the indicated account of the exchange.
-
+
-
+
If your system supports RFC 8905, you can do this by opening this URI:
-
+
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx
index 8b3ffb4ac..0d39fc298 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx
@@ -19,12 +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 { useReservesAPI } from "../../../../hooks/reserves.js";
-import { useTranslator } from "../../../../i18n/index.js";
import { Notification } from "../../../../utils/types.js";
import { CreatedSuccessfully } from "./CreatedSuccessfully.js";
import { CreatePage } from "./CreatePage.js";
@@ -35,7 +35,7 @@ interface Props {
export default function CreateReserve({ onBack, onConfirm }: Props): VNode {
const { createReserve } = useReservesAPI();
const [notif, setNotif] = useState(undefined);
- const i18n = useTranslator();
+ const { i18n } = useTranslationContext();
const [createdOk, setCreatedOk] = useState<
| {
@@ -59,7 +59,7 @@ export default function CreateReserve({ onBack, onConfirm }: Props): VNode {
.then((r) => setCreatedOk({ request, response: r.data }))
.catch((error) => {
setNotif({
- message: i18n`could not create reserve`,
+ message: i18n.str`could not create reserve`,
type: "ERROR",
description: error.message,
});
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx
index b0b291859..1d54198c8 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx
@@ -20,6 +20,7 @@
*/
import { Amounts } from "@gnu-taler/taler-util";
+import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser";
import { format } from "date-fns";
import { Fragment, h, VNode } from "preact";
import { useState } from "preact/hooks";
@@ -29,13 +30,9 @@ import { Input } from "../../../../components/form/Input.js";
import { InputCurrency } from "../../../../components/form/InputCurrency.js";
import { InputDate } from "../../../../components/form/InputDate.js";
import { TextField } from "../../../../components/form/TextField.js";
-import {
- ContinueModal,
- SimpleModal,
-} from "../../../../components/modal/index.js";
+import { SimpleModal } from "../../../../components/modal/index.js";
import { MerchantBackend } from "../../../../declaration.js";
import { useTipDetails } from "../../../../hooks/reserves.js";
-import { Translate, useTranslator } from "../../../../i18n/index.js";
import { TipInfo } from "./TipInfo.js";
type Entity = MerchantBackend.Tips.ReserveDetail;
@@ -48,7 +45,7 @@ interface Props {
}
export function DetailPage({ id, selected, onBack }: Props): VNode {
- const i18n = useTranslator();
+ const { i18n } = useTranslationContext();
const didExchangeAckTransfer = Amounts.isNonZero(
Amounts.parseOrThrow(selected.exchange_initial_amount),
);
@@ -62,22 +59,22 @@ export function DetailPage({ id, selected, onBack }: Props): VNode {
name="creation_time"
- label={i18n`Created at`}
+ label={i18n.str`Created at`}
readonly
/>
name="expiration_time"
- label={i18n`Valid until`}
+ label={i18n.str`Valid until`}
readonly
/>
name="merchant_initial_amount"
- label={i18n`Created balance`}
+ label={i18n.str`Created balance`}
readonly
/>
name="exchange_url"
- label={i18n`Exchange URL`}
+ label={i18n.str`Exchange URL`}
readonly
>
@@ -89,27 +86,27 @@ export function DetailPage({ id, selected, onBack }: Props): VNode {
name="exchange_initial_amount"
- label={i18n`Exchange balance`}
+ label={i18n.str`Exchange balance`}
readonly
/>
name="pickup_amount"
- label={i18n`Picked up`}
+ label={i18n.str`Picked up`}
readonly
/>
name="committed_amount"
- label={i18n`Committed`}
+ label={i18n.str`Committed`}
readonly
/>
)}
name="payto_uri"
- label={i18n`Account address`}
+ label={i18n.str`Account address`}
readonly
/>
-
+
{didExchangeAckTransfer ? (
@@ -120,7 +117,7 @@ export function DetailPage({ id, selected, onBack }: Props): VNode {
- Tips
+ Tips
@@ -139,18 +136,18 @@ export function DetailPage({ id, selected, onBack }: Props): VNode {
) : (
-
+
To complete the setup of the reserve, you must now initiate a
wire transfer using the given wire transfer subject and
crediting the specified amount to the indicated account of the
exchange.
-
+
-
+
If your system supports RFC 8905, you can do this by opening
this URI:
-
+
@@ -163,7 +160,7 @@ export function DetailPage({ id, selected, onBack }: Props): VNode {
- Back
+ Back
@@ -174,6 +171,7 @@ export function DetailPage({ id, selected, onBack }: Props): VNode {
}
function EmptyTable(): VNode {
+ const { i18n } = useTranslationContext();
return (
@@ -182,7 +180,9 @@ function EmptyTable(): VNode {
- No tips has been authorized from this reserve
+
+ No tips has been authorized from this reserve
+
);
@@ -193,22 +193,23 @@ interface TableProps {
}
function Table({ tips }: TableProps): VNode {
+ const { i18n } = useTranslationContext();
return (
- Authorized
+ Authorized
- Picked up
+ Picked up
- Reason
+ Reason
- Expiration
+ Expiration
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeTipModal.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeTipModal.tsx
index 5200abedf..3a591c555 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeTipModal.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeTipModal.tsx
@@ -19,8 +19,10 @@
* @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 * as yup from "yup";
import {
FormErrors,
FormProvider,
@@ -32,10 +34,8 @@ import {
ContinueModal,
} from "../../../../components/modal/index.js";
import { MerchantBackend } from "../../../../declaration.js";
-import { useTranslator } from "../../../../i18n/index.js";
import { AuthorizeTipSchema } from "../../../../schemas/index.js";
import { CreatedSuccessfully } from "./CreatedSuccessfully.js";
-import * as yup from "yup";
interface AuthorizeTipModalProps {
onCancel: () => void;
@@ -54,7 +54,7 @@ export function AuthorizeTipModal({
// const result = useOrderDetails(id)
type State = MerchantBackend.Tips.TipCreateRequest;
const [form, setValue] = useState>({});
- const i18n = useTranslator();
+ const { i18n } = useTranslationContext();
// const [errors, setErrors] = useState>({})
let errors: FormErrors = {};
@@ -104,19 +104,19 @@ export function AuthorizeTipModal({
>
name="amount"
- label={i18n`Amount`}
- tooltip={i18n`amount of tip`}
+ label={i18n.str`Amount`}
+ tooltip={i18n.str`amount of tip`}
/>
name="justification"
- label={i18n`Justification`}
+ label={i18n.str`Justification`}
inputType="multiline"
- tooltip={i18n`reason for the tip`}
+ tooltip={i18n.str`reason for the tip`}
/>
name="next_url"
- label={i18n`URL after tip`}
- tooltip={i18n`URL to visit after tip payment`}
+ label={i18n.str`URL after tip`}
+ tooltip={i18n.str`URL to visit after tip payment`}
/>
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.tsx
index 86b79d1dd..36768855d 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.tsx
@@ -19,10 +19,10 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
+import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser";
import { format } from "date-fns";
import { Fragment, h, VNode } from "preact";
import { MerchantBackend, WithId } from "../../../../declaration.js";
-import { Translate, useTranslator } from "../../../../i18n/index.js";
type Entity = MerchantBackend.Tips.ReserveStatusEntry & WithId;
@@ -51,7 +51,7 @@ export function CardTable({
return prev;
}, new Array>([], []));
- const i18n = useTranslator();
+ const { i18n } = useTranslationContext();
return (
@@ -62,7 +62,7 @@ export function CardTable({
- Reserves not yet funded
+ Reserves not yet funded
@@ -86,11 +86,14 @@ export function CardTable({
- Reserves ready
+ Reserves ready