autumn-js 0.1.7 → 0.1.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 (118) hide show
  1. package/dist/libraries/backend/better-auth.d.mts +33 -33
  2. package/dist/libraries/backend/better-auth.d.ts +33 -33
  3. package/dist/libraries/backend/better-auth.mjs +3 -3
  4. package/dist/libraries/backend/convex.mjs +3 -3
  5. package/dist/libraries/backend/elysia.mjs +3 -3
  6. package/dist/libraries/backend/express.d.mts +1 -1
  7. package/dist/libraries/backend/express.d.ts +1 -1
  8. package/dist/libraries/backend/express.mjs +3 -3
  9. package/dist/libraries/backend/fastify.mjs +3 -3
  10. package/dist/libraries/backend/hono.mjs +3 -3
  11. package/dist/libraries/backend/index.d.mts +1 -1
  12. package/dist/libraries/backend/index.d.ts +1 -1
  13. package/dist/libraries/backend/index.mjs +3 -3
  14. package/dist/libraries/backend/next.mjs +3 -3
  15. package/dist/libraries/backend/react-router.mjs +3 -3
  16. package/dist/libraries/backend/remix_dep.mjs +3 -3
  17. package/dist/libraries/backend/routes/backendRouter.mjs +3 -3
  18. package/dist/libraries/backend/supabase.mjs +3 -3
  19. package/dist/libraries/backend/tanstack.mjs +3 -3
  20. package/dist/libraries/backend/utils/withAuth.d.mts +1 -1
  21. package/dist/libraries/backend/utils/withAuth.d.ts +1 -1
  22. package/dist/libraries/react/AutumnContext.mjs +4 -4
  23. package/dist/libraries/react/BaseAutumnProvider.js +5 -1
  24. package/dist/libraries/react/BaseAutumnProvider.mjs +7 -7
  25. package/dist/libraries/react/ReactAutumnProvider.js +5 -1
  26. package/dist/libraries/react/ReactAutumnProvider.mjs +8 -8
  27. package/dist/libraries/react/{chunk-OTZ65PCT.mjs → chunk-2TQBFCWM.mjs} +4 -4
  28. package/dist/libraries/react/{chunk-FEISQQNM.mjs → chunk-5K2M3CQZ.mjs} +1 -1
  29. package/dist/libraries/react/{chunk-ZJBEC254.mjs → chunk-5OJIHAX7.mjs} +5 -1
  30. package/dist/libraries/react/{chunk-FMRBH4CP.mjs → chunk-6I7KWRND.mjs} +1 -1
  31. package/dist/libraries/react/{chunk-ULIUD6YP.mjs → chunk-A5YPS4K4.mjs} +2 -2
  32. package/dist/libraries/react/{chunk-FJWZPMWU.mjs → chunk-BXMZYHE7.mjs} +3 -3
  33. package/dist/libraries/react/{chunk-QQKJE2ND.mjs → chunk-HUKIJ7DB.mjs} +2 -2
  34. package/dist/libraries/react/{chunk-SZJOMZTC.mjs → chunk-I6BTXKGK.mjs} +1 -1
  35. package/dist/libraries/react/{chunk-SFGXTDMX.mjs → chunk-JK2TFCOG.mjs} +2 -2
  36. package/dist/libraries/react/{chunk-KUS3X33V.mjs → chunk-M7SUFZ42.mjs} +1 -1
  37. package/dist/libraries/react/{chunk-YWQTQ72B.mjs → chunk-NHDZWWMZ.mjs} +2 -2
  38. package/dist/libraries/react/{chunk-KYZ3DYMI.mjs → chunk-OUWRRLOI.mjs} +443 -440
  39. package/dist/libraries/react/{chunk-JFTZRU2U.mjs → chunk-T3B4TVD4.mjs} +1 -1
  40. package/dist/libraries/react/{chunk-ECOBNPRU.mjs → chunk-TM6QWQLU.mjs} +3 -3
  41. package/dist/libraries/react/{chunk-GWVZB5GK.mjs → chunk-UOJ6NIVD.mjs} +2 -2
  42. package/dist/libraries/react/{chunk-HMZZIUCF.mjs → chunk-WEKDMT3Y.mjs} +1 -1
  43. package/dist/libraries/react/{chunk-56PEGK2Z.mjs → chunk-WH5MYLSM.mjs} +1 -1
  44. package/dist/libraries/react/{chunk-I2A7PK2L.mjs → chunk-WT5K3J2K.mjs} +17 -17
  45. package/dist/libraries/react/{chunk-JGDTNJTR.mjs → chunk-YCDNQZT5.mjs} +2 -2
  46. package/dist/libraries/react/client/ReactAutumnClient.mjs +3 -3
  47. package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.js +8 -3
  48. package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.mjs +26 -26
  49. package/dist/libraries/react/components/paywall-dialog/paywall-dialog-synced.mjs +26 -26
  50. package/dist/libraries/react/components/pricing-table/pricing-table-synced.js +8 -3
  51. package/dist/libraries/react/components/pricing-table/pricing-table-synced.mjs +26 -26
  52. package/dist/libraries/react/components/ui/accordion.mjs +3 -3
  53. package/dist/libraries/react/components/ui/button.d.mts +1 -1
  54. package/dist/libraries/react/components/ui/button.d.ts +1 -1
  55. package/dist/libraries/react/components/ui/dialog.mjs +4 -4
  56. package/dist/libraries/react/components/ui/popover.mjs +5 -5
  57. package/dist/libraries/react/components/ui/switch.mjs +3 -3
  58. package/dist/libraries/react/hooks/helpers/useAutumnBase.js +5 -1
  59. package/dist/libraries/react/hooks/helpers/useAutumnBase.mjs +1 -1
  60. package/dist/libraries/react/hooks/useAnalytics.mjs +5 -5
  61. package/dist/libraries/react/hooks/useCustomer.js +5 -1
  62. package/dist/libraries/react/hooks/useCustomer.mjs +7 -7
  63. package/dist/libraries/react/hooks/useCustomerBase.js +5 -1
  64. package/dist/libraries/react/hooks/useCustomerBase.mjs +6 -6
  65. package/dist/libraries/react/hooks/useEntity.d.mts +2 -2
  66. package/dist/libraries/react/hooks/useEntity.d.ts +2 -2
  67. package/dist/libraries/react/hooks/useEntity.js +5 -1
  68. package/dist/libraries/react/hooks/useEntity.mjs +7 -7
  69. package/dist/libraries/react/hooks/useEntityBase.d.mts +2 -2
  70. package/dist/libraries/react/hooks/useEntityBase.d.ts +2 -2
  71. package/dist/libraries/react/hooks/useEntityBase.js +5 -1
  72. package/dist/libraries/react/hooks/useEntityBase.mjs +6 -6
  73. package/dist/libraries/react/hooks/usePaywall.mjs +5 -5
  74. package/dist/libraries/react/hooks/usePricingTable.mjs +5 -5
  75. package/dist/libraries/react/index.js +8 -3
  76. package/dist/libraries/react/index.mjs +8 -3
  77. package/dist/next/client/NextAutumnClient.d.mts +20 -20
  78. package/dist/next/client/NextAutumnClient.d.ts +20 -20
  79. package/dist/next/client/NextAutumnProvider.d.mts +2 -2
  80. package/dist/next/client/NextAutumnProvider.d.ts +2 -2
  81. package/dist/next/client/{attachTypes-EvdK0fPK.d.mts → attachTypes-DZFtFEmv.d.mts} +7 -7
  82. package/dist/next/client/{attachTypes-DKlQexnQ.d.ts → attachTypes-DxJ0LCjT.d.ts} +7 -7
  83. package/dist/next/client/{clientAttachTypes-CGPjsdPk.d.ts → clientAttachTypes-BXtfXB4v.d.ts} +29 -29
  84. package/dist/next/client/{clientAttachTypes-CZFjz8Rq.d.mts → clientAttachTypes-qsdoMt_B.d.mts} +29 -29
  85. package/dist/next/client/clientUtils.d.mts +3 -3
  86. package/dist/next/client/clientUtils.d.ts +3 -3
  87. package/dist/next/client/{cusTypes-DEURYNg4.d.ts → cusTypes-BHYpk8bK.d.ts} +7 -7
  88. package/dist/next/client/{cusTypes-y5wEmx07.d.mts → cusTypes-Q54uLNO5.d.mts} +7 -7
  89. package/dist/next/client/{entTypes-KRxjcMFv.d.mts → entTypes-CHHBdhBK.d.mts} +1 -1
  90. package/dist/next/client/{entTypes-CRFgWhOr.d.ts → entTypes-vjIG3B1G.d.ts} +1 -1
  91. package/dist/next/client/hooks/useAutumn.d.mts +5 -5
  92. package/dist/next/client/hooks/useAutumn.d.ts +5 -5
  93. package/dist/next/client/hooks/useCustomer.d.mts +5 -5
  94. package/dist/next/client/hooks/useCustomer.d.ts +5 -5
  95. package/dist/next/client/hooks/useEntity.d.mts +6 -6
  96. package/dist/next/client/hooks/useEntity.d.ts +6 -6
  97. package/dist/next/client/hooks/usePricingTable.d.mts +1 -1
  98. package/dist/next/client/hooks/usePricingTable.d.ts +1 -1
  99. package/dist/next/client/types.d.mts +3 -3
  100. package/dist/next/client/types.d.ts +3 -3
  101. package/dist/next/server/auth/withNextAuth.d.mts +1 -1
  102. package/dist/next/server/auth/withNextAuth.d.ts +1 -1
  103. package/dist/next/server/componentActions.d.mts +1 -1
  104. package/dist/next/server/componentActions.d.ts +1 -1
  105. package/dist/next/server/cusActions.d.mts +17 -17
  106. package/dist/next/server/cusActions.d.ts +17 -17
  107. package/dist/next/server/genActions.d.mts +1 -1
  108. package/dist/next/server/genActions.d.ts +1 -1
  109. package/package.json +1 -1
  110. package/dist/libraries/backend/{chunk-3OVRYTZX.mjs → chunk-BRZHNRU5.mjs} +6 -6
  111. package/dist/libraries/backend/{referralTypes-B50JL4PY.d.mts → referralTypes-DyuV6oJo.d.mts} +43 -43
  112. package/dist/libraries/backend/{referralTypes-dW2HaxKV.d.ts → referralTypes-zcdPSX-p.d.ts} +43 -43
  113. package/dist/libraries/react/{chunk-HIC6P67K.mjs → chunk-IDSAD3KF.mjs} +6 -6
  114. package/dist/libraries/react/{chunk-7TYAAD2T.mjs → chunk-KWNH6C27.mjs} +11 -11
  115. package/dist/next/client/{prodTypes-DzTLP57C.d.mts → prodTypes-CxvB1YY3.d.mts} +8 -8
  116. package/dist/next/client/{prodTypes-DzTLP57C.d.ts → prodTypes-CxvB1YY3.d.ts} +8 -8
  117. package/dist/next/server/{cusTypes-CwopPHB0.d.ts → cusTypes-DgoOZMIt.d.mts} +8 -8
  118. package/dist/next/server/{cusTypes-CwopPHB0.d.mts → cusTypes-DgoOZMIt.d.ts} +8 -8
@@ -3,30 +3,31 @@
3
3
  import {
4
4
  getCheckoutContent
5
5
  } from "./chunk-BLM4DAAR.mjs";
6
- import {
7
- getPricingTableContent
8
- } from "./chunk-URQMBRFZ.mjs";
9
6
  import {
10
7
  getPaywallContent
11
8
  } from "./chunk-I5ZGIAIX.mjs";
12
9
  import {
13
- Input
14
- } from "./chunk-GUM4HIGI.mjs";
10
+ getPricingTableContent
11
+ } from "./chunk-URQMBRFZ.mjs";
15
12
  import {
16
13
  Popover,
17
14
  PopoverContent,
18
15
  PopoverTrigger
19
- } from "./chunk-OTZ65PCT.mjs";
16
+ } from "./chunk-2TQBFCWM.mjs";
20
17
  import {
21
18
  Switch
22
- } from "./chunk-YWQTQ72B.mjs";
19
+ } from "./chunk-NHDZWWMZ.mjs";
20
+ import {
21
+ loadingStyles,
22
+ spinnerStyles
23
+ } from "./chunk-WVKYZYFT.mjs";
23
24
  import {
24
25
  Accordion,
25
26
  AccordionContent,
26
27
  AccordionItem,
27
28
  Header,
28
29
  Trigger2
29
- } from "./chunk-JGDTNJTR.mjs";
30
+ } from "./chunk-YCDNQZT5.mjs";
30
31
  import {
31
32
  Button
32
33
  } from "./chunk-EV5RNY5U.mjs";
@@ -35,456 +36,147 @@ import {
35
36
  DialogContent,
36
37
  DialogFooter,
37
38
  DialogTitle
38
- } from "./chunk-FJWZPMWU.mjs";
39
+ } from "./chunk-BXMZYHE7.mjs";
39
40
  import {
40
41
  ArrowRight,
41
42
  ChevronDown,
42
43
  LoaderCircle
43
44
  } from "./chunk-QJPZFEVW.mjs";
44
45
  import {
45
- useCustomer
46
- } from "./chunk-QQKJE2ND.mjs";
46
+ Input
47
+ } from "./chunk-GUM4HIGI.mjs";
47
48
  import {
48
49
  usePaywall
49
- } from "./chunk-FMRBH4CP.mjs";
50
+ } from "./chunk-6I7KWRND.mjs";
50
51
  import {
51
52
  usePricingTable
52
- } from "./chunk-SZJOMZTC.mjs";
53
+ } from "./chunk-I6BTXKGK.mjs";
53
54
  import {
54
55
  cn
55
56
  } from "./chunk-4J6OC4ZQ.mjs";
56
57
  import {
57
- loadingStyles,
58
- spinnerStyles
59
- } from "./chunk-WVKYZYFT.mjs";
58
+ useCustomer
59
+ } from "./chunk-HUKIJ7DB.mjs";
60
60
 
61
61
  // src/libraries/react/components/checkout-dialog/checkout-dialog-synced.tsx
62
- import { useEffect, useState } from "react";
62
+ import { useEffect, useState as useState2 } from "react";
63
+
64
+ // src/libraries/react/components/paywall-dialog/paywall-dialog-synced.tsx
63
65
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
64
- var formatCurrency = ({
65
- amount,
66
- currency
67
- }) => {
68
- return new Intl.NumberFormat("en-US", {
69
- style: "currency",
70
- currency
71
- }).format(amount);
72
- };
73
- function CheckoutDialog(params) {
74
- const { attach } = useCustomer();
75
- const [checkoutResult, setCheckoutResult] = useState(params?.checkoutResult);
76
- useEffect(() => {
77
- if (params.checkoutResult) {
78
- setCheckoutResult(params.checkoutResult);
79
- }
80
- }, [params.checkoutResult]);
81
- const [loading, setLoading] = useState(false);
82
- if (!checkoutResult) {
66
+ function PaywallDialog(params) {
67
+ const { data: preview } = usePaywall({
68
+ featureId: params?.featureId,
69
+ entityId: params?.entityId
70
+ });
71
+ if (!params || !preview) {
83
72
  return /* @__PURE__ */ jsx(Fragment, {});
84
73
  }
85
74
  const { open, setOpen } = params;
86
- const { title, message } = getCheckoutContent(checkoutResult);
87
- const isFree = checkoutResult?.product.properties?.is_free;
88
- const isPaid = isFree === false;
75
+ const { title, message } = getPaywallContent(preview);
89
76
  return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { className: "au-p-0 au-pt-4 au-gap-0 au-text-foreground au-overflow-hidden au-text-sm", children: [
90
- /* @__PURE__ */ jsx(DialogTitle, { className: "au-px-6 au-mb-1", children: title }),
91
- /* @__PURE__ */ jsx("div", { className: "au-px-6 au-mt-1 au-mb-4 au-text-muted-foreground", children: message }),
92
- isPaid && checkoutResult && /* @__PURE__ */ jsx(
93
- PriceInformation,
94
- {
95
- checkoutResult,
96
- setCheckoutResult
97
- }
98
- ),
99
- /* @__PURE__ */ jsx(DialogFooter, { className: "au-flex au-flex-col sm:au-flex-row au-justify-between au-gap-x-4 au-py-2 au-pl-6 au-pr-3 au-bg-secondary au-border-t au-shadow-inner", children: /* @__PURE__ */ jsx(
77
+ /* @__PURE__ */ jsx(DialogTitle, { className: cn("au-font-bold au-text-xl au-px-6"), children: title }),
78
+ /* @__PURE__ */ jsx("div", { className: "au-px-6 au-my-2", children: message }),
79
+ /* @__PURE__ */ jsx(DialogFooter, { className: "au-flex au-flex-col sm:au-flex-row au-justify-between au-gap-x-4 au-py-2 au-mt-4 au-pl-6 au-pr-3 au-bg-secondary au-border-t", children: /* @__PURE__ */ jsx(
100
80
  Button,
101
81
  {
102
82
  size: "sm",
83
+ className: "au-font-medium au-shadow au-transition au-min-w-20",
103
84
  onClick: async () => {
104
- setLoading(true);
105
- const options = checkoutResult.options.map((option) => {
106
- return {
107
- featureId: option.feature_id,
108
- quantity: option.quantity
109
- };
110
- });
111
- await attach({
112
- productId: checkoutResult.product.id,
113
- options
114
- });
115
85
  setOpen(false);
116
- setLoading(false);
117
86
  },
118
- disabled: loading,
119
- className: "au-min-w-16 au-flex au-items-center au-gap-2",
120
- children: loading ? /* @__PURE__ */ jsx(LoaderCircle, { className: "au-w-4 au-h-4 au-animate-spin" }) : /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("span", { className: "au-whitespace-nowrap au-flex au-gap-1", children: "Confirm" }) })
87
+ children: "Confirm"
121
88
  }
122
89
  ) })
123
90
  ] }) });
124
91
  }
125
- function PriceInformation({
126
- checkoutResult,
127
- setCheckoutResult
92
+
93
+ // src/libraries/react/components/pricing-table/pricing-table-synced.tsx
94
+ import React from "react";
95
+ import { createContext, useContext, useState } from "react";
96
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
97
+ function PricingTable({
98
+ productDetails
128
99
  }) {
129
- return /* @__PURE__ */ jsxs("div", { className: "au-px-6 au-mb-4 au-flex au-flex-col au-gap-4", children: [
130
- /* @__PURE__ */ jsx(
131
- ProductItems,
132
- {
133
- checkoutResult,
134
- setCheckoutResult
135
- }
136
- ),
137
- /* @__PURE__ */ jsxs("div", { className: "au-flex au-flex-col au-gap-2", children: [
138
- checkoutResult?.has_prorations && checkoutResult.lines.length > 0 && /* @__PURE__ */ jsx(CheckoutLines, { checkoutResult }),
139
- /* @__PURE__ */ jsx(DueAmounts, { checkoutResult })
140
- ] })
141
- ] });
142
- }
143
- function DueAmounts({ checkoutResult }) {
144
- const { next_cycle, product } = checkoutResult;
145
- const nextCycleAtStr = next_cycle ? new Date(next_cycle.starts_at).toLocaleDateString() : void 0;
146
- const hasUsagePrice = product.items.some(
147
- (item) => item.usage_model === "pay_per_use"
100
+ const { customer, checkout } = useCustomer({ errorOnNotFound: false });
101
+ const [isAnnual, setIsAnnual] = useState(false);
102
+ const { products, isLoading, error } = usePricingTable({ productDetails });
103
+ if (isLoading) {
104
+ return /* @__PURE__ */ jsx2("div", { style: loadingStyles, children: /* @__PURE__ */ jsx2(LoaderCircle, { style: spinnerStyles }) });
105
+ }
106
+ if (error) {
107
+ return /* @__PURE__ */ jsx2("div", { children: " Something went wrong..." });
108
+ }
109
+ const intervals = Array.from(
110
+ new Set(
111
+ products?.map((p) => p.properties?.interval_group).filter((i) => !!i)
112
+ )
148
113
  );
149
- const showNextCycle = next_cycle && next_cycle.total !== checkoutResult.total;
150
- return /* @__PURE__ */ jsxs("div", { className: "au-flex au-flex-col au-gap-1", children: [
151
- /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between", children: [
152
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("p", { className: "au-font-medium au-text-md", children: "Total due today" }) }),
153
- /* @__PURE__ */ jsx("p", { className: "au-font-medium au-text-md", children: formatCurrency({
154
- amount: checkoutResult?.total,
155
- currency: checkoutResult?.currency
156
- }) })
157
- ] }),
158
- showNextCycle && /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between au-text-muted-foreground", children: [
159
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("p", { className: "au-text-md", children: [
160
- "Due next cycle (",
161
- nextCycleAtStr,
162
- ")"
163
- ] }) }),
164
- /* @__PURE__ */ jsxs("p", { className: "au-text-md", children: [
165
- formatCurrency({
166
- amount: next_cycle.total,
167
- currency: checkoutResult?.currency
168
- }),
169
- hasUsagePrice && /* @__PURE__ */ jsx("span", { children: " + usage prices" })
170
- ] })
171
- ] })
172
- ] });
173
- }
174
- function ProductItems({
175
- checkoutResult,
176
- setCheckoutResult
177
- }) {
178
- const isUpdateQuantity = checkoutResult?.product.scenario === "active" && checkoutResult.product.properties.updateable;
179
- const isOneOff = checkoutResult?.product.properties.is_one_off;
180
- return /* @__PURE__ */ jsxs("div", { className: "au-flex au-flex-col au-gap-2", children: [
181
- /* @__PURE__ */ jsx("p", { className: "au-text-sm au-font-medium", children: "Price" }),
182
- checkoutResult?.product.items.filter((item) => item.type !== "feature").map((item, index) => {
183
- if (item.usage_model == "prepaid") {
184
- return /* @__PURE__ */ jsx(
185
- PrepaidItem,
186
- {
187
- item,
188
- checkoutResult,
189
- setCheckoutResult
190
- },
191
- index
192
- );
193
- }
194
- if (isUpdateQuantity) {
195
- return null;
114
+ const multiInterval = intervals.length > 1;
115
+ const intervalFilter = (product) => {
116
+ if (!product.properties?.interval_group) {
117
+ return true;
118
+ }
119
+ if (multiInterval) {
120
+ if (isAnnual) {
121
+ return product.properties?.interval_group === "year";
122
+ } else {
123
+ return product.properties?.interval_group === "month";
196
124
  }
197
- return /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between", children: [
198
- /* @__PURE__ */ jsx("p", { className: "au-text-muted-foreground", children: item.feature ? item.feature.name : isOneOff ? "Price" : "Subscription" }),
199
- /* @__PURE__ */ jsxs("p", { children: [
200
- item.display?.primary_text,
201
- " ",
202
- item.display?.secondary_text
203
- ] })
204
- ] }, index);
205
- })
206
- ] });
207
- }
208
- function CheckoutLines({ checkoutResult }) {
209
- return /* @__PURE__ */ jsx(Accordion, { type: "single", collapsible: true, children: /* @__PURE__ */ jsxs(AccordionItem, { value: "total", className: "au-border-b-0", children: [
210
- /* @__PURE__ */ jsx(CustomAccordionTrigger, { className: "au-justify-between au-w-full au-my-0 au-py-0 au-border-none", children: /* @__PURE__ */ jsxs("div", { className: "au-cursor-pointer au-flex au-items-center au-gap-1 au-w-full au-justify-end", children: [
211
- /* @__PURE__ */ jsx("p", { className: "au-font-light au-text-muted-foreground", children: "View details" }),
212
- /* @__PURE__ */ jsx(
213
- ChevronDown,
214
- {
215
- className: "au-text-muted-foreground au-mt-0.5 au-rotate-90 au-transition-transform au-duration-200 au-ease-in-out",
216
- size: 14
217
- }
218
- )
219
- ] }) }),
220
- /* @__PURE__ */ jsx(AccordionContent, { className: "au-mt-2 au-mb-0 au-pb-2 au-flex au-flex-col au-gap-2", children: checkoutResult?.lines.filter((line) => line.amount != 0).map((line, index) => {
221
- return /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between", children: [
222
- /* @__PURE__ */ jsx("p", { className: "au-text-muted-foreground", children: line.description }),
223
- /* @__PURE__ */ jsx("p", { className: "au-text-muted-foreground", children: new Intl.NumberFormat("en-US", {
224
- style: "currency",
225
- currency: checkoutResult?.currency
226
- }).format(line.amount) })
227
- ] }, index);
228
- }) })
229
- ] }) });
230
- }
231
- function CustomAccordionTrigger({
232
- className,
233
- children,
234
- ...props
235
- }) {
236
- return /* @__PURE__ */ jsx(Header, { className: "au-flex", children: /* @__PURE__ */ jsx(
237
- Trigger2,
125
+ }
126
+ return true;
127
+ };
128
+ return /* @__PURE__ */ jsx2("div", { className: cn("au-root"), children: products && /* @__PURE__ */ jsx2(
129
+ PricingTableContainer,
238
130
  {
239
- "data-slot": "accordion-trigger",
240
- className: cn(
241
- "focus-visible:au-border-ring focus-visible:au-ring-ring/50 au-flex au-flex-1 au-items-start au-justify-between au-gap-4 au-rounded-md au-py-4 au-text-left au-text-sm au-font-medium au-transition-all au-outline-none focus-visible:au-ring-[3px] disabled:au-pointer-events-none disabled:au-opacity-50 [&[data-state=open]_svg]:au-rotate-0",
242
- className
243
- ),
244
- ...props,
245
- children
131
+ products,
132
+ isAnnualToggle: isAnnual,
133
+ setIsAnnualToggle: setIsAnnual,
134
+ multiInterval,
135
+ children: products.filter(intervalFilter).map((product, index) => /* @__PURE__ */ jsx2(
136
+ PricingCard,
137
+ {
138
+ productId: product.id,
139
+ buttonProps: {
140
+ disabled: product.scenario === "active" && !product.properties.updateable || product.scenario === "scheduled",
141
+ onClick: async () => {
142
+ if (product.id && customer) {
143
+ await checkout({
144
+ productId: product.id,
145
+ dialog: CheckoutDialog
146
+ });
147
+ } else if (product.display?.button_url) {
148
+ window.open(product.display?.button_url, "_blank");
149
+ }
150
+ }
151
+ }
152
+ },
153
+ index
154
+ ))
246
155
  }
247
156
  ) });
248
157
  }
249
- var PrepaidItem = ({
250
- item,
251
- checkoutResult,
252
- setCheckoutResult
253
- }) => {
254
- const { quantity = 0, billing_units: billingUnits = 1 } = item;
255
- const [quantityInput, setQuantityInput] = useState(
256
- (quantity / billingUnits).toString()
257
- );
258
- const { checkout } = useCustomer();
259
- const [loading, setLoading] = useState(false);
260
- const [open, setOpen] = useState(false);
261
- const scenario = checkoutResult.product.scenario;
262
- const handleSave = async () => {
263
- setLoading(true);
264
- try {
265
- const newOptions = checkoutResult.options.filter((option) => option.feature_id !== item.feature_id).map((option) => {
266
- return {
267
- featureId: option.feature_id,
268
- quantity: option.quantity
269
- };
270
- });
271
- newOptions.push({
272
- featureId: item.feature_id,
273
- quantity: Number(quantityInput) * billingUnits
274
- });
275
- const { data, error } = await checkout({
276
- productId: checkoutResult.product.id,
277
- options: newOptions
278
- });
279
- if (error) {
280
- console.error(error);
281
- return;
282
- }
283
- setCheckoutResult(data);
284
- } catch (error) {
285
- console.error(error);
286
- } finally {
287
- setLoading(false);
288
- setOpen(false);
289
- }
290
- };
291
- const disableSelection = scenario === "renew";
292
- return /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between", children: [
293
- /* @__PURE__ */ jsxs("div", { className: "au-flex au-gap-2", children: [
294
- /* @__PURE__ */ jsx("p", { className: "au-text-muted-foreground", children: item.feature?.name }),
295
- /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
296
- /* @__PURE__ */ jsxs(
297
- PopoverTrigger,
298
- {
299
- className: cn(
300
- "au-text-muted-foreground au-text-xs au-px-1 au-py-0.5 au-rounded-md au-flex au-items-center au-gap-1 au-bg-accent/80",
301
- disableSelection !== true && "hover:au-bg-accent hover:au-text-foreground"
302
- ),
303
- disabled: disableSelection,
304
- children: [
305
- "Qty: ",
306
- quantity,
307
- /* @__PURE__ */ jsx(ChevronDown, { size: 12 })
308
- ]
309
- }
310
- ),
311
- /* @__PURE__ */ jsxs(
312
- PopoverContent,
313
- {
314
- align: "start",
315
- className: "au-w-80 au-text-sm au-p-4 au-pt-3 au-flex au-flex-col au-gap-4",
316
- children: [
317
- /* @__PURE__ */ jsxs("div", { className: "au-flex au-flex-col au-gap-1", children: [
318
- /* @__PURE__ */ jsx("p", { className: "au-text-sm au-font-medium", children: item.feature?.name }),
319
- /* @__PURE__ */ jsxs("p", { className: "au-text-muted-foreground", children: [
320
- item.display?.primary_text,
321
- " ",
322
- item.display?.secondary_text
323
- ] })
324
- ] }),
325
- /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between au-items-end", children: [
326
- /* @__PURE__ */ jsxs("div", { className: "au-flex au-gap-2 au-items-center", children: [
327
- /* @__PURE__ */ jsx(
328
- Input,
329
- {
330
- className: "au-h-7 au-w-16 focus:!au-ring-2",
331
- value: quantityInput,
332
- onChange: (e) => setQuantityInput(e.target.value)
333
- }
334
- ),
335
- /* @__PURE__ */ jsxs("p", { className: "au-text-muted-foreground", children: [
336
- billingUnits > 1 && `x ${billingUnits} `,
337
- item.feature?.name
338
- ] })
339
- ] }),
340
- /* @__PURE__ */ jsx(
341
- Button,
342
- {
343
- onClick: handleSave,
344
- className: "au-w-14 !au-h-7 au-text-sm au-items-center au-bg-white au-text-foreground au-shadow-sm au-border au-border-zinc-200 hover:au-bg-zinc-100",
345
- disabled: loading,
346
- children: loading ? /* @__PURE__ */ jsx(LoaderCircle, { className: "au-text-muted-foreground au-animate-spin !au-w-4 !au-h-4" }) : "Save"
347
- }
348
- )
349
- ] })
350
- ]
351
- }
352
- )
353
- ] })
354
- ] }),
355
- /* @__PURE__ */ jsxs("p", { children: [
356
- item.display?.primary_text,
357
- " ",
358
- item.display?.secondary_text
359
- ] })
360
- ] });
361
- };
362
- var PriceItem = ({
363
- children,
364
- className,
365
- ...props
366
- }) => {
367
- return /* @__PURE__ */ jsx(
368
- "div",
369
- {
370
- className: cn(
371
- "au-flex au-flex-col au-pb-4 sm:au-pb-0 au-gap-1 sm:au-flex-row au-justify-between sm:au-h-7 sm:au-gap-2 sm:au-items-center",
372
- className
373
- ),
374
- ...props,
375
- children
376
- }
377
- );
378
- };
379
- var PricingDialogButton = ({
380
- children,
381
- size,
382
- onClick,
383
- disabled,
384
- className
385
- }) => {
386
- return /* @__PURE__ */ jsxs(
387
- Button,
388
- {
389
- onClick,
390
- disabled,
391
- size,
392
- className: cn(className, "au-shadow-sm au-shadow-stone-400"),
393
- children: [
394
- children,
395
- /* @__PURE__ */ jsx(ArrowRight, { className: "!au-h-3" })
396
- ]
397
- }
398
- );
399
- };
400
-
401
- // src/libraries/react/components/pricing-table/pricing-table-synced.tsx
402
- import React2 from "react";
403
- import { createContext, useContext, useState as useState2 } from "react";
404
- import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
405
- function PricingTable({
406
- productDetails
407
- }) {
408
- const { customer, checkout } = useCustomer({ errorOnNotFound: false });
409
- const [isAnnual, setIsAnnual] = useState2(false);
410
- const { products, isLoading, error } = usePricingTable({ productDetails });
411
- if (isLoading) {
412
- return /* @__PURE__ */ jsx2("div", { style: loadingStyles, children: /* @__PURE__ */ jsx2(LoaderCircle, { style: spinnerStyles }) });
413
- }
414
- if (error) {
415
- return /* @__PURE__ */ jsx2("div", { children: " Something went wrong..." });
416
- }
417
- const intervals = Array.from(
418
- new Set(
419
- products?.map((p) => p.properties?.interval_group).filter((i) => !!i)
420
- )
421
- );
422
- const multiInterval = intervals.length > 1;
423
- const intervalFilter = (product) => {
424
- if (!product.properties?.interval_group) {
425
- return true;
426
- }
427
- if (multiInterval) {
428
- if (isAnnual) {
429
- return product.properties?.interval_group === "year";
430
- } else {
431
- return product.properties?.interval_group === "month";
432
- }
433
- }
434
- return true;
435
- };
436
- return /* @__PURE__ */ jsx2("div", { className: cn("au-root"), children: products && /* @__PURE__ */ jsx2(
437
- PricingTableContainer,
438
- {
439
- products,
440
- isAnnualToggle: isAnnual,
441
- setIsAnnualToggle: setIsAnnual,
442
- multiInterval,
443
- children: products.filter(intervalFilter).map((product, index) => /* @__PURE__ */ jsx2(
444
- PricingCard,
445
- {
446
- productId: product.id,
447
- buttonProps: {
448
- disabled: product.scenario === "active" && !product.properties.updateable || product.scenario === "scheduled",
449
- onClick: async () => {
450
- if (product.id && customer) {
451
- await checkout({
452
- productId: product.id,
453
- dialog: CheckoutDialog
454
- });
455
- } else if (product.display?.button_url) {
456
- window.open(product.display?.button_url, "_blank");
457
- }
458
- }
459
- }
460
- },
461
- index
462
- ))
463
- }
464
- ) });
465
- }
466
- var PricingTableContext = createContext({
467
- isAnnualToggle: false,
468
- setIsAnnualToggle: () => {
469
- },
470
- products: [],
471
- showFeatures: true
472
- });
473
- var usePricingTableContext = (componentName) => {
474
- const context = useContext(PricingTableContext);
475
- if (context === void 0) {
476
- throw new Error(`${componentName} must be used within <PricingTable />`);
477
- }
478
- return context;
479
- };
480
- var PricingTableContainer = ({
481
- children,
482
- products,
483
- showFeatures = true,
484
- className,
485
- isAnnualToggle,
486
- setIsAnnualToggle,
487
- multiInterval
158
+ var PricingTableContext = createContext({
159
+ isAnnualToggle: false,
160
+ setIsAnnualToggle: () => {
161
+ },
162
+ products: [],
163
+ showFeatures: true
164
+ });
165
+ var usePricingTableContext = (componentName) => {
166
+ const context = useContext(PricingTableContext);
167
+ if (context === void 0) {
168
+ throw new Error(`${componentName} must be used within <PricingTable />`);
169
+ }
170
+ return context;
171
+ };
172
+ var PricingTableContainer = ({
173
+ children,
174
+ products,
175
+ showFeatures = true,
176
+ className,
177
+ isAnnualToggle,
178
+ setIsAnnualToggle,
179
+ multiInterval
488
180
  }) => {
489
181
  if (!products) {
490
182
  throw new Error("products is required in <PricingTable />");
@@ -636,8 +328,8 @@ var PricingFeatureList = ({
636
328
  )) })
637
329
  ] });
638
330
  };
639
- var PricingCardButton = React2.forwardRef(({ recommended, children, className, onClick, ...props }, ref) => {
640
- const [loading, setLoading] = useState2(false);
331
+ var PricingCardButton = React.forwardRef(({ recommended, children, className, onClick, ...props }, ref) => {
332
+ const [loading, setLoading] = useState(false);
641
333
  const handleClick = async (e) => {
642
334
  setLoading(true);
643
335
  try {
@@ -695,37 +387,350 @@ var RecommendedBadge = ({ recommended }) => {
695
387
  return /* @__PURE__ */ jsx2("div", { className: "au-bg-secondary au-absolute au-border au-text-muted-foreground au-text-sm au-font-medium lg:au-rounded-full au-px-3 lg:au-py-0.5 lg:au-top-4 lg:au-right-4 au-top-[-1px] au-right-[-1px] au-rounded-bl-lg", children: recommended });
696
388
  };
697
389
 
698
- // src/libraries/react/components/paywall-dialog/paywall-dialog-synced.tsx
390
+ // src/libraries/react/components/checkout-dialog/checkout-dialog-synced.tsx
699
391
  import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
700
- function PaywallDialog(params) {
701
- const { data: preview } = usePaywall({
702
- featureId: params?.featureId,
703
- entityId: params?.entityId
704
- });
705
- if (!params || !preview) {
392
+ var formatCurrency = ({
393
+ amount,
394
+ currency
395
+ }) => {
396
+ return new Intl.NumberFormat("en-US", {
397
+ style: "currency",
398
+ currency
399
+ }).format(amount);
400
+ };
401
+ function CheckoutDialog(params) {
402
+ const { attach } = useCustomer();
403
+ const [checkoutResult, setCheckoutResult] = useState2(params?.checkoutResult);
404
+ useEffect(() => {
405
+ if (params.checkoutResult) {
406
+ setCheckoutResult(params.checkoutResult);
407
+ }
408
+ }, [params.checkoutResult]);
409
+ const [loading, setLoading] = useState2(false);
410
+ if (!checkoutResult) {
706
411
  return /* @__PURE__ */ jsx3(Fragment3, {});
707
412
  }
708
413
  const { open, setOpen } = params;
709
- const { title, message } = getPaywallContent(preview);
710
- return /* @__PURE__ */ jsx3(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs3(DialogContent, { className: "au-p-0 au-pt-4 au-gap-0 au-text-foreground au-overflow-hidden au-text-sm", children: [
711
- /* @__PURE__ */ jsx3(DialogTitle, { className: cn("au-font-bold au-text-xl au-px-6"), children: title }),
712
- /* @__PURE__ */ jsx3("div", { className: "au-px-6 au-my-2", children: message }),
713
- /* @__PURE__ */ jsx3(DialogFooter, { className: "au-flex au-flex-col sm:au-flex-row au-justify-between au-gap-x-4 au-py-2 au-mt-4 au-pl-6 au-pr-3 au-bg-secondary au-border-t", children: /* @__PURE__ */ jsx3(
414
+ const { title, message } = getCheckoutContent(checkoutResult);
415
+ const isFree = checkoutResult?.product.properties?.is_free;
416
+ const isPaid = isFree === false;
417
+ return /* @__PURE__ */ jsx3(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs3(DialogContent, { className: "au-p-0 au-pt-4 au-gap-0 au-text-foreground au-text-sm", children: [
418
+ /* @__PURE__ */ jsx3(DialogTitle, { className: "au-px-6 au-mb-1", children: title }),
419
+ /* @__PURE__ */ jsx3("div", { className: "au-px-6 au-mt-1 au-mb-4 au-text-muted-foreground", children: message }),
420
+ isPaid && checkoutResult && /* @__PURE__ */ jsx3(
421
+ PriceInformation,
422
+ {
423
+ checkoutResult,
424
+ setCheckoutResult
425
+ }
426
+ ),
427
+ /* @__PURE__ */ jsx3(DialogFooter, { className: "au-flex au-flex-col sm:au-flex-row au-justify-between au-gap-x-4 au-py-2 au-pl-6 au-pr-3 au-bg-secondary au-border-t au-shadow-inner", children: /* @__PURE__ */ jsx3(
714
428
  Button,
715
429
  {
716
430
  size: "sm",
717
- className: "au-font-medium au-shadow au-transition au-min-w-20",
718
431
  onClick: async () => {
432
+ setLoading(true);
433
+ const options = checkoutResult.options.map((option) => {
434
+ return {
435
+ featureId: option.feature_id,
436
+ quantity: option.quantity
437
+ };
438
+ });
439
+ await attach({
440
+ productId: checkoutResult.product.id,
441
+ options
442
+ });
719
443
  setOpen(false);
444
+ setLoading(false);
720
445
  },
721
- children: "Confirm"
446
+ disabled: loading,
447
+ className: "au-min-w-16 au-flex au-items-center au-gap-2",
448
+ children: loading ? /* @__PURE__ */ jsx3(LoaderCircle, { className: "au-w-4 au-h-4 au-animate-spin" }) : /* @__PURE__ */ jsx3(Fragment3, { children: /* @__PURE__ */ jsx3("span", { className: "au-whitespace-nowrap au-flex au-gap-1", children: "Confirm" }) })
722
449
  }
723
450
  ) })
724
451
  ] }) });
725
452
  }
453
+ function PriceInformation({
454
+ checkoutResult,
455
+ setCheckoutResult
456
+ }) {
457
+ return /* @__PURE__ */ jsxs3("div", { className: "au-px-6 au-mb-4 au-flex au-flex-col au-gap-4", children: [
458
+ /* @__PURE__ */ jsx3(
459
+ ProductItems,
460
+ {
461
+ checkoutResult,
462
+ setCheckoutResult
463
+ }
464
+ ),
465
+ /* @__PURE__ */ jsxs3("div", { className: "au-flex au-flex-col au-gap-2", children: [
466
+ checkoutResult?.has_prorations && checkoutResult.lines.length > 0 && /* @__PURE__ */ jsx3(CheckoutLines, { checkoutResult }),
467
+ /* @__PURE__ */ jsx3(DueAmounts, { checkoutResult })
468
+ ] })
469
+ ] });
470
+ }
471
+ function DueAmounts({ checkoutResult }) {
472
+ const { next_cycle, product } = checkoutResult;
473
+ const nextCycleAtStr = next_cycle ? new Date(next_cycle.starts_at).toLocaleDateString() : void 0;
474
+ const hasUsagePrice = product.items.some(
475
+ (item) => item.usage_model === "pay_per_use"
476
+ );
477
+ const showNextCycle = next_cycle && next_cycle.total !== checkoutResult.total;
478
+ return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-flex-col au-gap-1", children: [
479
+ /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between", children: [
480
+ /* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsx3("p", { className: "au-font-medium au-text-md", children: "Total due today" }) }),
481
+ /* @__PURE__ */ jsx3("p", { className: "au-font-medium au-text-md", children: formatCurrency({
482
+ amount: checkoutResult?.total,
483
+ currency: checkoutResult?.currency
484
+ }) })
485
+ ] }),
486
+ showNextCycle && /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between au-text-muted-foreground", children: [
487
+ /* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsxs3("p", { className: "au-text-md", children: [
488
+ "Due next cycle (",
489
+ nextCycleAtStr,
490
+ ")"
491
+ ] }) }),
492
+ /* @__PURE__ */ jsxs3("p", { className: "au-text-md", children: [
493
+ formatCurrency({
494
+ amount: next_cycle.total,
495
+ currency: checkoutResult?.currency
496
+ }),
497
+ hasUsagePrice && /* @__PURE__ */ jsx3("span", { children: " + usage prices" })
498
+ ] })
499
+ ] })
500
+ ] });
501
+ }
502
+ function ProductItems({
503
+ checkoutResult,
504
+ setCheckoutResult
505
+ }) {
506
+ const isUpdateQuantity = checkoutResult?.product.scenario === "active" && checkoutResult.product.properties.updateable;
507
+ const isOneOff = checkoutResult?.product.properties.is_one_off;
508
+ return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-flex-col au-gap-2", children: [
509
+ /* @__PURE__ */ jsx3("p", { className: "au-text-sm au-font-medium", children: "Price" }),
510
+ checkoutResult?.product.items.filter((item) => item.type !== "feature").map((item, index) => {
511
+ if (item.usage_model == "prepaid") {
512
+ return /* @__PURE__ */ jsx3(
513
+ PrepaidItem,
514
+ {
515
+ item,
516
+ checkoutResult,
517
+ setCheckoutResult
518
+ },
519
+ index
520
+ );
521
+ }
522
+ if (isUpdateQuantity) {
523
+ return null;
524
+ }
525
+ return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between", children: [
526
+ /* @__PURE__ */ jsx3("p", { className: "au-text-muted-foreground", children: item.feature ? item.feature.name : isOneOff ? "Price" : "Subscription" }),
527
+ /* @__PURE__ */ jsxs3("p", { children: [
528
+ item.display?.primary_text,
529
+ " ",
530
+ item.display?.secondary_text
531
+ ] })
532
+ ] }, index);
533
+ })
534
+ ] });
535
+ }
536
+ function CheckoutLines({ checkoutResult }) {
537
+ return /* @__PURE__ */ jsx3(Accordion, { type: "single", collapsible: true, children: /* @__PURE__ */ jsxs3(AccordionItem, { value: "total", className: "au-border-b-0", children: [
538
+ /* @__PURE__ */ jsx3(CustomAccordionTrigger, { className: "au-justify-between au-w-full au-my-0 au-py-0 au-border-none", children: /* @__PURE__ */ jsxs3("div", { className: "au-cursor-pointer au-flex au-items-center au-gap-1 au-w-full au-justify-end", children: [
539
+ /* @__PURE__ */ jsx3("p", { className: "au-font-light au-text-muted-foreground", children: "View details" }),
540
+ /* @__PURE__ */ jsx3(
541
+ ChevronDown,
542
+ {
543
+ className: "au-text-muted-foreground au-mt-0.5 au-rotate-90 au-transition-transform au-duration-200 au-ease-in-out",
544
+ size: 14
545
+ }
546
+ )
547
+ ] }) }),
548
+ /* @__PURE__ */ jsx3(AccordionContent, { className: "au-mt-2 au-mb-0 au-pb-2 au-flex au-flex-col au-gap-2", children: checkoutResult?.lines.filter((line) => line.amount != 0).map((line, index) => {
549
+ return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between", children: [
550
+ /* @__PURE__ */ jsx3("p", { className: "au-text-muted-foreground", children: line.description }),
551
+ /* @__PURE__ */ jsx3("p", { className: "au-text-muted-foreground", children: new Intl.NumberFormat("en-US", {
552
+ style: "currency",
553
+ currency: checkoutResult?.currency
554
+ }).format(line.amount) })
555
+ ] }, index);
556
+ }) })
557
+ ] }) });
558
+ }
559
+ function CustomAccordionTrigger({
560
+ className,
561
+ children,
562
+ ...props
563
+ }) {
564
+ return /* @__PURE__ */ jsx3(Header, { className: "au-flex", children: /* @__PURE__ */ jsx3(
565
+ Trigger2,
566
+ {
567
+ "data-slot": "accordion-trigger",
568
+ className: cn(
569
+ "focus-visible:au-border-ring focus-visible:au-ring-ring/50 au-flex au-flex-1 au-items-start au-justify-between au-gap-4 au-rounded-md au-py-4 au-text-left au-text-sm au-font-medium au-transition-all au-outline-none focus-visible:au-ring-[3px] disabled:au-pointer-events-none disabled:au-opacity-50 [&[data-state=open]_svg]:au-rotate-0",
570
+ className
571
+ ),
572
+ ...props,
573
+ children
574
+ }
575
+ ) });
576
+ }
577
+ var PrepaidItem = ({
578
+ item,
579
+ checkoutResult,
580
+ setCheckoutResult
581
+ }) => {
582
+ const { quantity = 0, billing_units: billingUnits = 1 } = item;
583
+ const [quantityInput, setQuantityInput] = useState2(
584
+ (quantity / billingUnits).toString()
585
+ );
586
+ const { checkout } = useCustomer();
587
+ const [loading, setLoading] = useState2(false);
588
+ const [open, setOpen] = useState2(false);
589
+ const scenario = checkoutResult.product.scenario;
590
+ const handleSave = async () => {
591
+ setLoading(true);
592
+ try {
593
+ const newOptions = checkoutResult.options.filter((option) => option.feature_id !== item.feature_id).map((option) => {
594
+ return {
595
+ featureId: option.feature_id,
596
+ quantity: option.quantity
597
+ };
598
+ });
599
+ newOptions.push({
600
+ featureId: item.feature_id,
601
+ quantity: Number(quantityInput) * billingUnits
602
+ });
603
+ const { data, error } = await checkout({
604
+ productId: checkoutResult.product.id,
605
+ options: newOptions,
606
+ dialog: CheckoutDialog
607
+ });
608
+ if (error) {
609
+ console.error(error);
610
+ return;
611
+ }
612
+ setCheckoutResult(data);
613
+ } catch (error) {
614
+ console.error(error);
615
+ } finally {
616
+ setLoading(false);
617
+ setOpen(false);
618
+ }
619
+ };
620
+ const disableSelection = scenario === "renew";
621
+ return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between", children: [
622
+ /* @__PURE__ */ jsxs3("div", { className: "au-flex au-gap-2", children: [
623
+ /* @__PURE__ */ jsx3("p", { className: "au-text-muted-foreground", children: item.feature?.name }),
624
+ /* @__PURE__ */ jsxs3(Popover, { open, onOpenChange: setOpen, children: [
625
+ /* @__PURE__ */ jsxs3(
626
+ PopoverTrigger,
627
+ {
628
+ className: cn(
629
+ "au-text-muted-foreground au-text-xs au-px-1 au-py-0.5 au-rounded-md au-flex au-items-center au-gap-1 au-bg-accent/80",
630
+ disableSelection !== true && "hover:au-bg-accent hover:au-text-foreground"
631
+ ),
632
+ disabled: disableSelection,
633
+ children: [
634
+ "Qty: ",
635
+ quantity,
636
+ /* @__PURE__ */ jsx3(ChevronDown, { size: 12 })
637
+ ]
638
+ }
639
+ ),
640
+ /* @__PURE__ */ jsxs3(
641
+ PopoverContent,
642
+ {
643
+ align: "start",
644
+ className: "au-w-80 au-text-sm au-p-4 au-pt-3 au-flex au-flex-col au-gap-4",
645
+ children: [
646
+ /* @__PURE__ */ jsxs3("div", { className: "au-flex au-flex-col au-gap-1", children: [
647
+ /* @__PURE__ */ jsx3("p", { className: "au-text-sm au-font-medium", children: item.feature?.name }),
648
+ /* @__PURE__ */ jsxs3("p", { className: "au-text-muted-foreground", children: [
649
+ item.display?.primary_text,
650
+ " ",
651
+ item.display?.secondary_text
652
+ ] })
653
+ ] }),
654
+ /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between au-items-end", children: [
655
+ /* @__PURE__ */ jsxs3("div", { className: "au-flex au-gap-2 au-items-center", children: [
656
+ /* @__PURE__ */ jsx3(
657
+ Input,
658
+ {
659
+ className: "au-h-7 au-w-16 focus:!au-ring-2",
660
+ value: quantityInput,
661
+ onChange: (e) => setQuantityInput(e.target.value)
662
+ }
663
+ ),
664
+ /* @__PURE__ */ jsxs3("p", { className: "au-text-muted-foreground", children: [
665
+ billingUnits > 1 && `x ${billingUnits} `,
666
+ item.feature?.name
667
+ ] })
668
+ ] }),
669
+ /* @__PURE__ */ jsx3(
670
+ Button,
671
+ {
672
+ onClick: handleSave,
673
+ className: "au-w-14 !au-h-7 au-text-sm au-items-center au-bg-white au-text-foreground au-shadow-sm au-border au-border-zinc-200 hover:au-bg-zinc-100",
674
+ disabled: loading,
675
+ children: loading ? /* @__PURE__ */ jsx3(LoaderCircle, { className: "au-text-muted-foreground au-animate-spin !au-w-4 !au-h-4" }) : "Save"
676
+ }
677
+ )
678
+ ] })
679
+ ]
680
+ }
681
+ )
682
+ ] })
683
+ ] }),
684
+ /* @__PURE__ */ jsxs3("p", { children: [
685
+ item.display?.primary_text,
686
+ " ",
687
+ item.display?.secondary_text
688
+ ] })
689
+ ] });
690
+ };
691
+ var PriceItem = ({
692
+ children,
693
+ className,
694
+ ...props
695
+ }) => {
696
+ return /* @__PURE__ */ jsx3(
697
+ "div",
698
+ {
699
+ className: cn(
700
+ "au-flex au-flex-col au-pb-4 sm:au-pb-0 au-gap-1 sm:au-flex-row au-justify-between sm:au-h-7 sm:au-gap-2 sm:au-items-center",
701
+ className
702
+ ),
703
+ ...props,
704
+ children
705
+ }
706
+ );
707
+ };
708
+ var PricingDialogButton = ({
709
+ children,
710
+ size,
711
+ onClick,
712
+ disabled,
713
+ className
714
+ }) => {
715
+ return /* @__PURE__ */ jsxs3(
716
+ Button,
717
+ {
718
+ onClick,
719
+ disabled,
720
+ size,
721
+ className: cn(className, "au-shadow-sm au-shadow-stone-400"),
722
+ children: [
723
+ children,
724
+ /* @__PURE__ */ jsx3(ArrowRight, { className: "!au-h-3" })
725
+ ]
726
+ }
727
+ );
728
+ };
726
729
 
727
730
  export {
728
- PaywallDialog,
731
+ CheckoutDialog,
732
+ PriceItem,
733
+ PricingDialogButton,
729
734
  PricingTable,
730
735
  usePricingTableContext,
731
736
  PricingTableContainer,
@@ -734,7 +739,5 @@ export {
734
739
  PricingCardButton,
735
740
  AnnualSwitch,
736
741
  RecommendedBadge,
737
- CheckoutDialog,
738
- PriceItem,
739
- PricingDialogButton
742
+ PaywallDialog
740
743
  };