|
@@ -4,7 +4,6 @@ import { useTranslation } from 'react-i18next'
|
|
|
import { toast } from 'sonner'
|
|
import { toast } from 'sonner'
|
|
|
import { formatQuota } from '@/lib/format'
|
|
import { formatQuota } from '@/lib/format'
|
|
|
import { cn } from '@/lib/utils'
|
|
import { cn } from '@/lib/utils'
|
|
|
-import { useStatus } from '@/hooks/use-status'
|
|
|
|
|
import { Button } from '@/components/ui/button'
|
|
import { Button } from '@/components/ui/button'
|
|
|
import { Card, CardContent, CardHeader } from '@/components/ui/card'
|
|
import { Card, CardContent, CardHeader } from '@/components/ui/card'
|
|
|
import { Progress } from '@/components/ui/progress'
|
|
import { Progress } from '@/components/ui/progress'
|
|
@@ -52,12 +51,29 @@ function getEpayMethods(payMethods: PaymentMethod[] = []): PaymentMethod[] {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function getBillingPreferenceLabel(
|
|
|
|
|
+ preference: string,
|
|
|
|
|
+ t: (key: string) => string
|
|
|
|
|
+): string {
|
|
|
|
|
+ switch (preference) {
|
|
|
|
|
+ case 'subscription_first':
|
|
|
|
|
+ return t('Subscription First')
|
|
|
|
|
+ case 'wallet_first':
|
|
|
|
|
+ return t('Wallet First')
|
|
|
|
|
+ case 'subscription_only':
|
|
|
|
|
+ return t('Subscription Only')
|
|
|
|
|
+ case 'wallet_only':
|
|
|
|
|
+ return t('Wallet Only')
|
|
|
|
|
+ default:
|
|
|
|
|
+ return preference
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export function SubscriptionPlansCard({
|
|
export function SubscriptionPlansCard({
|
|
|
topupInfo,
|
|
topupInfo,
|
|
|
onAvailabilityChange,
|
|
onAvailabilityChange,
|
|
|
}: SubscriptionPlansCardProps) {
|
|
}: SubscriptionPlansCardProps) {
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
- const { status } = useStatus()
|
|
|
|
|
|
|
|
|
|
const [plans, setPlans] = useState<PlanRecord[]>([])
|
|
const [plans, setPlans] = useState<PlanRecord[]>([])
|
|
|
const [activeSubscriptions, setActiveSubscriptions] = useState<
|
|
const [activeSubscriptions, setActiveSubscriptions] = useState<
|
|
@@ -74,9 +90,9 @@ export function SubscriptionPlansCard({
|
|
|
const [purchaseOpen, setPurchaseOpen] = useState(false)
|
|
const [purchaseOpen, setPurchaseOpen] = useState(false)
|
|
|
const [selectedPlan, setSelectedPlan] = useState<PlanRecord | null>(null)
|
|
const [selectedPlan, setSelectedPlan] = useState<PlanRecord | null>(null)
|
|
|
|
|
|
|
|
- const enableStripe = !!status?.enable_stripe_topup
|
|
|
|
|
|
|
+ const enableStripe = !!topupInfo?.enable_stripe_topup
|
|
|
const enableCreem = !!topupInfo?.enable_creem_topup
|
|
const enableCreem = !!topupInfo?.enable_creem_topup
|
|
|
- const enableOnlineTopUp = !!status?.enable_online_topup
|
|
|
|
|
|
|
+ const enableOnlineTopUp = !!topupInfo?.enable_online_topup
|
|
|
const epayMethods = useMemo(
|
|
const epayMethods = useMemo(
|
|
|
() => getEpayMethods(topupInfo?.pay_methods),
|
|
() => getEpayMethods(topupInfo?.pay_methods),
|
|
|
[topupInfo?.pay_methods]
|
|
[topupInfo?.pay_methods]
|
|
@@ -264,22 +280,24 @@ export function SubscriptionPlansCard({
|
|
|
onValueChange={(v) => v !== null && handlePreferenceChange(v)}
|
|
onValueChange={(v) => v !== null && handlePreferenceChange(v)}
|
|
|
>
|
|
>
|
|
|
<SelectTrigger className='h-8 flex-1 text-xs sm:w-[140px] sm:flex-none'>
|
|
<SelectTrigger className='h-8 flex-1 text-xs sm:w-[140px] sm:flex-none'>
|
|
|
- <SelectValue />
|
|
|
|
|
|
|
+ <SelectValue>
|
|
|
|
|
+ {getBillingPreferenceLabel(displayPref, t)}
|
|
|
|
|
+ </SelectValue>
|
|
|
</SelectTrigger>
|
|
</SelectTrigger>
|
|
|
<SelectContent>
|
|
<SelectContent>
|
|
|
<SelectItem value='subscription_first' disabled={disablePref}>
|
|
<SelectItem value='subscription_first' disabled={disablePref}>
|
|
|
- {t('Subscription First')}
|
|
|
|
|
|
|
+ {getBillingPreferenceLabel('subscription_first', t)}
|
|
|
{disablePref ? ` (${t('No Active')})` : ''}
|
|
{disablePref ? ` (${t('No Active')})` : ''}
|
|
|
</SelectItem>
|
|
</SelectItem>
|
|
|
<SelectItem value='wallet_first'>
|
|
<SelectItem value='wallet_first'>
|
|
|
- {t('Wallet First')}
|
|
|
|
|
|
|
+ {getBillingPreferenceLabel('wallet_first', t)}
|
|
|
</SelectItem>
|
|
</SelectItem>
|
|
|
<SelectItem value='subscription_only' disabled={disablePref}>
|
|
<SelectItem value='subscription_only' disabled={disablePref}>
|
|
|
- {t('Subscription Only')}
|
|
|
|
|
|
|
+ {getBillingPreferenceLabel('subscription_only', t)}
|
|
|
{disablePref ? ` (${t('No Active')})` : ''}
|
|
{disablePref ? ` (${t('No Active')})` : ''}
|
|
|
</SelectItem>
|
|
</SelectItem>
|
|
|
<SelectItem value='wallet_only'>
|
|
<SelectItem value='wallet_only'>
|
|
|
- {t('Wallet Only')}
|
|
|
|
|
|
|
+ {getBillingPreferenceLabel('wallet_only', t)}
|
|
|
</SelectItem>
|
|
</SelectItem>
|
|
|
</SelectContent>
|
|
</SelectContent>
|
|
|
</Select>
|
|
</Select>
|