/* This file is part of GNU Taler (C) 2022-2024 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 */ import { Amounts, HttpStatusCode, TalerError, assertUnreachable, } from "@gnu-taler/taler-util"; import { Loading, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { ErrorLoadingWithDebug } from "../../components/ErrorLoadingWithDebug.js"; import { useBankCoreApiContext } from "@gnu-taler/web-util/browser"; import { useBusinessAccounts } from "../../hooks/regional.js"; import { RouteDefinition } from "@gnu-taler/web-util/browser"; import { RenderAmount } from "../PaytoWireTransferForm.js"; interface Props { routeCreate: RouteDefinition; routeShowAccount: RouteDefinition<{ account: string }>; routeRemoveAccount: RouteDefinition<{ account: string }>; routeUpdatePasswordAccount: RouteDefinition<{ account: string }>; } export function AccountList({ routeCreate, routeRemoveAccount, routeShowAccount, routeUpdatePasswordAccount, }: Props): VNode { const result = useBusinessAccounts(); const { i18n } = useTranslationContext(); const { config } = useBankCoreApiContext(); if (!result) { return ; } if (result instanceof TalerError) { return ; } if (result.type === "fail") { switch (result.case) { case HttpStatusCode.Unauthorized: return ; default: assertUnreachable(result.case); } } const onGoStart = result.isFirstPage ? undefined : result.loadFirst; const onGoNext = result.isLastPage ? undefined : result.loadNext; const accounts = result.body; return (
{!accounts.length ? (
{/* FIXME: ADD empty list */}
) : ( {accounts.map((item, idx) => { const balance = !item.balance ? undefined : Amounts.parse(item.balance.amount); const noBalance = Amounts.isZero(item.balance.amount); const balanceIsDebit = item.balance && item.balance.credit_debit_indicator == "debit"; return ( ); })}
{i18n.str`Username`} {i18n.str`Name`} {i18n.str`Balance`} {i18n.str`Actions`}
{item.username} {item.name} {!balance ? ( i18n.str`Unknown` ) : ( )} Change password
{/* {config.allow_conversion ? Cashouts
: undefined} */} {noBalance ? ( Remove ) : undefined}
)}
); }