@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.06 kB
JavaScript
"use client";
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const billingAddressInitialState={_billing_address_clone_id:""},setBillingAddress=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:"setBillingAddress",payload:{_billing_address_clone_id:id}})}}catch(error){console.error("Set billing address",error)}};export function setBillingCustomerAddressId({dispatch,order,setCloneAddress}){const customerAddressId=order?.billing_address?.reference;try{customerAddressId&&(dispatch({type:"setBillingCustomerAddressId",payload:{billingCustomerAddressId:customerAddressId}}),setCloneAddress(customerAddressId,"billing_address"))}catch(error){console.error("error",error)}}const type=["setBillingAddress","setBillingCustomerAddressId","cleanup"],billingAddressReducer=(state,reducer)=>baseReducer(state,reducer,type);export default billingAddressReducer;