From 8f32ad272dd319b74e0a4a3d3ecc1472884c87e2 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 6 Mar 2023 15:12:43 -0300 Subject: centered forms, show balance in accont info --- packages/demobank-ui/src/declaration.d.ts | 13 +- packages/demobank-ui/src/pages/AdminPage.tsx | 473 ++++++++++++++------------- 2 files changed, 259 insertions(+), 227 deletions(-) (limited to 'packages/demobank-ui/src') diff --git a/packages/demobank-ui/src/declaration.d.ts b/packages/demobank-ui/src/declaration.d.ts index 03ab8f2a8..8dc5fd8b2 100644 --- a/packages/demobank-ui/src/declaration.d.ts +++ b/packages/demobank-ui/src/declaration.d.ts @@ -99,6 +99,11 @@ type Amount = string; type UUID = string; type Integer = number; +interface Balance { + amount: Amount; + credit_debit_indicator: "credit" | "debit"; +} + namespace SandboxBackend { export interface Config { // Name of this API, always "circuit". @@ -161,10 +166,7 @@ namespace SandboxBackend { interface BankAccountBalanceResponse { // Available balance on the account. - balance: { - amount: Amount; - credit_debit_indicator: "credit" | "debit"; - }; + balance: Balance; // payto://-URI of the account. (New) paytoUri: string; } @@ -304,6 +306,9 @@ namespace SandboxBackend { // Legal subject owning the account. name: string; + + // current balance of the account + balance: Balance; } interface CircuitAccountData { diff --git a/packages/demobank-ui/src/pages/AdminPage.tsx b/packages/demobank-ui/src/pages/AdminPage.tsx index 3d0c09cbf..58b048b83 100644 --- a/packages/demobank-ui/src/pages/AdminPage.tsx +++ b/packages/demobank-ui/src/pages/AdminPage.tsx @@ -230,7 +230,10 @@ export function AdminPage({ onLoadNotOk }: Props): VNode {

-
+
{!customers.length ? (
) : ( @@ -242,12 +245,18 @@ export function AdminPage({ onLoadNotOk }: Props): VNode { {i18n.str`Username`} {i18n.str`Name`} - - + {i18n.str`Balance`} + {i18n.str`Actions`} {customers.map((item, idx) => { + const balance = !item.balance + ? undefined + : Amounts.parse(item.balance.amount); + const balanceIsDebit = + item.balance && + item.balance.credit_debit_indicator == "debit"; return ( @@ -262,6 +271,20 @@ export function AdminPage({ onLoadNotOk }: Props): VNode { {item.name} + + {!balance ? ( + i18n.str`unknown` + ) : ( + + {balanceIsDebit ? - : null} + {`${Amounts.stringifyValue( + balance, + )}`} +   + {`${balance.currency}`} + + )} + change password - - +   { @@ -283,8 +305,7 @@ export function AdminPage({ onLoadNotOk }: Props): VNode { > cashouts - - +   { @@ -384,82 +405,84 @@ export function UpdateAccountPassword({ saveError(undefined)} /> )} -
-
- - { - setPassword(e.currentTarget.value); - }} - /> - -
-
- - { - setRepeat(e.currentTarget.value); - }} - /> - -
-
-

-

-
+
+
+
+ { - e.preventDefault(); - onClear(); + type="password" + value={password ?? ""} + onChange={(e) => { + setPassword(e.currentTarget.value); }} /> -
-
+ + +
+ { - e.preventDefault(); - if (!!errors || !password) return; - try { - const r = await changePassword(account, { - new_password: password, - }); - onUpdateSuccess(); - } catch (error) { - if (error instanceof RequestError) { - saveError(buildRequestErrorMessage(i18n, error.cause)); - } else { - saveError({ - title: i18n.str`Operation failed, please report`, - description: - error instanceof Error - ? error.message - : JSON.stringify(error), - }); - } - } + type="password" + value={repeat ?? ""} + onChange={(e) => { + setRepeat(e.currentTarget.value); }} /> + +
+ +

+

+
+ { + e.preventDefault(); + onClear(); + }} + /> +
+
+ { + e.preventDefault(); + if (!!errors || !password) return; + try { + const r = await changePassword(account, { + new_password: password, + }); + onUpdateSuccess(); + } catch (error) { + if (error instanceof RequestError) { + saveError(buildRequestErrorMessage(i18n, error.cause)); + } else { + saveError({ + title: i18n.str`Operation failed, please report`, + description: + error instanceof Error + ? error.message + : JSON.stringify(error), + }); + } + } + }} + /> +
-
-

+

+
); } @@ -488,81 +511,83 @@ function CreateNewAccount({ saveError(undefined)} /> )} - { - console.log(a); - setSubmitAccount(a); - }} - /> +
+ { + console.log(a); + setSubmitAccount(a); + }} + /> -

-

-
- { - e.preventDefault(); - onClose(); - }} - /> -
-
- { - e.preventDefault(); +

+

+
+ { + e.preventDefault(); + onClose(); + }} + /> +
+
+ { + e.preventDefault(); - if (!submitAccount) return; - try { - const account: SandboxBackend.Circuit.CircuitAccountRequest = - { - cashout_address: submitAccount.cashout_address, - contact_data: submitAccount.contact_data, - internal_iban: submitAccount.iban, - name: submitAccount.name, - username: submitAccount.username, - password: randomPassword(), - }; - - await createAccount(account); - onCreateSuccess(account.password); - } catch (error) { - if (error instanceof RequestError) { - saveError( - buildRequestErrorMessage(i18n, error.cause, { - onClientError: (status) => - status === HttpStatusCode.Forbidden - ? i18n.str`The rights to perform the operation are not sufficient` - : status === HttpStatusCode.BadRequest - ? i18n.str`Input data was invalid` - : status === HttpStatusCode.Conflict - ? i18n.str`At least one registration detail was not available` - : undefined, - }), - ); - } else { - saveError({ - title: i18n.str`Operation failed, please report`, - description: - error instanceof Error - ? error.message - : JSON.stringify(error), - }); + if (!submitAccount) return; + try { + const account: SandboxBackend.Circuit.CircuitAccountRequest = + { + cashout_address: submitAccount.cashout_address, + contact_data: submitAccount.contact_data, + internal_iban: submitAccount.iban, + name: submitAccount.name, + username: submitAccount.username, + password: randomPassword(), + }; + + await createAccount(account); + onCreateSuccess(account.password); + } catch (error) { + if (error instanceof RequestError) { + saveError( + buildRequestErrorMessage(i18n, error.cause, { + onClientError: (status) => + status === HttpStatusCode.Forbidden + ? i18n.str`The rights to perform the operation are not sufficient` + : status === HttpStatusCode.BadRequest + ? i18n.str`Input data was invalid` + : status === HttpStatusCode.Conflict + ? i18n.str`At least one registration detail was not available` + : undefined, + }), + ); + } else { + saveError({ + title: i18n.str`Operation failed, please report`, + description: + error instanceof Error + ? error.message + : JSON.stringify(error), + }); + } } - } - }} - /> + }} + /> +
-
-

+

+
); } @@ -608,90 +633,92 @@ export function ShowAccountDetails({ {error && ( saveError(undefined)} /> )} - setSubmitAccount(a)} - /> +
+ setSubmitAccount(a)} + /> -

-

-
- {onClear ? ( - { - e.preventDefault(); - onClear(); - }} - /> - ) : undefined} -
-
+

+

- { - e.preventDefault(); - onChangePassword(); - }} - /> + {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) { - if (error instanceof RequestError) { - saveError( - buildRequestErrorMessage(i18n, error.cause, { - onClientError: (status) => - status === HttpStatusCode.Forbidden - ? i18n.str`The rights to change the account are not sufficient` - : status === HttpStatusCode.NotFound - ? i18n.str`The username was not found` - : undefined, - }), - ); - } else { - saveError({ - title: i18n.str`Operation failed, please report`, - description: - error instanceof Error - ? error.message - : JSON.stringify(error), +
+
+ { + 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) { + if (error instanceof RequestError) { + saveError( + buildRequestErrorMessage(i18n, error.cause, { + onClientError: (status) => + status === HttpStatusCode.Forbidden + ? i18n.str`The rights to change the account are not sufficient` + : status === HttpStatusCode.NotFound + ? i18n.str`The username was not found` + : undefined, + }), + ); + } else { + saveError({ + title: i18n.str`Operation failed, please report`, + description: + error instanceof Error + ? error.message + : JSON.stringify(error), + }); + } } } - } - }} - /> + }} + /> +
-
-

+

+
); } -- cgit v1.2.3