@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 880 B
JavaScript
"use client";
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.getSkuList=exports.skuListsInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),actionType=["getSkuList","setSkuList"];exports.skuListsInitialState={listIds:[]};const getSkuList=async({listIds,config,dispatch})=>{const skuLists={};try{const sdk=(0,getSdk_1.default)(config);listIds.forEach(async id=>{const skuCodes=(await sdk.sku_lists.retrieve(id,{include:["skus"],fields:{skus:["code"]}})).skus;skuLists[id]=skuCodes}),dispatch({payload:{skuLists},type:"getSkuList"})}catch(error){console.error(error)}};exports.getSkuList=getSkuList;const skuListsReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,actionType);exports.default=skuListsReducer;