@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.05 kB
JavaScript
"use client";
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const shippingAddressInitialState={_shipping_address_clone_id:""},setShippingAddress=async(id,options)=>{try{if(options?.order){if(options.customerAddressId){const sdk=getSdk(options.config),attributes={id,reference:options.customerAddressId};await sdk.addresses.update(attributes)}options.dispatch({type:"setShippingAddress",payload:{_shipping_address_clone_id:id}})}}catch(error){console.error(error)}};export function setShippingCustomerAddressId({dispatch,order,setCloneAddress}){const customerAddressId=order?.shipping_address?.reference;try{customerAddressId&&(dispatch({type:"setShippingCustomerAddressId",payload:{shippingCustomerAddressId:customerAddressId}}),setCloneAddress(customerAddressId,"shipping_address"))}catch(error){console.error("error",error)}}const type=["setShippingAddress","setShippingCustomerAddressId","cleanup"],shippingAddressReducer=(state,reducer)=>baseReducer(state,reducer,type);export default shippingAddressReducer;