aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/admin/AccountList.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/pages/admin/AccountList.tsx')
-rw-r--r--packages/demobank-ui/src/pages/admin/AccountList.tsx58
1 files changed, 35 insertions, 23 deletions
diff --git a/packages/demobank-ui/src/pages/admin/AccountList.tsx b/packages/demobank-ui/src/pages/admin/AccountList.tsx
index 8a1e8294a..39b43b9b1 100644
--- a/packages/demobank-ui/src/pages/admin/AccountList.tsx
+++ b/packages/demobank-ui/src/pages/admin/AccountList.tsx
@@ -1,22 +1,26 @@
import { Amounts, TalerError } from "@gnu-taler/taler-util";
import { useTranslationContext } from "@gnu-taler/web-util/browser";
-import { VNode, h } from "preact";
+import { Fragment, VNode, h } from "preact";
import { ErrorLoading } from "../../components/ErrorLoading.js";
import { Loading } from "../../components/Loading.js";
import { useBusinessAccounts } from "../../hooks/circuit.js";
import { assertUnreachable } from "../HomePage.js";
import { RenderAmount } from "../PaytoWireTransferForm.js";
-import { AccountAction } from "./Home.js";
+import { useBankCoreApiContext } from "../../context/config.js";
interface Props {
- onAction: (type: AccountAction, account: string) => void;
- account: string | undefined;
onCreateAccount: () => void;
+
+ onShowAccountDetails: (aid: string) => void;
+ onRemoveAccount: (aid: string) => void;
+ onUpdateAccountPassword: (aid: string) => void;
+ onShowCashoutForAccount: (aid: string) => void;
}
-export function AccountList({ account, onAction, onCreateAccount }: Props): VNode {
+export function AccountList({ onRemoveAccount, onShowAccountDetails, onUpdateAccountPassword, onShowCashoutForAccount, onCreateAccount }: Props): VNode {
const result = useBusinessAccounts();
const { i18n } = useTranslationContext();
+ const { config } = useBankCoreApiContext()
if (!result) {
return <Loading />
@@ -74,6 +78,7 @@ export function AccountList({ account, onAction, onCreateAccount }: Props): VNod
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";
@@ -83,7 +88,7 @@ export function AccountList({ account, onAction, onCreateAccount }: Props): VNod
<a href="#" class="text-indigo-600 hover:text-indigo-900"
onClick={(e) => {
e.preventDefault();
- onAction("show-details", item.username)
+ onShowAccountDetails(item.username)
}}
>
{item.username}
@@ -94,7 +99,7 @@ export function AccountList({ account, onAction, onCreateAccount }: Props): VNod
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
{item.name}
</td>
- <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
+ <td data-negative={noBalance ? undefined : balanceIsDebit ? "true" : "false"} class="whitespace-nowrap px-3 py-4 text-sm text-gray-500 data-[negative=false]:text-green-600 data-[negative=true]:text-red-600 ">
{!balance ? (
i18n.str`unknown`
) : (
@@ -107,27 +112,34 @@ export function AccountList({ account, onAction, onCreateAccount }: Props): VNod
<a href="#" class="text-indigo-600 hover:text-indigo-900"
onClick={(e) => {
e.preventDefault();
- onAction("update-password", item.username)
+ onUpdateAccountPassword(item.username)
}}
>
change password
</a>
<br />
- <a href="#" class="text-indigo-600 hover:text-indigo-900" onClick={(e) => {
- e.preventDefault();
- onAction("show-cashout", item.username)
- }}
- >
- cashouts
- </a>
- <br />
- <a href="#" class="text-indigo-600 hover:text-indigo-900" onClick={(e) => {
- e.preventDefault();
- onAction("remove-account", item.username)
- }}
- >
- remove
- </a>
+ {config.have_cashout ?
+ <Fragment>
+
+ <a href="#" class="text-indigo-600 hover:text-indigo-900" onClick={(e) => {
+ e.preventDefault();
+ onShowCashoutForAccount(item.username)
+ }}
+ >
+ cashouts
+ </a>
+ <br />
+ </Fragment>
+ : undefined}
+ {noBalance ?
+ <a href="#" class="text-indigo-600 hover:text-indigo-900" onClick={(e) => {
+ e.preventDefault();
+ onRemoveAccount(item.username)
+ }}
+ >
+ remove
+ </a>
+ : undefined}
</td>
</tr>
})}