Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-months-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@noaignite/react-centra-checkout': patch
---

`Context`: Update `data` type on `addBundleItem` handler
5 changes: 5 additions & 0 deletions .changeset/rotten-pugs-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@noaignite/react-centra-checkout': patch
---

Add missing `'use client'` directives
5 changes: 5 additions & 0 deletions .changeset/tangy-toys-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@noaignite/react-centra-checkout': minor
---

`Context`: Add support for `data` in `addItem` handler
57 changes: 54 additions & 3 deletions packages/react-centra-checkout/src/Context.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import type * as CheckoutApi from '@noaignite/centra-types'
import { isPlainObject } from '@noaignite/utils'
import type Cookies from 'js-cookie'
Expand Down Expand Up @@ -67,14 +69,63 @@ export interface ContextMethods {
addItem?: (
item: string,
quantity?: number,
data?: {
/**
* The URL to the product added, so the item can be linked back to its origin
*/
productUrl?: string
/**
* The category id of the added product, so the item can be linked back to its origin.
*/
category?: string
/**
* Requires shared secret. Comment that will end up on the order line
*/
comment?: string
/**
* Localized size (localizedSize) & localization definition name (localizationDefinitionName)
*/
localizedProdSize?: string
/**
* The ID of subscription plan
*/
subscriptionPlan?: string
Comment on lines +73 to +92
Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data type definition for addItem is duplicated in the addBundleItem interface (lines 109-127). Consider extracting this into a shared interface to avoid code duplication and ensure consistency.

Copilot uses AI. Check for mistakes.
},
) => Promise<CheckoutApi.Response<CheckoutApi.SelectionResponse>>
/**
* @param item - The Centra item id
* @param data - Bundle data
*/
addBundleItem?: (
item: string,
data?: Record<string, unknown>,
data?: {
/**
* The quantity of items that should be added to the cart.
* Minimum should be 1.
* Defaults to 1.
*/
quantity?: number
/**
* The URL to the product added, so the item can be linked back to its origin
*/
productUrl?: string
/**
* The category id of the added product, so the item can be linked back to its origin
*/
category?: string
/**
* Requires shared secret. Comment that will end up on the order line
*/
comment?: string
/**
* Localized size (localizedSize) & localization definition name (localizationDefinitionName)
*/
localizedProdSize?: string
/**
* The ID of subscription plan
*/
subscriptionPlan?: string
},
) => Promise<CheckoutApi.Response<CheckoutApi.SelectionResponse>>
/**
* @param giftCertificate - The `giftCertificate` value of the gift certificate to add
Expand Down Expand Up @@ -355,9 +406,9 @@ export function CentraProvider(props: ProviderProps) {
/* HANDLER METHODS */

const addItem = useCallback<NonNullable<ContextMethods['addItem']>>(
(item, quantity = 1) =>
(item, quantity = 1, data) =>
onSelectionResponse(
apiClient.request('POST', `items/${item}/quantity/${quantity}`),
apiClient.request('POST', `items/${item}/quantity/${quantity}`, data),
selectionApiCall,
),
[apiClient, selectionApiCall],
Expand Down
2 changes: 2 additions & 0 deletions packages/react-centra-checkout/src/PaymentEmbed.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import type * as CheckoutApi from '@noaignite/centra-types'
import { isPlainObject } from '@noaignite/utils'
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
Expand Down
2 changes: 2 additions & 0 deletions packages/react-centra-checkout/src/ShipwalletEmbed.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import { useEffect } from 'react'
import { useCentraSelection } from './Context'
import { HtmlEmbed } from './internal/HtmlEmbed'
Expand Down