[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] 02/03: add use-template button
From: |
gnunet |
Subject: |
[taler-wallet-core] 02/03: add use-template button |
Date: |
Fri, 27 Jan 2023 19:09:26 +0100 |
This is an automated email from the git hooks/post-receive script.
sebasjm pushed a commit to branch master
in repository wallet-core.
commit 1b2b5d62de5888eae895db69cf6ae51dbfddb32b
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Fri Jan 27 12:35:10 2023 -0300
add use-template button
---
.../merchant-backoffice-ui/src/InstanceRoutes.tsx | 18 +++++
.../src/components/form/Input.tsx | 1 +
.../src/components/form/InputWithAddon.tsx | 1 +
.../merchant-backoffice-ui/src/declaration.d.ts | 5 +-
.../merchant-backoffice-ui/src/hooks/templates.ts | 15 ++--
.../src/paths/instance/details/DetailPage.tsx | 4 +-
.../src/paths/instance/details/stories.tsx | 4 +-
.../instance/orders/create/Create.stories.tsx | 2 +-
.../paths/instance/orders/create/CreatePage.tsx | 4 +-
.../paths/instance/templates/create/CreatePage.tsx | 2 +-
.../src/paths/instance/templates/list/ListPage.tsx | 3 +
.../src/paths/instance/templates/list/Table.tsx | 30 +++++--
.../src/paths/instance/templates/list/index.tsx | 5 ++
.../paths/instance/templates/update/UpdatePage.tsx | 2 +-
.../use/Use.stories.tsx} | 37 +--------
.../{create/CreatePage.tsx => use/UsePage.tsx} | 93 +++++++---------------
.../instance/templates/{list => use}/index.tsx | 71 ++++++++---------
.../src/paths/instance/update/Update.stories.tsx | 4 +-
18 files changed, 133 insertions(+), 168 deletions(-)
diff --git a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx
b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx
index 1c55572bb..3be793ada 100644
--- a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx
+++ b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx
@@ -48,6 +48,7 @@ import ReservesCreatePage from
"./paths/instance/reserves/create/index.js";
import ReservesDetailsPage from "./paths/instance/reserves/details/index.js";
import ReservesListPage from "./paths/instance/reserves/list/index.js";
import TemplateCreatePage from "./paths/instance/templates/create/index.js";
+import TemplateUsePage from "./paths/instance/templates/use/index.js";
import TemplateListPage from "./paths/instance/templates/list/index.js";
import TemplateUpdatePage from "./paths/instance/templates/update/index.js";
import TransferCreatePage from "./paths/instance/transfers/create/index.js";
@@ -85,6 +86,7 @@ export enum InstancePaths {
templates_list = "/templates",
templates_update = "/templates/:tid/update",
templates_new = "/templates/new",
+ templates_use = "/templates/:tid/use",
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -399,6 +401,9 @@ export function InstanceRoutes({
onCreate={() => {
route(InstancePaths.templates_new);
}}
+ onNewOrder={(id: string) => {
+ route(InstancePaths.templates_use.replace(":tid", id));
+ }}
onSelect={(id: string) => {
route(InstancePaths.templates_update.replace(":tid", id));
}}
@@ -426,6 +431,19 @@ export function InstanceRoutes({
route(InstancePaths.templates_list);
}}
/>
+ <Route
+ path={InstancePaths.templates_use}
+ component={TemplateUsePage}
+ onOrderCreated={(id: string) => {
+ route(InstancePaths.order_details.replace(":oid", id));
+ }}
+ onUnauthorized={LoginPageAccessDenied}
+ onLoadError={ServerErrorRedirectTo(InstancePaths.templates_list)}
+ onNotFound={IfAdminCreateDefaultOr(NotFoundPage)}
+ onBack={() => {
+ route(InstancePaths.templates_list);
+ }}
+ />
{/**
* reserves pages
diff --git a/packages/merchant-backoffice-ui/src/components/form/Input.tsx
b/packages/merchant-backoffice-ui/src/components/form/Input.tsx
index 54140ba4d..c1ddcb064 100644
--- a/packages/merchant-backoffice-ui/src/components/form/Input.tsx
+++ b/packages/merchant-backoffice-ui/src/components/form/Input.tsx
@@ -92,6 +92,7 @@ export function Input<T>({
inputType={inputType}
placeholder={placeholder}
readonly={readonly}
+ disabled={readonly}
name={String(name)}
value={toStr(value)}
onChange={(e: h.JSX.TargetedEvent<HTMLInputElement>): void =>
diff --git
a/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx
b/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx
index 620922584..e5118c722 100644
--- a/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx
+++ b/packages/merchant-backoffice-ui/src/components/form/InputWithAddon.tsx
@@ -86,6 +86,7 @@ export function InputWithAddon<T>({
type={inputType}
placeholder={placeholder}
readonly={readonly}
+ disabled={readonly}
name={String(name)}
value={toStr(value)}
onChange={(e): void =>
onChange(fromStr(e.currentTarget.value))}
diff --git a/packages/merchant-backoffice-ui/src/declaration.d.ts
b/packages/merchant-backoffice-ui/src/declaration.d.ts
index 25b66bdea..b0621c13c 100644
--- a/packages/merchant-backoffice-ui/src/declaration.d.ts
+++ b/packages/merchant-backoffice-ui/src/declaration.d.ts
@@ -1347,7 +1347,7 @@ export namespace MerchantBackend {
interface UsingTemplateDetails {
// Subject of the template
- subject?: string;
+ summary?: string;
// The amount entered by the customer.
amount?: Amount;
@@ -1355,7 +1355,8 @@ export namespace MerchantBackend {
interface UsingTemplateResponse {
// After enter the request. The user will be pay with a taler URL.
- taler_url: string;
+ order_id: string,
+ token: string,
}
}
diff --git a/packages/merchant-backoffice-ui/src/hooks/templates.ts
b/packages/merchant-backoffice-ui/src/hooks/templates.ts
index 672eaf792..3a28b903d 100644
--- a/packages/merchant-backoffice-ui/src/hooks/templates.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/templates.ts
@@ -62,14 +62,14 @@ export function useTemplateAPI(): TemplateAPI {
return res;
};
- const createOrder = async (
+ const createOrderFromTemplate = async (
templateId: string,
data: MerchantBackend.Template.UsingTemplateDetails,
): Promise<
HttpResponseOk<MerchantBackend.Template.UsingTemplateResponse>
> => {
const res = await request<MerchantBackend.Template.UsingTemplateResponse>(
- `/private/templates/${templateId}`,
+ `/templates/${templateId}`,
{
method: "POST",
data,
@@ -79,7 +79,7 @@ export function useTemplateAPI(): TemplateAPI {
return res;
};
- return { createTemplate, updateTemplate, deleteTemplate, createOrder };
+ return { createTemplate, updateTemplate, deleteTemplate,
createOrderFromTemplate };
}
export interface TemplateAPI {
@@ -91,7 +91,7 @@ export interface TemplateAPI {
data: MerchantBackend.Template.TemplatePatchDetails,
) => Promise<HttpResponseOk<void>>;
deleteTemplate: (id: string) => Promise<HttpResponseOk<void>>;
- createOrder: (
+ createOrderFromTemplate: (
id: string,
data: MerchantBackend.Template.UsingTemplateDetails,
) => Promise<HttpResponseOk<MerchantBackend.Template.UsingTemplateResponse>>;
@@ -174,10 +174,9 @@ export function useInstanceTemplates(
if (afterData.data.templates.length < MAX_RESULT_SIZE) {
setPageAfter(pageAfter + 1);
} else {
- const from = `${
- afterData.data.templates[afterData.data.templates.length - 1]
- .template_id
- }`;
+ const from =
`${afterData.data.templates[afterData.data.templates.length - 1]
+ .template_id
+ }`;
if (from && updatePosition) updatePosition(from);
}
},
diff --git
a/packages/merchant-backoffice-ui/src/paths/instance/details/DetailPage.tsx
b/packages/merchant-backoffice-ui/src/paths/instance/details/DetailPage.tsx
index 4ab415e85..9a35b0797 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/details/DetailPage.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/details/DetailPage.tsx
@@ -40,8 +40,8 @@ function convert(
const payto_uris = accounts.filter((a) => a.active).map((a) => a.payto_uri);
const defaults = {
default_wire_fee_amortization: 1,
- default_pay_delay: { d_us: 1000 * 60 * 60 }, //one hour
- default_wire_transfer_delay: { d_us: 1000 * 60 * 60 * 2 }, //two hours
+ default_pay_delay: { d_us: 1000 * 60 * 60 * 1000 }, //one hour
+ default_wire_transfer_delay: { d_us: 1000 * 60 * 60 * 2 * 1000 }, //two
hours
};
return { ...defaults, ...rest, payto_uris };
}
diff --git
a/packages/merchant-backoffice-ui/src/paths/instance/details/stories.tsx
b/packages/merchant-backoffice-ui/src/paths/instance/details/stories.tsx
index cdbe732a4..3a6e0fbfe 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/details/stories.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/details/stories.tsx
@@ -59,11 +59,11 @@ export const Example = createExample(TestedComponent, {
default_max_deposit_fee: "TESTKUDOS:2",
default_max_wire_fee: "TESTKUDOS:1",
default_pay_delay: {
- d_us: 1000000,
+ d_us: 1000 * 1000, //one second
},
default_wire_fee_amortization: 1,
default_wire_transfer_delay: {
- d_us: 100000,
+ d_us: 1000 * 1000, //one second
},
merchant_pub: "ASDWQEKASJDKSADJ",
},
diff --git
a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/Create.stories.tsx
b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/Create.stories.tsx
index 5f8dbbdd9..fcf611c3c 100644
---
a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/Create.stories.tsx
+++
b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/Create.stories.tsx
@@ -45,7 +45,7 @@ export const Example = createExample(TestedComponent, {
default_max_deposit_fee: "",
default_max_wire_fee: "",
default_pay_delay: {
- d_us: 1000 * 60 * 60,
+ d_us: 1000 * 1000 * 60 * 60, //one hour
},
default_wire_fee_amortization: 1,
},
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 0c2e92418..f4a82f377 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
@@ -61,7 +61,9 @@ function with_defaults(config: InstanceConfig):
Partial<Entity> {
const defaultPayDeadline =
!config.default_pay_delay || config.default_pay_delay.d_us === "forever"
? undefined
- : add(new Date(), { seconds: config.default_pay_delay.d_us / 1000 });
+ : add(new Date(), {
+ seconds: config.default_pay_delay.d_us / (1000 * 1000),
+ });
return {
inventoryProducts: {},
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 2a47c22a0..2b8d718fb 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
@@ -72,7 +72,7 @@ export function CreatePage({ onCreate, onBack }: Props):
VNode {
? i18n.str`can't be empty`
: state.template_contract.pay_duration.d_us === "forever"
? undefined
- : state.template_contract.pay_duration.d_us < 1000
+ : state.template_contract.pay_duration.d_us < 1000 * 1000 //less
than one second
? i18n.str`to short`
: undefined,
}),
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 9d289e957..8482f7f52 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
@@ -31,6 +31,7 @@ export interface Props {
onCreate: () => void;
onDelete: (e: MerchantBackend.Template.TemplateEntry) => void;
onSelect: (e: MerchantBackend.Template.TemplateEntry) => void;
+ onNewOrder: (e: MerchantBackend.Template.TemplateEntry) => void;
}
export function ListPage({
@@ -38,6 +39,7 @@ export function ListPage({
onCreate,
onDelete,
onSelect,
+ onNewOrder,
onLoadMoreBefore,
onLoadMoreAfter,
}: Props): VNode {
@@ -54,6 +56,7 @@ export function ListPage({
onCreate={onCreate}
onDelete={onDelete}
onSelect={onSelect}
+ onNewOrder={onNewOrder}
onLoadMoreBefore={onLoadMoreBefore}
hasMoreBefore={!onLoadMoreBefore}
onLoadMoreAfter={onLoadMoreAfter}
diff --git
a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/Table.tsx
b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/Table.tsx
index fd6ea5f6f..6635d6c55 100644
---
a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/Table.tsx
+++
b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/Table.tsx
@@ -30,6 +30,7 @@ interface Props {
templates: Entity[];
onDelete: (e: Entity) => void;
onSelect: (e: Entity) => void;
+ onNewOrder: (e: Entity) => void;
onCreate: () => void;
onLoadMoreBefore?: () => void;
hasMoreBefore?: boolean;
@@ -42,6 +43,7 @@ export function CardTable({
onCreate,
onDelete,
onSelect,
+ onNewOrder,
onLoadMoreAfter,
onLoadMoreBefore,
hasMoreAfter,
@@ -81,6 +83,7 @@ export function CardTable({
instances={templates}
onDelete={onDelete}
onSelect={onSelect}
+ onNewOrder={onNewOrder}
rowSelection={rowSelection}
rowSelectionHandler={rowSelectionHandler}
onLoadMoreAfter={onLoadMoreAfter}
@@ -101,6 +104,7 @@ interface TableProps {
rowSelection: string[];
instances: Entity[];
onDelete: (e: Entity) => void;
+ onNewOrder: (e: Entity) => void;
onSelect: (e: Entity) => void;
rowSelectionHandler: StateUpdater<string[]>;
onLoadMoreBefore?: () => void;
@@ -118,6 +122,7 @@ function Table({
instances,
onLoadMoreAfter,
onDelete,
+ onNewOrder,
onSelect,
onLoadMoreBefore,
hasMoreAfter,
@@ -164,14 +169,23 @@ function Table({
>
{i.template_description}
</td>
- <td>
- <button
- class="button is-danger is-small has-tooltip-left"
- data-tooltip={i18n.str`delete selected templates from the
database`}
- onClick={() => onDelete(i)}
- >
- Delete
- </button>
+ <td class="is-actions-cell right-sticky">
+ <div class="buttons is-right">
+ <button
+ class="button is-danger is-small has-tooltip-left"
+ data-tooltip={i18n.str`delete selected templates from
the database`}
+ onClick={() => onDelete(i)}
+ >
+ Delete
+ </button>
+ <button
+ class="button is-info is-small has-tooltip-left"
+ data-tooltip={i18n.str`delete selected templates from
the database`}
+ onClick={() => onNewOrder(i)}
+ >
+ New order
+ </button>
+ </div>
</td>
</tr>
);
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 e1a2d019e..5fce3a819 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
@@ -39,6 +39,7 @@ interface Props {
onNotFound: () => VNode;
onCreate: () => void;
onSelect: (id: string) => void;
+ onNewOrder: (id: string) => void;
}
export default function ListTemplates({
@@ -46,6 +47,7 @@ export default function ListTemplates({
onLoadError,
onCreate,
onSelect,
+ onNewOrder,
onNotFound,
}: Props): VNode {
const [position, setPosition] = useState<string | undefined>(undefined);
@@ -73,6 +75,9 @@ export default function ListTemplates({
onSelect={(e) => {
onSelect(e.template_id);
}}
+ onNewOrder={(e) => {
+ onNewOrder(e.template_id);
+ }}
onDelete={(e: MerchantBackend.Template.TemplateEntry) =>
deleteTemplate(e.template_id)
.then(() =>
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 a49e8000b..718a67ae0 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
@@ -65,7 +65,7 @@ export function UpdatePage({ template, onUpdate, onBack }:
Props): VNode {
? i18n.str`can't be empty`
: state.template_contract.pay_duration.d_us === "forever"
? undefined
- : state.template_contract.pay_duration.d_us < 1000
+ : state.template_contract.pay_duration.d_us < 1000 * 1000 // less
than one second
? i18n.str`to short`
: undefined,
}),
diff --git
a/packages/merchant-backoffice-ui/src/paths/instance/update/Update.stories.tsx
b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/Use.stories.tsx
similarity index 50%
copy from
packages/merchant-backoffice-ui/src/paths/instance/update/Update.stories.tsx
copy to
packages/merchant-backoffice-ui/src/paths/instance/templates/use/Use.stories.tsx
index 58b8d87ea..f073b4235 100644
---
a/packages/merchant-backoffice-ui/src/paths/instance/update/Update.stories.tsx
+++
b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/Use.stories.tsx
@@ -20,42 +20,9 @@
*/
import { h, VNode, FunctionalComponent } from "preact";
-import { UpdatePage as TestedComponent } from "./UpdatePage.js";
+import { CreatePage as TestedComponent } from "./UsePage.js";
export default {
- title: "Pages/Instance/Update",
+ title: "Pages/Templates/Create",
component: TestedComponent,
- argTypes: {
- onUpdate: { action: "onUpdate" },
- onBack: { action: "onBack" },
- },
};
-
-function createExample<Props>(
- Component: FunctionalComponent<Props>,
- props: Partial<Props>,
-) {
- const r = (args: any) => <Component {...args} />;
- r.args = props;
- return r;
-}
-
-export const Example = createExample(TestedComponent, {
- selected: {
- accounts: [],
- name: "name",
- auth: { method: "external" },
- address: {},
- jurisdiction: {},
- default_max_deposit_fee: "TESTKUDOS:2",
- default_max_wire_fee: "TESTKUDOS:1",
- default_pay_delay: {
- d_us: 1000000,
- },
- default_wire_fee_amortization: 1,
- default_wire_transfer_delay: {
- d_us: 100000,
- },
- merchant_pub: "ASDWQEKASJDKSADJ",
- },
-});
diff --git
a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx
b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/UsePage.tsx
similarity index 51%
copy from
packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx
copy to
packages/merchant-backoffice-ui/src/paths/instance/templates/use/UsePage.tsx
index 2a47c22a0..a63469763 100644
---
a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx
+++
b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/UsePage.tsx
@@ -29,53 +29,33 @@ import {
} from "../../../../components/form/FormProvider.js";
import { Input } from "../../../../components/form/Input.js";
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 { useBackendContext } from "../../../../context/backend.js";
import { MerchantBackend } from "../../../../declaration.js";
-import { undefinedIfEmpty } from "../../../../utils/table.js";
-type Entity = MerchantBackend.Template.TemplateAddDetails;
+type Entity = MerchantBackend.Template.UsingTemplateDetails;
interface Props {
- onCreate: (d: Entity) => Promise<void>;
+ template: MerchantBackend.Template.TemplateDetails;
+ onCreateOrder: (d: Entity) => Promise<void>;
onBack?: () => void;
}
-export function CreatePage({ onCreate, onBack }: Props): VNode {
+export function UsePage({ template, onCreateOrder, onBack }: Props): VNode {
const { i18n } = useTranslationContext();
- const backend = useBackendContext();
const [state, setState] = useState<Partial<Entity>>({
- template_contract: {
- minimum_age: 0,
- pay_duration: {
- d_us: 1000 * 1000 * 60 * 30, //30 min
- },
- },
+ amount: template.template_contract.amount,
+ summary: template.template_contract.summary,
});
const errors: FormErrors<Entity> = {
- template_id: !state.template_id ? i18n.str`should not be empty` :
undefined,
- template_description: !state.template_description
- ? i18n.str`should not be empty`
- : undefined,
- template_contract: !state.template_contract
- ? undefined
- : undefinedIfEmpty({
- minimum_age:
- state.template_contract.minimum_age < 0
- ? i18n.str`should be greater that 0`
- : undefined,
- pay_duration: !state.template_contract.pay_duration
- ? i18n.str`can't be empty`
- : state.template_contract.pay_duration.d_us === "forever"
- ? undefined
- : state.template_contract.pay_duration.d_us < 1000
- ? i18n.str`to short`
- : undefined,
- }),
+ amount:
+ !template.template_contract.amount && !state.amount
+ ? i18n.str`Amount is required`
+ : undefined,
+ summary:
+ !template.template_contract.summary && !state.summary
+ ? i18n.str`Order summary is required`
+ : undefined,
};
const hasErrors = Object.keys(errors).some(
@@ -84,7 +64,13 @@ export function CreatePage({ onCreate, onBack }: Props):
VNode {
const submitForm = () => {
if (hasErrors) return Promise.reject();
- return onCreate(state as any);
+ if (template.template_contract.amount) {
+ delete state.amount;
+ }
+ if (template.template_contract.summary) {
+ delete state.summary;
+ }
+ return onCreateOrder(state as any);
};
return (
@@ -98,42 +84,19 @@ export function CreatePage({ onCreate, onBack }: Props):
VNode {
valueHandler={setState}
errors={errors}
>
- <InputWithAddon<Entity>
- name="template_id"
- addonBefore={`${backend.url}/instances/templates/`}
- label={i18n.str`Identifier`}
- tooltip={i18n.str`Name of the template in URLs.`}
+ <InputCurrency<Entity>
+ name="amount"
+ label={i18n.str`Amount`}
+ readonly={!!template.template_contract.amount}
+ tooltip={i18n.str`Amount of the order`}
/>
-
<Input<Entity>
- name="template_description"
- label={i18n.str`Description`}
- help=""
- tooltip={i18n.str`Describe what this template stands for`}
- />
- <Input
- name="template_contract.summary"
+ name="summary"
inputType="multiline"
label={i18n.str`Order summary`}
+ readonly={!!template.template_contract.summary}
tooltip={i18n.str`Title of the order to be shown to the
customer`}
/>
- <InputCurrency
- name="template_contract.amount"
- label={i18n.str`Order price`}
- tooltip={i18n.str`Order price`}
- />
- <InputNumber
- name="template_contract.minimum_age"
- label={i18n.str`Minimum age`}
- help=""
- tooltip={i18n.str`Is this contract restricted to some age?`}
- />
- <InputDuration
- name="template_contract.pay_duration"
- label={i18n.str`Payment timeout`}
- help=""
- tooltip={i18n.str`How much time has the customer to complete
the payment once the order was created.`}
- />
</FormProvider>
<div class="buttons is-right mt-5">
diff --git
a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx
b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/index.tsx
similarity index 62%
copy from
packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx
copy to
packages/merchant-backoffice-ui/src/paths/instance/templates/use/index.tsx
index e1a2d019e..fa9a98c6d 100644
---
a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/use/index.tsx
@@ -25,34 +25,36 @@ import { useState } from "preact/hooks";
import { Loading } from "../../../../components/exception/loading.js";
import { NotificationCard } from "../../../../components/menu/index.js";
import { MerchantBackend } from "../../../../declaration.js";
-import { HttpError } from "../../../../utils/request.js";
import {
- useInstanceTemplates,
useTemplateAPI,
+ useTemplateDetails,
} from "../../../../hooks/templates.js";
+import { HttpError } from "../../../../utils/request.js";
import { Notification } from "../../../../utils/types.js";
-import { ListPage } from "./ListPage.js";
+import { UsePage } from "./UsePage.js";
+export type Entity = MerchantBackend.Transfers.TransferInformation;
interface Props {
+ onBack?: () => void;
+ onOrderCreated: (id: string) => void;
onUnauthorized: () => VNode;
- onLoadError: (error: HttpError) => VNode;
onNotFound: () => VNode;
- onCreate: () => void;
- onSelect: (id: string) => void;
+ onLoadError: (e: HttpError) => VNode;
+ tid: string;
}
-export default function ListTemplates({
- onUnauthorized,
+export default function TemplateUsePage({
+ tid,
+ onOrderCreated,
+ onBack,
onLoadError,
- onCreate,
- onSelect,
onNotFound,
+ onUnauthorized,
}: Props): VNode {
- const [position, setPosition] = useState<string | undefined>(undefined);
- const { i18n } = useTranslationContext();
+ const { createOrderFromTemplate } = useTemplateAPI();
+ const result = useTemplateDetails(tid);
const [notif, setNotif] = useState<Notification | undefined>(undefined);
- const { deleteTemplate } = useTemplateAPI();
- const result = useInstanceTemplates({ position }, (id) => setPosition(id));
+ const { i18n } = useTranslationContext();
if (result.clientError && result.isUnauthorized) return onUnauthorized();
if (result.clientError && result.isNotfound) return onNotFound();
@@ -60,36 +62,25 @@ export default function ListTemplates({
if (!result.ok) return onLoadError(result);
return (
- <Fragment>
+ <>
<NotificationCard notification={notif} />
-
- <ListPage
- templates={result.data.templates}
- onLoadMoreBefore={
- result.isReachingStart ? result.loadMorePrev : undefined
- }
- onLoadMoreAfter={result.isReachingEnd ? result.loadMore : undefined}
- onCreate={onCreate}
- onSelect={(e) => {
- onSelect(e.template_id);
- }}
- onDelete={(e: MerchantBackend.Template.TemplateEntry) =>
- deleteTemplate(e.template_id)
- .then(() =>
+ <UsePage
+ template={result.data}
+ onBack={onBack}
+ onCreateOrder={(
+ request: MerchantBackend.Template.UsingTemplateDetails,
+ ) => {
+ return createOrderFromTemplate(tid, request)
+ .then((res) => onOrderCreated(res.data.order_id))
+ .catch((error) => {
setNotif({
- message: i18n.str`template delete successfully`,
- type: "SUCCESS",
- }),
- )
- .catch((error) =>
- setNotif({
- message: i18n.str`could not delete the template`,
+ message: i18n.str`could not create order from template`,
type: "ERROR",
description: error.message,
- }),
- )
- }
+ });
+ });
+ }}
/>
- </Fragment>
+ </>
);
}
diff --git
a/packages/merchant-backoffice-ui/src/paths/instance/update/Update.stories.tsx
b/packages/merchant-backoffice-ui/src/paths/instance/update/Update.stories.tsx
index 58b8d87ea..045c96c2c 100644
---
a/packages/merchant-backoffice-ui/src/paths/instance/update/Update.stories.tsx
+++
b/packages/merchant-backoffice-ui/src/paths/instance/update/Update.stories.tsx
@@ -50,11 +50,11 @@ export const Example = createExample(TestedComponent, {
default_max_deposit_fee: "TESTKUDOS:2",
default_max_wire_fee: "TESTKUDOS:1",
default_pay_delay: {
- d_us: 1000000,
+ d_us: 1000 * 1000, //one second
},
default_wire_fee_amortization: 1,
default_wire_transfer_delay: {
- d_us: 100000,
+ d_us: 1000 * 1000, //one second
},
merchant_pub: "ASDWQEKASJDKSADJ",
},
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.