diff options
Diffstat (limited to 'packages/bank-ui/src/pages/admin')
-rw-r--r-- | packages/bank-ui/src/pages/admin/AccountForm.tsx | 68 | ||||
-rw-r--r-- | packages/bank-ui/src/pages/admin/CreateNewAccount.tsx | 9 |
2 files changed, 70 insertions, 7 deletions
diff --git a/packages/bank-ui/src/pages/admin/AccountForm.tsx b/packages/bank-ui/src/pages/admin/AccountForm.tsx index c8195ddb0..21e3e6588 100644 --- a/packages/bank-ui/src/pages/admin/AccountForm.tsx +++ b/packages/bank-ui/src/pages/admin/AccountForm.tsx @@ -52,6 +52,7 @@ const REGEX_JUST_NUMBERS_REGEX = /^\+[0-9 ]*$/; export type AccountFormData = { debit_threshold?: string; + min_cashout?: string; isExchange?: boolean; isPublic?: boolean; name?: string; @@ -111,6 +112,9 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ debit_threshold: Amounts.stringifyValue( template?.debit_threshold ?? config.default_debit_threshold, ), + min_cashout: Amounts.stringifyValue( + template?.min_cashout ?? `${config.currency}:0`, + ), isExchange: template?.is_taler_exchange, isPublic: template?.is_public, name: template?.name ?? "", @@ -140,12 +144,18 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ (config.allow_edit_cashout_payto_uri || userIsAdmin)); const editableThreshold = userIsAdmin && (purpose === "create" || purpose === "update"); + const editableMinCashout = + userIsAdmin && (purpose === "create" || purpose === "update"); const editableAccount = purpose === "create" && userIsAdmin; function updateForm(newForm: typeof defaultValue): void { - const trimmedAmountStr = newForm.debit_threshold?.trim(); - const parsedAmount = Amounts.parse( - `${config.currency}:${trimmedAmountStr}`, + const trimmedMinCashoutStr = newForm.min_cashout?.trim(); + const parsedMinCashout = Amounts.parse( + `${config.currency}:${trimmedMinCashoutStr}`, + ); + const trimmedDebitThresholdStr = newForm.debit_threshold?.trim(); + const parsedDebitThreshold = Amounts.parse( + `${config.currency}:${trimmedDebitThresholdStr}`, ); const errors = undefinedIfEmpty< @@ -189,9 +199,16 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ : undefined, debit_threshold: !editableThreshold ? undefined - : !trimmedAmountStr + : !trimmedDebitThresholdStr + ? undefined + : !parsedDebitThreshold + ? i18n.str`Not valid` + : undefined, + min_cashout: !editableMinCashout + ? undefined + : !trimmedMinCashoutStr ? undefined - : !parsedAmount + : !parsedMinCashout ? i18n.str`Not valid` : undefined, name: !editableName @@ -248,9 +265,12 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ } const internalURI = !internal ? undefined : stringifyPaytoUri(internal); - const threshold = !parsedAmount + const threshold = !parsedDebitThreshold + ? undefined + : Amounts.stringify(parsedDebitThreshold); + const minCashout = !parsedMinCashout ? undefined - : Amounts.stringify(parsedAmount); + : Amounts.stringify(parsedMinCashout); switch (purpose) { case "create": { @@ -265,6 +285,7 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ phone: !newForm.phone ? undefined : newForm.phone, }), debit_threshold: threshold ?? config.default_debit_threshold, + min_cashout: minCashout, cashout_payto_uri: cashoutURI, payto_uri: internalURI, is_public: newForm.isPublic, @@ -288,6 +309,7 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ phone: !newForm.phone ? undefined : newForm.phone, }), debit_threshold: threshold, + min_cashout: minCashout, is_public: newForm.isPublic, name: newForm.name, tan_channel: @@ -533,6 +555,38 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ </div> <div class="sm:col-span-5"> + <label + for="minCashout" + class="block text-sm font-medium leading-6 text-gray-900" + >{i18n.str`Minimum cashout`}</label> + <InputAmount + name="minCashout" + left + currency={config.currency} + value={form.min_cashout ?? defaultValue.min_cashout} + onChange={ + !editableMinCashout + ? undefined + : (e) => { + form.min_cashout = e as AmountString; + updateForm(structuredClone(form)); + } + } + /> + <ShowInputErrorLabel + message={ + errors?.min_cashout ? String(errors?.min_cashout) : undefined + } + isDirty={form.min_cashout !== undefined} + /> + <p class="mt-2 text-sm text-gray-500"> + <i18n.Translate> + Custom minimum cashout amount for this account. + </i18n.Translate> + </p> + </div> + + <div class="sm:col-span-5"> <div class="flex items-center justify-between"> <span class="flex flex-grow flex-col"> <span diff --git a/packages/bank-ui/src/pages/admin/CreateNewAccount.tsx b/packages/bank-ui/src/pages/admin/CreateNewAccount.tsx index 7d2d449b0..3898088ed 100644 --- a/packages/bank-ui/src/pages/admin/CreateNewAccount.tsx +++ b/packages/bank-ui/src/pages/admin/CreateNewAccount.tsx @@ -146,6 +146,15 @@ export function CreateNewAccount({ debug: resp.detail, when: AbsoluteTime.now(), }); + case TalerErrorCode.BANK_NON_ADMIN_SET_MIN_CASHOUT: { + return notify({ + type: "error", + title: i18n.str`Only the administrator can change the minimun cashout limit.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + when: AbsoluteTime.now(), + }); + } default: assertUnreachable(resp); } |