commit 07df6b6b872aa088b42d716323a208d41243317a
parent e0a799b765a0b6643e8715343371e19b645fe2dc
Author: Sebastian <sebasjm@gmail.com>
Date: Fri, 1 Jul 2022 12:09:23 -0300
add tip details and some fixes with time format
Diffstat:
5 files changed, 133 insertions(+), 16 deletions(-)
diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/details/DetailPage.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/details/DetailPage.tsx
@@ -22,15 +22,18 @@
import { Amounts } from "@gnu-taler/taler-util";
import { format } from "date-fns";
import { Fragment, h, VNode } from "preact";
+import { useState } from "preact/hooks";
import { QR } from "../../../../components/exception/QR";
import { FormProvider } from "../../../../components/form/FormProvider";
import { Input } from "../../../../components/form/Input";
import { InputCurrency } from "../../../../components/form/InputCurrency";
import { InputDate } from "../../../../components/form/InputDate";
import { TextField } from "../../../../components/form/TextField";
+import { ContinueModal, SimpleModal } from "../../../../components/modal";
import { MerchantBackend } from "../../../../declaration";
import { useTipDetails } from "../../../../hooks/reserves";
import { Translate, useTranslator } from "../../../../i18n";
+import { TipInfo } from "./TipInfo";
type Entity = MerchantBackend.Tips.ReserveDetail;
type CT = MerchantBackend.ContractTerms;
@@ -223,6 +226,7 @@ function TipRow({
id: string;
entry: MerchantBackend.Tips.TipStatusEntry;
}) {
+ const [selected, setSelected] = useState(false);
const result = useTipDetails(id);
if (result.loading) {
return (
@@ -245,16 +249,30 @@ function TipRow({
);
}
const info = result.data;
+ function onSelect() {
+ setSelected(true);
+ }
return (
- <tr>
- <td>{info.total_authorized}</td>
- <td>{info.total_picked_up}</td>
- <td>{info.reason}</td>
- <td>
- {info.expiration.t_s === "never"
- ? "never"
- : format(info.expiration.t_s, "yyyy/MM/dd HH:mm:ss")}
- </td>
- </tr>
+ <Fragment>
+ {selected && (
+ <SimpleModal
+ description="tip"
+ active
+ onCancel={() => setSelected(false)}
+ >
+ <TipInfo id={id} amount={info.total_authorized} entity={info} />
+ </SimpleModal>
+ )}
+ <tr>
+ <td onClick={onSelect}>{info.total_authorized}</td>
+ <td onClick={onSelect}>{info.total_picked_up}</td>
+ <td onClick={onSelect}>{info.reason}</td>
+ <td onClick={onSelect}>
+ {info.expiration.t_s === "never"
+ ? "never"
+ : format(info.expiration.t_s * 1000, "yyyy/MM/dd HH:mm:ss")}
+ </td>
+ </tr>
+ </Fragment>
);
}
diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/details/TipInfo.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/details/TipInfo.tsx
@@ -0,0 +1,87 @@
+/*
+ This file is part of GNU Taler
+ (C) 2021 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+import { format } from "date-fns";
+import { Fragment, h, VNode } from "preact";
+import { useBackendContext } from "../../../../context/backend";
+import { MerchantBackend } from "../../../../declaration";
+
+type Entity = MerchantBackend.Tips.TipDetails;
+
+interface Props {
+ id: string;
+ entity: Entity;
+ amount: string;
+}
+
+export function TipInfo({ id, amount, entity }: Props): VNode {
+ const { url } = useBackendContext();
+ const tipHost = url.replace(/.*:\/\//, ""); // remove protocol part
+ const proto = url.startsWith("http://") ? "taler+http" : "taler";
+ const tipURL = `${proto}://tip/${tipHost}/${id}`;
+ return (
+ <Fragment>
+ <div class="field is-horizontal">
+ <div class="field-label is-normal">
+ <label class="label">Amount</label>
+ </div>
+ <div class="field-body is-flex-grow-3">
+ <div class="field">
+ <p class="control">
+ <input readonly class="input" value={amount} />
+ </p>
+ </div>
+ </div>
+ </div>
+ <div class="field is-horizontal">
+ <div class="field-label is-normal">
+ <label class="label">URL</label>
+ </div>
+ <div class="field-body is-flex-grow-3">
+ <div class="field" style={{ overflowWrap: "anywhere" }}>
+ <p class="control">
+ <a target="_blank" rel="noreferrer" href={tipURL}>
+ {tipURL}
+ </a>
+ </p>
+ </div>
+ </div>
+ </div>
+ <div class="field is-horizontal">
+ <div class="field-label is-normal">
+ <label class="label">Valid until</label>
+ </div>
+ <div class="field-body is-flex-grow-3">
+ <div class="field">
+ <p class="control">
+ <input
+ class="input"
+ readonly
+ value={
+ !entity.expiration || entity.expiration.t_s === "never"
+ ? "never"
+ : format(
+ entity.expiration.t_s * 1000,
+ "yyyy/MM/dd HH:mm:ss"
+ )
+ }
+ />
+ </p>
+ </div>
+ </div>
+ </div>
+ </Fragment>
+ );
+}
diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/list/CreatedSuccessfully.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/list/CreatedSuccessfully.tsx
@@ -85,7 +85,10 @@ export function CreatedSuccessfully({
!entity.tip_expiration ||
entity.tip_expiration.t_s === "never"
? "never"
- : format(entity.tip_expiration.t_s, "yyyy/MM/dd HH:mm:ss")
+ : format(
+ entity.tip_expiration.t_s * 1000,
+ "yyyy/MM/dd HH:mm:ss"
+ )
}
/>
</p>
diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/list/Table.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/list/Table.tsx
@@ -161,7 +161,7 @@ function Table({ instances, onNewTip, onSelect, onDelete }: TableProps): VNode {
>
{i.creation_time.t_s === "never"
? "never"
- : format(i.creation_time.t_s, "yyyy/MM/dd HH:mm:ss")}
+ : format(i.creation_time.t_s * 1000, "yyyy/MM/dd HH:mm:ss")}
</td>
<td
onClick={(): void => onSelect(i)}
@@ -169,7 +169,10 @@ function Table({ instances, onNewTip, onSelect, onDelete }: TableProps): VNode {
>
{i.expiration_time.t_s === "never"
? "never"
- : format(i.expiration_time.t_s, "yyyy/MM/dd HH:mm:ss")}
+ : format(
+ i.expiration_time.t_s * 1000,
+ "yyyy/MM/dd HH:mm:ss"
+ )}
</td>
<td
onClick={(): void => onSelect(i)}
@@ -269,7 +272,7 @@ function TableWithoutFund({
>
{i.creation_time.t_s === "never"
? "never"
- : format(i.creation_time.t_s, "yyyy/MM/dd HH:mm:ss")}
+ : format(i.creation_time.t_s * 1000, "yyyy/MM/dd HH:mm:ss")}
</td>
<td
onClick={(): void => onSelect(i)}
@@ -277,7 +280,10 @@ function TableWithoutFund({
>
{i.expiration_time.t_s === "never"
? "never"
- : format(i.expiration_time.t_s, "yyyy/MM/dd HH:mm:ss")}
+ : format(
+ i.expiration_time.t_s * 1000,
+ "yyyy/MM/dd HH:mm:ss"
+ )}
</td>
<td
onClick={(): void => onSelect(i)}
diff --git a/packages/merchant-backoffice/src/paths/instance/transfers/list/Table.tsx b/packages/merchant-backoffice/src/paths/instance/transfers/list/Table.tsx
@@ -171,7 +171,10 @@ function Table({
{i.execution_time
? i.execution_time.t_s == "never"
? i18n`never`
- : format(i.execution_time.t_s, "yyyy/MM/dd HH:mm:ss")
+ : format(
+ i.execution_time.t_s * 1000,
+ "yyyy/MM/dd HH:mm:ss"
+ )
: i18n`unknown`}
</td>
<td>