mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 14:41:21 +00:00
fix: allow topup amount input to be fully cleared (#6473)
This commit is contained in:
@@ -116,7 +116,10 @@ export function RechargeFormCard({
|
|||||||
const [localAmount, setLocalAmount] = useState(topupAmount.toString())
|
const [localAmount, setLocalAmount] = useState(topupAmount.toString())
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLocalAmount(topupAmount.toString())
|
// Empty string must survive, otherwise the field can never be cleared
|
||||||
|
setLocalAmount((prev) =>
|
||||||
|
prev === '' && topupAmount === 0 ? prev : topupAmount.toString()
|
||||||
|
)
|
||||||
}, [topupAmount])
|
}, [topupAmount])
|
||||||
|
|
||||||
const handleAmountChange = (value: string) => {
|
const handleAmountChange = (value: string) => {
|
||||||
@@ -317,7 +320,10 @@ export function RechargeFormCard({
|
|||||||
{hasStandardPaymentMethods ? (
|
{hasStandardPaymentMethods ? (
|
||||||
<div className='grid grid-cols-2 gap-1.5 sm:gap-3 lg:grid-cols-3'>
|
<div className='grid grid-cols-2 gap-1.5 sm:gap-3 lg:grid-cols-3'>
|
||||||
{topupInfo?.pay_methods?.map((method) => {
|
{topupInfo?.pay_methods?.map((method) => {
|
||||||
const minTopup = method.min_topup || 0
|
const minTopup = Math.max(
|
||||||
|
method.min_topup || 0,
|
||||||
|
getMinTopupAmount(topupInfo)
|
||||||
|
)
|
||||||
const disabled = minTopup > topupAmount
|
const disabled = minTopup > topupAmount
|
||||||
const disabledReason = disabled
|
const disabledReason = disabled
|
||||||
? t('Minimum topup amount: {{amount}}', {
|
? t('Minimum topup amount: {{amount}}', {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
For commercial licensing, please contact support@quantumnous.com
|
For commercial licensing, please contact support@quantumnous.com
|
||||||
*/
|
*/
|
||||||
import { useState, useEffect, useCallback, useMemo } from 'react'
|
import { useState, useEffect, useCallback, useMemo, useRef } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import { SectionPageLayout } from '@/components/layout'
|
import { SectionPageLayout } from '@/components/layout'
|
||||||
@@ -137,8 +137,10 @@ export function Wallet(props: WalletProps) {
|
|||||||
}, [props.initialShowHistory])
|
}, [props.initialShowHistory])
|
||||||
|
|
||||||
// Initialize topup amount when topup info is loaded
|
// Initialize topup amount when topup info is loaded
|
||||||
|
const topupAmountInitializedRef = useRef(false)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (topupInfo && topupAmount === 0) {
|
if (topupInfo && !topupAmountInitializedRef.current) {
|
||||||
|
topupAmountInitializedRef.current = true
|
||||||
const minTopup = getMinTopupAmount(topupInfo)
|
const minTopup = getMinTopupAmount(topupInfo)
|
||||||
setTopupAmount(minTopup)
|
setTopupAmount(minTopup)
|
||||||
|
|
||||||
@@ -146,7 +148,7 @@ export function Wallet(props: WalletProps) {
|
|||||||
const defaultPaymentType = getDefaultPaymentType(topupInfo)
|
const defaultPaymentType = getDefaultPaymentType(topupInfo)
|
||||||
calculatePaymentAmount(minTopup, defaultPaymentType)
|
calculatePaymentAmount(minTopup, defaultPaymentType)
|
||||||
}
|
}
|
||||||
}, [topupInfo, topupAmount, calculatePaymentAmount])
|
}, [topupInfo, calculatePaymentAmount])
|
||||||
|
|
||||||
// Get current payment type (selected or default)
|
// Get current payment type (selected or default)
|
||||||
const getCurrentPaymentType = useCallback(() => {
|
const getCurrentPaymentType = useCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user