@sudobility/subscription_pages 0.0.6 → 0.0.8

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.
Files changed (2) hide show
  1. package/dist/index.js +99 -95
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { jsx as i, jsxs as E } from "react/jsx-runtime";
2
- import { useState as S } from "react";
3
- import { usePackagesByDuration as oe, useUserSubscription as V, getSubscriptionInstance as X, refreshSubscription as Z, useAllOfferings as le, useOfferingPackages as se, periodToMonths as J } from "@sudobility/subscription_lib";
4
- import { SubscriptionLayout as L, SubscriptionTile as ue, SegmentedControl as ee } from "@sudobility/subscription-components";
5
- function me({
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
7
  onNavigateToLogin: l,
8
8
  userId: p,
@@ -10,20 +10,20 @@ function me({
10
10
  featuresByPackage: f,
11
11
  freeFeatures: s,
12
12
  title: g = "Choose Your Plan",
13
- className: y
13
+ className: x
14
14
  }) {
15
15
  const {
16
- packagesByDuration: x,
16
+ packagesByDuration: I,
17
17
  availableDurations: h,
18
- isLoading: D,
18
+ isLoading: C,
19
19
  error: b
20
- } = oe(), {
20
+ } = le(), {
21
21
  subscription: r,
22
- isLoading: $,
23
- error: B
24
- } = V({ userId: p, userEmail: o }), [e, N] = S(null), [F, u] = S(null), [M, P] = S(!1), C = e ?? h[0] ?? null, O = D || $, I = b || B, w = async (t, m) => {
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
- P(!0), u(null), await X().purchase({
26
+ A(!0), u(null), await X().purchase({
27
27
  packageId: t,
28
28
  offeringId: m,
29
29
  customerEmail: o
@@ -33,9 +33,9 @@ function me({
33
33
  d instanceof Error ? d.message : "Purchase failed"
34
34
  );
35
35
  } finally {
36
- P(!1);
36
+ A(!1);
37
37
  }
38
- }, R = () => n ? (r == null ? void 0 : r.isActive) && r.packageId ? {
38
+ }, T = () => n ? (r == null ? void 0 : r.isActive) && r.packageId ? {
39
39
  title: "Free",
40
40
  price: "$0",
41
41
  features: s ?? [],
@@ -61,7 +61,7 @@ function me({
61
61
  label: "Try it for Free",
62
62
  onClick: l
63
63
  }
64
- }, A = (t) => {
64
+ }, L = (t) => {
65
65
  if (!n)
66
66
  return {
67
67
  label: "Log in to Continue",
@@ -71,23 +71,23 @@ function me({
71
71
  if ((r == null ? void 0 : r.packageId) !== t.package.packageId)
72
72
  return m ? {
73
73
  label: "Change Subscription",
74
- onClick: () => w(t.package.packageId, t.offerId)
74
+ onClick: () => E(t.package.packageId, t.offerId)
75
75
  } : {
76
76
  label: "Subscribe",
77
- onClick: () => w(t.package.packageId, t.offerId)
77
+ onClick: () => E(t.package.packageId, t.offerId)
78
78
  };
79
79
  };
80
- if (O)
81
- return /* @__PURE__ */ i(
82
- L,
80
+ if (R)
81
+ return /* @__PURE__ */ c(
82
+ $,
83
83
  {
84
84
  title: g,
85
- className: y,
85
+ className: x,
86
86
  variant: "cta",
87
- children: /* @__PURE__ */ i("p", { children: "Loading subscription plans..." })
87
+ children: /* @__PURE__ */ c("p", { children: "Loading subscription plans..." })
88
88
  }
89
89
  );
90
- const T = F ?? (I ? I.message : null), U = n && (r != null && r.isActive) && r.packageId ? {
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,36 +107,36 @@ function me({
107
107
  ] : []
108
108
  ]
109
109
  }
110
- } : void 0, Y = C ? x[C] ?? [] : [];
111
- return /* @__PURE__ */ i(
112
- L,
110
+ } : void 0, j = k ? I[k] ?? [] : [];
111
+ return /* @__PURE__ */ c(
112
+ $,
113
113
  {
114
114
  title: g,
115
- className: y,
115
+ className: x,
116
116
  variant: "cta",
117
- error: T,
118
- currentStatus: U,
119
- freeTileConfig: R(),
120
- aboveProducts: h.length > 1 ? /* @__PURE__ */ i(
117
+ error: U,
118
+ currentStatus: Y,
119
+ freeTileConfig: T(),
120
+ aboveProducts: h.length > 1 ? /* @__PURE__ */ c(
121
121
  ee,
122
122
  {
123
123
  options: h.map((t) => ({
124
124
  value: t,
125
125
  label: t.charAt(0).toUpperCase() + t.slice(1)
126
126
  })),
127
- value: C ?? h[0],
128
- onChange: (t) => N(t)
127
+ value: k ?? h[0],
128
+ onChange: (t) => F(t)
129
129
  }
130
130
  ) : void 0,
131
- children: Y.map((t) => {
132
- var k;
133
- const m = n && (r == null ? void 0 : r.isActive) && r.packageId === t.package.packageId, d = A(t);
134
- return /* @__PURE__ */ i(
135
- ue,
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: ((k = t.package.product) == null ? void 0 : k.priceString) ?? "$0",
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
141
  features: (f == null ? void 0 : f[t.package.packageId]) ?? [],
142
142
  isSelected: !1,
@@ -144,7 +144,7 @@ function me({
144
144
  },
145
145
  isCurrentPlan: m,
146
146
  ctaButton: d,
147
- disabled: M
147
+ disabled: w
148
148
  },
149
149
  `${t.offerId}-${t.package.packageId}`
150
150
  );
@@ -155,14 +155,14 @@ function me({
155
155
  function K(n) {
156
156
  return n.charAt(0).toUpperCase() + n.slice(1);
157
157
  }
158
- const de = {
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 pe(n, l) {
165
+ function fe(n, l) {
166
166
  if (!n.product || !l.product) return null;
167
167
  const p = J(n.product.period), o = J(l.product.period);
168
168
  if (p <= 0 || o <= 0 || p === 1 / 0 || o === 1 / 0 || p === o) return null;
@@ -173,7 +173,7 @@ function pe(n, l) {
173
173
  );
174
174
  return g > 0 ? g : null;
175
175
  }
176
- function ve({
176
+ function Ce({
177
177
  isLoggedIn: n,
178
178
  onNavigateToLogin: l,
179
179
  userId: p,
@@ -181,39 +181,43 @@ function ve({
181
181
  featuresByPackage: f,
182
182
  freeFeatures: s,
183
183
  title: g = "Choose Your Plan",
184
- className: y,
185
- t: x,
184
+ className: x,
185
+ t: I,
186
186
  renderOfferingContent: h,
187
- initialOfferId: D
187
+ initialOfferId: C
188
188
  }) {
189
189
  var q;
190
- const b = (a, c) => x ? x(a, c) : c, {
190
+ const b = (a, i) => I ? I(a, i) : i, {
191
191
  offerings: r,
192
- isLoading: $,
193
- error: B
194
- } = le(), {
192
+ isLoading: B,
193
+ error: N
194
+ } = se(), {
195
195
  subscription: e,
196
- isLoading: N,
197
- error: F
198
- } = V({ userId: p, userEmail: o }), [u, M] = S(
199
- D ?? "free"
200
- ), [P, C] = S(null), [O, I] = S(!1), w = ((q = r[0]) == null ? void 0 : q.offerId) ?? "", R = u !== "free" ? u : w, {
201
- packages: A,
202
- isLoading: T,
203
- error: U
204
- } = se(R), Y = $ || N || T, t = B || F || U, m = async (a, c) => {
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, {
205
+ packages: L,
206
+ isLoading: U,
207
+ error: Y
208
+ } = ue(T), j = B || F || U, t = N || M || Y, m = async (a, i) => {
205
209
  try {
206
- I(!0), C(null), await X().purchase({
210
+ P(!0), k(null), await X().purchase({
207
211
  packageId: a,
208
- offeringId: c,
212
+ offeringId: i,
209
213
  customerEmail: o
210
214
  }), await Z();
211
215
  } catch (v) {
212
- C(
216
+ k(
213
217
  v instanceof Error ? v.message : "Purchase failed"
214
218
  );
215
219
  } finally {
216
- I(!1);
220
+ P(!1);
217
221
  }
218
222
  }, d = [
219
223
  { value: "free", label: b("free", "Free") },
@@ -221,7 +225,7 @@ function ve({
221
225
  value: a.offerId,
222
226
  label: b(a.offerId, K(a.offerId))
223
227
  }))
224
- ], k = A[0] ?? null, re = () => n ? (e == null ? void 0 : e.isActive) && e.packageId ? {
228
+ ], S = L[0] ?? null, re = () => n ? (e == null ? void 0 : e.isActive) && e.packageId ? {
225
229
  title: b("free", "Free"),
226
230
  price: "$0",
227
231
  features: s ?? [],
@@ -247,22 +251,22 @@ function ve({
247
251
  label: "Try it for Free",
248
252
  onClick: l
249
253
  }
250
- }, 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, c) => {
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) => {
251
255
  if (!n) return l;
252
256
  if ((e == null ? void 0 : e.packageId) !== a.packageId)
253
- return () => m(a.packageId, c);
257
+ return () => m(a.packageId, i);
254
258
  };
255
- if (Y)
256
- return /* @__PURE__ */ i(
257
- L,
259
+ if (j)
260
+ return /* @__PURE__ */ c(
261
+ $,
258
262
  {
259
263
  title: g,
260
- className: y,
264
+ className: x,
261
265
  variant: "cta",
262
- children: /* @__PURE__ */ i("p", { children: "Loading subscription plans..." })
266
+ children: /* @__PURE__ */ c("p", { children: "Loading subscription plans..." })
263
267
  }
264
268
  );
265
- const ne = P ?? (t ? t.message : null), ie = n && (e != null && e.isActive) && e.packageId ? {
269
+ const ne = A ?? (t ? t.message : null), ce = n && (e != null && e.isActive) && e.packageId ? {
266
270
  isActive: !0,
267
271
  activeContent: {
268
272
  title: "Active Subscription",
@@ -283,49 +287,49 @@ function ve({
283
287
  ]
284
288
  }
285
289
  } : void 0, _ = u === "free";
286
- return /* @__PURE__ */ i(
287
- L,
290
+ return /* @__PURE__ */ c(
291
+ $,
288
292
  {
289
293
  title: g,
290
- className: y,
294
+ className: x,
291
295
  variant: "cta",
292
296
  error: ne,
293
- currentStatus: ie,
297
+ currentStatus: ce,
294
298
  freeTileConfig: _ ? re() : void 0,
295
- aboveProducts: d.length > 1 ? /* @__PURE__ */ i("div", { className: "flex justify-center mb-6", children: /* @__PURE__ */ i(
299
+ aboveProducts: d.length > 1 ? /* @__PURE__ */ c("div", { className: "flex justify-center mb-6", children: /* @__PURE__ */ c(
296
300
  ee,
297
301
  {
298
302
  options: d,
299
303
  value: u,
300
- onChange: M
304
+ onChange: w
301
305
  }
302
306
  ) }) : void 0,
303
- children: !_ && /* @__PURE__ */ E("div", { className: "col-span-full space-y-6", children: [
304
- h && /* @__PURE__ */ i("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) }),
305
- /* @__PURE__ */ i("div", { className: "space-y-3", children: A.map((a) => {
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) => {
306
310
  var G, H;
307
- const c = (G = a.product) == null ? void 0 : G.period, v = c ? b(c, de[c] ?? K(c)) : a.name, j = n && (e == null ? void 0 : e.isActive) && e.packageId === a.packageId, z = k && a.packageId !== k.packageId ? pe(k, a) : null, Q = te(a), W = ae(a, u), ce = ((H = a.product) == null ? void 0 : H.priceString) ?? "$0";
308
- return /* @__PURE__ */ E(
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(
309
313
  "div",
310
314
  {
311
- className: "flex items-center justify-between rounded-xl p-4 transition-all " + (j ? "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"),
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"),
312
316
  children: [
313
- /* @__PURE__ */ E("div", { className: "min-w-0 flex-1", children: [
314
- /* @__PURE__ */ i("p", { className: "text-base font-semibold text-gray-900 dark:text-gray-100", children: v }),
315
- /* @__PURE__ */ i("p", { className: "text-xs text-gray-400 dark:text-gray-500", children: a.packageId }),
316
- z !== null ? /* @__PURE__ */ E("p", { className: "text-sm font-medium text-green-600 dark:text-green-400", children: [
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: [
317
321
  "Save ",
318
322
  z,
319
323
  "%"
320
- ] }) : j ? /* @__PURE__ */ i("p", { className: "text-sm font-medium text-blue-600 dark:text-blue-400", children: "Current Plan" }) : null
324
+ ] }) : O ? /* @__PURE__ */ c("p", { className: "text-sm font-medium text-blue-600 dark:text-blue-400", children: "Current Plan" }) : null
321
325
  ] }),
322
- j ? /* @__PURE__ */ i("span", { className: "ml-4 flex-shrink-0 text-sm font-semibold text-blue-600 dark:text-blue-400", children: Q }) : /* @__PURE__ */ i(
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(
323
327
  "button",
324
328
  {
325
329
  onClick: W,
326
- disabled: O || !W,
330
+ disabled: R || !W,
327
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",
328
- children: `${ce} · ${Q}`
332
+ children: `${ie} · ${Q}`
329
333
  }
330
334
  )
331
335
  ]
@@ -338,6 +342,6 @@ function ve({
338
342
  );
339
343
  }
340
344
  export {
341
- me as SubscriptionByDurationPage,
342
- ve as SubscriptionByOfferPage
345
+ ve as SubscriptionByDurationPage,
346
+ Ce as SubscriptionByOfferPage
343
347
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/subscription_pages",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
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.27",
31
+ "@sudobility/subscription_lib": "^0.0.28",
32
32
  "@sudobility/subscription-components": "^1.0.27",
33
33
  "@sudobility/types": "^1.9.58"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@sudobility/subscription-components": "^1.0.27",
37
- "@sudobility/subscription_lib": "^0.0.27",
37
+ "@sudobility/subscription_lib": "^0.0.28",
38
38
  "@sudobility/types": "^1.9.58",
39
39
  "@testing-library/jest-dom": "^6.0.0",
40
40
  "@testing-library/react": "^16.0.0",