import { notifyInfo, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; import { Cashouts } from "../../components/Cashouts/index.js"; import { ShowCashoutDetails } from "../business/Home.js"; import { handleNotOkResult } from "../HomePage.js"; import { ShowAccountDetails } from "../ShowAccountDetails.js"; import { UpdateAccountPassword } from "../UpdateAccountPassword.js"; import { AdminAccount } from "./Account.js"; import { AccountList } from "./AccountList.js"; import { CreateNewAccount } from "./CreateNewAccount.js"; import { RemoveAccount } from "./RemoveAccount.js"; /** * Query account information and show QR code if there is pending withdrawal */ interface Props { onRegister: () => void; } export type AccountAction = "show-details" | "show-cashout" | "update-password" | "remove-account" | "show-cashouts-details"; export function AdminHome({ onRegister }: Props): VNode { const [action, setAction] = useState<{ type: AccountAction, account: string } | undefined>() const [createAccount, setCreateAccount] = useState(false); const { i18n } = useTranslationContext(); if (action) { switch (action.type) { case "show-cashouts-details": return { setAction(undefined); }} /> case "show-cashout": return (

Cashout for account {action.account}

{ setAction({ type: "show-cashouts-details", account: action.account }); }} />

{ e.preventDefault(); setAction(undefined); }} />

) case "update-password": return { notifyInfo(i18n.str`Password changed`); setAction(undefined); }} onCancel={() => { setAction(undefined); }} /> case "remove-account": return { notifyInfo(i18n.str`Account removed`); setAction(undefined); }} onCancel={() => { setAction(undefined); }} /> case "show-details": return { setAction({ type: "update-password", account: action.account, }) }} onUpdateSuccess={() => { notifyInfo(i18n.str`Account updated`); setAction(undefined); }} onClear={() => { setAction(undefined); }} /> } } if (createAccount) { return ( setCreateAccount(false)} onCreateSuccess={(password) => { notifyInfo( i18n.str`Account created with password "${password}". The user must change the password on the next login.`, ); setCreateAccount(false); }} /> ); } return ( { setCreateAccount(true); }} account={undefined} onAction={(type, account) => setAction({ account, type })} onRegister={onRegister} /> ); }