@meaple-com/react-headless-components 2.0.1 → 4.0.0

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/README.md CHANGED
@@ -14,8 +14,8 @@ bun add @meaple-com/react-headless-components @meaple-com/react-query @meaple-co
14
14
 
15
15
  **Peer dependencies:**
16
16
 
17
- - `react` ^19.0.0
18
- - `@meaple-com/react-query` ^1.0.6
17
+ - `react` ^19.0.0
18
+ - `@meaple-com/react-query` ^1.0.6
19
19
 
20
20
  Make sure the app is wrapped with `QueryClientProvider` and `MeapleSDKProvider` as described in [@meaple-com/react-query](https://www.npmjs.com/package/@meaple-com/react-query).
21
21
 
@@ -28,7 +28,7 @@ import { CartProvider } from '@meaple-com/react-headless-components';
28
28
 
29
29
  <CartProvider initialCoupon={null}>
30
30
  {/* Components that use Cart, Coupon, ListEventTickets, etc. */}
31
- </CartProvider>
31
+ </CartProvider>;
32
32
  ```
33
33
 
34
34
  ## Components
@@ -37,28 +37,28 @@ Components use a **render-props** API: they call `children` with data and state
37
37
 
38
38
  ### Lists (read-only)
39
39
 
40
- | Component | Description | Render props |
41
- |-----------|-------------|--------------|
42
- | **`ListEvents`** | List events (uses `useEvents`) | `events`, `isPending`, `error` |
43
- | **`ListCategories`** | List categories | `categories`, `isPending`, `error` |
44
- | **`ListEventTickets`** | Tickets for an event | `tickets`, `isPending`, `error` |
45
- | **`ListEventProducts`** | Products for an event | `products`, `isPending`, `error` |
46
- | **`ListUserEvents`** | Current user’s events | `events`, `isPending`, `error` |
47
- | **`ListUserEventTickets`** | Current user’s tickets for an event | `tickets`, `isPending`, `error` |
48
- | **`ListUserOrders`** | Current user’s orders | `orders`, `isPending`, `error` |
40
+ | Component | Description | Render props |
41
+ | -------------------------- | ----------------------------------- | ---------------------------------- |
42
+ | **`ListEvents`** | List events (uses `useEvents`) | `events`, `isPending`, `error` |
43
+ | **`ListCategories`** | List categories | `categories`, `isPending`, `error` |
44
+ | **`ListEventTickets`** | Tickets for an event | `tickets`, `isPending`, `error` |
45
+ | **`ListEventProducts`** | Products for an event | `products`, `isPending`, `error` |
46
+ | **`ListUserEvents`** | Current user’s events | `events`, `isPending`, `error` |
47
+ | **`ListUserEventTickets`** | Current user’s tickets for an event | `tickets`, `isPending`, `error` |
48
+ | **`ListUserOrders`** | Current user’s orders | `orders`, `isPending`, `error` |
49
49
 
50
50
  ### Order and coupon
51
51
 
52
- | Component | Description | Render props |
53
- |-----------|-------------|--------------|
54
- | **`GetOrder`** | Single order by ID | order data, `isPending`, `error` |
55
- | **`Coupon`** | Check and apply coupon | mutation + coupon state |
56
- | **`Cart`** | Cart totals, items, clear | `items`, `totalAmount`, `totalPrice`, `totalDiscount`, `clearCart`, etc. |
57
- | **`TicketQuantityController`** | Add/remove ticket to/from cart | quantity controls (uses `useTicketQuantity`) |
52
+ | Component | Description | Render props |
53
+ | ------------------------------ | ------------------------------ | ------------------------------------------------------------------------ |
54
+ | **`GetOrder`** | Single order by ID | order data, `isPending`, `error` |
55
+ | **`Coupon`** | Check and apply coupon | mutation + coupon state |
56
+ | **`Cart`** | Cart totals, items, clear | `items`, `totalAmount`, `totalPrice`, `totalDiscount`, `clearCart`, etc. |
57
+ | **`TicketQuantityController`** | Add/remove ticket to/from cart | quantity controls (uses `useTicketQuantity`) |
58
58
 
59
59
  ### Hooks
60
60
 
61
- - **`useCart()`** – Cart context (items, increment, decrement, clear, coupon, applyCoupon, computeItemDiscount). Use inside `CartProvider`.
61
+ - **`useCart()`** – Cart context (items, increment, decrement, clear, coupon, applyCoupon, computeItemDiscount). Use inside `CartProvider`.
62
62
  - **`useTicketQuantity(ticket, options?)`** – Quantity in cart for a ticket (and optional seat), plus increment/decrement.
63
63
 
64
64
  ## Example: Event list and cart
package/dist/index.cjs CHANGED
@@ -163,17 +163,19 @@ var Cart = ({
163
163
  0
164
164
  );
165
165
  }, [platformFee, cart.items, feeType]);
166
+ const discountedPrice = Math.max(rawPrice - totalDiscount, 0);
166
167
  const totalFee = (0, import_react2.useMemo)(() => {
167
168
  if (!platformFee) return 0;
168
169
  const { fee, minFeeAmount, thresholdAmount } = feeType === `POS` && platformFee.pos ? platformFee.pos : platformFee;
169
170
  if (fee === 0) return 0;
170
171
  if (rawFeeAmount <= 0) return 0;
172
+ if (discountedPrice <= 0) return 0;
171
173
  if (rawFeeAmount < minFeeAmount && rawPrice < thresholdAmount) {
172
174
  return minFeeAmount;
173
175
  }
174
176
  return rawFeeAmount;
175
- }, [feeType, platformFee, rawFeeAmount, rawPrice]);
176
- const totalPrice = Math.max(rawPrice - totalDiscount, 0) + totalFee;
177
+ }, [feeType, platformFee, rawFeeAmount, rawPrice, discountedPrice]);
178
+ const totalPrice = discountedPrice + totalFee;
177
179
  return children({
178
180
  totalAmount,
179
181
  totalDiscount,
@@ -268,6 +270,7 @@ var import_react_query4 = require("@meaple-com/react-query");
268
270
  var ListEventProducts = ({
269
271
  children,
270
272
  eventId,
273
+ channelId,
271
274
  privateToken,
272
275
  options
273
276
  }) => {
@@ -276,9 +279,10 @@ var ListEventProducts = ({
276
279
  privateToken,
277
280
  options
278
281
  );
279
- const { data: platformFee } = (0, import_react_query4.usePlatformFee)(eventId, {
280
- enabled: !!eventId
281
- });
282
+ const { data: platformFee } = (0, import_react_query4.usePlatformFee)(
283
+ { eventId, channelId },
284
+ { enabled: !!eventId && !!channelId }
285
+ );
282
286
  const fee = platformFee?.fee ?? 0;
283
287
  return children({
284
288
  products: data?.products ?? [],
@@ -304,6 +308,7 @@ var import_react_query6 = require("@meaple-com/react-query");
304
308
  var ListEventTickets = ({
305
309
  children,
306
310
  eventId,
311
+ channelId,
307
312
  privateToken,
308
313
  predecessorIds,
309
314
  options
@@ -314,9 +319,10 @@ var ListEventTickets = ({
314
319
  predecessorIds,
315
320
  options
316
321
  );
317
- const { data: platformFee } = (0, import_react_query6.usePlatformFee)(eventId, {
318
- enabled: !!eventId
319
- });
322
+ const { data: platformFee } = (0, import_react_query6.usePlatformFee)(
323
+ { eventId, channelId },
324
+ { enabled: !!eventId && !!channelId }
325
+ );
320
326
  const fee = platformFee?.fee ?? 0;
321
327
  return children({
322
328
  tickets: data?.tickets ?? [],
package/dist/index.d.cts CHANGED
@@ -123,10 +123,11 @@ type ListEventProductsProps = {
123
123
  error: Error | null;
124
124
  }) => ReactNode;
125
125
  eventId: string;
126
+ channelId: string;
126
127
  privateToken?: string | null;
127
128
  options?: Parameters<typeof useEventProducts>[2];
128
129
  };
129
- declare const ListEventProducts: ({ children, eventId, privateToken, options, }: ListEventProductsProps) => ReactNode;
130
+ declare const ListEventProducts: ({ children, eventId, channelId, privateToken, options, }: ListEventProductsProps) => ReactNode;
130
131
 
131
132
  type ListEventsProps = {
132
133
  children: (props: {
@@ -148,11 +149,12 @@ type ListEventTicketsProps = {
148
149
  error: Error | null;
149
150
  }) => ReactNode;
150
151
  eventId: string;
152
+ channelId: string;
151
153
  privateToken?: string | null;
152
154
  predecessorIds?: string[];
153
155
  options?: Parameters<typeof useEventTickets>[3];
154
156
  };
155
- declare const ListEventTickets: ({ children, eventId, privateToken, predecessorIds, options, }: ListEventTicketsProps) => ReactNode;
157
+ declare const ListEventTickets: ({ children, eventId, channelId, privateToken, predecessorIds, options, }: ListEventTicketsProps) => ReactNode;
156
158
 
157
159
  type SectionType = 'coming_soon' | 'past' | 'awards';
158
160
  type ListUserEventsProps = {
package/dist/index.d.ts CHANGED
@@ -123,10 +123,11 @@ type ListEventProductsProps = {
123
123
  error: Error | null;
124
124
  }) => ReactNode;
125
125
  eventId: string;
126
+ channelId: string;
126
127
  privateToken?: string | null;
127
128
  options?: Parameters<typeof useEventProducts>[2];
128
129
  };
129
- declare const ListEventProducts: ({ children, eventId, privateToken, options, }: ListEventProductsProps) => ReactNode;
130
+ declare const ListEventProducts: ({ children, eventId, channelId, privateToken, options, }: ListEventProductsProps) => ReactNode;
130
131
 
131
132
  type ListEventsProps = {
132
133
  children: (props: {
@@ -148,11 +149,12 @@ type ListEventTicketsProps = {
148
149
  error: Error | null;
149
150
  }) => ReactNode;
150
151
  eventId: string;
152
+ channelId: string;
151
153
  privateToken?: string | null;
152
154
  predecessorIds?: string[];
153
155
  options?: Parameters<typeof useEventTickets>[3];
154
156
  };
155
- declare const ListEventTickets: ({ children, eventId, privateToken, predecessorIds, options, }: ListEventTicketsProps) => ReactNode;
157
+ declare const ListEventTickets: ({ children, eventId, channelId, privateToken, predecessorIds, options, }: ListEventTicketsProps) => ReactNode;
156
158
 
157
159
  type SectionType = 'coming_soon' | 'past' | 'awards';
158
160
  type ListUserEventsProps = {
package/dist/index.js CHANGED
@@ -129,17 +129,19 @@ var Cart = ({
129
129
  0
130
130
  );
131
131
  }, [platformFee, cart.items, feeType]);
132
+ const discountedPrice = Math.max(rawPrice - totalDiscount, 0);
132
133
  const totalFee = useMemo(() => {
133
134
  if (!platformFee) return 0;
134
135
  const { fee, minFeeAmount, thresholdAmount } = feeType === `POS` && platformFee.pos ? platformFee.pos : platformFee;
135
136
  if (fee === 0) return 0;
136
137
  if (rawFeeAmount <= 0) return 0;
138
+ if (discountedPrice <= 0) return 0;
137
139
  if (rawFeeAmount < minFeeAmount && rawPrice < thresholdAmount) {
138
140
  return minFeeAmount;
139
141
  }
140
142
  return rawFeeAmount;
141
- }, [feeType, platformFee, rawFeeAmount, rawPrice]);
142
- const totalPrice = Math.max(rawPrice - totalDiscount, 0) + totalFee;
143
+ }, [feeType, platformFee, rawFeeAmount, rawPrice, discountedPrice]);
144
+ const totalPrice = discountedPrice + totalFee;
143
145
  return children({
144
146
  totalAmount,
145
147
  totalDiscount,
@@ -234,6 +236,7 @@ import { useEventProducts, usePlatformFee } from "@meaple-com/react-query";
234
236
  var ListEventProducts = ({
235
237
  children,
236
238
  eventId,
239
+ channelId,
237
240
  privateToken,
238
241
  options
239
242
  }) => {
@@ -242,9 +245,10 @@ var ListEventProducts = ({
242
245
  privateToken,
243
246
  options
244
247
  );
245
- const { data: platformFee } = usePlatformFee(eventId, {
246
- enabled: !!eventId
247
- });
248
+ const { data: platformFee } = usePlatformFee(
249
+ { eventId, channelId },
250
+ { enabled: !!eventId && !!channelId }
251
+ );
248
252
  const fee = platformFee?.fee ?? 0;
249
253
  return children({
250
254
  products: data?.products ?? [],
@@ -270,6 +274,7 @@ import { useEventTickets, usePlatformFee as usePlatformFee2 } from "@meaple-com/
270
274
  var ListEventTickets = ({
271
275
  children,
272
276
  eventId,
277
+ channelId,
273
278
  privateToken,
274
279
  predecessorIds,
275
280
  options
@@ -280,9 +285,10 @@ var ListEventTickets = ({
280
285
  predecessorIds,
281
286
  options
282
287
  );
283
- const { data: platformFee } = usePlatformFee2(eventId, {
284
- enabled: !!eventId
285
- });
288
+ const { data: platformFee } = usePlatformFee2(
289
+ { eventId, channelId },
290
+ { enabled: !!eventId && !!channelId }
291
+ );
286
292
  const fee = platformFee?.fee ?? 0;
287
293
  return children({
288
294
  tickets: data?.tickets ?? [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meaple-com/react-headless-components",
3
- "version": "2.0.1",
3
+ "version": "4.0.0",
4
4
  "description": "Headless React components for Meaple SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,11 +28,11 @@
28
28
  "clean": "rimraf dist"
29
29
  },
30
30
  "dependencies": {
31
- "@meaple-com/types": "^4.0.0"
31
+ "@meaple-com/types": "^4.1.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@eslint/js": "^9.36.0",
35
- "@meaple-com/react-query": "^1.1.1",
35
+ "@meaple-com/react-query": "^2.0.0",
36
36
  "@types/react": "^19.0.0",
37
37
  "@typescript-eslint/eslint-plugin": "^7.18.0",
38
38
  "@typescript-eslint/parser": "^7.18.0",
@@ -44,7 +44,7 @@
44
44
  "rimraf": "^5.0.5"
45
45
  },
46
46
  "peerDependencies": {
47
- "@meaple-com/react-query": "^1.1.1",
47
+ "@meaple-com/react-query": "^2.0.0",
48
48
  "react": "^19.2.4"
49
49
  },
50
50
  "files": [