@sudobility/subscription_pages 0.0.13 → 0.0.14
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/index.js +77 -77
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs as m, jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { useState as C, useEffect as
|
|
3
|
-
import { SubscriptionPlatform as
|
|
4
|
-
import { usePackagesByDuration as
|
|
5
|
-
import { SubscriptionLayout as
|
|
2
|
+
import { useState as C, useEffect as xe } from "react";
|
|
3
|
+
import { SubscriptionPlatform as le } from "@sudobility/types";
|
|
4
|
+
import { usePackagesByDuration as ke, useUserSubscription as se, useBackendSubscription as de, getSubscriptionInstance as ue, refreshSubscription as fe, useAllOfferings as Ce, useOfferingPackages as Ie, periodToMonths as ie } from "@sudobility/subscription_lib";
|
|
5
|
+
import { SubscriptionLayout as I, SubscriptionTile as Pe, SegmentedControl as pe } from "@sudobility/subscription-components";
|
|
6
6
|
const Ae = {
|
|
7
7
|
web: "Web",
|
|
8
8
|
ios: "iOS",
|
|
@@ -54,12 +54,12 @@ function $e({
|
|
|
54
54
|
isLoggedIn: n,
|
|
55
55
|
onNavigateToLogin: c,
|
|
56
56
|
userId: i,
|
|
57
|
-
userEmail:
|
|
57
|
+
userEmail: d,
|
|
58
58
|
featuresByPackage: b,
|
|
59
|
-
freeFeatures:
|
|
60
|
-
title:
|
|
59
|
+
freeFeatures: f,
|
|
60
|
+
title: u = "Choose Your Plan",
|
|
61
61
|
className: v,
|
|
62
|
-
currentPlatform:
|
|
62
|
+
currentPlatform: P = le.Web,
|
|
63
63
|
networkClient: A,
|
|
64
64
|
baseUrl: w,
|
|
65
65
|
token: E,
|
|
@@ -69,27 +69,27 @@ function $e({
|
|
|
69
69
|
const {
|
|
70
70
|
packagesByDuration: M,
|
|
71
71
|
availableDurations: S,
|
|
72
|
-
isLoading:
|
|
72
|
+
isLoading: x,
|
|
73
73
|
error: h
|
|
74
|
-
} =
|
|
74
|
+
} = ke(), {
|
|
75
75
|
subscription: r,
|
|
76
76
|
isLoading: j,
|
|
77
77
|
error: W
|
|
78
|
-
} =
|
|
78
|
+
} = se({ userId: i, userEmail: d }), L = de(
|
|
79
79
|
A ?? {},
|
|
80
80
|
w ?? "",
|
|
81
81
|
E ?? "",
|
|
82
82
|
i ?? "",
|
|
83
83
|
{ testMode: _, enabled: !!(A && w && E && i) }
|
|
84
|
-
), B = ((O = L.data) == null ? void 0 : O.platform) ?? null, V = !B || B ===
|
|
84
|
+
), B = ((O = L.data) == null ? void 0 : O.platform) ?? null, V = !B || B === P, [N, $] = C(null), [q, s] = C(null), [U, F] = C(!1), k = N ?? S[0] ?? null, z = x || j, D = h || W, Q = async (t, p) => {
|
|
85
85
|
try {
|
|
86
|
-
F(!0),
|
|
86
|
+
F(!0), s(null), await ue().purchase({
|
|
87
87
|
packageId: t,
|
|
88
|
-
offeringId:
|
|
89
|
-
customerEmail:
|
|
90
|
-
}), await
|
|
88
|
+
offeringId: p,
|
|
89
|
+
customerEmail: d
|
|
90
|
+
}), await fe();
|
|
91
91
|
} catch (g) {
|
|
92
|
-
|
|
92
|
+
s(
|
|
93
93
|
g instanceof Error ? g.message : "Purchase failed"
|
|
94
94
|
);
|
|
95
95
|
} finally {
|
|
@@ -98,16 +98,16 @@ function $e({
|
|
|
98
98
|
}, G = () => n ? (r == null ? void 0 : r.isActive) && r.packageId ? {
|
|
99
99
|
title: "Free",
|
|
100
100
|
price: "$0",
|
|
101
|
-
features:
|
|
101
|
+
features: f ?? []
|
|
102
102
|
} : {
|
|
103
103
|
title: "Free",
|
|
104
104
|
price: "$0",
|
|
105
|
-
features:
|
|
105
|
+
features: f ?? [],
|
|
106
106
|
topBadge: { text: "Current", color: "blue" }
|
|
107
107
|
} : {
|
|
108
108
|
title: "Free",
|
|
109
109
|
price: "$0",
|
|
110
|
-
features:
|
|
110
|
+
features: f ?? [],
|
|
111
111
|
ctaButton: {
|
|
112
112
|
label: "Try it for Free",
|
|
113
113
|
onClick: c
|
|
@@ -120,8 +120,8 @@ function $e({
|
|
|
120
120
|
label: "Log in to Continue",
|
|
121
121
|
onClick: c
|
|
122
122
|
};
|
|
123
|
-
const
|
|
124
|
-
return
|
|
123
|
+
const p = (r == null ? void 0 : r.isActive) && r.packageId, g = (r == null ? void 0 : r.packageId) === t.package.packageId && (r == null ? void 0 : r.offeringId) === t.offerId;
|
|
124
|
+
return p ? {
|
|
125
125
|
label: g ? "Manage Subscription" : "Change Subscription",
|
|
126
126
|
onClick: T
|
|
127
127
|
} : {
|
|
@@ -131,9 +131,9 @@ function $e({
|
|
|
131
131
|
};
|
|
132
132
|
if (z)
|
|
133
133
|
return /* @__PURE__ */ a(
|
|
134
|
-
|
|
134
|
+
I,
|
|
135
135
|
{
|
|
136
|
-
title:
|
|
136
|
+
title: u,
|
|
137
137
|
className: v,
|
|
138
138
|
variant: "cta",
|
|
139
139
|
children: /* @__PURE__ */ a("p", { children: "Loading subscription plans..." })
|
|
@@ -141,9 +141,9 @@ function $e({
|
|
|
141
141
|
);
|
|
142
142
|
if (!V && L.data)
|
|
143
143
|
return /* @__PURE__ */ a(
|
|
144
|
-
|
|
144
|
+
I,
|
|
145
145
|
{
|
|
146
|
-
title:
|
|
146
|
+
title: u,
|
|
147
147
|
className: v,
|
|
148
148
|
variant: "cta",
|
|
149
149
|
children: /* @__PURE__ */ a(
|
|
@@ -151,7 +151,7 @@ function $e({
|
|
|
151
151
|
{
|
|
152
152
|
backendSubscription: L.data,
|
|
153
153
|
managementUrl: r == null ? void 0 : r.managementUrl,
|
|
154
|
-
currentPlatform:
|
|
154
|
+
currentPlatform: P
|
|
155
155
|
}
|
|
156
156
|
)
|
|
157
157
|
}
|
|
@@ -176,32 +176,32 @@ function $e({
|
|
|
176
176
|
] : []
|
|
177
177
|
]
|
|
178
178
|
}
|
|
179
|
-
} : void 0, R =
|
|
179
|
+
} : void 0, R = k ? M[k] ?? [] : [];
|
|
180
180
|
return /* @__PURE__ */ a(
|
|
181
|
-
|
|
181
|
+
I,
|
|
182
182
|
{
|
|
183
|
-
title:
|
|
183
|
+
title: u,
|
|
184
184
|
className: v,
|
|
185
185
|
variant: "cta",
|
|
186
186
|
error: J,
|
|
187
187
|
currentStatus: K,
|
|
188
188
|
freeTileConfig: G(),
|
|
189
189
|
aboveProducts: S.length > 1 ? /* @__PURE__ */ a(
|
|
190
|
-
|
|
190
|
+
pe,
|
|
191
191
|
{
|
|
192
192
|
options: S.map((t) => ({
|
|
193
193
|
value: t,
|
|
194
194
|
label: t.charAt(0).toUpperCase() + t.slice(1)
|
|
195
195
|
})),
|
|
196
|
-
value:
|
|
196
|
+
value: k ?? S[0],
|
|
197
197
|
onChange: (t) => $(t)
|
|
198
198
|
}
|
|
199
199
|
) : void 0,
|
|
200
200
|
children: R.map((t) => {
|
|
201
201
|
var Y;
|
|
202
|
-
const
|
|
202
|
+
const p = n && (r == null ? void 0 : r.isActive) && r.packageId === t.package.packageId && r.offeringId === t.offerId, g = H(t);
|
|
203
203
|
return /* @__PURE__ */ a(
|
|
204
|
-
|
|
204
|
+
Pe,
|
|
205
205
|
{
|
|
206
206
|
id: t.package.packageId,
|
|
207
207
|
title: t.package.name,
|
|
@@ -211,7 +211,7 @@ function $e({
|
|
|
211
211
|
isSelected: !1,
|
|
212
212
|
onSelect: () => {
|
|
213
213
|
},
|
|
214
|
-
isCurrentPlan:
|
|
214
|
+
isCurrentPlan: p,
|
|
215
215
|
ctaButton: g,
|
|
216
216
|
disabled: U
|
|
217
217
|
},
|
|
@@ -233,35 +233,35 @@ const we = {
|
|
|
233
233
|
};
|
|
234
234
|
function Ee(n, c) {
|
|
235
235
|
if (!n.product || !c.product) return null;
|
|
236
|
-
const i = ie(n.product.period),
|
|
237
|
-
if (i <= 0 ||
|
|
238
|
-
const b = n.product.price / i,
|
|
236
|
+
const i = ie(n.product.period), d = ie(c.product.period);
|
|
237
|
+
if (i <= 0 || d <= 0 || i === 1 / 0 || d === 1 / 0 || i === d) return null;
|
|
238
|
+
const b = n.product.price / i, f = c.product.price / d;
|
|
239
239
|
if (b <= 0) return null;
|
|
240
|
-
const
|
|
241
|
-
(b -
|
|
240
|
+
const u = Math.round(
|
|
241
|
+
(b - f) / b * 100
|
|
242
242
|
);
|
|
243
|
-
return
|
|
243
|
+
return u > 0 ? u : null;
|
|
244
244
|
}
|
|
245
245
|
function Ue({
|
|
246
246
|
isLoggedIn: n,
|
|
247
247
|
onNavigateToLogin: c,
|
|
248
248
|
userId: i,
|
|
249
|
-
userEmail:
|
|
249
|
+
userEmail: d,
|
|
250
250
|
featuresByPackage: b,
|
|
251
|
-
freeFeatures:
|
|
252
|
-
title:
|
|
251
|
+
freeFeatures: f,
|
|
252
|
+
title: u = "Choose Your Plan",
|
|
253
253
|
className: v,
|
|
254
|
-
currentPlatform:
|
|
254
|
+
currentPlatform: P = le.Web,
|
|
255
255
|
networkClient: A,
|
|
256
256
|
baseUrl: w,
|
|
257
257
|
token: E,
|
|
258
258
|
testMode: _,
|
|
259
259
|
t: M,
|
|
260
260
|
renderOfferingContent: S,
|
|
261
|
-
initialOfferId:
|
|
261
|
+
initialOfferId: x
|
|
262
262
|
}) {
|
|
263
263
|
var Z, ee;
|
|
264
|
-
const h = (o,
|
|
264
|
+
const h = (o, l) => M ? M(o, l) : l, {
|
|
265
265
|
offerings: r,
|
|
266
266
|
isLoading: j,
|
|
267
267
|
error: W
|
|
@@ -269,31 +269,31 @@ function Ue({
|
|
|
269
269
|
subscription: e,
|
|
270
270
|
isLoading: L,
|
|
271
271
|
error: B
|
|
272
|
-
} =
|
|
272
|
+
} = se({ userId: i, userEmail: d }), N = de(
|
|
273
273
|
A ?? {},
|
|
274
274
|
w ?? "",
|
|
275
275
|
E ?? "",
|
|
276
276
|
i ?? "",
|
|
277
277
|
{ testMode: _, enabled: !!(A && w && E && i) }
|
|
278
|
-
), $ = ((Z = N.data) == null ? void 0 : Z.platform) ?? null, q = !$ || $ ===
|
|
279
|
-
|
|
278
|
+
), $ = ((Z = N.data) == null ? void 0 : Z.platform) ?? null, q = !$ || $ === P, [s, U] = C(
|
|
279
|
+
x ?? "free"
|
|
280
280
|
);
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}, [
|
|
284
|
-
const [F,
|
|
281
|
+
xe(() => {
|
|
282
|
+
x && U(x);
|
|
283
|
+
}, [x]);
|
|
284
|
+
const [F, k] = C(null), [z, D] = C(!1), Q = ((ee = r[0]) == null ? void 0 : ee.offerId) ?? "", G = s !== "free" ? s : Q, {
|
|
285
285
|
packages: T,
|
|
286
286
|
isLoading: H,
|
|
287
287
|
error: J
|
|
288
|
-
} =
|
|
288
|
+
} = Ie(G), K = j || L || H, R = W || B || J, O = async (o, l) => {
|
|
289
289
|
try {
|
|
290
|
-
D(!0),
|
|
290
|
+
D(!0), k(null), await ue().purchase({
|
|
291
291
|
packageId: o,
|
|
292
|
-
offeringId:
|
|
293
|
-
customerEmail:
|
|
294
|
-
}), await
|
|
292
|
+
offeringId: l,
|
|
293
|
+
customerEmail: d
|
|
294
|
+
}), await fe();
|
|
295
295
|
} catch (y) {
|
|
296
|
-
|
|
296
|
+
k(
|
|
297
297
|
y instanceof Error ? y.message : "Purchase failed"
|
|
298
298
|
);
|
|
299
299
|
} finally {
|
|
@@ -305,31 +305,31 @@ function Ue({
|
|
|
305
305
|
value: o.offerId,
|
|
306
306
|
label: h(o.offerId, ce(o.offerId))
|
|
307
307
|
}))
|
|
308
|
-
],
|
|
308
|
+
], p = T[0] ?? null, g = () => n ? (e == null ? void 0 : e.isActive) && e.packageId ? {
|
|
309
309
|
title: h("free", "Free"),
|
|
310
310
|
price: "$0",
|
|
311
|
-
features:
|
|
311
|
+
features: f ?? []
|
|
312
312
|
} : {
|
|
313
313
|
title: h("free", "Free"),
|
|
314
314
|
price: "$0",
|
|
315
|
-
features:
|
|
315
|
+
features: f ?? [],
|
|
316
316
|
topBadge: { text: "Current", color: "blue" }
|
|
317
317
|
} : {
|
|
318
318
|
title: h("free", "Free"),
|
|
319
319
|
price: "$0",
|
|
320
|
-
features:
|
|
320
|
+
features: f ?? [],
|
|
321
321
|
ctaButton: {
|
|
322
322
|
label: "Try it for Free",
|
|
323
323
|
onClick: c
|
|
324
324
|
}
|
|
325
325
|
}, Y = () => {
|
|
326
326
|
e != null && e.managementUrl && window.open(e.managementUrl, "_blank");
|
|
327
|
-
}, me = (o) => n ? (e == null ? void 0 : e.isActive) && e.packageId ? (e == null ? void 0 : e.packageId) === o.packageId ? "Manage Subscription" : "Change Subscription" : "Subscribe" : "Log in to Continue", be = (o,
|
|
327
|
+
}, me = (o) => n ? (e == null ? void 0 : e.isActive) && e.packageId ? (e == null ? void 0 : e.packageId) === o.packageId && (e == null ? void 0 : e.offeringId) === s ? "Manage Subscription" : "Change Subscription" : "Subscribe" : "Log in to Continue", be = (o, l) => n ? (e == null ? void 0 : e.isActive) && e.packageId ? Y : () => O(o.packageId, l) : c;
|
|
328
328
|
if (K)
|
|
329
329
|
return /* @__PURE__ */ a(
|
|
330
|
-
|
|
330
|
+
I,
|
|
331
331
|
{
|
|
332
|
-
title:
|
|
332
|
+
title: u,
|
|
333
333
|
className: v,
|
|
334
334
|
variant: "cta",
|
|
335
335
|
children: /* @__PURE__ */ a("p", { children: "Loading subscription plans..." })
|
|
@@ -337,9 +337,9 @@ function Ue({
|
|
|
337
337
|
);
|
|
338
338
|
if (!q && N.data)
|
|
339
339
|
return /* @__PURE__ */ a(
|
|
340
|
-
|
|
340
|
+
I,
|
|
341
341
|
{
|
|
342
|
-
title:
|
|
342
|
+
title: u,
|
|
343
343
|
className: v,
|
|
344
344
|
variant: "cta",
|
|
345
345
|
children: /* @__PURE__ */ a(
|
|
@@ -347,7 +347,7 @@ function Ue({
|
|
|
347
347
|
{
|
|
348
348
|
backendSubscription: N.data,
|
|
349
349
|
managementUrl: e == null ? void 0 : e.managementUrl,
|
|
350
|
-
currentPlatform:
|
|
350
|
+
currentPlatform: P
|
|
351
351
|
}
|
|
352
352
|
)
|
|
353
353
|
}
|
|
@@ -372,29 +372,29 @@ function Ue({
|
|
|
372
372
|
] : []
|
|
373
373
|
]
|
|
374
374
|
}
|
|
375
|
-
} : void 0, X =
|
|
375
|
+
} : void 0, X = s === "free";
|
|
376
376
|
return /* @__PURE__ */ a(
|
|
377
|
-
|
|
377
|
+
I,
|
|
378
378
|
{
|
|
379
|
-
title:
|
|
379
|
+
title: u,
|
|
380
380
|
className: v,
|
|
381
381
|
variant: "cta",
|
|
382
382
|
error: he,
|
|
383
383
|
currentStatus: ve,
|
|
384
384
|
freeTileConfig: X ? g() : void 0,
|
|
385
385
|
aboveProducts: t.length > 1 ? /* @__PURE__ */ a("div", { className: "flex justify-center mb-6", children: /* @__PURE__ */ a(
|
|
386
|
-
|
|
386
|
+
pe,
|
|
387
387
|
{
|
|
388
388
|
options: t,
|
|
389
|
-
value:
|
|
389
|
+
value: s,
|
|
390
390
|
onChange: U
|
|
391
391
|
}
|
|
392
392
|
) }) : void 0,
|
|
393
393
|
children: !X && /* @__PURE__ */ m("div", { className: "col-span-full space-y-6", children: [
|
|
394
|
-
S && /* @__PURE__ */ a("div", { className: "rounded-xl bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700 p-5", children: S(
|
|
394
|
+
S && /* @__PURE__ */ a("div", { className: "rounded-xl bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700 p-5", children: S(s) }),
|
|
395
395
|
/* @__PURE__ */ a("div", { className: "space-y-3", children: T.map((o) => {
|
|
396
396
|
var ne, oe;
|
|
397
|
-
const
|
|
397
|
+
const l = (ne = o.product) == null ? void 0 : ne.period, y = l ? h(l, we[l] ?? ce(l)) : o.name, re = n && (e == null ? void 0 : e.isActive) && e.packageId === o.packageId && e.offeringId === s, te = p && o.packageId !== p.packageId ? Ee(p, o) : null, Se = me(o), ae = be(o, s), ye = ((oe = o.product) == null ? void 0 : oe.priceString) ?? "$0";
|
|
398
398
|
return /* @__PURE__ */ m(
|
|
399
399
|
"div",
|
|
400
400
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/subscription_pages",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Subscription page components for React web applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^18.0.0 || ^19.0.0",
|
|
30
30
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
31
|
-
"@sudobility/subscription_lib": "^0.0.
|
|
31
|
+
"@sudobility/subscription_lib": "^0.0.34",
|
|
32
32
|
"@sudobility/subscription-components": "^1.0.28",
|
|
33
33
|
"@sudobility/types": "^1.9.59"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@sudobility/subscription-components": "^1.0.28",
|
|
37
|
-
"@sudobility/subscription_lib": "^0.0.
|
|
37
|
+
"@sudobility/subscription_lib": "^0.0.34",
|
|
38
38
|
"@sudobility/types": "^1.9.59",
|
|
39
39
|
"@tanstack/react-query": "^5.91.2",
|
|
40
40
|
"@testing-library/jest-dom": "^6.0.0",
|