From ba8b40c9150586982e42e76d364d76202627bd6f Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 10 Feb 2023 09:51:37 -0300 Subject: business account --- packages/demobank-ui/src/pages/AdminPage.tsx | 117 ++++++++++++++++----------- 1 file changed, 68 insertions(+), 49 deletions(-) (limited to 'packages/demobank-ui/src/pages/AdminPage.tsx') diff --git a/packages/demobank-ui/src/pages/AdminPage.tsx b/packages/demobank-ui/src/pages/AdminPage.tsx index 9efd37f12..f8efddd80 100644 --- a/packages/demobank-ui/src/pages/AdminPage.tsx +++ b/packages/demobank-ui/src/pages/AdminPage.tsx @@ -24,8 +24,8 @@ import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { ErrorMessage, usePageContext } from "../context/pageState.js"; import { - useAccountDetails, - useAccounts, + useBusinessAccountDetails, + useBusinessAccounts, useAdminAccountAPI, } from "../hooks/circuit.js"; import { @@ -71,7 +71,7 @@ export function AdminPage({ onLoadNotOk }: Props): VNode { })); } - const result = useAccounts({ account }); + const result = useBusinessAccounts({ account }); const { i18n } = useTranslationContext(); if (result.loading) return
; @@ -86,6 +86,10 @@ export function AdminPage({ onLoadNotOk }: Props): VNode { { + setUpdatePassword(showDetails); + setShowDetails(undefined); + }} onUpdateSuccess={() => { showInfoMessage(i18n.str`Account updated`); setShowDetails(undefined); @@ -230,7 +234,7 @@ function initializeFromTemplate( return initial as any; } -function UpdateAccountPassword({ +export function UpdateAccountPassword({ account, onClear, onUpdateSuccess, @@ -242,7 +246,7 @@ function UpdateAccountPassword({ account: string; }): VNode { const { i18n } = useTranslationContext(); - const result = useAccountDetails(account); + const result = useBusinessAccountDetails(account); const { changePassword } = useAdminAccountAPI(); const [password, setPassword] = useState(); const [repeat, setRepeat] = useState(); @@ -268,7 +272,7 @@ function UpdateAccountPassword({

- Admin panel + Update password for {account}

{error && ( @@ -276,10 +280,6 @@ function UpdateAccountPassword({ )}
-
- - -

- Admin panel + New account

{error && ( @@ -428,19 +428,21 @@ function CreateNewAccount({ ); } -function ShowAccountDetails({ +export function ShowAccountDetails({ account, onClear, onUpdateSuccess, onLoadNotOk, + onChangePassword, }: { onLoadNotOk: (error: HttpResponsePaginated) => VNode; - onClear: () => void; + onClear?: () => void; + onChangePassword: () => void; onUpdateSuccess: () => void; account: string; }): VNode { const { i18n } = useTranslationContext(); - const result = useAccountDetails(account); + const result = useBusinessAccountDetails(account); const { updateAccount } = useAdminAccountAPI(); const [update, setUpdate] = useState(false); const [submitAccount, setSubmitAccount] = useState< @@ -459,7 +461,7 @@ function ShowAccountDetails({

- Admin panel + Business account details

{error && ( @@ -474,42 +476,59 @@ function ShowAccountDetails({

- { - e.preventDefault(); - onClear(); - }} - /> + {onClear ? ( + { + e.preventDefault(); + onClear(); + }} + /> + ) : undefined}
-
- { - e.preventDefault(); - - if (!update) { - setUpdate(true); - } else { - if (!submitAccount) return; - try { - await updateAccount(account, { - cashout_address: submitAccount.cashout_address, - contact_data: submitAccount.contact_data, - }); - onUpdateSuccess(); - } catch (error) { - handleError(error, saveError, i18n); +
+
+ { + e.preventDefault(); + onChangePassword(); + }} + /> +
+
+ { + e.preventDefault(); + + if (!update) { + setUpdate(true); + } else { + if (!submitAccount) return; + try { + await updateAccount(account, { + cashout_address: submitAccount.cashout_address, + contact_data: submitAccount.contact_data, + }); + onUpdateSuccess(); + } catch (error) { + handleError(error, saveError, i18n); + } } - } - }} - /> + }} + /> +

-- cgit v1.2.3