This commit is contained in:
imeepos
2026-01-28 15:26:00 +08:00
parent 4bf364d955
commit 7d73cfbc3e
12 changed files with 826 additions and 414 deletions

View File

@@ -68,6 +68,7 @@ export default function MembershipScreen() {
const { width: screenWidth } = useWindowDimensions()
const [agreed, setAgreed] = useState(false)
const [pointsDrawerVisible, setPointsDrawerVisible] = useState(false)
const [isSubscribing, setIsSubscribing] = useState(false)
const { t } = useTranslation()
@@ -138,24 +139,29 @@ export default function MembershipScreen() {
const [currentImageIndex, setCurrentImageIndex] = useState(0)
// 处理订阅按钮点击
const handleSubscribe = () => {
const handleSubscribe = async () => {
if (!agreed || !selectedPlan) return
const planData = creditPlans[selectedPlanIndex]
if (!planData) return
if (hasActiveSubscription) {
upgradeSubscription({ credits: planData.credits })
} else if (activeAuthSubscription?.cancelAtPeriodEnd) {
restoreSubscription()
} else {
const pricingItem = stripePricingData?.pricing_table_items?.[selectedPlanIndex]
if (pricingItem) {
createSubscription({
priceId: pricingItem.price_id,
productId: pricingItem.product_id,
})
setIsSubscribing(true)
try {
if (hasActiveSubscription) {
await upgradeSubscription({ credits: planData.credits })
} else if (activeAuthSubscription?.cancelAtPeriodEnd) {
await restoreSubscription()
} else {
const pricingItem = stripePricingData?.pricing_table_items?.[selectedPlanIndex]
if (pricingItem) {
await createSubscription({
priceId: pricingItem.price_id,
productId: pricingItem.product_id,
})
}
}
} finally {
setIsSubscribing(false)
}
}
@@ -393,7 +399,7 @@ export default function MembershipScreen() {
<View style={[styles.subscribeContainer, { paddingBottom: Math.max(insets.bottom, 3) }]}>
{/* 立即开通按钮 */}
<Pressable
disabled={!agreed || isLoadingSubscriptions || isStripePricingLoading}
disabled={!agreed || isLoadingSubscriptions || isStripePricingLoading || isSubscribing}
style={styles.subscribeButtonPressable}
onPress={handleSubscribe}
>
@@ -410,10 +416,10 @@ export default function MembershipScreen() {
end={{ x: 0, y: 0 }}
style={[
styles.subscribeButton,
(!agreed || isLoadingSubscriptions || isStripePricingLoading) && styles.subscribeButtonDisabled,
(!agreed || isLoadingSubscriptions || isStripePricingLoading || isSubscribing) && styles.subscribeButtonDisabled,
]}
>
{isLoadingSubscriptions || isStripePricingLoading ? (
{isLoadingSubscriptions || isStripePricingLoading || isSubscribing ? (
<ActivityIndicator color="#F5F5F5" />
) : (
<Text style={currentPlan.recommended ? styles.subscribeButtonText : styles.subscribeButtonText1}>{t('membership.subscribeNow')}</Text>