@windrun-huaiin/third-ui 7.5.1 → 7.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -24,17 +24,30 @@ export function MoneyPriceInteractive({
|
|
|
24
24
|
const { redirectToSignIn, user } = useClerk();
|
|
25
25
|
const router = useRouter();
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
27
|
+
const [billingType, setBillingType] = useState<'monthly' | 'yearly'>(() => {
|
|
28
|
+
// 懒初始化:只在组件首次渲染时计算一次
|
|
29
|
+
// 如果用户有活跃订阅,通过 priceId 精确匹配计费周期
|
|
30
30
|
if (fingerprintContext?.xSubscription?.status === 'active' && fingerprintContext.xSubscription.priceId) {
|
|
31
|
-
|
|
31
|
+
const userPriceId = fingerprintContext.xSubscription.priceId;
|
|
32
|
+
const providerConfig = getActiveProviderConfig(config);
|
|
33
|
+
|
|
34
|
+
// 检查所有年付计划的 priceId
|
|
35
|
+
const yearlyPriceIds = [
|
|
36
|
+
providerConfig.products.free.plans.yearly.priceId,
|
|
37
|
+
providerConfig.products.pro.plans.yearly.priceId,
|
|
38
|
+
providerConfig.products.ultra.plans.yearly.priceId
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
// 如果匹配到年付计划,返回 yearly,否则返回 monthly
|
|
42
|
+
if (yearlyPriceIds.includes(userPriceId)) {
|
|
43
|
+
return 'yearly';
|
|
44
|
+
} else {
|
|
45
|
+
return 'monthly';
|
|
46
|
+
}
|
|
32
47
|
}
|
|
33
48
|
// 否则使用默认值
|
|
34
49
|
return data.billingSwitch.defaultKey as 'monthly' | 'yearly';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const [billingType, setBillingType] = useState<'monthly' | 'yearly'>(getInitialBillingType());
|
|
50
|
+
});
|
|
38
51
|
const [isProcessing, setIsProcessing] = useState(false);
|
|
39
52
|
const [tooltip, setTooltip] = useState<{
|
|
40
53
|
show: boolean;
|
|
@@ -248,20 +261,6 @@ export function MoneyPriceInteractive({
|
|
|
248
261
|
// State for button portals
|
|
249
262
|
const [buttonPortals, setButtonPortals] = useState<React.ReactElement[]>([]);
|
|
250
263
|
|
|
251
|
-
// 当 fingerprint context 变化时,更新 billing type 以匹配用户的订阅状态
|
|
252
|
-
useEffect(() => {
|
|
253
|
-
const newBillingType = getInitialBillingType();
|
|
254
|
-
if (newBillingType !== billingType) {
|
|
255
|
-
setBillingType(newBillingType);
|
|
256
|
-
// 延迟执行以确保 DOM 已渲染
|
|
257
|
-
setTimeout(() => {
|
|
258
|
-
updatePriceDisplay(newBillingType);
|
|
259
|
-
updateButtonStyles(newBillingType);
|
|
260
|
-
updateDiscountInfo(newBillingType);
|
|
261
|
-
}, 0);
|
|
262
|
-
}
|
|
263
|
-
}, [fingerprintContext, getInitialBillingType, billingType, updatePriceDisplay, updateButtonStyles, updateDiscountInfo]);
|
|
264
|
-
|
|
265
264
|
// 处理月付/年付切换和 tooltip 功能
|
|
266
265
|
useEffect(() => {
|
|
267
266
|
const monthlyButton = document.querySelector('[data-billing-button="monthly"]') as HTMLButtonElement;
|