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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `pickup-point-selector` now registers itself into the `DeliveryPromiseContext` `uiRegistry` (`pickupPoint` entry) on mount and unregisters on unmount, matching `shopper-location-setter` and `shipping-method-selector`. This lets consumers (e.g. `vtex.search-result`) detect that a delivery-promise block is present.

## [1.4.0] - 2026-07-14

### Changed
Expand Down
11 changes: 11 additions & 0 deletions react/PickupPointSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ function PickupPointSelector({ mode = 'default' }: Props) {
const dispatch = useDeliveryPromiseDispatch()
const lastHandledFulfillmentSelectionAppliedId = useRef(0)

useEffect(() => {
dispatch({
type: 'REGISTER_PICKUP_POINT_BLOCK',
args: { required: false },
})

return () => {
dispatch({ type: 'UNREGISTER_PICKUP_POINT_BLOCK' })
}
}, [dispatch])

// Close the modal once a fulfillment selection is applied (new pickup, or
// pickup cleared via RESET_FULFILLMENT_METHOD). The old reload tore the modal
// down for free; with the soft refresh the tree stays alive.
Expand Down
60 changes: 60 additions & 0 deletions react/__tests__/UseDeliveryPromise.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,66 @@ describe('useDeliveryPromise actions and behavior', () => {
})
})

it('REGISTER_PICKUP_POINT_BLOCK sets uiRegistry.pickupPoint and UNREGISTER removes it without touching other entries', async () => {
function PickupRegistryProbe() {
const { dispatch, state } = useDeliveryPromise()

return (
<div>
<span data-testid="registry">{JSON.stringify(state.uiRegistry)}</span>
<button
data-testid="reg-shopper-and-pickup"
type="button"
onClick={async () => {
await dispatch({
type: 'REGISTER_SHOPPER_LOCATION_BLOCK',
args: { required: false },
} as never)
await dispatch({
type: 'REGISTER_PICKUP_POINT_BLOCK',
args: { required: false },
} as never)
}}
>
reg
</button>
<button
data-testid="unreg-pickup"
type="button"
onClick={() =>
dispatch({ type: 'UNREGISTER_PICKUP_POINT_BLOCK' } as never)
}
>
unreg pickup
</button>
</div>
)
}

const { getByTestId } = render(<PickupRegistryProbe />)

expect(getByTestId('registry').textContent).toBe('{}')

fireEvent.click(getByTestId('reg-shopper-and-pickup'))

await waitFor(() => {
expect(getByTestId('registry').textContent).toBe(
JSON.stringify({
shopperLocation: { required: false },
pickupPoint: { required: false },
})
)
})

fireEvent.click(getByTestId('unreg-pickup'))

await waitFor(() => {
expect(getByTestId('registry').textContent).toBe(
JSON.stringify({ shopperLocation: { required: false } })
)
})
})

it('REQUEST_OPEN_SHIPPING_METHOD_MODAL increments shippingMethodModalRequestId', async () => {
function RequestOpenProbe() {
const { dispatch, state } = useDeliveryPromise()
Expand Down
12 changes: 12 additions & 0 deletions react/context/DeliveryPromiseContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ZipCodeError = {
export type DeliveryPromiseUiRegistry = {
shopperLocation?: { required: boolean }
shippingMethod?: { required: boolean }
pickupPoint?: { required: boolean }
}

export interface State {
Expand Down Expand Up @@ -98,6 +99,15 @@ interface UnregisterShippingMethodBlock {
type: 'UNREGISTER_SHIPPING_METHOD_BLOCK'
}

interface RegisterPickupPointBlock {
type: 'REGISTER_PICKUP_POINT_BLOCK'
args: { required: boolean }
}

interface UnregisterPickupPointBlock {
type: 'UNREGISTER_PICKUP_POINT_BLOCK'
}

interface RequestOpenShippingMethodModal {
type: 'REQUEST_OPEN_SHIPPING_METHOD_MODAL'
}
Expand All @@ -117,6 +127,8 @@ export type DeliveryPromiseActions =
| UnregisterShopperLocationBlock
| RegisterShippingMethodBlock
| UnregisterShippingMethodBlock
| RegisterPickupPointBlock
| UnregisterPickupPointBlock
| RequestOpenShippingMethodModal
| ClearZipCode

Expand Down
19 changes: 19 additions & 0 deletions react/context/useDeliveryPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,25 @@ export const useDeliveryPromise = () => {

return

case 'REGISTER_PICKUP_POINT_BLOCK':
setUiRegistry((prev) => ({
...prev,
pickupPoint: { required: action.args.required },
}))

return

case 'UNREGISTER_PICKUP_POINT_BLOCK':
setUiRegistry((prev) => {
const next = { ...prev }

delete next.pickupPoint

return next
})

return

case 'REQUEST_OPEN_SHIPPING_METHOD_MODAL':
setShippingMethodModalRequestId((n) => n + 1)

Expand Down
Loading