购买套餐添加count_min字段
This commit is contained in:
@@ -3,18 +3,18 @@ import {FormField} from '@/components/ui/form'
|
||||
import {RadioGroup} from '@/components/ui/radio-group'
|
||||
import FormOption from '@/components/composites/purchase/option'
|
||||
import {Schema} from '@/components/composites/purchase/long/form'
|
||||
import {useEffect} from 'react'
|
||||
import {useEffect, useMemo} from 'react'
|
||||
import {useFormContext, useWatch} from 'react-hook-form'
|
||||
import {Card} from '@/components/ui/card'
|
||||
import {BillingMethodField} from '../shared/billing-method-field'
|
||||
import {FeatureList} from '../shared/feature-list'
|
||||
import {NumberStepperField} from '../shared/number-stepper-field'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku'
|
||||
import {getAvailablePurchaseExpires, getAvailablePurchaseLives, getPurchaseSkuCountMin, getPurchaseSkuPrice, hasPurchaseSku, PurchaseSkuData} from '../shared/sku'
|
||||
|
||||
export default function Center({skuData}: {
|
||||
skuData: PurchaseSkuData
|
||||
}) {
|
||||
const {setValue} = useFormContext<Schema>()
|
||||
const {setValue, getValues} = useFormContext<Schema>()
|
||||
const type = useWatch<Schema>({name: 'type'}) as Schema['type']
|
||||
const live = useWatch<Schema>({name: 'live'}) as Schema['live']
|
||||
const expire = useWatch<Schema>({name: 'expire'}) as Schema['expire']
|
||||
@@ -26,6 +26,27 @@ export default function Center({skuData}: {
|
||||
? getAvailablePurchaseExpires(skuData, {mode: type, live})
|
||||
: []
|
||||
|
||||
const currentCountMin = useMemo(() => {
|
||||
if (!type || !live) return 0
|
||||
const expireValue = type === '1' ? expire : '0'
|
||||
return getPurchaseSkuCountMin(skuData, {mode: type, live, expire: expireValue})
|
||||
}, [type, live, expire, skuData])
|
||||
|
||||
useEffect(() => {
|
||||
if (type === '1') {
|
||||
const current = getValues('daily_limit')
|
||||
if (current < currentCountMin) {
|
||||
setValue('daily_limit', currentCountMin)
|
||||
}
|
||||
}
|
||||
else {
|
||||
const current = getValues('quota')
|
||||
if (current < currentCountMin) {
|
||||
setValue('quota', currentCountMin)
|
||||
}
|
||||
}
|
||||
}, [currentCountMin, type, setValue, getValues])
|
||||
|
||||
useEffect(() => {
|
||||
const nextType = modeList.includes(type) ? type : modeList[0]
|
||||
|
||||
@@ -146,14 +167,14 @@ export default function Center({skuData}: {
|
||||
<NumberStepperField
|
||||
name="daily_limit"
|
||||
label="每日提取上限"
|
||||
min={100}
|
||||
min={currentCountMin || 100}
|
||||
step={100}
|
||||
/>
|
||||
) : (
|
||||
<NumberStepperField
|
||||
name="quota"
|
||||
label="IP 购买数量"
|
||||
min={500}
|
||||
min={currentCountMin || 500}
|
||||
step={100}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user