diff options
Diffstat (limited to 'packages/bank-ui/src/pages/admin/AccountForm.tsx')
-rw-r--r-- | packages/bank-ui/src/pages/admin/AccountForm.tsx | 75 |
1 files changed, 65 insertions, 10 deletions
diff --git a/packages/bank-ui/src/pages/admin/AccountForm.tsx b/packages/bank-ui/src/pages/admin/AccountForm.tsx index 026f6e9b3..ba5da609f 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,13 +199,21 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ : undefined, debit_threshold: !editableThreshold ? undefined - : !trimmedAmountStr + : !trimmedDebitThresholdStr ? undefined - : !parsedAmount + : !parsedDebitThreshold + ? i18n.str`Not valid` + : undefined, + min_cashout: !editableMinCashout + ? undefined + : !trimmedMinCashoutStr + ? undefined + : !parsedMinCashout ? i18n.str`Not valid` : undefined, name: !editableName ? undefined // disabled + : purpose === "update" && newForm.name === undefined ? undefined // the field hasn't been changed : !newForm.name ? i18n.str`Required` : undefined, @@ -248,9 +266,12 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ } const internalURI = !internal ? undefined : stringifyPaytoUri(internal); - const threshold = !parsedAmount + const threshold = !parsedDebitThreshold ? undefined - : Amounts.stringify(parsedAmount); + : Amounts.stringify(parsedDebitThreshold); + const minCashout = !parsedMinCashout + ? undefined + : Amounts.stringify(parsedMinCashout); switch (purpose) { case "create": { @@ -265,6 +286,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 +310,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: @@ -512,9 +535,9 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ !editableThreshold ? undefined : (e) => { - form.debit_threshold = e as AmountString; - updateForm(structuredClone(form)); - } + form.debit_threshold = e as AmountString; + updateForm(structuredClone(form)); + } } /> <ShowInputErrorLabel @@ -533,6 +556,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 |