UNPKG

@commercelayer/react-components

Version:
2 lines 1.5 kB
"use client"; "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setShippingAddress=exports.shippingAddressInitialState=void 0,exports.setShippingCustomerAddressId=setShippingCustomerAddressId;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.shippingAddressInitialState={_shipping_address_clone_id:""};const setShippingAddress=(id,options)=>tslib_1.__awaiter(void 0,void 0,void 0,function*(){try{if(options?.order){if(options.customerAddressId){const sdk=(0,getSdk_1.default)(options.config),attributes={id,reference:options.customerAddressId};yield sdk.addresses.update(attributes)}options.dispatch({type:"setShippingAddress",payload:{_shipping_address_clone_id:id}})}}catch(error){console.error(error)}});exports.setShippingAddress=setShippingAddress;function setShippingCustomerAddressId({dispatch,order,setCloneAddress}){var _a;const customerAddressId=(_a=order?.shipping_address)===null||_a===void 0?void 0:_a.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)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=shippingAddressReducer;