@sudobility/subscription_pages 0.0.5 → 0.0.7
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 +150 -143
- package/dist/pages/SubscriptionByOfferPage.d.ts +6 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { usePackagesByDuration as
|
|
4
|
-
import { SubscriptionLayout as
|
|
5
|
-
function
|
|
1
|
+
import { jsx as c, jsxs as D } from "react/jsx-runtime";
|
|
2
|
+
import { useState as y, useEffect as oe } from "react";
|
|
3
|
+
import { usePackagesByDuration as le, useUserSubscription as V, getSubscriptionInstance as X, refreshSubscription as Z, useAllOfferings as se, useOfferingPackages as ue, periodToMonths as J } from "@sudobility/subscription_lib";
|
|
4
|
+
import { SubscriptionLayout as $, SubscriptionTile as de, SegmentedControl as ee } from "@sudobility/subscription-components";
|
|
5
|
+
function ve({
|
|
6
6
|
isLoggedIn: n,
|
|
7
|
-
onNavigateToLogin:
|
|
8
|
-
userId:
|
|
7
|
+
onNavigateToLogin: l,
|
|
8
|
+
userId: p,
|
|
9
9
|
userEmail: o,
|
|
10
|
-
featuresByPackage:
|
|
11
|
-
freeFeatures:
|
|
12
|
-
title:
|
|
13
|
-
className:
|
|
10
|
+
featuresByPackage: f,
|
|
11
|
+
freeFeatures: s,
|
|
12
|
+
title: g = "Choose Your Plan",
|
|
13
|
+
className: x
|
|
14
14
|
}) {
|
|
15
15
|
const {
|
|
16
16
|
packagesByDuration: I,
|
|
17
|
-
availableDurations:
|
|
18
|
-
isLoading:
|
|
19
|
-
error:
|
|
20
|
-
} =
|
|
17
|
+
availableDurations: h,
|
|
18
|
+
isLoading: C,
|
|
19
|
+
error: b
|
|
20
|
+
} = le(), {
|
|
21
21
|
subscription: r,
|
|
22
|
-
isLoading:
|
|
23
|
-
error:
|
|
24
|
-
} = V({ userId:
|
|
22
|
+
isLoading: B,
|
|
23
|
+
error: N
|
|
24
|
+
} = V({ userId: p, userEmail: o }), [e, F] = y(null), [M, u] = y(null), [w, A] = y(!1), k = e ?? h[0] ?? null, R = C || B, P = b || N, E = async (t, m) => {
|
|
25
25
|
try {
|
|
26
|
-
|
|
26
|
+
A(!0), u(null), await X().purchase({
|
|
27
27
|
packageId: t,
|
|
28
|
-
offeringId:
|
|
28
|
+
offeringId: m,
|
|
29
29
|
customerEmail: o
|
|
30
30
|
}), await Z();
|
|
31
|
-
} catch (
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
} catch (d) {
|
|
32
|
+
u(
|
|
33
|
+
d instanceof Error ? d.message : "Purchase failed"
|
|
34
34
|
);
|
|
35
35
|
} finally {
|
|
36
|
-
|
|
36
|
+
A(!1);
|
|
37
37
|
}
|
|
38
|
-
},
|
|
38
|
+
}, T = () => n ? (r == null ? void 0 : r.isActive) && r.packageId ? {
|
|
39
39
|
title: "Free",
|
|
40
40
|
price: "$0",
|
|
41
|
-
features:
|
|
41
|
+
features: s ?? [],
|
|
42
42
|
ctaButton: {
|
|
43
43
|
label: "Cancel Subscription",
|
|
44
44
|
onClick: () => {
|
|
@@ -48,7 +48,7 @@ function he({
|
|
|
48
48
|
} : {
|
|
49
49
|
title: "Free",
|
|
50
50
|
price: "$0",
|
|
51
|
-
features:
|
|
51
|
+
features: s ?? [],
|
|
52
52
|
ctaButton: {
|
|
53
53
|
label: "Current Plan"
|
|
54
54
|
},
|
|
@@ -56,20 +56,20 @@ function he({
|
|
|
56
56
|
} : {
|
|
57
57
|
title: "Free",
|
|
58
58
|
price: "$0",
|
|
59
|
-
features:
|
|
59
|
+
features: s ?? [],
|
|
60
60
|
ctaButton: {
|
|
61
61
|
label: "Try it for Free",
|
|
62
|
-
onClick:
|
|
62
|
+
onClick: l
|
|
63
63
|
}
|
|
64
|
-
},
|
|
64
|
+
}, L = (t) => {
|
|
65
65
|
if (!n)
|
|
66
66
|
return {
|
|
67
67
|
label: "Log in to Continue",
|
|
68
|
-
onClick:
|
|
68
|
+
onClick: l
|
|
69
69
|
};
|
|
70
|
-
const
|
|
70
|
+
const m = (r == null ? void 0 : r.isActive) && r.packageId;
|
|
71
71
|
if ((r == null ? void 0 : r.packageId) !== t.package.packageId)
|
|
72
|
-
return
|
|
72
|
+
return m ? {
|
|
73
73
|
label: "Change Subscription",
|
|
74
74
|
onClick: () => E(t.package.packageId, t.offerId)
|
|
75
75
|
} : {
|
|
@@ -77,17 +77,17 @@ function he({
|
|
|
77
77
|
onClick: () => E(t.package.packageId, t.offerId)
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
|
-
if (
|
|
81
|
-
return /* @__PURE__ */
|
|
82
|
-
|
|
80
|
+
if (R)
|
|
81
|
+
return /* @__PURE__ */ c(
|
|
82
|
+
$,
|
|
83
83
|
{
|
|
84
|
-
title:
|
|
85
|
-
className:
|
|
84
|
+
title: g,
|
|
85
|
+
className: x,
|
|
86
86
|
variant: "cta",
|
|
87
|
-
children: /* @__PURE__ */
|
|
87
|
+
children: /* @__PURE__ */ c("p", { children: "Loading subscription plans..." })
|
|
88
88
|
}
|
|
89
89
|
);
|
|
90
|
-
const
|
|
90
|
+
const U = M ?? (P ? P.message : null), Y = n && (r != null && r.isActive) && r.packageId ? {
|
|
91
91
|
isActive: !0,
|
|
92
92
|
activeContent: {
|
|
93
93
|
title: "Active Subscription",
|
|
@@ -107,44 +107,44 @@ function he({
|
|
|
107
107
|
] : []
|
|
108
108
|
]
|
|
109
109
|
}
|
|
110
|
-
} : void 0,
|
|
111
|
-
return /* @__PURE__ */
|
|
112
|
-
|
|
110
|
+
} : void 0, j = k ? I[k] ?? [] : [];
|
|
111
|
+
return /* @__PURE__ */ c(
|
|
112
|
+
$,
|
|
113
113
|
{
|
|
114
|
-
title:
|
|
115
|
-
className:
|
|
114
|
+
title: g,
|
|
115
|
+
className: x,
|
|
116
116
|
variant: "cta",
|
|
117
|
-
error:
|
|
118
|
-
currentStatus:
|
|
119
|
-
freeTileConfig:
|
|
120
|
-
aboveProducts:
|
|
117
|
+
error: U,
|
|
118
|
+
currentStatus: Y,
|
|
119
|
+
freeTileConfig: T(),
|
|
120
|
+
aboveProducts: h.length > 1 ? /* @__PURE__ */ c(
|
|
121
121
|
ee,
|
|
122
122
|
{
|
|
123
|
-
options:
|
|
123
|
+
options: h.map((t) => ({
|
|
124
124
|
value: t,
|
|
125
125
|
label: t.charAt(0).toUpperCase() + t.slice(1)
|
|
126
126
|
})),
|
|
127
|
-
value:
|
|
128
|
-
onChange: (t) =>
|
|
127
|
+
value: k ?? h[0],
|
|
128
|
+
onChange: (t) => F(t)
|
|
129
129
|
}
|
|
130
130
|
) : void 0,
|
|
131
|
-
children:
|
|
132
|
-
var
|
|
133
|
-
const
|
|
134
|
-
return /* @__PURE__ */
|
|
135
|
-
|
|
131
|
+
children: j.map((t) => {
|
|
132
|
+
var S;
|
|
133
|
+
const m = n && (r == null ? void 0 : r.isActive) && r.packageId === t.package.packageId, d = L(t);
|
|
134
|
+
return /* @__PURE__ */ c(
|
|
135
|
+
de,
|
|
136
136
|
{
|
|
137
137
|
id: t.package.packageId,
|
|
138
138
|
title: t.package.name,
|
|
139
|
-
price: ((
|
|
139
|
+
price: ((S = t.package.product) == null ? void 0 : S.priceString) ?? "$0",
|
|
140
140
|
periodLabel: t.package.product ? `/${t.package.product.period}` : void 0,
|
|
141
|
-
features: (
|
|
141
|
+
features: (f == null ? void 0 : f[t.package.packageId]) ?? [],
|
|
142
142
|
isSelected: !1,
|
|
143
143
|
onSelect: () => {
|
|
144
144
|
},
|
|
145
|
-
isCurrentPlan:
|
|
146
|
-
ctaButton:
|
|
147
|
-
disabled:
|
|
145
|
+
isCurrentPlan: m,
|
|
146
|
+
ctaButton: d,
|
|
147
|
+
disabled: w
|
|
148
148
|
},
|
|
149
149
|
`${t.offerId}-${t.package.packageId}`
|
|
150
150
|
);
|
|
@@ -155,73 +155,80 @@ function he({
|
|
|
155
155
|
function K(n) {
|
|
156
156
|
return n.charAt(0).toUpperCase() + n.slice(1);
|
|
157
157
|
}
|
|
158
|
-
const
|
|
158
|
+
const pe = {
|
|
159
159
|
weekly: "Weekly",
|
|
160
160
|
monthly: "Monthly",
|
|
161
161
|
quarterly: "Quarterly",
|
|
162
162
|
yearly: "Yearly",
|
|
163
163
|
lifetime: "Lifetime"
|
|
164
164
|
};
|
|
165
|
-
function
|
|
166
|
-
if (!n.product || !
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
171
|
-
const
|
|
172
|
-
(
|
|
165
|
+
function fe(n, l) {
|
|
166
|
+
if (!n.product || !l.product) return null;
|
|
167
|
+
const p = J(n.product.period), o = J(l.product.period);
|
|
168
|
+
if (p <= 0 || o <= 0 || p === 1 / 0 || o === 1 / 0 || p === o) return null;
|
|
169
|
+
const f = n.product.price / p, s = l.product.price / o;
|
|
170
|
+
if (f <= 0) return null;
|
|
171
|
+
const g = Math.round(
|
|
172
|
+
(f - s) / f * 100
|
|
173
173
|
);
|
|
174
|
-
return
|
|
174
|
+
return g > 0 ? g : null;
|
|
175
175
|
}
|
|
176
|
-
function
|
|
176
|
+
function Ce({
|
|
177
177
|
isLoggedIn: n,
|
|
178
|
-
onNavigateToLogin:
|
|
179
|
-
userId:
|
|
178
|
+
onNavigateToLogin: l,
|
|
179
|
+
userId: p,
|
|
180
180
|
userEmail: o,
|
|
181
|
-
featuresByPackage:
|
|
182
|
-
freeFeatures:
|
|
183
|
-
title:
|
|
184
|
-
className:
|
|
181
|
+
featuresByPackage: f,
|
|
182
|
+
freeFeatures: s,
|
|
183
|
+
title: g = "Choose Your Plan",
|
|
184
|
+
className: x,
|
|
185
185
|
t: I,
|
|
186
|
-
renderOfferingContent:
|
|
186
|
+
renderOfferingContent: h,
|
|
187
|
+
initialOfferId: C
|
|
187
188
|
}) {
|
|
188
189
|
var q;
|
|
189
|
-
const
|
|
190
|
-
offerings:
|
|
191
|
-
isLoading:
|
|
192
|
-
error:
|
|
193
|
-
} =
|
|
190
|
+
const b = (a, i) => I ? I(a, i) : i, {
|
|
191
|
+
offerings: r,
|
|
192
|
+
isLoading: B,
|
|
193
|
+
error: N
|
|
194
|
+
} = se(), {
|
|
194
195
|
subscription: e,
|
|
195
|
-
isLoading:
|
|
196
|
-
error:
|
|
197
|
-
} = V({ userId:
|
|
196
|
+
isLoading: F,
|
|
197
|
+
error: M
|
|
198
|
+
} = V({ userId: p, userEmail: o }), [u, w] = y(
|
|
199
|
+
C ?? "free"
|
|
200
|
+
);
|
|
201
|
+
oe(() => {
|
|
202
|
+
C && w(C);
|
|
203
|
+
}, [C]);
|
|
204
|
+
const [A, k] = y(null), [R, P] = y(!1), E = ((q = r[0]) == null ? void 0 : q.offerId) ?? "", T = u !== "free" ? u : E, {
|
|
198
205
|
packages: L,
|
|
199
206
|
isLoading: U,
|
|
200
207
|
error: Y
|
|
201
|
-
} =
|
|
208
|
+
} = ue(T), j = B || F || U, t = N || M || Y, m = async (a, i) => {
|
|
202
209
|
try {
|
|
203
|
-
|
|
210
|
+
P(!0), k(null), await X().purchase({
|
|
204
211
|
packageId: a,
|
|
205
|
-
offeringId:
|
|
212
|
+
offeringId: i,
|
|
206
213
|
customerEmail: o
|
|
207
214
|
}), await Z();
|
|
208
215
|
} catch (v) {
|
|
209
|
-
|
|
216
|
+
k(
|
|
210
217
|
v instanceof Error ? v.message : "Purchase failed"
|
|
211
218
|
);
|
|
212
219
|
} finally {
|
|
213
|
-
|
|
220
|
+
P(!1);
|
|
214
221
|
}
|
|
215
|
-
},
|
|
216
|
-
{ value: "free", label:
|
|
217
|
-
...
|
|
222
|
+
}, d = [
|
|
223
|
+
{ value: "free", label: b("free", "Free") },
|
|
224
|
+
...r.map((a) => ({
|
|
218
225
|
value: a.offerId,
|
|
219
|
-
label:
|
|
226
|
+
label: b(a.offerId, K(a.offerId))
|
|
220
227
|
}))
|
|
221
|
-
],
|
|
222
|
-
title:
|
|
228
|
+
], S = L[0] ?? null, re = () => n ? (e == null ? void 0 : e.isActive) && e.packageId ? {
|
|
229
|
+
title: b("free", "Free"),
|
|
223
230
|
price: "$0",
|
|
224
|
-
features:
|
|
231
|
+
features: s ?? [],
|
|
225
232
|
ctaButton: {
|
|
226
233
|
label: "Cancel Subscription",
|
|
227
234
|
onClick: () => {
|
|
@@ -229,37 +236,37 @@ function me({
|
|
|
229
236
|
}
|
|
230
237
|
}
|
|
231
238
|
} : {
|
|
232
|
-
title:
|
|
239
|
+
title: b("free", "Free"),
|
|
233
240
|
price: "$0",
|
|
234
|
-
features:
|
|
241
|
+
features: s ?? [],
|
|
235
242
|
ctaButton: {
|
|
236
243
|
label: "Current Plan"
|
|
237
244
|
},
|
|
238
245
|
topBadge: { text: "Current Plan", color: "blue" }
|
|
239
246
|
} : {
|
|
240
|
-
title:
|
|
247
|
+
title: b("free", "Free"),
|
|
241
248
|
price: "$0",
|
|
242
|
-
features:
|
|
249
|
+
features: s ?? [],
|
|
243
250
|
ctaButton: {
|
|
244
251
|
label: "Try it for Free",
|
|
245
|
-
onClick:
|
|
252
|
+
onClick: l
|
|
246
253
|
}
|
|
247
|
-
},
|
|
248
|
-
if (!n) return
|
|
254
|
+
}, te = (a) => n ? (e == null ? void 0 : e.packageId) === a.packageId ? "Current Plan" : (e == null ? void 0 : e.isActive) && e.packageId ? "Change Subscription" : "Subscribe" : "Log in to Continue", ae = (a, i) => {
|
|
255
|
+
if (!n) return l;
|
|
249
256
|
if ((e == null ? void 0 : e.packageId) !== a.packageId)
|
|
250
|
-
return () =>
|
|
257
|
+
return () => m(a.packageId, i);
|
|
251
258
|
};
|
|
252
259
|
if (j)
|
|
253
|
-
return /* @__PURE__ */
|
|
254
|
-
|
|
260
|
+
return /* @__PURE__ */ c(
|
|
261
|
+
$,
|
|
255
262
|
{
|
|
256
|
-
title:
|
|
257
|
-
className:
|
|
263
|
+
title: g,
|
|
264
|
+
className: x,
|
|
258
265
|
variant: "cta",
|
|
259
|
-
children: /* @__PURE__ */
|
|
266
|
+
children: /* @__PURE__ */ c("p", { children: "Loading subscription plans..." })
|
|
260
267
|
}
|
|
261
268
|
);
|
|
262
|
-
const
|
|
269
|
+
const ne = A ?? (t ? t.message : null), ce = n && (e != null && e.isActive) && e.packageId ? {
|
|
263
270
|
isActive: !0,
|
|
264
271
|
activeContent: {
|
|
265
272
|
title: "Active Subscription",
|
|
@@ -279,50 +286,50 @@ function me({
|
|
|
279
286
|
] : []
|
|
280
287
|
]
|
|
281
288
|
}
|
|
282
|
-
} : void 0, _ =
|
|
283
|
-
return /* @__PURE__ */
|
|
284
|
-
|
|
289
|
+
} : void 0, _ = u === "free";
|
|
290
|
+
return /* @__PURE__ */ c(
|
|
291
|
+
$,
|
|
285
292
|
{
|
|
286
|
-
title:
|
|
287
|
-
className:
|
|
293
|
+
title: g,
|
|
294
|
+
className: x,
|
|
288
295
|
variant: "cta",
|
|
289
|
-
error:
|
|
290
|
-
currentStatus:
|
|
291
|
-
freeTileConfig: _ ?
|
|
292
|
-
aboveProducts:
|
|
296
|
+
error: ne,
|
|
297
|
+
currentStatus: ce,
|
|
298
|
+
freeTileConfig: _ ? re() : void 0,
|
|
299
|
+
aboveProducts: d.length > 1 ? /* @__PURE__ */ c("div", { className: "flex justify-center mb-6", children: /* @__PURE__ */ c(
|
|
293
300
|
ee,
|
|
294
301
|
{
|
|
295
|
-
options:
|
|
296
|
-
value:
|
|
297
|
-
onChange:
|
|
302
|
+
options: d,
|
|
303
|
+
value: u,
|
|
304
|
+
onChange: w
|
|
298
305
|
}
|
|
299
306
|
) }) : void 0,
|
|
300
|
-
children: !_ && /* @__PURE__ */
|
|
301
|
-
|
|
302
|
-
/* @__PURE__ */
|
|
307
|
+
children: !_ && /* @__PURE__ */ D("div", { className: "col-span-full space-y-6", children: [
|
|
308
|
+
h && /* @__PURE__ */ c("div", { className: "rounded-xl bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700 p-5", children: h(u) }),
|
|
309
|
+
/* @__PURE__ */ c("div", { className: "space-y-3", children: L.map((a) => {
|
|
303
310
|
var G, H;
|
|
304
|
-
const
|
|
305
|
-
return /* @__PURE__ */
|
|
311
|
+
const i = (G = a.product) == null ? void 0 : G.period, v = i ? b(i, pe[i] ?? K(i)) : a.name, O = n && (e == null ? void 0 : e.isActive) && e.packageId === a.packageId, z = S && a.packageId !== S.packageId ? fe(S, a) : null, Q = te(a), W = ae(a, u), ie = ((H = a.product) == null ? void 0 : H.priceString) ?? "$0";
|
|
312
|
+
return /* @__PURE__ */ D(
|
|
306
313
|
"div",
|
|
307
314
|
{
|
|
308
|
-
className: "flex items-center justify-between rounded-xl p-4 transition-all " + (
|
|
315
|
+
className: "flex items-center justify-between rounded-xl p-4 transition-all " + (O ? "bg-blue-50 dark:bg-blue-900/20 border-2 border-blue-500 dark:border-blue-400" : "bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700"),
|
|
309
316
|
children: [
|
|
310
|
-
/* @__PURE__ */
|
|
311
|
-
/* @__PURE__ */
|
|
312
|
-
/* @__PURE__ */
|
|
313
|
-
z !== null ? /* @__PURE__ */
|
|
317
|
+
/* @__PURE__ */ D("div", { className: "min-w-0 flex-1", children: [
|
|
318
|
+
/* @__PURE__ */ c("p", { className: "text-base font-semibold text-gray-900 dark:text-gray-100", children: v }),
|
|
319
|
+
/* @__PURE__ */ c("p", { className: "text-xs text-gray-400 dark:text-gray-500", children: a.packageId }),
|
|
320
|
+
z !== null ? /* @__PURE__ */ D("p", { className: "text-sm font-medium text-green-600 dark:text-green-400", children: [
|
|
314
321
|
"Save ",
|
|
315
322
|
z,
|
|
316
323
|
"%"
|
|
317
|
-
] }) :
|
|
324
|
+
] }) : O ? /* @__PURE__ */ c("p", { className: "text-sm font-medium text-blue-600 dark:text-blue-400", children: "Current Plan" }) : null
|
|
318
325
|
] }),
|
|
319
|
-
/* @__PURE__ */
|
|
326
|
+
O ? /* @__PURE__ */ c("span", { className: "ml-4 flex-shrink-0 text-sm font-semibold text-blue-600 dark:text-blue-400", children: Q }) : /* @__PURE__ */ c(
|
|
320
327
|
"button",
|
|
321
328
|
{
|
|
322
329
|
onClick: W,
|
|
323
|
-
disabled:
|
|
324
|
-
className: "ml-4 flex-shrink-0 rounded-lg px-4 py-2 text-sm font-semibold transition-colors
|
|
325
|
-
children:
|
|
330
|
+
disabled: R || !W,
|
|
331
|
+
className: "ml-4 flex-shrink-0 rounded-lg px-4 py-2 text-sm font-semibold transition-colors bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
332
|
+
children: `${ie} · ${Q}`
|
|
326
333
|
}
|
|
327
334
|
)
|
|
328
335
|
]
|
|
@@ -335,6 +342,6 @@ function me({
|
|
|
335
342
|
);
|
|
336
343
|
}
|
|
337
344
|
export {
|
|
338
|
-
|
|
339
|
-
|
|
345
|
+
ve as SubscriptionByDurationPage,
|
|
346
|
+
Ce as SubscriptionByOfferPage
|
|
340
347
|
};
|
|
@@ -29,5 +29,10 @@ export interface SubscriptionByOfferPageProps {
|
|
|
29
29
|
* Return a list of strings or React elements shown in a styled container.
|
|
30
30
|
*/
|
|
31
31
|
renderOfferingContent?: (offerId: string) => React.ReactNode;
|
|
32
|
+
/**
|
|
33
|
+
* If set, automatically select the specified offering on mount.
|
|
34
|
+
* Must match an offering identifier from RevenueCat.
|
|
35
|
+
*/
|
|
36
|
+
initialOfferId?: string;
|
|
32
37
|
}
|
|
33
|
-
export declare function SubscriptionByOfferPage({ isLoggedIn, onNavigateToLogin, userId, userEmail, featuresByPackage: _featuresByPackage, freeFeatures, title, className, t: translate, renderOfferingContent, }: SubscriptionByOfferPageProps): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export declare function SubscriptionByOfferPage({ isLoggedIn, onNavigateToLogin, userId, userEmail, featuresByPackage: _featuresByPackage, freeFeatures, title, className, t: translate, renderOfferingContent, initialOfferId, }: SubscriptionByOfferPageProps): import("react/jsx-runtime").JSX.Element;
|