/* This file is part of GNU Taler (C) 2021-2023 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 */ /** * * @author Sebastian Javier Marchano (sebasjm) */ import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { format } from "date-fns"; import { Fragment, h, VNode } from "preact"; import { MerchantBackend, WithId } from "../../../../declaration.js"; import { datetimeFormatForSettings, useSettings } from "../../../../hooks/useSettings.js"; type Entity = MerchantBackend.Rewards.ReserveStatusEntry & WithId; interface Props { instances: Entity[]; onNewReward: (id: Entity) => void; onSelect: (id: Entity) => void; onDelete: (id: Entity) => void; onCreate: () => void; } export function CardTable({ instances, onCreate, onSelect, onNewReward, onDelete, }: Props): VNode { const [withoutFunds, withFunds] = instances.reduce((prev, current) => { const amount = current.exchange_initial_amount; if (amount.endsWith(":0")) { prev[0] = prev[0].concat(current); } else { prev[1] = prev[1].concat(current); } return prev; }, new Array>([], [])); const { i18n } = useTranslationContext(); return ( {withoutFunds.length > 0 && (

Reserves not yet funded

)}

Reserves ready

{withFunds.length > 0 ? ( ) : ( )} ); } interface TableProps { instances: Entity[]; onNewReward: (id: Entity) => void; onDelete: (id: Entity) => void; onSelect: (id: Entity) => void; } function Table({ instances, onNewReward, onSelect, onDelete }: TableProps): VNode { const { i18n } = useTranslationContext(); const [settings] = useSettings(); return (
{instances.map((i) => { return ( ); })}
Created at Expires at Initial Picked up Committed
onSelect(i)} style={{ cursor: "pointer" }} > {i.creation_time.t_s === "never" ? "never" : format(i.creation_time.t_s * 1000, datetimeFormatForSettings(settings))} onSelect(i)} style={{ cursor: "pointer" }} > {i.expiration_time.t_s === "never" ? "never" : format( i.expiration_time.t_s * 1000, datetimeFormatForSettings(settings), )} onSelect(i)} style={{ cursor: "pointer" }} > {i.exchange_initial_amount} onSelect(i)} style={{ cursor: "pointer" }} > {i.pickup_amount} onSelect(i)} style={{ cursor: "pointer" }} > {i.committed_amount}
); } function EmptyTable(): VNode { const { i18n } = useTranslationContext(); return (

There is no ready reserves yet, add more pressing the + sign or fund them

); } function TableWithoutFund({ instances, onSelect, onDelete, }: TableProps): VNode { const { i18n } = useTranslationContext(); const [settings] = useSettings(); return (
{instances.map((i) => { return ( ); })}
Created at Expires at Expected Balance
onSelect(i)} style={{ cursor: "pointer" }} > {i.creation_time.t_s === "never" ? "never" : format(i.creation_time.t_s * 1000, datetimeFormatForSettings(settings))} onSelect(i)} style={{ cursor: "pointer" }} > {i.expiration_time.t_s === "never" ? "never" : format( i.expiration_time.t_s * 1000, datetimeFormatForSettings(settings), )} onSelect(i)} style={{ cursor: "pointer" }} > {i.merchant_initial_amount}
); }