@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 1.41 kB
JavaScript
"use client";
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.setBillingAddress=exports.billingAddressInitialState=void 0,exports.setBillingCustomerAddressId=setBillingCustomerAddressId;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.billingAddressInitialState={_billing_address_clone_id:""};const setBillingAddress=async(id,options)=>{try{if(options?.order){if(options.customerAddressId){const sdk=(0,getSdk_1.default)(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)}};exports.setBillingAddress=setBillingAddress;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)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=billingAddressReducer;