diff options
author | Sebastian <sebasjm@gmail.com> | 2022-12-20 17:45:24 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-12-20 17:45:24 -0300 |
commit | c59f9a2556731ad95ab8bd7eefe7fa8a41629834 (patch) | |
tree | 5cb60195d66cebbee0ba99e05eafe22f369a46a8 /packages/merchant-backoffice-ui/src/paths/admin | |
parent | 382e66b179d6fda2598936196b2ae1b97bfab8ef (diff) | |
download | wallet-core-c59f9a2556731ad95ab8bd7eefe7fa8a41629834.tar.xz |
use translation context from web-utils, don't use match react-router since is broken
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/admin')
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx | 12 | ||||
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx | 53 | ||||
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx | 6 | ||||
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/admin/create/stories.tsx (renamed from packages/merchant-backoffice-ui/src/paths/admin/create/stories.ts) | 22 | ||||
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/admin/list/TableActive.tsx | 29 | ||||
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/admin/list/View.tsx | 18 | ||||
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx | 12 |
7 files changed, 86 insertions, 66 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx index 052d61544..91b6b4b56 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx @@ -20,6 +20,7 @@ */ import { h, VNode, FunctionalComponent } from "preact"; +import { ConfigContextProvider } from "../../../context/config.js"; import { CreatePage as TestedComponent } from "./CreatePage.js"; export default { @@ -35,7 +36,16 @@ function createExample<Props>( Component: FunctionalComponent<Props>, props: Partial<Props>, ) { - const r = (args: any) => <Component {...args} />; + const r = (args: any) => ( + <ConfigContextProvider + value={{ + currency: "ARS", + version: "1", + }} + > + <Component {...args} /> + </ConfigContextProvider> + ); r.args = props; return r; } diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx index 6fcabb18b..bf5f5d7c9 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx @@ -19,20 +19,19 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { Amounts } from "@gnu-taler/taler-util"; +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 { AsyncButton } from "../../../components/exception/AsyncButton.js"; import { FormErrors, FormProvider, } from "../../../components/form/FormProvider.js"; +import { DefaultInstanceFormFields } from "../../../components/instance/DefaultInstanceFormFields.js"; import { SetTokenNewInstanceModal } from "../../../components/modal/index.js"; import { MerchantBackend } from "../../../declaration.js"; -import { Translate, useTranslator } from "../../../i18n/index.js"; -import { DefaultInstanceFormFields } from "../../../components/instance/DefaultInstanceFormFields.js"; import { INSTANCE_ID_REGEX, PAYTO_REGEX } from "../../../utils/constants.js"; -import { Amounts } from "@gnu-taler/taler-util"; import { undefinedIfEmpty } from "../../../utils/table.js"; export type Entity = MerchantBackend.Instances.InstanceConfigurationMessage & { @@ -61,55 +60,57 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode { const [isTokenDialogActive, updateIsTokenDialogActive] = useState<boolean>(false); - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); const errors: FormErrors<Entity> = { id: !value.id - ? i18n`required` + ? i18n.str`required` : !INSTANCE_ID_REGEX.test(value.id) - ? i18n`is not valid` + ? i18n.str`is not valid` : undefined, - name: !value.name ? i18n`required` : undefined, + name: !value.name ? i18n.str`required` : undefined, payto_uris: !value.payto_uris || !value.payto_uris.length - ? i18n`required` + ? i18n.str`required` : undefinedIfEmpty( value.payto_uris.map((p) => { - return !PAYTO_REGEX.test(p) ? i18n`is not valid` : undefined; + return !PAYTO_REGEX.test(p) ? i18n.str`is not valid` : undefined; }), ), default_max_deposit_fee: !value.default_max_deposit_fee - ? i18n`required` + ? i18n.str`required` : !Amounts.parse(value.default_max_deposit_fee) - ? i18n`invalid format` + ? i18n.str`invalid format` : undefined, default_max_wire_fee: !value.default_max_wire_fee - ? i18n`required` + ? i18n.str`required` : !Amounts.parse(value.default_max_wire_fee) - ? i18n`invalid format` + ? i18n.str`invalid format` : undefined, default_wire_fee_amortization: value.default_wire_fee_amortization === undefined - ? i18n`required` + ? i18n.str`required` : isNaN(value.default_wire_fee_amortization) - ? i18n`is not a number` + ? i18n.str`is not a number` : value.default_wire_fee_amortization < 1 - ? i18n`must be 1 or greater` + ? i18n.str`must be 1 or greater` : undefined, - default_pay_delay: !value.default_pay_delay ? i18n`required` : undefined, + default_pay_delay: !value.default_pay_delay + ? i18n.str`required` + : undefined, default_wire_transfer_delay: !value.default_wire_transfer_delay - ? i18n`required` + ? i18n.str`required` : undefined, address: undefinedIfEmpty({ address_lines: value.address?.address_lines && value.address?.address_lines.length > 7 - ? i18n`max 7 lines` + ? i18n.str`max 7 lines` : undefined, }), jurisdiction: undefinedIfEmpty({ address_lines: value.address?.address_lines && value.address?.address_lines.length > 7 - ? i18n`max 7 lines` + ? i18n.str`max 7 lines` : undefined, }), }; @@ -174,14 +175,14 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode { <h1 class="title"> <button class="button is-danger has-tooltip-bottom" - data-tooltip={i18n`change authorization configuration`} + data-tooltip={i18n.str`change authorization configuration`} onClick={() => updateIsTokenDialogActive(true)} > <div class="icon is-centered"> <i class="mdi mdi-lock-reset" /> </div> <span> - <Translate>Set access token</Translate> + <i18n.Translate>Set access token</i18n.Translate> </span> </button> </h1> @@ -205,7 +206,7 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode { <div class="buttons is-right mt-5"> {onBack && ( <button class="button" onClick={onBack}> - <Translate>Cancel</Translate> + <i18n.Translate>Cancel</i18n.Translate> </button> )} <AsyncButton @@ -213,11 +214,11 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode { disabled={!isTokenSet || hasErrors} data-tooltip={ hasErrors - ? i18n`Need to complete marked fields and choose authorization method` + ? i18n.str`Need to complete marked fields and choose authorization method` : "confirm operation" } > - <Translate>Confirm</Translate> + <i18n.Translate>Confirm</i18n.Translate> </AsyncButton> </div> </div> diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx index ed2f3f068..4da6916a0 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx @@ -17,12 +17,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 { useAdminAPI } from "../../../hooks/instance.js"; -import { useTranslator } from "../../../i18n/index.js"; import { Notification } from "../../../utils/types.js"; import { CreatePage } from "./CreatePage.js"; import { InstanceCreatedSuccessfully } from "./InstanceCreatedSuccessfully.js"; @@ -38,7 +38,7 @@ export default function Create({ onBack, onConfirm, forceId }: Props): VNode { const { createInstance } = useAdminAPI(); const [notif, setNotif] = useState<Notification | undefined>(undefined); const [createdOk, setCreatedOk] = useState<Entity | undefined>(undefined); - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); if (createdOk) { return ( @@ -62,7 +62,7 @@ export default function Create({ onBack, onConfirm, forceId }: Props): VNode { }) .catch((error) => { setNotif({ - message: i18n`Failed to create instance`, + message: i18n.str`Failed to create instance`, type: "ERROR", description: error.message, }); diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/stories.ts b/packages/merchant-backoffice-ui/src/paths/admin/create/stories.tsx index 45b94ec8c..0012f9b9b 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/stories.ts +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/stories.tsx @@ -20,6 +20,7 @@ */ import { h, VNode, FunctionalComponent } from "preact"; +import { ConfigContextProvider } from "../../../context/config.js"; import { CreatePage as TestedComponent } from "./CreatePage.js"; export default { @@ -32,17 +33,20 @@ export default { }; function createExample<Props>( - Component: FunctionalComponent<Props>, + Internal: FunctionalComponent<Props>, props: Partial<Props>, ) { - const r = (args: any) => h(Component, args); - // const r = (args: any) => <Component {...args} />; - r.args = props; - return r; + const component = (args: any) => ( + <ConfigContextProvider + value={{ + currency: "TESTKUDOS", + version: "1", + }} + > + <Internal {...(props as any)} /> + </ConfigContextProvider> + ); + return { component, props }; } export const Example = createExample(TestedComponent, {}); -// export const Example = (a: any): VNode => <CreatePage {...a} />; -// Example.args = { -// isLoading: false -// } diff --git a/packages/merchant-backoffice-ui/src/paths/admin/list/TableActive.tsx b/packages/merchant-backoffice-ui/src/paths/admin/list/TableActive.tsx index 546f34f3a..223db2fed 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/list/TableActive.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/list/TableActive.tsx @@ -19,10 +19,10 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { h, VNode } from "preact"; import { StateUpdater, useEffect, useState } from "preact/hooks"; import { MerchantBackend } from "../../../declaration.js"; -import { Translate, useTranslator } from "../../../i18n/index.js"; interface Props { instances: MerchantBackend.Instances.Instance[]; @@ -68,7 +68,7 @@ export function CardTable({ } }, [actionQueue, selected, onUpdate]); - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); return ( <div class="card has-table"> @@ -77,7 +77,7 @@ export function CardTable({ <span class="icon"> <i class="mdi mdi-desktop-mac" /> </span> - <Translate>Instances</Translate> + <i18n.Translate>Instances</i18n.Translate> </p> <div class="card-header-icon" aria-label="more options"> @@ -90,11 +90,14 @@ export function CardTable({ ) } > - <Translate>Delete</Translate> + <i18n.Translate>Delete</i18n.Translate> </button> </div> <div class="card-header-icon" aria-label="more options"> - <span class="has-tooltip-left" data-tooltip={i18n`add new instance`}> + <span + class="has-tooltip-left" + data-tooltip={i18n.str`add new instance`} + > <button class="button is-info" type="button" onClick={onCreate}> <span class="icon is-small"> <i class="mdi mdi-plus mdi-36px" /> @@ -149,6 +152,7 @@ function Table({ onDelete, onPurge, }: TableProps): VNode { + const { i18n } = useTranslationContext(); return ( <div class="table-container"> <table class="table is-fullwidth is-striped is-hoverable is-fullwidth"> @@ -171,10 +175,10 @@ function Table({ </label> </th> <th> - <Translate>ID</Translate> + <i18n.Translate>ID</i18n.Translate> </th> <th> - <Translate>Name</Translate> + <i18n.Translate>Name</i18n.Translate> </th> <th /> </tr> @@ -213,7 +217,7 @@ function Table({ type="button" onClick={(): void => onUpdate(i.id)} > - <Translate>Edit</Translate> + <i18n.Translate>Edit</i18n.Translate> </button> {!i.deleted && ( <button @@ -221,7 +225,7 @@ function Table({ type="button" onClick={(): void => onDelete(i)} > - <Translate>Delete</Translate> + <i18n.Translate>Delete</i18n.Translate> </button> )} {i.deleted && ( @@ -230,7 +234,7 @@ function Table({ type="button" onClick={(): void => onPurge(i)} > - <Translate>Purge</Translate> + <i18n.Translate>Purge</i18n.Translate> </button> )} </div> @@ -245,6 +249,7 @@ function Table({ } function EmptyTable(): VNode { + const { i18n } = useTranslationContext(); return ( <div class="content has-text-grey has-text-centered"> <p> @@ -253,9 +258,9 @@ function EmptyTable(): VNode { </span> </p> <p> - <Translate> + <i18n.Translate> There is no instances yet, add more pressing the + sign - </Translate> + </i18n.Translate> </p> </div> ); diff --git a/packages/merchant-backoffice-ui/src/paths/admin/list/View.tsx b/packages/merchant-backoffice-ui/src/paths/admin/list/View.tsx index 5180c671c..7376a88cb 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/list/View.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/list/View.tsx @@ -19,11 +19,11 @@ * @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 { MerchantBackend } from "../../../declaration.js"; import { CardTable as CardTableActive } from "./TableActive.js"; -import { useState } from "preact/hooks"; -import { Translate, useTranslator } from "../../../i18n/index.js"; interface Props { instances: MerchantBackend.Instances.Instance[]; @@ -48,7 +48,7 @@ export function View({ const showIsActive = show === "active" ? "is-active" : ""; const showIsDeleted = show === "deleted" ? "is-active" : ""; const showAll = show === null ? "is-active" : ""; - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); const showingInstances = showIsDeleted ? instances.filter((i) => i.deleted) @@ -66,30 +66,30 @@ export function View({ <li class={showIsActive}> <div class="has-tooltip-right" - data-tooltip={i18n`Only show active instances`} + data-tooltip={i18n.str`Only show active instances`} > <a onClick={() => setShow("active")}> - <Translate>Active</Translate> + <i18n.Translate>Active</i18n.Translate> </a> </div> </li> <li class={showIsDeleted}> <div class="has-tooltip-right" - data-tooltip={i18n`Only show deleted instances`} + data-tooltip={i18n.str`Only show deleted instances`} > <a onClick={() => setShow("deleted")}> - <Translate>Deleted</Translate> + <i18n.Translate>Deleted</i18n.Translate> </a> </div> </li> <li class={showAll}> <div class="has-tooltip-right" - data-tooltip={i18n`Show all instances`} + data-tooltip={i18n.str`Show all instances`} > <a onClick={() => setShow(null)}> - <Translate>All</Translate> + <i18n.Translate>All</i18n.Translate> </a> </div> </li> diff --git a/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx index 36d58dd41..9a81b72d4 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/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"; @@ -27,7 +28,6 @@ import { DeleteModal, PurgeModal } from "../../../components/modal/index.js"; import { MerchantBackend } from "../../../declaration.js"; import { HttpError } from "../../../hooks/backend.js"; import { useAdminAPI, useBackendInstances } from "../../../hooks/instance.js"; -import { useTranslator } from "../../../i18n/index.js"; import { Notification } from "../../../utils/types.js"; import { View } from "./View.js"; @@ -56,7 +56,7 @@ export default function Instances({ useState<MerchantBackend.Instances.Instance | null>(null); const { deleteInstance, purgeInstance } = useAdminAPI(); const [notif, setNotif] = useState<Notification | undefined>(undefined); - const i18n = useTranslator(); + const { i18n } = useTranslationContext(); if (result.clientError && result.isUnauthorized) return onUnauthorized(); if (result.clientError && result.isNotfound) return onNotFound(); @@ -84,12 +84,12 @@ export default function Instances({ await deleteInstance(deleting.id); // pushNotification({ message: 'delete_success', type: 'SUCCESS' }) setNotif({ - message: i18n`Instance "${deleting.name}" (ID: ${deleting.id}) has been deleted`, + message: i18n.str`Instance "${deleting.name}" (ID: ${deleting.id}) has been deleted`, type: "SUCCESS", }); } catch (error) { setNotif({ - message: i18n`Failed to delete instance`, + message: i18n.str`Failed to delete instance`, type: "ERROR", description: error instanceof Error ? error.message : undefined, }); @@ -107,12 +107,12 @@ export default function Instances({ try { await purgeInstance(purging.id); setNotif({ - message: i18n`Instance "${purging.name}" (ID: ${purging.id}) has been disabled`, + message: i18n.str`Instance "${purging.name}" (ID: ${purging.id}) has been disabled`, type: "SUCCESS", }); } catch (error) { setNotif({ - message: i18n`Failed to purge instance`, + message: i18n.str`Failed to purge instance`, type: "ERROR", description: error instanceof Error ? error.message : undefined, }); |