UNPKG

@commercelayer/react-components

Version:
2 lines 1.1 kB
"use client"; import{jsx as _jsx}from"react/jsx-runtime";import{useReducer,useContext}from"react";import GiftCardContext from"../../context/GiftCardContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import giftCardReducer,{giftCardInitialState,addGiftCardRecipient,addGiftCard,addGiftCardError,addGiftCardLoading}from"../../reducers/GiftCardReducer";import OrderContext from"../../context/OrderContext";export function GiftCardContainer(props){const{children}=props,[state,dispatch]=useReducer(giftCardReducer,giftCardInitialState),config=useContext(CommerceLayerContext),{getOrder,createOrder,order}=useContext(OrderContext),giftCardValue={...state,addGiftCardRecipient:async values=>{await addGiftCardRecipient(values,config,dispatch)},addGiftCard:async values=>{await addGiftCard({...values},{config,dispatch,getOrder,createOrder,order})},addGiftCardError:errors=>{addGiftCardError(errors,dispatch)},addGiftCardLoading:loading=>{addGiftCardLoading(loading,dispatch)}};return _jsx(GiftCardContext.Provider,{value:giftCardValue,children})}export default GiftCardContainer;