@windrun-huaiin/third-ui 7.3.14 → 7.4.1
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/dist/main/money-price/money-price-interactive.js +35 -12
- package/dist/main/money-price/money-price-interactive.mjs +35 -12
- package/dist/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
- package/dist/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
- package/package.json +3 -3
- package/src/main/money-price/money-price-interactive.tsx +36 -10
|
@@ -15,7 +15,7 @@ var moneyPriceTypes = require('./money-price-types.js');
|
|
|
15
15
|
|
|
16
16
|
function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath }) {
|
|
17
17
|
const fingerprintContext = fingerprintProvider.useFingerprintContextSafe();
|
|
18
|
-
const { redirectToSignIn } = nextjs.useClerk();
|
|
18
|
+
const { redirectToSignIn, user } = nextjs.useClerk();
|
|
19
19
|
const router = navigation.useRouter();
|
|
20
20
|
const [billingType, setBillingType] = React.useState(data.billingSwitch.defaultKey);
|
|
21
21
|
const [isProcessing, setIsProcessing] = React.useState(false);
|
|
@@ -38,14 +38,17 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
|
|
|
38
38
|
}, [fingerprintContext]);
|
|
39
39
|
// 优化 userContext 使用 useMemo
|
|
40
40
|
const userContext = React.useMemo(() => {
|
|
41
|
-
var _a, _b, _c
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
// 使用 Clerk 的 user 对象判断登录状态
|
|
43
|
+
const isAuth = !!(user === null || user === void 0 ? void 0 : user.id);
|
|
44
|
+
const userState = getUserState();
|
|
45
|
+
return {
|
|
46
|
+
isAuthenticated: isAuth,
|
|
47
|
+
subscriptionStatus: isAuth ? userState : moneyPriceTypes.UserState.Anonymous,
|
|
48
|
+
subscriptionType: ((_b = (_a = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _a === void 0 ? void 0 : _a.priceId) === null || _b === void 0 ? void 0 : _b.includes('yearly')) ? 'yearly' : 'monthly',
|
|
49
|
+
subscriptionEndDate: (_c = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _c === void 0 ? void 0 : _c.subPeriodEnd
|
|
50
|
+
};
|
|
51
|
+
}, [user, fingerprintContext, getUserState]);
|
|
49
52
|
// 处理登录
|
|
50
53
|
const handleLogin = React.useCallback(() => {
|
|
51
54
|
if (signInPath) {
|
|
@@ -57,6 +60,7 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
|
|
|
57
60
|
}, [signInPath, redirectToSignIn, router]);
|
|
58
61
|
// 处理升级
|
|
59
62
|
const handleUpgrade = React.useCallback((plan, billingType) => tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
var _a;
|
|
60
64
|
if (!upgradeApiEndpoint) {
|
|
61
65
|
router.push('/');
|
|
62
66
|
return;
|
|
@@ -76,12 +80,31 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
|
|
|
76
80
|
provider: config.activeProvider
|
|
77
81
|
})
|
|
78
82
|
});
|
|
83
|
+
// 检查是否是重定向或非JSON响应
|
|
84
|
+
if (response.redirected || response.status === 302 || response.status === 301) {
|
|
85
|
+
// 如果是重定向,直接跳转到重定向URL(通常是登录页面)
|
|
86
|
+
window.location.href = response.url;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// 检查Content-Type是否为JSON
|
|
90
|
+
const contentType = response.headers.get('content-type');
|
|
91
|
+
if (!contentType || !contentType.includes('application/json')) {
|
|
92
|
+
// 如果不是JSON响应,可能是HTML登录页面,提示用户重新登录
|
|
93
|
+
console.error('Received non-JSON response, user may need to login');
|
|
94
|
+
if (signInPath) {
|
|
95
|
+
window.location.href = signInPath;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
redirectToSignIn();
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
79
102
|
const result = yield response.json();
|
|
80
|
-
if (result.success && result.
|
|
81
|
-
window.location.href = result.
|
|
103
|
+
if (result.success && ((_a = result.data) === null || _a === void 0 ? void 0 : _a.sessionUrl)) {
|
|
104
|
+
window.location.href = result.data.sessionUrl;
|
|
82
105
|
}
|
|
83
106
|
else {
|
|
84
|
-
console.error('Failed to create checkout session:', result.error);
|
|
107
|
+
console.error('Failed to create checkout session:', result.error || 'Unknown error');
|
|
85
108
|
}
|
|
86
109
|
}
|
|
87
110
|
catch (error) {
|
|
@@ -13,7 +13,7 @@ import { UserState } from './money-price-types.mjs';
|
|
|
13
13
|
|
|
14
14
|
function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath }) {
|
|
15
15
|
const fingerprintContext = useFingerprintContextSafe();
|
|
16
|
-
const { redirectToSignIn } = useClerk();
|
|
16
|
+
const { redirectToSignIn, user } = useClerk();
|
|
17
17
|
const router = useRouter();
|
|
18
18
|
const [billingType, setBillingType] = useState(data.billingSwitch.defaultKey);
|
|
19
19
|
const [isProcessing, setIsProcessing] = useState(false);
|
|
@@ -36,14 +36,17 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
|
|
|
36
36
|
}, [fingerprintContext]);
|
|
37
37
|
// 优化 userContext 使用 useMemo
|
|
38
38
|
const userContext = useMemo(() => {
|
|
39
|
-
var _a, _b, _c
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
// 使用 Clerk 的 user 对象判断登录状态
|
|
41
|
+
const isAuth = !!(user === null || user === void 0 ? void 0 : user.id);
|
|
42
|
+
const userState = getUserState();
|
|
43
|
+
return {
|
|
44
|
+
isAuthenticated: isAuth,
|
|
45
|
+
subscriptionStatus: isAuth ? userState : UserState.Anonymous,
|
|
46
|
+
subscriptionType: ((_b = (_a = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _a === void 0 ? void 0 : _a.priceId) === null || _b === void 0 ? void 0 : _b.includes('yearly')) ? 'yearly' : 'monthly',
|
|
47
|
+
subscriptionEndDate: (_c = fingerprintContext === null || fingerprintContext === void 0 ? void 0 : fingerprintContext.xSubscription) === null || _c === void 0 ? void 0 : _c.subPeriodEnd
|
|
48
|
+
};
|
|
49
|
+
}, [user, fingerprintContext, getUserState]);
|
|
47
50
|
// 处理登录
|
|
48
51
|
const handleLogin = useCallback(() => {
|
|
49
52
|
if (signInPath) {
|
|
@@ -55,6 +58,7 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
|
|
|
55
58
|
}, [signInPath, redirectToSignIn, router]);
|
|
56
59
|
// 处理升级
|
|
57
60
|
const handleUpgrade = useCallback((plan, billingType) => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
var _a;
|
|
58
62
|
if (!upgradeApiEndpoint) {
|
|
59
63
|
router.push('/');
|
|
60
64
|
return;
|
|
@@ -74,12 +78,31 @@ function MoneyPriceInteractive({ data, config, upgradeApiEndpoint, signInPath })
|
|
|
74
78
|
provider: config.activeProvider
|
|
75
79
|
})
|
|
76
80
|
});
|
|
81
|
+
// 检查是否是重定向或非JSON响应
|
|
82
|
+
if (response.redirected || response.status === 302 || response.status === 301) {
|
|
83
|
+
// 如果是重定向,直接跳转到重定向URL(通常是登录页面)
|
|
84
|
+
window.location.href = response.url;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// 检查Content-Type是否为JSON
|
|
88
|
+
const contentType = response.headers.get('content-type');
|
|
89
|
+
if (!contentType || !contentType.includes('application/json')) {
|
|
90
|
+
// 如果不是JSON响应,可能是HTML登录页面,提示用户重新登录
|
|
91
|
+
console.error('Received non-JSON response, user may need to login');
|
|
92
|
+
if (signInPath) {
|
|
93
|
+
window.location.href = signInPath;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
redirectToSignIn();
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
77
100
|
const result = yield response.json();
|
|
78
|
-
if (result.success && result.
|
|
79
|
-
window.location.href = result.
|
|
101
|
+
if (result.success && ((_a = result.data) === null || _a === void 0 ? void 0 : _a.sessionUrl)) {
|
|
102
|
+
window.location.href = result.data.sessionUrl;
|
|
80
103
|
}
|
|
81
104
|
else {
|
|
82
|
-
console.error('Failed to create checkout session:', result.error);
|
|
105
|
+
console.error('Failed to create checkout session:', result.error || 'Unknown error');
|
|
83
106
|
}
|
|
84
107
|
}
|
|
85
108
|
catch (error) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var coseBase$1 = require('../../../../../_virtual/cose-
|
|
3
|
+
var coseBase$1 = require('../../../../../_virtual/cose-base.js');
|
|
4
4
|
var layoutBase = require('../../../layout-base@1.0.2/node_modules/layout-base/layout-base.js');
|
|
5
5
|
|
|
6
6
|
var coseBase = coseBase$1.__module.exports;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var coseBase$1 = require('../../../../../_virtual/cose-
|
|
3
|
+
var coseBase$1 = require('../../../../../_virtual/cose-base2.js');
|
|
4
4
|
var layoutBase = require('../../../layout-base@2.0.1/node_modules/layout-base/layout-base.js');
|
|
5
5
|
|
|
6
6
|
var coseBase = coseBase$1.__module.exports;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windrun-huaiin/third-ui",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.1",
|
|
4
4
|
"description": "Third-party integrated UI components for windrun-huaiin projects",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"mermaid": "^11.6.0",
|
|
76
76
|
"react-medium-image-zoom": "^5.2.14",
|
|
77
77
|
"zod": "^3.22.4",
|
|
78
|
-
"@windrun-huaiin/
|
|
79
|
-
"@windrun-huaiin/
|
|
78
|
+
"@windrun-huaiin/base-ui": "^8.1.2",
|
|
79
|
+
"@windrun-huaiin/lib": "^7.1.2"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"react": "19.1.0",
|
|
@@ -21,7 +21,7 @@ export function MoneyPriceInteractive({
|
|
|
21
21
|
signInPath
|
|
22
22
|
}: MoneyPriceInteractiveProps) {
|
|
23
23
|
const fingerprintContext = useFingerprintContextSafe();
|
|
24
|
-
const { redirectToSignIn } = useClerk();
|
|
24
|
+
const { redirectToSignIn, user } = useClerk();
|
|
25
25
|
const router = useRouter();
|
|
26
26
|
const [billingType, setBillingType] = useState<'monthly' | 'yearly'>(
|
|
27
27
|
data.billingSwitch.defaultKey as 'monthly' | 'yearly'
|
|
@@ -47,12 +47,18 @@ export function MoneyPriceInteractive({
|
|
|
47
47
|
}, [fingerprintContext]);
|
|
48
48
|
|
|
49
49
|
// 优化 userContext 使用 useMemo
|
|
50
|
-
const userContext = useMemo<UserContext>(() =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
const userContext = useMemo<UserContext>(() => {
|
|
51
|
+
// 使用 Clerk 的 user 对象判断登录状态
|
|
52
|
+
const isAuth = !!user?.id;
|
|
53
|
+
const userState = getUserState();
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
isAuthenticated: isAuth,
|
|
57
|
+
subscriptionStatus: isAuth ? userState : UserState.Anonymous,
|
|
58
|
+
subscriptionType: fingerprintContext?.xSubscription?.priceId?.includes('yearly') ? 'yearly' : 'monthly',
|
|
59
|
+
subscriptionEndDate: fingerprintContext?.xSubscription?.subPeriodEnd
|
|
60
|
+
};
|
|
61
|
+
}, [user, fingerprintContext, getUserState]);
|
|
56
62
|
|
|
57
63
|
// 处理登录
|
|
58
64
|
const handleLogin = useCallback(() => {
|
|
@@ -92,12 +98,32 @@ export function MoneyPriceInteractive({
|
|
|
92
98
|
})
|
|
93
99
|
});
|
|
94
100
|
|
|
101
|
+
// 检查是否是重定向或非JSON响应
|
|
102
|
+
if (response.redirected || response.status === 302 || response.status === 301) {
|
|
103
|
+
// 如果是重定向,直接跳转到重定向URL(通常是登录页面)
|
|
104
|
+
window.location.href = response.url;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 检查Content-Type是否为JSON
|
|
109
|
+
const contentType = response.headers.get('content-type');
|
|
110
|
+
if (!contentType || !contentType.includes('application/json')) {
|
|
111
|
+
// 如果不是JSON响应,可能是HTML登录页面,提示用户重新登录
|
|
112
|
+
console.error('Received non-JSON response, user may need to login');
|
|
113
|
+
if (signInPath) {
|
|
114
|
+
window.location.href = signInPath;
|
|
115
|
+
} else {
|
|
116
|
+
redirectToSignIn();
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
95
121
|
const result = await response.json();
|
|
96
122
|
|
|
97
|
-
if (result.success && result.
|
|
98
|
-
window.location.href = result.
|
|
123
|
+
if (result.success && result.data?.sessionUrl) {
|
|
124
|
+
window.location.href = result.data.sessionUrl;
|
|
99
125
|
} else {
|
|
100
|
-
console.error('Failed to create checkout session:', result.error);
|
|
126
|
+
console.error('Failed to create checkout session:', result.error || 'Unknown error');
|
|
101
127
|
}
|
|
102
128
|
} catch (error) {
|
|
103
129
|
console.error('Error during upgrade:', error);
|