@bikdotai/bik-component-library 0.0.454-beta.ppi-7 → 0.0.454-beta.ppi-9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -29,6 +29,10 @@ export interface Collection {
29
29
  export type SelectedItems = {
30
30
  [key: string]: Collection;
31
31
  };
32
+ export type SearchedItems = {
33
+ collections: SelectedItems;
34
+ products: SelectedItems;
35
+ };
32
36
  export type CollectionFetcherReturn = Promise<{
33
37
  collections: {
34
38
  [key: string]: {
@@ -57,7 +61,7 @@ export type ProductPickerInterface = {
57
61
  hideInCollectionSearch?: boolean;
58
62
  customCollectionRestriction?: boolean;
59
63
  searchInCollectionFetcher: (storeId: string, collectionId: string, query: string) => ProductFetcherReturn;
60
- searchFetcher: (storeId: string, query: string) => Promise<SelectedItems>;
64
+ searchFetcher: (storeId: string, query: string) => Promise<SearchedItems>;
61
65
  collectionFetcher: (offset: number, storeId: string) => CollectionFetcherReturn;
62
66
  productFetcher: (collectionId: string, storeId: string, limit?: number, offset?: number) => ProductFetcherReturn;
63
67
  fbStatusFetcher?: (storeId: string, variantIds: string[]) => FbStatusFetcherReturn;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),c=require("../../assets/icons/search.svg.js"),o=require("react"),r=require("../../constants/Theme.js"),s=require("../button/Button.js"),n=require("../input/Input.js"),i=require("../modals/styledModal.js"),l=require("../spinner/Spinner.js"),a=require("../tag/Tag.js"),d=require("./collectionScreen.js"),u=require("./productInfoOverlay.js"),h=require("./productScreen.js"),p=require("./rearrangeScreen.js"),S=require("./reducers.js"),C=require("./searchScreen.js"),x=require("./selectedScreen.js"),g=require("./style.js"),j=require("./type.js");exports.ScreenName=void 0,(e=exports.ScreenName||(exports.ScreenName={})).Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products";exports.ProductPickerModal=e=>{const{storeId:m,selectedItems:b,onClose:y,visible:f,zIndex:P,exactLimit:v,limit:I,hideCollectionCheckbox:k,hideProductCheckbox:F,outOfStockAction:O=j.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:R,selectProductsFromCustomCollection:T,hideSelectionCount:q,title:D,width:E,renderWithoutModal:w,onClickSave:N,pickerType:A,hideProductVariants:B=!1,startupScreen:$=exports.ScreenName.Collections,rearrangeEnabled:M,selectSingleItem:V=!1,showProductDetailInfoIcon:L}=e,[_,z]=o.useReducer(S.collectionsReducer,{}),[G,H]=o.useState([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes($)?$:exports.ScreenName.Collections),[W,K]=o.useState("grid"),[U,Y]=o.useState(""),[J,Q]=o.useState(""),[X,Z]=o.useState(0),[ee,te]=o.useState(!1),[ce,oe]=o.useState(0),[re,se]=o.useState(""),[ne,ie]=o.useState(!1),[le,ae]=o.useState(!1),[de,ue]=o.useReducer(S.searchReducer,{}),[he,pe]=o.useReducer(S.selectedColectionsReducer,Object.keys(b).length>0?b:{}),Se=o.useRef(null),[Ce,xe]=o.useState(!1),[ge,je]=o.useState();o.useEffect((()=>{te(!0),ae(!0),e.collectionFetcher(X,m).then((e=>{z({type:"fetched",data:(null==e?void 0:e.collections)||{}}),te(!1),Z((e=>e+1)),ae(!1)})).catch()}),[]),o.useEffect((()=>{let e=0;Object.keys(he||[]).forEach((t=>{var c;Object.keys((null===(c=he[t])||void 0===c?void 0:c.products)||[]).forEach((c=>{var o,r;Object.keys((null===(r=null===(o=he[t].products)||void 0===o?void 0:o[c])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),oe(e)})),o.useEffect((()=>{J&&(te(!0),e.productFetcher(J,m).then((e=>{Object.keys(e).length&&z({type:"productsFetched",data:{collectionId:J,products:e}}),te(!1)})).catch())}),[J]),o.useEffect((()=>{const t=setTimeout((()=>{"rearrange"!==G&&(re.length?(ie(!0),e.searchFetcher(m,re).then((e=>{ue({type:"set",data:e}),H("searchProducts"),te(!1),ie(!1)}))):H("collections"))}),800);return()=>clearTimeout(t)}),[re]),o.useEffect((()=>{N&&(e.onAdd(he,ce),me())}),[N]),o.useEffect((()=>{V&&Object.keys(he||{}).length&&ce&&(e.onAdd(he,ce),me())}),[V,he,ce]);const me=()=>{pe({type:"reset",data:{}})},be=t.jsxs(g.ContainerStyle,{children:[e.postHeader&&t.jsx("div",Object.assign({style:{padding:"0 24px"}},{children:e.postHeader})),!e.hideGlobalSearch&&t.jsx(t.Fragment,{children:("collections"===G||"searchProducts"===G)&&t.jsx("div",Object.assign({style:{padding:w?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t.jsx(n.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>ne?t.jsx(l.Spinner,{size:"small",color:r.COLORS.content.primary}):t.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:re,onChangeText:e=>{e.length&&e.trim().length?se(e):se("")}})}))}),t.jsxs(g.ScrollContainerStyle,Object.assign({ref:Se},{children:["collections"===G&&t.jsx(d.CollectionsScreen,{customCollectionRestriction:e.customCollectionRestriction,dataLoading:le,collections:_,selectedCollectionsDispatch:pe,setCollectionId:Y,setSelectedCollectionId:Q,setScreen:H,selectedCollections:he,collectionFetcher:e.collectionFetcher,storeId:m,collectionsDispatch:z,setSaveDisabled:te,pagingControls:{curPage:X,setCurPage:Z},hideCollectionCheckbox:k,renderWithoutModal:w,pickerType:A}),"products"===G&&U&&t.jsx(S.CollectionIdContext.Provider,Object.assign({value:U},{children:t.jsx(h.ProductsScreen,{hideInCollectionSearch:e.hideInCollectionSearch,customCollectionRestriction:e.customCollectionRestriction,productFetcher:e.productFetcher,setScreen:H,storeId:m,data:_[U],collectionsDispatch:z,selectedCollectionsDispatch:pe,selectedData:he,setSaveDisabled:te,searchInCollectionFetcher:e.searchInCollectionFetcher,hideProductCheckbox:F,outOfStockAction:O,hideVariantCheckbox:R,selectProductsFromCustomCollection:T,renderWithoutModal:w,pickerType:A,hideProductVariants:B,fbStatusFetcher:e.fbStatusFetcher,onInfoIconClick:e=>{xe(!0),je(e)},showProductDetailInfoIcon:L})})),"view"===G&&t.jsx(x.SelectedScreen,{selectedCollections:he||{},selectedCollectionsDispatch:pe,setScreen:H,collections:_,outOfStockAction:O,storeId:m,fbStatusFetcher:e.fbStatusFetcher}),"rearrange"===G&&t.jsx(p.RearrangeScreen,{selectedCollections:he||{},selectedCollectionsDispatch:pe,setScreen:H,outOfStockAction:O,rearrangeViewType:"grid"===W?"list":"grid",scrollContainerRef:Se,storeId:m,fbStatusFetcher:e.fbStatusFetcher}),"searchProducts"===G&&t.jsx(C.SearchScreen,{customCollectionRestriction:e.customCollectionRestriction,selectedCollections:he||{},searchedCollections:de||{},searchedCollectionsDispatch:ue,selectedCollectionsDispatch:pe,setScreen:H,collections:_,onBackPress:()=>{se(""),ue({type:"set",data:{}})},pickerType:A,hideProductCheckbox:F,hideProductVariants:B,hideVariantCheckbox:R,storeId:m,fbStatusFetcher:e.fbStatusFetcher})]}))]});return t.jsx(t.Fragment,{children:w?be:t.jsxs(i.StyledModal,Object.assign({zIndex:P,open:f,onClose:()=>{null==y||y(),me()},headingTitle:D||("collections"===G||"products"===G?"Select Products":"view"===G?"Selected Products":"searchProducts"===G?"Searched Products":"rearrange"===G?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:E||"600px"},headerRightCustomElement:"rearrange"===G?(console.log("ignore:",K),t.jsx(t.Fragment,{})):t.jsx(t.Fragment,{}),primaryButton:{buttonText:ee?"Loading...":G===exports.ScreenName.RearrangeProducts?"Done":"Add",disabled:ee||ce<1||v&&ce<v||!v&&I&&ce>I||!1,onClick:()=>{e.onAdd(he,ce),me()}},footerLeftCustomElement:q?t.jsx(t.Fragment,{}):v&&ce>v?t.jsx(a.Tag,{tagText:`You can only select ${v} products`,type:"negative"}):I&&ce>I?t.jsx(a.Tag,{tagText:`You can only select ${I} products`,type:"negative"}):ce>0?t.jsx(s.Button,{onClick:()=>{H(M?exports.ScreenName.RearrangeProducts:exports.ScreenName.SelectedProducts)},buttonText:v?`${ce}/${v} products selected`:`${ce} products selected`,buttonType:["rearrange","view"].includes(G)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(G)}):t.jsx(s.Button,{disabled:!0,buttonText:v?`${ce}/${v} products selected`:`${ce} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:Ce},{children:[be,Ce&&ge?t.jsx(u.ProductInfoOverlay,{productData:ge,outOfStockAction:O,onClose:()=>{xe(!1)}}):t.jsx(t.Fragment,{})]}))})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),c=require("../../assets/icons/search.svg.js"),o=require("react"),r=require("../../constants/Theme.js"),s=require("../button/Button.js"),n=require("../input/Input.js"),l=require("../modals/styledModal.js"),i=require("../spinner/Spinner.js"),a=require("../tag/Tag.js"),d=require("./collectionScreen.js"),u=require("./productInfoOverlay.js"),h=require("./productScreen.js"),p=require("./rearrangeScreen.js"),S=require("./reducers.js"),C=require("./searchScreen.js"),x=require("./selectedScreen.js"),g=require("./style.js"),j=require("./type.js");exports.ScreenName=void 0,(e=exports.ScreenName||(exports.ScreenName={})).Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products";exports.ProductPickerModal=e=>{const{storeId:m,selectedItems:b,onClose:y,visible:f,zIndex:P,exactLimit:v,limit:I,hideCollectionCheckbox:k,hideProductCheckbox:F,outOfStockAction:O=j.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:R,selectProductsFromCustomCollection:T,hideSelectionCount:q,title:D,width:E,renderWithoutModal:w,onClickSave:N,pickerType:A,hideProductVariants:B=!1,startupScreen:$=exports.ScreenName.Collections,rearrangeEnabled:M,selectSingleItem:V=!1,showProductDetailInfoIcon:L}=e,[_,z]=o.useReducer(S.collectionsReducer,{}),[G,H]=o.useState([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes($)?$:exports.ScreenName.Collections),[W,K]=o.useState("grid"),[U,Y]=o.useState(""),[J,Q]=o.useState(""),[X,Z]=o.useState(0),[ee,te]=o.useState(!1),[ce,oe]=o.useState(0),[re,se]=o.useState(""),[ne,le]=o.useState(!1),[ie,ae]=o.useState(!1),[de,ue]=o.useReducer(S.searchReducer,{collections:{},products:{}}),[he,pe]=o.useReducer(S.selectedColectionsReducer,Object.keys(b).length>0?b:{}),Se=o.useRef(null),[Ce,xe]=o.useState(!1),[ge,je]=o.useState();o.useEffect((()=>{te(!0),ae(!0),e.collectionFetcher(X,m).then((e=>{z({type:"fetched",data:(null==e?void 0:e.collections)||{}}),te(!1),Z((e=>e+1)),ae(!1)})).catch()}),[]),o.useEffect((()=>{let e=0;Object.keys(he||[]).forEach((t=>{var c;Object.keys((null===(c=he[t])||void 0===c?void 0:c.products)||[]).forEach((c=>{var o,r;Object.keys((null===(r=null===(o=he[t].products)||void 0===o?void 0:o[c])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),oe(e)})),o.useEffect((()=>{J&&(te(!0),e.productFetcher(J,m).then((e=>{Object.keys(e).length&&z({type:"productsFetched",data:{collectionId:J,products:e}}),te(!1)})).catch())}),[J]),o.useEffect((()=>{const t=setTimeout((()=>{"rearrange"!==G&&(re.length?(le(!0),e.searchFetcher(m,re).then((e=>{ue({type:"set",data:e}),H("searchProducts"),te(!1),le(!1)}))):H("collections"))}),800);return()=>clearTimeout(t)}),[re]),o.useEffect((()=>{N&&(e.onAdd(he,ce),me())}),[N]),o.useEffect((()=>{V&&Object.keys(he||{}).length&&ce&&(e.onAdd(he,ce),me())}),[V,he,ce]);const me=()=>{pe({type:"reset",data:{}})},be=t.jsxs(g.ContainerStyle,{children:[e.postHeader&&t.jsx("div",Object.assign({style:{padding:"0 24px"}},{children:e.postHeader})),!e.hideGlobalSearch&&t.jsx(t.Fragment,{children:("collections"===G||"searchProducts"===G)&&t.jsx("div",Object.assign({style:{padding:w?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t.jsx(n.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>ne?t.jsx(i.Spinner,{size:"small",color:r.COLORS.content.primary}):t.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:re,onChangeText:e=>{e.length&&e.trim().length?se(e):se("")}})}))}),t.jsxs(g.ScrollContainerStyle,Object.assign({ref:Se},{children:["collections"===G&&t.jsx(d.CollectionsScreen,{customCollectionRestriction:e.customCollectionRestriction,dataLoading:ie,collections:_,selectedCollectionsDispatch:pe,setCollectionId:Y,setSelectedCollectionId:Q,setScreen:H,selectedCollections:he,collectionFetcher:e.collectionFetcher,storeId:m,collectionsDispatch:z,setSaveDisabled:te,pagingControls:{curPage:X,setCurPage:Z},hideCollectionCheckbox:k,renderWithoutModal:w,pickerType:A}),"products"===G&&U&&t.jsx(S.CollectionIdContext.Provider,Object.assign({value:U},{children:t.jsx(h.ProductsScreen,{hideInCollectionSearch:e.hideInCollectionSearch,customCollectionRestriction:e.customCollectionRestriction,productFetcher:e.productFetcher,setScreen:H,storeId:m,data:_[U],collectionsDispatch:z,selectedCollectionsDispatch:pe,selectedData:he,setSaveDisabled:te,searchInCollectionFetcher:e.searchInCollectionFetcher,hideProductCheckbox:F,outOfStockAction:O,hideVariantCheckbox:R,selectProductsFromCustomCollection:T,renderWithoutModal:w,pickerType:A,hideProductVariants:B,fbStatusFetcher:e.fbStatusFetcher,onInfoIconClick:e=>{xe(!0),je(e)},showProductDetailInfoIcon:L})})),"view"===G&&t.jsx(x.SelectedScreen,{selectedCollections:he||{},selectedCollectionsDispatch:pe,setScreen:H,collections:_,outOfStockAction:O,storeId:m,fbStatusFetcher:e.fbStatusFetcher}),"rearrange"===G&&t.jsx(p.RearrangeScreen,{selectedCollections:he||{},selectedCollectionsDispatch:pe,setScreen:H,outOfStockAction:O,rearrangeViewType:"grid"===W?"list":"grid",scrollContainerRef:Se,storeId:m,fbStatusFetcher:e.fbStatusFetcher}),"searchProducts"===G&&t.jsx(C.SearchScreen,{customCollectionRestriction:e.customCollectionRestriction,selectedCollections:he||{},searchedCollections:de||{},searchedCollectionsDispatch:ue,selectedCollectionsDispatch:pe,setScreen:H,collections:_,onBackPress:()=>{se(""),ue({type:"set",data:{collections:{},products:{}}})},pickerType:A,hideProductCheckbox:F,hideProductVariants:B,hideVariantCheckbox:R,storeId:m,fbStatusFetcher:e.fbStatusFetcher})]}))]});return t.jsx(t.Fragment,{children:w?be:t.jsxs(l.StyledModal,Object.assign({zIndex:P,open:f,onClose:()=>{null==y||y(),me()},headingTitle:D||("collections"===G||"products"===G?"Select Products":"view"===G?"Selected Products":"searchProducts"===G?"Searched Products":"rearrange"===G?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:E||"600px"},headerRightCustomElement:"rearrange"===G?(console.log("ignore:",K),t.jsx(t.Fragment,{})):t.jsx(t.Fragment,{}),primaryButton:{buttonText:ee?"Loading...":G===exports.ScreenName.RearrangeProducts?"Done":"Add",disabled:ee||ce<1||v&&ce<v||!v&&I&&ce>I||!1,onClick:()=>{e.onAdd(he,ce),me()}},footerLeftCustomElement:q?t.jsx(t.Fragment,{}):v&&ce>v?t.jsx(a.Tag,{tagText:`You can only select ${v} products`,type:"negative"}):I&&ce>I?t.jsx(a.Tag,{tagText:`You can only select ${I} products`,type:"negative"}):ce>0?t.jsx(s.Button,{onClick:()=>{H(M?exports.ScreenName.RearrangeProducts:exports.ScreenName.SelectedProducts)},buttonText:v?`${ce}/${v} products selected`:`${ce} products selected`,buttonType:["rearrange","view"].includes(G)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(G)}):t.jsx(s.Button,{disabled:!0,buttonText:v?`${ce}/${v} products selected`:`${ce} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:Ce},{children:[be,Ce&&ge?t.jsx(u.ProductInfoOverlay,{productData:ge,outOfStockAction:O,onClose:()=>{xe(!1)}}):t.jsx(t.Fragment,{})]}))})};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),o=require("../../assets/icons/box.svg.js"),i=require("../../assets/icons/search.svg.js"),n=require("lodash"),s=require("react"),c=require("../../constants/Theme.js"),l=require("../../assets/icons/info.svg.js"),r=require("../checkBox/CheckBox.js"),d=require("../icon-button/IconButton.js"),a=require("../input/Input.js"),u=require("../shimmer/ShimmerComponent/BikShimmer.js"),v=require("../shimmer-image/ShimmerImage.js"),h=require("../spinner/Spinner.js"),p=require("../tooltips/Tooltip.js"),j=require("../TypographyStyle.js"),g=require("./emptyState.js"),b=require("./ProductPickerTag.js"),f=require("./reducers.js"),y=require("./style.js"),O=require("./type.js"),k=require("./utility.js");const x=t=>{const{collectionId:o,productId:i,data:n,selectedData:s,selectedCollectionsDispatch:c,viewOnly:l,upliftAdditions:r,isProductPartiallyChecked:d,hideProductCheckbox:a,outOfStockAction:u,hideVariantCheckbox:v,hideProductVariants:h,pickerType:p,onInfoIconClick:j,showProductDetailInfoIcon:g}=t,b=e=>{var t,n,c,l,r,d;if(!(null===(n=null===(t=null==s?void 0:s[o])||void 0===t?void 0:t.products)||void 0===n?void 0:n[i]))return!1;return!!(null===(d=null===(r=null===(l=null===(c=null==s?void 0:s[o])||void 0===c?void 0:c.products)||void 0===l?void 0:l[i])||void 0===r?void 0:r.variants)||void 0===d?void 0:d[e])};return e.jsxs("div",{children:[e.jsx(I,{isVariant:!1,data:n,productId:i,collectionId:o,isSelected:!!(null===(y=null===(f=null==s?void 0:s[o])||void 0===f?void 0:f.products)||void 0===y?void 0:y[i]),isPartiallyChecked:d,selectedCollectionsDispatch:c,upliftAdditions:r,viewOnly:l,hideProductCheckbox:a,hideVariantCheckbox:v,hideProductVariants:h,pickerType:p,outOfStockAction:u,onInfoIconClick:j,showProductDetailInfoIcon:g},i),h?null:Object.keys(n.variants||[]).length>1&&Object.keys(n.variants||[]).map((t=>e.jsx(I,{isVariant:!0,hideVariantCheckbox:v,data:n.variants[t],variantId:t,productId:i,viewOnly:l,upliftAdditions:r,collectionId:o,isSelected:b(t),selectedCollectionsDispatch:c,outOfStockAction:u,onInfoIconClick:j,showProductDetailInfoIcon:g},t)))]});var f,y},I=t=>{const{isVariant:o,data:i,productId:n,collectionId:s,variantId:a,isSelected:u,selectedCollectionsDispatch:h,viewOnly:g,upliftAdditions:f,isPartiallyChecked:O,hideProductCheckbox:k,outOfStockAction:x,hideVariantCheckbox:I,hideProductVariants:C,pickerType:P,onInfoIconClick:m,showProductDetailInfoIcon:S}=t;return e.jsxs(y.ProductCardStyle,Object.assign({isVariant:o,onClick:e=>{"PRODUCT"===P&&C&&(e.stopPropagation(),h({type:"reset",data:{}}),f("variantSelected",{productId:n,variantId:a||Object.keys(i.variants)[0],collectionId:s,variant:i}))},isActive:u},{children:[o&&!g&&!I||!o&&!g&&!k?e.jsx(r.CheckBox,{isChecked:u,isPartiallyChecked:O||!1,onValueChange:function(e){o?e?f("variantSelected",{productId:n,variantId:a,collectionId:s,variant:i}):h({type:"variantUnselected",data:{productId:n,variantId:a,collectionId:s}}):e?f("productSelected",{productId:n,collectionId:s,product:i}):h({type:"productUnselected",data:{productId:n,collectionId:s}})}}):e.jsx(e.Fragment,{}),e.jsx("div",{children:e.jsx(v.ShimmerImage,{width:40,height:40,imageUrl:i.image,alt:"Item",borderRadius:4})}),e.jsx(p.Tooltip,Object.assign({variant:"light",body:i.name,placement:"bottom",delay:400},{children:e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",flex:1}},{children:[e.jsxs("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},{children:[e.jsx(j.BodyPrimary,Object.assign({numberOfLines:1},{children:i.name})),S&&e.jsx(d.IconButton,{onClick:()=>{null==m||m(i)},Icon:()=>e.jsx(l.default,{width:20,height:20,color:c.COLORS.content.placeholder})})]})),e.jsx(b.ProductPickerTag,{isVariant:o,data:i,outOfStockAction:x})]}))}))]}))};exports.ProductCard=I,exports.ProductGroup=x,exports.ProductsScreen=l=>{const{data:v,collectionsDispatch:p,selectedData:b,selectedCollectionsDispatch:I,productFetcher:C,storeId:P,setScreen:m,setSaveDisabled:S,hideInCollectionSearch:E,customCollectionRestriction:D,hideProductCheckbox:T,outOfStockAction:A=O.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:V=!1,selectProductsFromCustomCollection:w=!1,pickerType:q,hideProductVariants:F,fbStatusFetcher:R,onInfoIconClick:B,showProductDetailInfoIcon:L}=l,U=s.useContext(f.CollectionIdContext),_=s.useRef(null),H=s.useRef(0),[J,K]=s.useState(!1),[M,N]=s.useState(""),[W,z]=s.useState(!1),[G,Q]=s.useState(v),X=s.useRef(!1);s.useEffect((()=>{const e=setTimeout((()=>{M.length?(z(!0),l.searchInCollectionFetcher(P,U,M).then((e=>{const t=n.cloneDeep(v);t.products=e,Q(t);const o=$(null!=e?e:{},!0);ee(o,null!=e?e:{},!0),S(!1),z(!1)}))):Q(v)}),800);return()=>clearTimeout(e)}),[M]),s.useEffect((()=>{var e,t,o,i,n,s,c,l;console.log("vj: collectionId change before",v,v.products,null===(t=Object.keys(null!==(e=v.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length,X),X.current=!1,H.current=Math.floor((null===(i=Object.keys(null!==(o=v.products)&&void 0!==o?o:{}))||void 0===i?void 0:i.length)/10);const r=$(null!==(n=v.products)&&void 0!==n?n:{});ee(r,null!==(s=v.products)&&void 0!==s?s:{}),console.log("vj: collectionId change after",v,v.products,null===(l=Object.keys(null!==(c=v.products)&&void 0!==c?c:{}))||void 0===l?void 0:l.length,X)}),[U]);const Y=!!D&&v.isSmartCollection,Z=e=>{var t,o,i,n,s,c,l,r;let d=0,a=0;return!!((null===(o=null===(t=null==b?void 0:b[U])||void 0===t?void 0:t.products)||void 0===o?void 0:o[e])&&(null===(s=Object.keys((null===(n=null===(i=null==v?void 0:v.products)||void 0===i?void 0:i[e])||void 0===n?void 0:n.variants)||[]))||void 0===s||s.forEach((()=>a++)),Object.keys((null===(r=null===(l=null===(c=null==b?void 0:b[U])||void 0===c?void 0:c.products)||void 0===l?void 0:l[e])||void 0===r?void 0:r.variants)||[]).forEach((()=>d++)),d>0&&a!==d))};s.useEffect((()=>{(null==v?void 0:v.products)||te(10)}),[]);const $=(e,t)=>{const o=[];return console.log("vj: getVariantIdsForFbStatusFetch",e),Object.keys(null!=e?e:{}).forEach((i=>{var n,s;const c=null!==(s=null===(n=null==e?void 0:e[i])||void 0===n?void 0:n.variants)&&void 0!==s?s:{};Object.keys(c).forEach((n=>{var s,c,l,r,d;let a;a=t?null===(c=null===(s=null==e?void 0:e[i])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[n]:null===(d=null===(r=null===(l=null==v?void 0:v.products)||void 0===l?void 0:l[i])||void 0===r?void 0:r.variants)||void 0===d?void 0:d[n],console.log("vj: variant fb status",{data:v,variant:a}),(null==a?void 0:a.fbStatus)||o.push(n)}))})),console.log("vj: getVariantIdsForFbStatusFetch returning",o),o},ee=(e,t,o)=>{if(console.log("fetchFbStatusAndDispatchProducts",{variantIdsToFetchFbStatus:e,fbStatusFetcher:R}),!R){const e=Object.assign({},t);if(Object.keys(t).forEach((o=>{var i,n,s;console.log("vj: response variants",null===(i=null==t?void 0:t[o])||void 0===i?void 0:i.variants),Object.keys(null!==(s=null===(n=null==t?void 0:t[o])||void 0===n?void 0:n.variants)&&void 0!==s?s:{}).forEach((i=>{var n,s;const c=null===(n=null==t?void 0:t[o].variants)||void 0===n?void 0:n[i];c&&(c.fbStatus="APPROVED");const l=null===(s=null==e?void 0:e[o])||void 0===s?void 0:s.variants;l&&l[i]&&(l[i]=c)}))})),console.log("vj: fetchFbStatusAndDispatchProducts updated Products",e),o){const t=Object.assign({},G);t.products=e,Q(t)}else p({type:"productsPaged",data:{collectionId:U,products:e}})}e.length>0&&R&&R(P,e).then((e=>{console.log("vj: response",{response:e,products:t});const i=Object.assign({},t);if(Object.keys(t).forEach((o=>{var n,s,c;console.log("vj: response variants",null===(n=null==t?void 0:t[o])||void 0===n?void 0:n.variants),Object.keys(null!==(c=null===(s=null==t?void 0:t[o])||void 0===s?void 0:s.variants)&&void 0!==c?c:{}).forEach((n=>{var s,c;const l=null===(s=null==t?void 0:t[o].variants)||void 0===s?void 0:s[n];console.log("vj: v",{v:l,vId:n,status:e[n],response:e}),l&&"REJECTED"===e[n]?l.fbStatus="REJECTED":l&&"APPROVED"===e[n]&&(l.fbStatus="APPROVED");const r=null===(c=null==i?void 0:i[o])||void 0===c?void 0:c.variants;r&&r[n]&&(r[n]=l)}))})),console.log("vj: updated Products",i),o){const e=Object.assign({},G);e.products=i,Q(e)}else p({type:"productsPaged",data:{collectionId:U,products:i}})})).catch((e=>{const i=Object.assign({},t);if(Object.keys(t).forEach((e=>{var o,n,s;console.log("vj: response variants",null===(o=null==t?void 0:t[e])||void 0===o?void 0:o.variants),Object.keys(null!==(s=null===(n=null==t?void 0:t[e])||void 0===n?void 0:n.variants)&&void 0!==s?s:{}).forEach((o=>{var n,s;const c=null===(n=null==t?void 0:t[e].variants)||void 0===n?void 0:n[o];c&&(c.fbStatus="APPROVED");const l=null===(s=null==i?void 0:i[e])||void 0===s?void 0:s.variants;l&&l[o]&&(l[o]=c)}))})),console.log("vj: fetchFbStatusAndDispatchProducts updated Products",i),o){const e=Object.assign({},G);e.products=i,Q(e)}else p({type:"productsPaged",data:{collectionId:U,products:i}})}))};s.useEffect((()=>{console.log("vj: observertarget",_.current);const e=new IntersectionObserver((e=>{console.log("vj: observertargetinside",e),e[0].isIntersecting&&(console.log("vj: nextPageRef",H.current,X),H.current>=0&&!X.current&&(S(!0),K(!0),C(U,P,10,H.current).then((e=>{if(console.log("vj: fetched products",e,X,Object.keys(e).length),Object.keys(e).length||(console.log("vj: setHasAllCollectionLoaded ",!0),X.current=!0),Object.keys(e).length){const t=G;t.products=Object.assign(Object.assign({},G.products),e),Q(t);const o=$(e);ee(o,e),H.current+=1}K(!1),S(!1)})).catch()))}),{threshold:1});return _.current&&e.observe(_.current),()=>{_.current&&e.unobserve(_.current)}}),[_]);const te=e=>{console.log("vj: getProductsForCollection"),S(!0),z(!0),C(U,P,e,0).then((t=>{if(Object.keys(t).length||(console.log("vj: setHasAllCollectionLoaded ",!0),X.current=!0),Object.keys(t).length){Q(Object.assign(Object.assign({},G),{products:t})),console.log("vj: next page when products loaded",H.current);const e=$(t);ee(e,t),H.current=1}console.log("vj: product data",{productData:t,limit:e,data:v}),e||I({type:"selected",data:{id:U,val:Object.assign(Object.assign({},v),{products:t})}}),S(!1),z(!1)})).catch()},oe=(e,t)=>{const o=k.liftTheStateUp(t,v);I({type:e,data:Object.assign(Object.assign({},o),{isRestricted:D})})};return e.jsxs("div",{children:[e.jsxs(y.ProductScreenHeader,{children:[e.jsx(d.IconButton,{Icon:t.default,height:16,onClick:()=>{m("collections")}}),e.jsx(j.BodyCaption,Object.assign({style:{color:c.COLORS.content.secondary}},{children:v.name}))]}),!E&&e.jsx("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(a.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>W&&M.length?e.jsx(h.Spinner,{size:"small",color:c.COLORS.content.primary}):e.jsx(i.default,{})},id:"listInput",height:"24px",type:"text",value:M,onChangeText:e=>{e.length&&e.trim().length?N(e):N("")},placeholder:"Search products in this collection..."})})),e.jsxs("div",{children:[Object.keys((null==G?void 0:G.products)||[]).length>0&&!Y&&!M.length&&!T&&"-1"!==U&&e.jsxs(y.ProductScreenCollectionCardStyle,{children:[e.jsx(r.CheckBox,{isChecked:!!(null==b?void 0:b[U]),isPartiallyChecked:(e=>{var t;let o=0,i=0;if(b[e]){const n=null==v?void 0:v.products;n&&Object.keys(n).forEach((e=>{var t;const i=null===(t=n[e])||void 0===t?void 0:t.variants;i&&Object.keys(i).forEach((e=>o+=1))}));const s=null===(t=b[e])||void 0===t?void 0:t.products;return s&&Object.keys(s).forEach((e=>{var t;const o=null===(t=s[e])||void 0===t?void 0:t.variants;o&&Object.keys(o).forEach((()=>i+=1))})),i>0&&o!==i}return!1})(U),onValueChange:function(e){e?te():I({type:"unselected",data:{id:U}})}}),e.jsx("div",Object.assign({style:{width:40,height:40}},{children:e.jsx(o.default,{})})),e.jsx(j.TitleRegular,{children:"All Products"})]}),Object.keys((null==G?void 0:G.products)||[]).length?Object.keys(G.products||[]).map((t=>e.jsx(x,{outOfStockAction:A,collectionId:U,isProductPartiallyChecked:Z(t),productId:t,data:G.products[t],selectedData:b,selectedCollectionsDispatch:I,viewOnly:!w&&!!Y,upliftAdditions:oe,hideProductCheckbox:T,hideVariantCheckbox:V,hideProductVariants:F,pickerType:q,onInfoIconClick:B,showProductDetailInfoIcon:L},t))):W?[1,2,3,4,5,6,7,8,9,10].map(((t,o)=>e.jsx("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),o))):e.jsx(g.EmptyState,{title:"No products to show",subtitle:M.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),e.jsx("div",{ref:_})]}),J&&[1,2,3,4,5].map(((t,o)=>e.jsx("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),o)))]})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),o=require("../../assets/icons/box.svg.js"),c=require("../../assets/icons/search.svg.js"),i=require("lodash"),n=require("react"),s=require("../../constants/Theme.js"),r=require("../../assets/icons/info.svg.js"),l=require("../checkBox/CheckBox.js"),d=require("../icon-button/IconButton.js"),a=require("../input/Input.js"),u=require("../shimmer/ShimmerComponent/BikShimmer.js"),h=require("../shimmer-image/ShimmerImage.js"),v=require("../spinner/Spinner.js"),p=require("../tooltips/Tooltip.js"),j=require("../TypographyStyle.js"),g=require("./emptyState.js"),b=require("./ProductPickerTag.js"),f=require("./reducers.js"),x=require("./style.js"),I=require("./type.js"),y=require("./utility.js");const k=t=>{const{collectionId:o,productId:c,data:i,selectedData:n,selectedCollectionsDispatch:s,viewOnly:r,upliftAdditions:l,isProductPartiallyChecked:d,hideProductCheckbox:a,outOfStockAction:u,hideVariantCheckbox:h,hideProductVariants:v,pickerType:p,onInfoIconClick:j,showProductDetailInfoIcon:g}=t,b=e=>{var t,i,s,r,l,d;if(!(null===(i=null===(t=null==n?void 0:n[o])||void 0===t?void 0:t.products)||void 0===i?void 0:i[c]))return!1;return!!(null===(d=null===(l=null===(r=null===(s=null==n?void 0:n[o])||void 0===s?void 0:s.products)||void 0===r?void 0:r[c])||void 0===l?void 0:l.variants)||void 0===d?void 0:d[e])};return e.jsxs("div",{children:[e.jsx(O,{isVariant:!1,data:i,productId:c,collectionId:o,isSelected:!!(null===(x=null===(f=null==n?void 0:n[o])||void 0===f?void 0:f.products)||void 0===x?void 0:x[c]),isPartiallyChecked:d,selectedCollectionsDispatch:s,upliftAdditions:l,viewOnly:r,hideProductCheckbox:a,hideVariantCheckbox:h,hideProductVariants:v,pickerType:p,outOfStockAction:u,onInfoIconClick:j,showProductDetailInfoIcon:g},c),v?null:Object.keys(i.variants||[]).length>1&&Object.keys(i.variants||[]).map((t=>e.jsx(O,{isVariant:!0,hideVariantCheckbox:h,data:i.variants[t],variantId:t,productId:c,viewOnly:r,upliftAdditions:l,collectionId:o,isSelected:b(t),selectedCollectionsDispatch:s,outOfStockAction:u,onInfoIconClick:j,showProductDetailInfoIcon:g},t)))]});var f,x},O=t=>{const{isVariant:o,data:c,productId:i,collectionId:n,variantId:a,isSelected:u,selectedCollectionsDispatch:v,viewOnly:g,upliftAdditions:f,isPartiallyChecked:I,hideProductCheckbox:y,outOfStockAction:k,hideVariantCheckbox:O,hideProductVariants:C,pickerType:m,onInfoIconClick:P,showProductDetailInfoIcon:S}=t;return e.jsxs(x.ProductCardStyle,Object.assign({isVariant:o,onClick:e=>{"PRODUCT"===m&&C&&(e.stopPropagation(),v({type:"reset",data:{}}),f("variantSelected",{productId:i,variantId:a||Object.keys(c.variants)[0],collectionId:n,variant:c}))},isActive:u},{children:[o&&!g&&!O||!o&&!g&&!y?e.jsx(l.CheckBox,{isChecked:u,isPartiallyChecked:I||!1,onValueChange:function(e){o?e?f("variantSelected",{productId:i,variantId:a,collectionId:n,variant:c}):v({type:"variantUnselected",data:{productId:i,variantId:a,collectionId:n}}):e?f("productSelected",{productId:i,collectionId:n,product:c}):v({type:"productUnselected",data:{productId:i,collectionId:n}})}}):e.jsx(e.Fragment,{}),e.jsx("div",{children:e.jsx(h.ShimmerImage,{width:40,height:40,imageUrl:c.image,alt:"Item",borderRadius:4})}),e.jsx(p.Tooltip,Object.assign({variant:"light",body:c.name,placement:"bottom",delay:400},{children:e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",flex:1}},{children:[e.jsxs("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},{children:[e.jsx(j.BodyPrimary,Object.assign({numberOfLines:1},{children:c.name})),S&&e.jsx(d.IconButton,{onClick:()=>{null==P||P(c)},Icon:()=>e.jsx(r.default,{width:20,height:20,color:s.COLORS.content.placeholder})})]})),e.jsx(b.ProductPickerTag,{isVariant:o,data:c,outOfStockAction:k})]}))}))]}))};exports.ProductCard=O,exports.ProductGroup=k,exports.ProductsScreen=r=>{const{data:h,collectionsDispatch:p,selectedData:b,selectedCollectionsDispatch:O,productFetcher:C,storeId:m,setScreen:P,setSaveDisabled:S,hideInCollectionSearch:A,customCollectionRestriction:E,hideProductCheckbox:T,outOfStockAction:V=I.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:D=!1,selectProductsFromCustomCollection:w=!1,pickerType:q,hideProductVariants:R,fbStatusFetcher:B,onInfoIconClick:F,showProductDetailInfoIcon:L}=r,U=n.useContext(f.CollectionIdContext),_=n.useRef(null),H=n.useRef(0),[J,K]=n.useState(!1),[M,N]=n.useState(""),[W,z]=n.useState(!1),[G,Q]=n.useState(h),X=n.useRef(!1);n.useEffect((()=>{const e=setTimeout((()=>{M.length?(z(!0),r.searchInCollectionFetcher(m,U,M).then((e=>{const t=i.cloneDeep(h);t.products=e,Q(t);const o=y.getVariantIdsToFetchAtProductLevel(null!=e?e:{},h);$(o,null!=e?e:{},!0),S(!1),z(!1)}))):Q(h)}),800);return()=>clearTimeout(e)}),[M]),n.useEffect((()=>{var e,t,o,c,i,n,s,r;console.log("vj: collectionId change before",h,h.products,null===(t=Object.keys(null!==(e=h.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length,X),X.current=!1,H.current=Math.floor((null===(c=Object.keys(null!==(o=h.products)&&void 0!==o?o:{}))||void 0===c?void 0:c.length)/10);const l=y.getVariantIdsToFetchAtProductLevel(null!==(i=h.products)&&void 0!==i?i:{});$(l,null!==(n=h.products)&&void 0!==n?n:{}),console.log("vj: collectionId change after",h,h.products,null===(r=Object.keys(null!==(s=h.products)&&void 0!==s?s:{}))||void 0===r?void 0:r.length,X)}),[U]);const Y=!!E&&h.isSmartCollection,Z=e=>{var t,o,c,i,n,s,r,l;let d=0,a=0;return!!((null===(o=null===(t=null==b?void 0:b[U])||void 0===t?void 0:t.products)||void 0===o?void 0:o[e])&&(null===(n=Object.keys((null===(i=null===(c=null==h?void 0:h.products)||void 0===c?void 0:c[e])||void 0===i?void 0:i.variants)||[]))||void 0===n||n.forEach((()=>a++)),Object.keys((null===(l=null===(r=null===(s=null==b?void 0:b[U])||void 0===s?void 0:s.products)||void 0===r?void 0:r[e])||void 0===l?void 0:l.variants)||[]).forEach((()=>d++)),d>0&&a!==d))};n.useEffect((()=>{(null==h?void 0:h.products)||ee(10)}),[]);const $=(e,t,o)=>{console.log("fetchFbStatusAndDispatchProducts",{variantIdsToFetchFbStatus:e,fbStatusFetcher:B}),B||(o?y.markVariantsAsApprovedProductsLevel(t,p,U,G,Q):y.markVariantsAsApprovedProductsLevel(t,p,U)),e.length>0&&B&&B(m,e).then((e=>{console.log("vj: response",{response:e,products:t});const c=Object.assign({},t);if(Object.keys(t).forEach((o=>{var i,n,s;console.log("vj: response variants",null===(i=null==t?void 0:t[o])||void 0===i?void 0:i.variants),Object.keys(null!==(s=null===(n=null==t?void 0:t[o])||void 0===n?void 0:n.variants)&&void 0!==s?s:{}).forEach((i=>{var n,s;const r=null===(n=null==t?void 0:t[o].variants)||void 0===n?void 0:n[i];console.log("vj: v",{v:r,vId:i,status:e[i],response:e}),r&&"REJECTED"===e[i]?r.fbStatus="REJECTED":r&&"APPROVED"===e[i]&&(r.fbStatus="APPROVED");const l=null===(s=null==c?void 0:c[o])||void 0===s?void 0:s.variants;l&&l[i]&&(l[i]=r)}))})),o){const e=Object.assign({},G);e.products=c,Q(e)}else p({type:"productsPaged",data:{collectionId:U,products:c}})})).catch((e=>{o?y.markVariantsAsApprovedProductsLevel(t,p,U,G,Q):y.markVariantsAsApprovedProductsLevel(t,p,U)}))};n.useEffect((()=>{console.log("vj: observertarget",_.current);const e=new IntersectionObserver((e=>{console.log("vj: observertargetinside",e),e[0].isIntersecting&&(console.log("vj: nextPageRef",H.current,X),H.current>=0&&!X.current&&(S(!0),K(!0),C(U,m,10,H.current).then((e=>{if(console.log("vj: fetched products",e,X,Object.keys(e).length),Object.keys(e).length||(console.log("vj: setHasAllCollectionLoaded ",!0),X.current=!0),Object.keys(e).length){const t=G;t.products=Object.assign(Object.assign({},G.products),e),Q(t);const o=y.getVariantIdsToFetchAtProductLevel(e);$(o,e),H.current+=1}K(!1),S(!1)})).catch()))}),{threshold:1});return _.current&&e.observe(_.current),()=>{_.current&&e.unobserve(_.current)}}),[_]);const ee=e=>{console.log("vj: getProductsForCollection"),S(!0),z(!0),C(U,m,e,0).then((t=>{if(Object.keys(t).length||(console.log("vj: setHasAllCollectionLoaded ",!0),X.current=!0),Object.keys(t).length){Q(Object.assign(Object.assign({},G),{products:t})),console.log("vj: next page when products loaded",H.current);const e=y.getVariantIdsToFetchAtProductLevel(t);$(e,t),H.current=1}console.log("vj: product data",{productData:t,limit:e,data:h}),e||O({type:"selected",data:{id:U,val:Object.assign(Object.assign({},h),{products:t})}}),S(!1),z(!1)})).catch()},te=(e,t)=>{const o=y.liftTheStateUp(t,h);O({type:e,data:Object.assign(Object.assign({},o),{isRestricted:E})})};return e.jsxs("div",{children:[e.jsxs(x.ProductScreenHeader,{children:[e.jsx(d.IconButton,{Icon:t.default,height:16,onClick:()=>{P("collections")}}),e.jsx(j.BodyCaption,Object.assign({style:{color:s.COLORS.content.secondary}},{children:h.name}))]}),!A&&e.jsx("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(a.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>W&&M.length?e.jsx(v.Spinner,{size:"small",color:s.COLORS.content.primary}):e.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:M,onChangeText:e=>{e.length&&e.trim().length?N(e):N("")},placeholder:"Search products in this collection..."})})),e.jsxs("div",{children:[Object.keys((null==G?void 0:G.products)||[]).length>0&&!Y&&!M.length&&!T&&"-1"!==U&&e.jsxs(x.ProductScreenCollectionCardStyle,{children:[e.jsx(l.CheckBox,{isChecked:!!(null==b?void 0:b[U]),isPartiallyChecked:(e=>{var t;let o=0,c=0;if(b[e]){const i=null==h?void 0:h.products;i&&Object.keys(i).forEach((e=>{var t;const c=null===(t=i[e])||void 0===t?void 0:t.variants;c&&Object.keys(c).forEach((e=>o+=1))}));const n=null===(t=b[e])||void 0===t?void 0:t.products;return n&&Object.keys(n).forEach((e=>{var t;const o=null===(t=n[e])||void 0===t?void 0:t.variants;o&&Object.keys(o).forEach((()=>c+=1))})),c>0&&o!==c}return!1})(U),onValueChange:function(e){e?ee():O({type:"unselected",data:{id:U}})}}),e.jsx("div",Object.assign({style:{width:40,height:40}},{children:e.jsx(o.default,{})})),e.jsx(j.TitleRegular,{children:"All Products"})]}),Object.keys((null==G?void 0:G.products)||[]).length?Object.keys(G.products||[]).map((t=>e.jsx(k,{outOfStockAction:V,collectionId:U,isProductPartiallyChecked:Z(t),productId:t,data:G.products[t],selectedData:b,selectedCollectionsDispatch:O,viewOnly:!w&&!!Y,upliftAdditions:te,hideProductCheckbox:T,hideVariantCheckbox:D,hideProductVariants:R,pickerType:q,onInfoIconClick:F,showProductDetailInfoIcon:L},t))):W?[1,2,3,4,5,6,7,8,9,10].map(((t,o)=>e.jsx("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),o))):e.jsx(g.EmptyState,{title:"No products to show",subtitle:M.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),e.jsx("div",{ref:_})]}),J&&[1,2,3,4,5].map(((t,o)=>e.jsx("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),o)))]})};
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { Collection, SelectedItems } from '.';
2
+ import { Collection, SearchedItems, SelectedItems } from '.';
3
3
  export interface SelectedCollectionsActions {
4
4
  type: string;
5
5
  data: {
@@ -15,5 +15,9 @@ export interface CollectionsActions {
15
15
  }
16
16
  export declare function collectionsReducer(collections: Collection, action: CollectionsActions): any;
17
17
  export declare function paginationReducer(collections: SelectedItems, action: SelectedCollectionsActions): SelectedItems;
18
- export declare function searchReducer(collections: SelectedItems, action: SelectedCollectionsActions): SelectedItems;
18
+ export interface SearchReducerActions {
19
+ type: string;
20
+ data: SearchedItems;
21
+ }
22
+ export declare function searchReducer(collections: SearchedItems, action: SearchReducerActions): SearchedItems;
19
23
  export declare const CollectionIdContext: import("react").Context<string>;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("lodash");const e=require("react").createContext("");exports.CollectionIdContext=e,exports.collectionsReducer=function(t,e){let a={};switch(e.type){case"fetched":return a=Object.assign({},e.data),a;case"productsFetched":return console.log("vj: productsFetched",{collections:t,action:e}),a=Object.assign({},t),a[e.data.collectionId].products=e.data.products,console.log("vj: collectionsCopy",{collectionsCopy:a}),a;case"paged":return console.log("vj: paged",{collections:t,action:e}),a=Object.assign(Object.assign({},t),e.data),a;case"productsPaged":return console.log("vj: pagedProducts",{collections:t,action:e}),a=Object.assign({},t),e.data.collectionId,a[e.data.collectionId].products=Object.assign(Object.assign({},a[e.data.collectionId].products),e.data.products),a;default:return{}}},exports.paginationReducer=function(t,e){let a={};switch(e.type){case"paginate":console.log("vj: paginate",e),a=Object.assign({},t);for(const t in e.data)if(Object.prototype.hasOwnProperty.call(e.data,t)){const o=e.data[t];if(Object.prototype.hasOwnProperty.call(a,t)){const e=a[t];a[t]=Object.assign(Object.assign({},e),{products:Object.assign(Object.assign({},e.products),o.products)})}else a[t]=o}return console.log("vj: collections copy",a),a;case"update":return console.log("vj: update",e),a=Object.assign({},t),console.log("vj: update collection",e),a;case"set":return a=Object.assign(Object.assign({},t),e.data),console.log("vj: update collection",e),a;case"filter":a={};for(const o in t)if(o in e.data){const c=Object.assign({},t[o]),s=e.data[o],d={};for(const t in c.products)if(t in s.products){const e=Object.assign({},c.products[t]),a=s.products[t],o={};for(const t in e.variants)t in a.variants&&(o[t]=Object.assign({},e.variants[t]));Object.keys(o).length>0&&(e.variants=o,d[t]=e)}Object.keys(d).length>0&&(c.products=d,a[o]=c)}return a;default:return t}},exports.searchReducer=function(t,e){return"set"===e.type?e.data:t},exports.selectedColectionsReducer=function(e,a){var o,c,s,d,n,l;let r={},i="",u="",p="";switch(a.type){case"selected":return console.log("vj: selectedColectionsReducer selected",a),r=t.cloneDeep(e),a.data.val.isSmartCollection&&(a.data.isRestricted&&(r={}),r.isCustom=!0),r[a.data.id]=a.data.val,r;case"unselected":return r=t.cloneDeep(e),(null==r?void 0:r.isCustom)&&(r.isCustom=!1),delete r[a.data.id],r;case"productUnselected":return r=t.cloneDeep(e),i=a.data.productId,u=a.data.collectionId,delete r[u].products[i],Object.keys(r[u].products).length||((null==r?void 0:r.isCustom)&&(r.isCustom=!1),delete r[u]),r;case"productSelected":return r=t.cloneDeep(e),i=a.data.productId,u=a.data.collectionId,(null===(o=a.data.catalogOnlyData)||void 0===o?void 0:o.isSmartCollection)&&(a.data.isRestricted&&(r={}),r.isCustom=!0),(null==r?void 0:r[u])||(r[u]=a.data.catalogOnlyData,r[u].products={}),r[u].products[i]=a.data.product,r;case"variantSelected":return r=t.cloneDeep(e),i=a.data.productId,u=a.data.collectionId,p=a.data.variantId,(null===(c=a.data.catalogOnlyData)||void 0===c?void 0:c.isSmartCollection)&&(a.data.isRestricted&&(r={}),r.isCustom=!0),(null==r?void 0:r[u])||(r[u]=a.data.catalogOnlyData,r[u].products={},r[u].products[i]=a.data.productOnlyData,r[u].products[i].variants={}),(null===(d=null===(s=null==r?void 0:r[u])||void 0===s?void 0:s.products)||void 0===d?void 0:d[i])||((null===(n=null==r?void 0:r[u])||void 0===n?void 0:n.products)||(r[u].products={}),r[u].products[i]=a.data.productOnlyData,r[u].products[i].variants={}),r[u].products[i].variants[p]=a.data.variant,r;case"variantUnselected":return r=t.cloneDeep(e),i=a.data.productId,u=a.data.collectionId,p=a.data.variantId,delete r[u].products[i].variants[p],Object.keys(r[u].products[i].variants).length||(delete r[u].products[i],Object.keys(r[u].products).length||((null===(l=r[u])||void 0===l?void 0:l.isSmartCollection)&&(r.isCustom=!1),delete r[u])),r;case"update":default:return e;case"reset":return{}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("lodash");const e=require("react").createContext("");exports.CollectionIdContext=e,exports.collectionsReducer=function(t,e){let a={};switch(e.type){case"fetched":return a=Object.assign({},e.data),a;case"productsFetched":return a=Object.assign({},t),a[e.data.collectionId].products=e.data.products,a;case"paged":return a=Object.assign(Object.assign({},t),e.data),a;case"productsPaged":return a=Object.assign({},t),a[e.data.collectionId].products=Object.assign(Object.assign({},a[e.data.collectionId].products),e.data.products),a;default:return{}}},exports.paginationReducer=function(t,e){let a={};switch(e.type){case"paginate":console.log("vj: paginate",e),a=Object.assign({},t);for(const t in e.data)if(Object.prototype.hasOwnProperty.call(e.data,t)){const s=e.data[t];if(Object.prototype.hasOwnProperty.call(a,t)){const e=a[t];a[t]=Object.assign(Object.assign({},e),{products:Object.assign(Object.assign({},e.products),s.products)})}else a[t]=s}return a;case"update":return a=Object.assign({},t),a;case"set":return a=Object.assign(Object.assign({},t),e.data),a;case"filter":a={};for(const s in t)if(s in e.data){const c=Object.assign({},t[s]),d=e.data[s],o={};for(const t in c.products)if(t in d.products){const e=Object.assign({},c.products[t]),a=d.products[t],s={};for(const t in e.variants)t in a.variants&&(s[t]=Object.assign({},e.variants[t]));Object.keys(s).length>0&&(e.variants=s,o[t]=e)}Object.keys(o).length>0&&(c.products=o,a[s]=c)}return a;default:return t}},exports.searchReducer=function(t,e){return"set"===e.type?e.data:t},exports.selectedColectionsReducer=function(e,a){var s,c,d,o,r,n;let i={},l="",u="",p="";switch(a.type){case"selected":return i=t.cloneDeep(e),a.data.val.isSmartCollection&&(a.data.isRestricted&&(i={}),i.isCustom=!0),i[a.data.id]=a.data.val,i;case"unselected":return i=t.cloneDeep(e),(null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[a.data.id],i;case"productUnselected":return i=t.cloneDeep(e),l=a.data.productId,u=a.data.collectionId,delete i[u].products[l],Object.keys(i[u].products).length||((null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[u]),i;case"productSelected":return i=t.cloneDeep(e),l=a.data.productId,u=a.data.collectionId,(null===(s=a.data.catalogOnlyData)||void 0===s?void 0:s.isSmartCollection)&&(a.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[u])||(i[u]=a.data.catalogOnlyData,i[u].products={}),i[u].products[l]=a.data.product,i;case"variantSelected":return i=t.cloneDeep(e),l=a.data.productId,u=a.data.collectionId,p=a.data.variantId,(null===(c=a.data.catalogOnlyData)||void 0===c?void 0:c.isSmartCollection)&&(a.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[u])||(i[u]=a.data.catalogOnlyData,i[u].products={},i[u].products[l]=a.data.productOnlyData,i[u].products[l].variants={}),(null===(o=null===(d=null==i?void 0:i[u])||void 0===d?void 0:d.products)||void 0===o?void 0:o[l])||((null===(r=null==i?void 0:i[u])||void 0===r?void 0:r.products)||(i[u].products={}),i[u].products[l]=a.data.productOnlyData,i[u].products[l].variants={}),i[u].products[l].variants[p]=a.data.variant,i;case"variantUnselected":return i=t.cloneDeep(e),l=a.data.productId,u=a.data.collectionId,p=a.data.variantId,delete i[u].products[l].variants[p],Object.keys(i[u].products[l].variants).length||(delete i[u].products[l],Object.keys(i[u].products).length||((null===(n=i[u])||void 0===n?void 0:n.isSmartCollection)&&(i.isCustom=!1),delete i[u])),i;case"update":return i=Object.assign({},e),i;case"reset":return{};default:return e}};
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" />
2
- import { Collection, FbStatusFetcherReturn, SelectedItems } from '.';
3
- import { SelectedCollectionsActions } from './reducers';
2
+ import { Collection, FbStatusFetcherReturn, SearchedItems, SelectedItems } from '.';
3
+ import { SearchReducerActions, SelectedCollectionsActions } from './reducers';
4
4
  interface SearchScreenInterface {
5
5
  customCollectionRestriction?: boolean;
6
6
  selectedCollections: SelectedItems;
7
- searchedCollections: SelectedItems;
8
- searchedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>;
7
+ searchedCollections: SearchedItems;
8
+ searchedCollectionsDispatch: React.Dispatch<SearchReducerActions>;
9
9
  selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>;
10
10
  setScreen: React.Dispatch<React.SetStateAction<string>>;
11
11
  collections: {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),o=require("react"),i=require("../icon-button/IconButton.js"),r=require("../TypographyStyle.js"),c=require("./emptyState.js"),s=require("./productScreen.js"),l=require("./style.js"),d=require("./utility.js");exports.SearchScreen=n=>{const{customCollectionRestriction:u,selectedCollections:a,searchedCollections:v,searchedCollectionsDispatch:h,selectedCollectionsDispatch:p,setScreen:j,collections:y,onBackPress:b,hideVariantCheckbox:k,pickerType:x,hideProductVariants:C,hideProductCheckbox:f,storeId:S,fbStatusFetcher:P}=n;o.useEffect((()=>{d.fetchFbStatusCollection(v,S,h,P,"set")}),[v]);const q=(e,t)=>{var o,i,r,c,s,l,d,n,u;let v=0,h=0;return!!((null===(i=null===(o=null==a?void 0:a[e])||void 0===o?void 0:o.products)||void 0===i?void 0:i[t])&&(null===(l=Object.keys((null===(s=null===(c=null===(r=null==y?void 0:y[e])||void 0===r?void 0:r.products)||void 0===c?void 0:c[t])||void 0===s?void 0:s.variants)||[]))||void 0===l||l.forEach((()=>h++)),Object.keys((null===(u=null===(n=null===(d=null==a?void 0:a[e])||void 0===d?void 0:d.products)||void 0===n?void 0:n[t])||void 0===u?void 0:u.variants)||[]).forEach((()=>v++)),v>0&&h!==v))};return e.jsxs("div",{children:[e.jsxs(l.SelectedScreenHeader,{children:[e.jsx(i.IconButton,{Icon:t.default,onClick:()=>{j("collections"),b()}}),e.jsx(r.BodyCaption,{children:"Searched Products"})]}),e.jsx("div",{children:Object.keys(v).length?e.jsx(e.Fragment,{children:Object.keys(v).map((t=>{var o;return Object.keys((null===(o=null==v?void 0:v[t])||void 0===o?void 0:o.products)||[]).map((o=>{let i=!1;return(null==v?void 0:v.isCustom)&&(i=!0),e.jsx(s.ProductGroup,{collectionId:t,upliftAdditions:(e,o)=>((e,t,o)=>{const i=d.liftTheStateUp(o,v[e]);p({type:t,data:Object.assign(Object.assign({},i),{isRestricted:u})})})(t,e,o),productId:o,data:v[t].products[o],isProductPartiallyChecked:q(t,o),selectedData:a,selectedCollectionsDispatch:p,viewOnly:i,hideProductCheckbox:f,hideVariantCheckbox:k,hideProductVariants:C,pickerType:x},o)}))}))}):e.jsx(c.EmptyState,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),o=require("react"),i=require("../icon-button/IconButton.js"),r=require("../TypographyStyle.js"),l=require("./emptyState.js"),d=require("./productScreen.js"),c=require("./style.js"),s=require("./utility.js");exports.SearchScreen=u=>{const{customCollectionRestriction:n,selectedCollections:a,searchedCollections:v,searchedCollectionsDispatch:p,selectedCollectionsDispatch:h,setScreen:j,collections:y,onBackPress:b,hideVariantCheckbox:k,pickerType:x,hideProductVariants:C,hideProductCheckbox:f,storeId:S,fbStatusFetcher:P}=u;o.useEffect((()=>{var e;s.fetchFbStatusCollection(null!==(e=v.products)&&void 0!==e?e:{},S,p,P,"set")}),[null==v?void 0:v.products]);const q=(e,t)=>{var o,i,r,l,d,c,s,u,n;let v=0,p=0;return!!((null===(i=null===(o=null==a?void 0:a[e])||void 0===o?void 0:o.products)||void 0===i?void 0:i[t])&&(null===(c=Object.keys((null===(d=null===(l=null===(r=null==y?void 0:y[e])||void 0===r?void 0:r.products)||void 0===l?void 0:l[t])||void 0===d?void 0:d.variants)||[]))||void 0===c||c.forEach((()=>p++)),Object.keys((null===(n=null===(u=null===(s=null==a?void 0:a[e])||void 0===s?void 0:s.products)||void 0===u?void 0:u[t])||void 0===n?void 0:n.variants)||[]).forEach((()=>v++)),v>0&&p!==v))};return e.jsxs("div",{children:[e.jsxs(c.SelectedScreenHeader,{children:[e.jsx(i.IconButton,{Icon:t.default,onClick:()=>{j("collections"),b()}}),e.jsx(r.BodyCaption,{children:"Searched Products"})]}),e.jsx("div",{children:Object.keys(null==v?void 0:v.products).length?e.jsx(e.Fragment,{children:Object.keys(null==v?void 0:v.products).map((t=>{var o,i;return Object.keys((null===(i=null===(o=null==v?void 0:v.products)||void 0===o?void 0:o[t])||void 0===i?void 0:i.products)||[]).map((o=>{var i,r;let l=!1;return(null===(i=null==v?void 0:v.products)||void 0===i?void 0:i.isCustom)&&(l=!0),e.jsx(d.ProductGroup,{collectionId:t,upliftAdditions:(e,o)=>((e,t,o)=>{var i;const r=s.liftTheStateUp(o,null===(i=null==v?void 0:v.products)||void 0===i?void 0:i[e]);h({type:t,data:Object.assign(Object.assign({},r),{isRestricted:n})})})(t,e,o),productId:o,data:(null===(r=null==v?void 0:v.products)||void 0===r?void 0:r[t].products)[o],isProductPartiallyChecked:q(t,o),selectedData:a,selectedCollectionsDispatch:h,viewOnly:l,hideProductCheckbox:f,hideVariantCheckbox:k,hideProductVariants:C,pickerType:x},o)}))}))}):e.jsx(l.EmptyState,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};
@@ -1,6 +1,13 @@
1
- import { Collection, FbStatusFetcherReturn, SelectedItems } from './modal';
1
+ import { Collection, FbStatusFetcherReturn, Product, SelectedItems } from './modal';
2
+ import { CollectionsActions } from './reducers';
2
3
  export declare const liftTheStateUp: (payload: any, data: any) => any;
3
4
  export declare function paginateSelectedItems(selectedItems: SelectedItems, limit: number, offset: number): {
4
5
  [key: string]: Collection;
5
6
  };
6
7
  export declare const fetchFbStatusCollection: (data: SelectedItems, storeId: string, dispatcher: any, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, dispatchType?: string) => void;
8
+ export declare const getVariantIdsToFetchAtProductLevel: (products: {
9
+ [key: string]: Product;
10
+ }, globalData?: Collection) => string[];
11
+ export declare const markVariantsAsApprovedProductsLevel: (products: {
12
+ [key: string]: Product;
13
+ }, dispatcher: React.Dispatch<CollectionsActions>, collectionId: string, curScreenData?: Collection, setCurScreenData?: React.Dispatch<React.SetStateAction<Collection>>) => void;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("lodash");function t(o,t,n){if(!o)return{};const l=Object.keys(o).slice(n,n+t),e={};return l.forEach((t=>{e[t]=o[t]})),e}const n=(o,t,n)=>{Object.keys(o).forEach((t=>{var n,l;const e=null!==(l=null===(n=o[t])||void 0===n?void 0:n.products)&&void 0!==l?l:{};Object.keys(e).forEach((n=>{var l,e,s,d;const i=null!==(d=null===(s=null===(e=null===(l=o[t])||void 0===l?void 0:l.products)||void 0===e?void 0:e[n])||void 0===s?void 0:s.variants)&&void 0!==d?d:{};Object.keys(i).forEach((l=>{var e,s,d,i;const c=null===(i=null===(d=null===(s=null===(e=o[t])||void 0===e?void 0:e.products)||void 0===s?void 0:s[n])||void 0===d?void 0:d.variants)||void 0===i?void 0:i[l];c&&!c.fbStatus&&(c.fbStatus="APPROVED")}))}))})),t({type:n,data:o})};exports.fetchFbStatusCollection=function(o,t,l,e){let s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";e||n(o,l,s);const d=(o=>{const t=[];return Object.keys(o).forEach((n=>{var l,e;const s=null!==(e=null===(l=o[n])||void 0===l?void 0:l.products)&&void 0!==e?e:{};Object.keys(s).forEach((l=>{var e,s,d,i;const c=null!==(i=null===(d=null===(s=null===(e=o[n])||void 0===e?void 0:e.products)||void 0===s?void 0:s[l])||void 0===d?void 0:d.variants)&&void 0!==i?i:{};Object.keys(c).forEach((e=>{var s,d,i,c;const a=null===(c=null===(i=null===(d=null===(s=o[n])||void 0===s?void 0:s.products)||void 0===d?void 0:d[l])||void 0===i?void 0:i.variants)||void 0===c?void 0:c[e];(null==a?void 0:a.fbStatus)||t.push(e)}))}))})),t})(o);console.log("vj: variantids",d),d.length>0&&e&&e(t,d).then((t=>{const n=Object.assign({},o);Object.keys(n).forEach((o=>{var l,e;const s=null!==(e=null===(l=n[o])||void 0===l?void 0:l.products)&&void 0!==e?e:{};Object.keys(s).forEach((l=>{var e,s,d,i;const c=null!==(i=null===(d=null===(s=null===(e=n[o])||void 0===e?void 0:e.products)||void 0===s?void 0:s[l])||void 0===d?void 0:d.variants)&&void 0!==i?i:{};Object.keys(c).forEach((e=>{var s,d,i,c;const a=null===(c=null===(i=null===(d=null===(s=n[o])||void 0===s?void 0:s.products)||void 0===d?void 0:d[l])||void 0===i?void 0:i.variants)||void 0===c?void 0:c[e];a&&"REJECTED"===t[e]?a.fbStatus="REJECTED":a&&"APPROVED"===t[e]&&(a.fbStatus="APPROVED")}))}))})),console.log("updated data",n,s),l({type:s,data:n})})).catch((t=>{console.error("Error in fbStatusFetcher",t),n(o,l,s)}))},exports.liftTheStateUp=(t,n)=>{const l=o.cloneDeep(n);if(delete l.products,(t=Object.assign(Object.assign({},t),{catalogOnlyData:l})).productId&&n.products){const e=o.cloneDeep(n.products[t.productId]);(null==e?void 0:e.variants)&&delete e.variants,t=Object.assign(Object.assign({},t),{catalogOnlyData:l,productOnlyData:e})}return t},exports.paginateSelectedItems=function(o,n,l){var e;const s={};let d=0;console.log("paginated offset",l);for(const i in o)if(Object.prototype.hasOwnProperty.call(o,i)){const c=o[i],a=t(c.products,n,l-d);a&&Object.keys(a).length>0&&(s[i]=Object.assign(Object.assign({},c),{products:a})),d+=Object.keys(null!==(e=c.products)&&void 0!==e?e:{}).length}return s};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("lodash");function t(o,t,l){if(!o)return{};const n=Object.keys(o).slice(l,l+t),d={};return n.forEach((t=>{d[t]=o[t]})),d}const l=(o,t,l)=>{Object.keys(o).forEach((t=>{var l,n;const d=null!==(n=null===(l=o[t])||void 0===l?void 0:l.products)&&void 0!==n?n:{};Object.keys(d).forEach((l=>{var n,d,i,s;const e=null!==(s=null===(i=null===(d=null===(n=o[t])||void 0===n?void 0:n.products)||void 0===d?void 0:d[l])||void 0===i?void 0:i.variants)&&void 0!==s?s:{};Object.keys(e).forEach((n=>{var d,i,s,e;const v=null===(e=null===(s=null===(i=null===(d=o[t])||void 0===d?void 0:d.products)||void 0===i?void 0:i[l])||void 0===s?void 0:s.variants)||void 0===e?void 0:e[n];v&&!v.fbStatus&&(v.fbStatus="APPROVED")}))}))})),t({type:l,data:o})};exports.fetchFbStatusCollection=function(o,t,n,d){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";d||l(o,n,i);const s=(o=>{const t=[];return Object.keys(o).forEach((l=>{var n,d;const i=null!==(d=null===(n=o[l])||void 0===n?void 0:n.products)&&void 0!==d?d:{};Object.keys(i).forEach((n=>{var d,i,s,e;const v=null!==(e=null===(s=null===(i=null===(d=o[l])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)&&void 0!==e?e:{};Object.keys(v).forEach((d=>{var i,s,e,v;const a=null===(v=null===(e=null===(s=null===(i=o[l])||void 0===i?void 0:i.products)||void 0===s?void 0:s[n])||void 0===e?void 0:e.variants)||void 0===v?void 0:v[d];(null==a?void 0:a.fbStatus)||t.push(d)}))}))})),t})(o);console.log("vj: variantids",s),s.length>0&&d&&d(t,s).then((t=>{const l=Object.assign({},o);Object.keys(l).forEach((o=>{var n,d;const i=null!==(d=null===(n=l[o])||void 0===n?void 0:n.products)&&void 0!==d?d:{};Object.keys(i).forEach((n=>{var d,i,s,e;const v=null!==(e=null===(s=null===(i=null===(d=l[o])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)&&void 0!==e?e:{};Object.keys(v).forEach((d=>{var i,s,e,v;const a=null===(v=null===(e=null===(s=null===(i=l[o])||void 0===i?void 0:i.products)||void 0===s?void 0:s[n])||void 0===e?void 0:e.variants)||void 0===v?void 0:v[d];a&&"REJECTED"===t[d]?a.fbStatus="REJECTED":a&&"APPROVED"===t[d]&&(a.fbStatus="APPROVED")}))}))})),console.log("updated data",l,i),n({type:i,data:l})})).catch((t=>{console.error("Error in fbStatusFetcher",t),l(o,n,i)}))},exports.getVariantIdsToFetchAtProductLevel=(o,t)=>{const l=[];return Object.keys(null!=o?o:{}).forEach((n=>{var d,i;const s=null!==(i=null===(d=null==o?void 0:o[n])||void 0===d?void 0:d.variants)&&void 0!==i?i:{};Object.keys(s).forEach((d=>{var i,s,e,v,a;let c;c=t?null===(e=null===(s=null===(i=null==t?void 0:t.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)||void 0===e?void 0:e[d]:null===(a=null===(v=null==o?void 0:o[n])||void 0===v?void 0:v.variants)||void 0===a?void 0:a[d],(null==c?void 0:c.fbStatus)||l.push(d)}))})),l},exports.liftTheStateUp=(t,l)=>{const n=o.cloneDeep(l);if(delete n.products,(t=Object.assign(Object.assign({},t),{catalogOnlyData:n})).productId&&l.products){const d=o.cloneDeep(l.products[t.productId]);(null==d?void 0:d.variants)&&delete d.variants,t=Object.assign(Object.assign({},t),{catalogOnlyData:n,productOnlyData:d})}return t},exports.markVariantsAsApprovedProductsLevel=(o,t,l,n,d)=>{const i=Object.assign({},o);if(Object.keys(o).forEach((t=>{var l,n;Object.keys(null!==(n=null===(l=null==o?void 0:o[t])||void 0===l?void 0:l.variants)&&void 0!==n?n:{}).forEach((l=>{var n,d;const s=null===(n=null==o?void 0:o[t].variants)||void 0===n?void 0:n[l];s&&(s.fbStatus="APPROVED");const e=null===(d=null==i?void 0:i[t])||void 0===d?void 0:d.variants;e&&e[l]&&(e[l]=s)}))})),n&&d){const o=Object.assign({},n);o.products=i,d(o)}else t({type:"productsPaged",data:{collectionId:l,products:i}})},exports.paginateSelectedItems=function(o,l,n){var d;const i={};let s=0;console.log("paginated offset",n);for(const e in o)if(Object.prototype.hasOwnProperty.call(o,e)){const v=o[e],a=t(v.products,l,n-s);a&&Object.keys(a).length>0&&(i[e]=Object.assign(Object.assign({},v),{products:a})),s+=Object.keys(null!==(d=v.products)&&void 0!==d?d:{}).length}return i};
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -29,6 +29,10 @@ export interface Collection {
29
29
  export type SelectedItems = {
30
30
  [key: string]: Collection;
31
31
  };
32
+ export type SearchedItems = {
33
+ collections: SelectedItems;
34
+ products: SelectedItems;
35
+ };
32
36
  export type CollectionFetcherReturn = Promise<{
33
37
  collections: {
34
38
  [key: string]: {
@@ -57,7 +61,7 @@ export type ProductPickerInterface = {
57
61
  hideInCollectionSearch?: boolean;
58
62
  customCollectionRestriction?: boolean;
59
63
  searchInCollectionFetcher: (storeId: string, collectionId: string, query: string) => ProductFetcherReturn;
60
- searchFetcher: (storeId: string, query: string) => Promise<SelectedItems>;
64
+ searchFetcher: (storeId: string, query: string) => Promise<SearchedItems>;
61
65
  collectionFetcher: (offset: number, storeId: string) => CollectionFetcherReturn;
62
66
  productFetcher: (collectionId: string, storeId: string, limit?: number, offset?: number) => ProductFetcherReturn;
63
67
  fbStatusFetcher?: (storeId: string, variantIds: string[]) => FbStatusFetcherReturn;
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import c from"../../assets/icons/search.svg.js";import{useReducer as r,useState as s,useRef as n,useEffect as i}from"react";import{COLORS as l}from"../../constants/Theme.js";import{Button as d}from"../button/Button.js";import{Input as a}from"../input/Input.js";import{StyledModal as u}from"../modals/styledModal.js";import{Spinner as h}from"../spinner/Spinner.js";import{Tag as p}from"../tag/Tag.js";import{CollectionsScreen as m}from"./collectionScreen.js";import{ProductInfoOverlay as C}from"./productInfoOverlay.js";import{ProductsScreen as g}from"./productScreen.js";import{RearrangeScreen as f}from"./rearrangeScreen.js";import{collectionsReducer as b,searchReducer as S,selectedColectionsReducer as y,CollectionIdContext as P}from"./reducers.js";import{SearchScreen as v}from"./searchScreen.js";import{SelectedScreen as j}from"./selectedScreen.js";import{ContainerStyle as k,ScrollContainerStyle as x}from"./style.js";import{OUT_OF_STOCK_ACTION as I}from"./type.js";var F;!function(e){e.Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products"}(F||(F={}));const T=T=>{const{storeId:O,selectedItems:D,onClose:R,visible:w,zIndex:E,exactLimit:A,limit:$,hideCollectionCheckbox:V,hideProductCheckbox:B,outOfStockAction:L=I.BLUR,hideVariantCheckbox:M,selectProductsFromCustomCollection:z,hideSelectionCount:G,title:H,width:W,renderWithoutModal:Y,onClickSave:K,pickerType:U,hideProductVariants:q=!1,startupScreen:J=F.Collections,rearrangeEnabled:N,selectSingleItem:Q=!1,showProductDetailInfoIcon:X}=T,[Z,_]=r(b,{}),[ee,te]=s([F.Collections,F.RearrangeProducts].includes(J)?J:F.Collections),[oe,ce]=s("grid"),[re,se]=s(""),[ne,ie]=s(""),[le,de]=s(0),[ae,ue]=s(!1),[he,pe]=s(0),[me,Ce]=s(""),[ge,fe]=s(!1),[be,Se]=s(!1),[ye,Pe]=r(S,{}),[ve,je]=r(y,Object.keys(D).length>0?D:{}),ke=n(null),[xe,Ie]=s(!1),[Fe,Te]=s();i((()=>{ue(!0),Se(!0),T.collectionFetcher(le,O).then((e=>{_({type:"fetched",data:(null==e?void 0:e.collections)||{}}),ue(!1),de((e=>e+1)),Se(!1)})).catch()}),[]),i((()=>{let e=0;Object.keys(ve||[]).forEach((t=>{var o;Object.keys((null===(o=ve[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=ve[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),pe(e)})),i((()=>{ne&&(ue(!0),T.productFetcher(ne,O).then((e=>{Object.keys(e).length&&_({type:"productsFetched",data:{collectionId:ne,products:e}}),ue(!1)})).catch())}),[ne]),i((()=>{const e=setTimeout((()=>{"rearrange"!==ee&&(me.length?(fe(!0),T.searchFetcher(O,me).then((e=>{Pe({type:"set",data:e}),te("searchProducts"),ue(!1),fe(!1)}))):te("collections"))}),800);return()=>clearTimeout(e)}),[me]),i((()=>{K&&(T.onAdd(ve,he),Oe())}),[K]),i((()=>{Q&&Object.keys(ve||{}).length&&he&&(T.onAdd(ve,he),Oe())}),[Q,ve,he]);const Oe=()=>{je({type:"reset",data:{}})},De=e(k,{children:[T.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:T.postHeader})),!T.hideGlobalSearch&&t(o,{children:("collections"===ee||"searchProducts"===ee)&&t("div",Object.assign({style:{padding:Y?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(a,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>ge?t(h,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:me,onChangeText:e=>{e.length&&e.trim().length?Ce(e):Ce("")}})}))}),e(x,Object.assign({ref:ke},{children:["collections"===ee&&t(m,{customCollectionRestriction:T.customCollectionRestriction,dataLoading:be,collections:Z,selectedCollectionsDispatch:je,setCollectionId:se,setSelectedCollectionId:ie,setScreen:te,selectedCollections:ve,collectionFetcher:T.collectionFetcher,storeId:O,collectionsDispatch:_,setSaveDisabled:ue,pagingControls:{curPage:le,setCurPage:de},hideCollectionCheckbox:V,renderWithoutModal:Y,pickerType:U}),"products"===ee&&re&&t(P.Provider,Object.assign({value:re},{children:t(g,{hideInCollectionSearch:T.hideInCollectionSearch,customCollectionRestriction:T.customCollectionRestriction,productFetcher:T.productFetcher,setScreen:te,storeId:O,data:Z[re],collectionsDispatch:_,selectedCollectionsDispatch:je,selectedData:ve,setSaveDisabled:ue,searchInCollectionFetcher:T.searchInCollectionFetcher,hideProductCheckbox:B,outOfStockAction:L,hideVariantCheckbox:M,selectProductsFromCustomCollection:z,renderWithoutModal:Y,pickerType:U,hideProductVariants:q,fbStatusFetcher:T.fbStatusFetcher,onInfoIconClick:e=>{Ie(!0),Te(e)},showProductDetailInfoIcon:X})})),"view"===ee&&t(j,{selectedCollections:ve||{},selectedCollectionsDispatch:je,setScreen:te,collections:Z,outOfStockAction:L,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"rearrange"===ee&&t(f,{selectedCollections:ve||{},selectedCollectionsDispatch:je,setScreen:te,outOfStockAction:L,rearrangeViewType:"grid"===oe?"list":"grid",scrollContainerRef:ke,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"searchProducts"===ee&&t(v,{customCollectionRestriction:T.customCollectionRestriction,selectedCollections:ve||{},searchedCollections:ye||{},searchedCollectionsDispatch:Pe,selectedCollectionsDispatch:je,setScreen:te,collections:Z,onBackPress:()=>{Ce(""),Pe({type:"set",data:{}})},pickerType:U,hideProductCheckbox:B,hideProductVariants:q,hideVariantCheckbox:M,storeId:O,fbStatusFetcher:T.fbStatusFetcher})]}))]});return t(o,{children:Y?De:e(u,Object.assign({zIndex:E,open:w,onClose:()=>{null==R||R(),Oe()},headingTitle:H||("collections"===ee||"products"===ee?"Select Products":"view"===ee?"Selected Products":"searchProducts"===ee?"Searched Products":"rearrange"===ee?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:W||"600px"},headerRightCustomElement:"rearrange"===ee?(console.log("ignore:",ce),t(o,{})):t(o,{}),primaryButton:{buttonText:ae?"Loading...":ee===F.RearrangeProducts?"Done":"Add",disabled:ae||he<1||A&&he<A||!A&&$&&he>$||!1,onClick:()=>{T.onAdd(ve,he),Oe()}},footerLeftCustomElement:G?t(o,{}):A&&he>A?t(p,{tagText:`You can only select ${A} products`,type:"negative"}):$&&he>$?t(p,{tagText:`You can only select ${$} products`,type:"negative"}):t(d,he>0?{onClick:()=>{te(N?F.RearrangeProducts:F.SelectedProducts)},buttonText:A?`${he}/${A} products selected`:`${he} products selected`,buttonType:["rearrange","view"].includes(ee)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(ee)}:{disabled:!0,buttonText:A?`${he}/${A} products selected`:`${he} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:xe},{children:[De,xe&&Fe?t(C,{productData:Fe,outOfStockAction:L,onClose:()=>{Ie(!1)}}):t(o,{})]}))})};export{T as ProductPickerModal,F as ScreenName};
1
+ import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import c from"../../assets/icons/search.svg.js";import{useReducer as r,useState as s,useRef as n,useEffect as i}from"react";import{COLORS as l}from"../../constants/Theme.js";import{Button as d}from"../button/Button.js";import{Input as a}from"../input/Input.js";import{StyledModal as u}from"../modals/styledModal.js";import{Spinner as h}from"../spinner/Spinner.js";import{Tag as p}from"../tag/Tag.js";import{CollectionsScreen as m}from"./collectionScreen.js";import{ProductInfoOverlay as C}from"./productInfoOverlay.js";import{ProductsScreen as g}from"./productScreen.js";import{RearrangeScreen as f}from"./rearrangeScreen.js";import{collectionsReducer as b,searchReducer as S,selectedColectionsReducer as y,CollectionIdContext as P}from"./reducers.js";import{SearchScreen as v}from"./searchScreen.js";import{SelectedScreen as j}from"./selectedScreen.js";import{ContainerStyle as k,ScrollContainerStyle as x}from"./style.js";import{OUT_OF_STOCK_ACTION as I}from"./type.js";var F;!function(e){e.Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products"}(F||(F={}));const T=T=>{const{storeId:O,selectedItems:D,onClose:R,visible:w,zIndex:E,exactLimit:A,limit:$,hideCollectionCheckbox:V,hideProductCheckbox:B,outOfStockAction:L=I.BLUR,hideVariantCheckbox:M,selectProductsFromCustomCollection:z,hideSelectionCount:G,title:H,width:W,renderWithoutModal:Y,onClickSave:K,pickerType:U,hideProductVariants:q=!1,startupScreen:J=F.Collections,rearrangeEnabled:N,selectSingleItem:Q=!1,showProductDetailInfoIcon:X}=T,[Z,_]=r(b,{}),[ee,te]=s([F.Collections,F.RearrangeProducts].includes(J)?J:F.Collections),[oe,ce]=s("grid"),[re,se]=s(""),[ne,ie]=s(""),[le,de]=s(0),[ae,ue]=s(!1),[he,pe]=s(0),[me,Ce]=s(""),[ge,fe]=s(!1),[be,Se]=s(!1),[ye,Pe]=r(S,{collections:{},products:{}}),[ve,je]=r(y,Object.keys(D).length>0?D:{}),ke=n(null),[xe,Ie]=s(!1),[Fe,Te]=s();i((()=>{ue(!0),Se(!0),T.collectionFetcher(le,O).then((e=>{_({type:"fetched",data:(null==e?void 0:e.collections)||{}}),ue(!1),de((e=>e+1)),Se(!1)})).catch()}),[]),i((()=>{let e=0;Object.keys(ve||[]).forEach((t=>{var o;Object.keys((null===(o=ve[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=ve[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),pe(e)})),i((()=>{ne&&(ue(!0),T.productFetcher(ne,O).then((e=>{Object.keys(e).length&&_({type:"productsFetched",data:{collectionId:ne,products:e}}),ue(!1)})).catch())}),[ne]),i((()=>{const e=setTimeout((()=>{"rearrange"!==ee&&(me.length?(fe(!0),T.searchFetcher(O,me).then((e=>{Pe({type:"set",data:e}),te("searchProducts"),ue(!1),fe(!1)}))):te("collections"))}),800);return()=>clearTimeout(e)}),[me]),i((()=>{K&&(T.onAdd(ve,he),Oe())}),[K]),i((()=>{Q&&Object.keys(ve||{}).length&&he&&(T.onAdd(ve,he),Oe())}),[Q,ve,he]);const Oe=()=>{je({type:"reset",data:{}})},De=e(k,{children:[T.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:T.postHeader})),!T.hideGlobalSearch&&t(o,{children:("collections"===ee||"searchProducts"===ee)&&t("div",Object.assign({style:{padding:Y?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(a,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>ge?t(h,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:me,onChangeText:e=>{e.length&&e.trim().length?Ce(e):Ce("")}})}))}),e(x,Object.assign({ref:ke},{children:["collections"===ee&&t(m,{customCollectionRestriction:T.customCollectionRestriction,dataLoading:be,collections:Z,selectedCollectionsDispatch:je,setCollectionId:se,setSelectedCollectionId:ie,setScreen:te,selectedCollections:ve,collectionFetcher:T.collectionFetcher,storeId:O,collectionsDispatch:_,setSaveDisabled:ue,pagingControls:{curPage:le,setCurPage:de},hideCollectionCheckbox:V,renderWithoutModal:Y,pickerType:U}),"products"===ee&&re&&t(P.Provider,Object.assign({value:re},{children:t(g,{hideInCollectionSearch:T.hideInCollectionSearch,customCollectionRestriction:T.customCollectionRestriction,productFetcher:T.productFetcher,setScreen:te,storeId:O,data:Z[re],collectionsDispatch:_,selectedCollectionsDispatch:je,selectedData:ve,setSaveDisabled:ue,searchInCollectionFetcher:T.searchInCollectionFetcher,hideProductCheckbox:B,outOfStockAction:L,hideVariantCheckbox:M,selectProductsFromCustomCollection:z,renderWithoutModal:Y,pickerType:U,hideProductVariants:q,fbStatusFetcher:T.fbStatusFetcher,onInfoIconClick:e=>{Ie(!0),Te(e)},showProductDetailInfoIcon:X})})),"view"===ee&&t(j,{selectedCollections:ve||{},selectedCollectionsDispatch:je,setScreen:te,collections:Z,outOfStockAction:L,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"rearrange"===ee&&t(f,{selectedCollections:ve||{},selectedCollectionsDispatch:je,setScreen:te,outOfStockAction:L,rearrangeViewType:"grid"===oe?"list":"grid",scrollContainerRef:ke,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"searchProducts"===ee&&t(v,{customCollectionRestriction:T.customCollectionRestriction,selectedCollections:ve||{},searchedCollections:ye||{},searchedCollectionsDispatch:Pe,selectedCollectionsDispatch:je,setScreen:te,collections:Z,onBackPress:()=>{Ce(""),Pe({type:"set",data:{collections:{},products:{}}})},pickerType:U,hideProductCheckbox:B,hideProductVariants:q,hideVariantCheckbox:M,storeId:O,fbStatusFetcher:T.fbStatusFetcher})]}))]});return t(o,{children:Y?De:e(u,Object.assign({zIndex:E,open:w,onClose:()=>{null==R||R(),Oe()},headingTitle:H||("collections"===ee||"products"===ee?"Select Products":"view"===ee?"Selected Products":"searchProducts"===ee?"Searched Products":"rearrange"===ee?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:W||"600px"},headerRightCustomElement:"rearrange"===ee?(console.log("ignore:",ce),t(o,{})):t(o,{}),primaryButton:{buttonText:ae?"Loading...":ee===F.RearrangeProducts?"Done":"Add",disabled:ae||he<1||A&&he<A||!A&&$&&he>$||!1,onClick:()=>{T.onAdd(ve,he),Oe()}},footerLeftCustomElement:G?t(o,{}):A&&he>A?t(p,{tagText:`You can only select ${A} products`,type:"negative"}):$&&he>$?t(p,{tagText:`You can only select ${$} products`,type:"negative"}):t(d,he>0?{onClick:()=>{te(N?F.RearrangeProducts:F.SelectedProducts)},buttonText:A?`${he}/${A} products selected`:`${he} products selected`,buttonType:["rearrange","view"].includes(ee)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(ee)}:{disabled:!0,buttonText:A?`${he}/${A} products selected`:`${he} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:xe},{children:[De,xe&&Fe?t(C,{productData:Fe,outOfStockAction:L,onClose:()=>{Ie(!1)}}):t(o,{})]}))})};export{T as ProductPickerModal,F as ScreenName};
@@ -1 +1 @@
1
- import{jsxs as t,jsx as o,Fragment as e}from"react/jsx-runtime";import i from"../../assets/icons/arrow_left.svg.js";import n from"../../assets/icons/box.svg.js";import c from"../../assets/icons/search.svg.js";import{cloneDeep as l}from"lodash";import{useContext as s,useRef as d,useState as r,useEffect as a}from"react";import{COLORS as u}from"../../constants/Theme.js";import v from"../../assets/icons/info.svg.js";import{CheckBox as h}from"../checkBox/CheckBox.js";import{IconButton as p}from"../icon-button/IconButton.js";import{Input as g}from"../input/Input.js";import{BikShimmer as f}from"../shimmer/ShimmerComponent/BikShimmer.js";import{ShimmerImage as b}from"../shimmer-image/ShimmerImage.js";import{Spinner as j}from"../spinner/Spinner.js";import{Tooltip as m}from"../tooltips/Tooltip.js";import{BodyCaption as y,TitleRegular as k,BodyPrimary as I}from"../TypographyStyle.js";import{EmptyState as O}from"./emptyState.js";import{ProductPickerTag as C}from"./ProductPickerTag.js";import{CollectionIdContext as P}from"./reducers.js";import{ProductScreenHeader as S,ProductScreenCollectionCardStyle as x,ProductCardStyle as E}from"./style.js";import{OUT_OF_STOCK_ACTION as D}from"./type.js";import{liftTheStateUp as V}from"./utility.js";const w=e=>{const{data:v,collectionsDispatch:b,selectedData:m,selectedCollectionsDispatch:I,productFetcher:C,storeId:E,setScreen:w,setSaveDisabled:T,hideInCollectionSearch:F,customCollectionRestriction:R,hideProductCheckbox:B,outOfStockAction:U=D.BLUR,hideVariantCheckbox:L=!1,selectProductsFromCustomCollection:H=!1,pickerType:J,hideProductVariants:W,fbStatusFetcher:z,onInfoIconClick:K,showProductDetailInfoIcon:M}=e,N=s(P),_=d(null),q=d(0),[G,Q]=r(!1),[X,Y]=r(""),[Z,$]=r(!1),[tt,ot]=r(v),et=d(!1);a((()=>{const t=setTimeout((()=>{X.length?($(!0),e.searchInCollectionFetcher(E,N,X).then((t=>{const o=l(v);o.products=t,ot(o);const e=ct(null!=t?t:{},!0);lt(e,null!=t?t:{},!0),T(!1),$(!1)}))):ot(v)}),800);return()=>clearTimeout(t)}),[X]),a((()=>{var t,o,e,i,n,c,l,s;console.log("vj: collectionId change before",v,v.products,null===(o=Object.keys(null!==(t=v.products)&&void 0!==t?t:{}))||void 0===o?void 0:o.length,et),et.current=!1,q.current=Math.floor((null===(i=Object.keys(null!==(e=v.products)&&void 0!==e?e:{}))||void 0===i?void 0:i.length)/10);const d=ct(null!==(n=v.products)&&void 0!==n?n:{});lt(d,null!==(c=v.products)&&void 0!==c?c:{}),console.log("vj: collectionId change after",v,v.products,null===(s=Object.keys(null!==(l=v.products)&&void 0!==l?l:{}))||void 0===s?void 0:s.length,et)}),[N]);const it=!!R&&v.isSmartCollection,nt=t=>{var o,e,i,n,c,l,s,d;let r=0,a=0;return!!((null===(e=null===(o=null==m?void 0:m[N])||void 0===o?void 0:o.products)||void 0===e?void 0:e[t])&&(null===(c=Object.keys((null===(n=null===(i=null==v?void 0:v.products)||void 0===i?void 0:i[t])||void 0===n?void 0:n.variants)||[]))||void 0===c||c.forEach((()=>a++)),Object.keys((null===(d=null===(s=null===(l=null==m?void 0:m[N])||void 0===l?void 0:l.products)||void 0===s?void 0:s[t])||void 0===d?void 0:d.variants)||[]).forEach((()=>r++)),r>0&&a!==r))};a((()=>{(null==v?void 0:v.products)||st(10)}),[]);const ct=(t,o)=>{const e=[];return console.log("vj: getVariantIdsForFbStatusFetch",t),Object.keys(null!=t?t:{}).forEach((i=>{var n,c;const l=null!==(c=null===(n=null==t?void 0:t[i])||void 0===n?void 0:n.variants)&&void 0!==c?c:{};Object.keys(l).forEach((n=>{var c,l,s,d,r;let a;a=o?null===(l=null===(c=null==t?void 0:t[i])||void 0===c?void 0:c.variants)||void 0===l?void 0:l[n]:null===(r=null===(d=null===(s=null==v?void 0:v.products)||void 0===s?void 0:s[i])||void 0===d?void 0:d.variants)||void 0===r?void 0:r[n],console.log("vj: variant fb status",{data:v,variant:a}),(null==a?void 0:a.fbStatus)||e.push(n)}))})),console.log("vj: getVariantIdsForFbStatusFetch returning",e),e},lt=(t,o,e)=>{if(console.log("fetchFbStatusAndDispatchProducts",{variantIdsToFetchFbStatus:t,fbStatusFetcher:z}),!z){const t=Object.assign({},o);if(Object.keys(o).forEach((e=>{var i,n,c;console.log("vj: response variants",null===(i=null==o?void 0:o[e])||void 0===i?void 0:i.variants),Object.keys(null!==(c=null===(n=null==o?void 0:o[e])||void 0===n?void 0:n.variants)&&void 0!==c?c:{}).forEach((i=>{var n,c;const l=null===(n=null==o?void 0:o[e].variants)||void 0===n?void 0:n[i];l&&(l.fbStatus="APPROVED");const s=null===(c=null==t?void 0:t[e])||void 0===c?void 0:c.variants;s&&s[i]&&(s[i]=l)}))})),console.log("vj: fetchFbStatusAndDispatchProducts updated Products",t),e){const o=Object.assign({},tt);o.products=t,ot(o)}else b({type:"productsPaged",data:{collectionId:N,products:t}})}t.length>0&&z&&z(E,t).then((t=>{console.log("vj: response",{response:t,products:o});const i=Object.assign({},o);if(Object.keys(o).forEach((e=>{var n,c,l;console.log("vj: response variants",null===(n=null==o?void 0:o[e])||void 0===n?void 0:n.variants),Object.keys(null!==(l=null===(c=null==o?void 0:o[e])||void 0===c?void 0:c.variants)&&void 0!==l?l:{}).forEach((n=>{var c,l;const s=null===(c=null==o?void 0:o[e].variants)||void 0===c?void 0:c[n];console.log("vj: v",{v:s,vId:n,status:t[n],response:t}),s&&"REJECTED"===t[n]?s.fbStatus="REJECTED":s&&"APPROVED"===t[n]&&(s.fbStatus="APPROVED");const d=null===(l=null==i?void 0:i[e])||void 0===l?void 0:l.variants;d&&d[n]&&(d[n]=s)}))})),console.log("vj: updated Products",i),e){const t=Object.assign({},tt);t.products=i,ot(t)}else b({type:"productsPaged",data:{collectionId:N,products:i}})})).catch((t=>{const i=Object.assign({},o);if(Object.keys(o).forEach((t=>{var e,n,c;console.log("vj: response variants",null===(e=null==o?void 0:o[t])||void 0===e?void 0:e.variants),Object.keys(null!==(c=null===(n=null==o?void 0:o[t])||void 0===n?void 0:n.variants)&&void 0!==c?c:{}).forEach((e=>{var n,c;const l=null===(n=null==o?void 0:o[t].variants)||void 0===n?void 0:n[e];l&&(l.fbStatus="APPROVED");const s=null===(c=null==i?void 0:i[t])||void 0===c?void 0:c.variants;s&&s[e]&&(s[e]=l)}))})),console.log("vj: fetchFbStatusAndDispatchProducts updated Products",i),e){const t=Object.assign({},tt);t.products=i,ot(t)}else b({type:"productsPaged",data:{collectionId:N,products:i}})}))};a((()=>{console.log("vj: observertarget",_.current);const t=new IntersectionObserver((t=>{console.log("vj: observertargetinside",t),t[0].isIntersecting&&(console.log("vj: nextPageRef",q.current,et),q.current>=0&&!et.current&&(T(!0),Q(!0),C(N,E,10,q.current).then((t=>{if(console.log("vj: fetched products",t,et,Object.keys(t).length),Object.keys(t).length||(console.log("vj: setHasAllCollectionLoaded ",!0),et.current=!0),Object.keys(t).length){const o=tt;o.products=Object.assign(Object.assign({},tt.products),t),ot(o);const e=ct(t);lt(e,t),q.current+=1}Q(!1),T(!1)})).catch()))}),{threshold:1});return _.current&&t.observe(_.current),()=>{_.current&&t.unobserve(_.current)}}),[_]);const st=t=>{console.log("vj: getProductsForCollection"),T(!0),$(!0),C(N,E,t,0).then((o=>{if(Object.keys(o).length||(console.log("vj: setHasAllCollectionLoaded ",!0),et.current=!0),Object.keys(o).length){ot(Object.assign(Object.assign({},tt),{products:o})),console.log("vj: next page when products loaded",q.current);const t=ct(o);lt(t,o),q.current=1}console.log("vj: product data",{productData:o,limit:t,data:v}),t||I({type:"selected",data:{id:N,val:Object.assign(Object.assign({},v),{products:o})}}),T(!1),$(!1)})).catch()},dt=(t,o)=>{const e=V(o,v);I({type:t,data:Object.assign(Object.assign({},e),{isRestricted:R})})};return t("div",{children:[t(S,{children:[o(p,{Icon:i,height:16,onClick:()=>{w("collections")}}),o(y,Object.assign({style:{color:u.content.secondary}},{children:v.name}))]}),!F&&o("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:o(g,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>Z&&X.length?o(j,{size:"small",color:u.content.primary}):o(c,{})},id:"listInput",height:"24px",type:"text",value:X,onChangeText:t=>{t.length&&t.trim().length?Y(t):Y("")},placeholder:"Search products in this collection..."})})),t("div",{children:[Object.keys((null==tt?void 0:tt.products)||[]).length>0&&!it&&!X.length&&!B&&"-1"!==N&&t(x,{children:[o(h,{isChecked:!!(null==m?void 0:m[N]),isPartiallyChecked:(t=>{var o;let e=0,i=0;if(m[t]){const n=null==v?void 0:v.products;n&&Object.keys(n).forEach((t=>{var o;const i=null===(o=n[t])||void 0===o?void 0:o.variants;i&&Object.keys(i).forEach((t=>e+=1))}));const c=null===(o=m[t])||void 0===o?void 0:o.products;return c&&Object.keys(c).forEach((t=>{var o;const e=null===(o=c[t])||void 0===o?void 0:o.variants;e&&Object.keys(e).forEach((()=>i+=1))})),i>0&&e!==i}return!1})(N),onValueChange:function(t){t?st():I({type:"unselected",data:{id:N}})}}),o("div",Object.assign({style:{width:40,height:40}},{children:o(n,{})})),o(k,{children:"All Products"})]}),Object.keys((null==tt?void 0:tt.products)||[]).length?Object.keys(tt.products||[]).map((t=>o(A,{outOfStockAction:U,collectionId:N,isProductPartiallyChecked:nt(t),productId:t,data:tt.products[t],selectedData:m,selectedCollectionsDispatch:I,viewOnly:!H&&!!it,upliftAdditions:dt,hideProductCheckbox:B,hideVariantCheckbox:L,hideProductVariants:W,pickerType:J,onInfoIconClick:K,showProductDetailInfoIcon:M},t))):Z?[1,2,3,4,5,6,7,8,9,10].map(((t,e)=>o("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:o(f,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),e))):o(O,{title:"No products to show",subtitle:X.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),o("div",{ref:_})]}),G&&[1,2,3,4,5].map(((t,e)=>o("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:o(f,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),e)))]})},A=e=>{const{collectionId:i,productId:n,data:c,selectedData:l,selectedCollectionsDispatch:s,viewOnly:d,upliftAdditions:r,isProductPartiallyChecked:a,hideProductCheckbox:u,outOfStockAction:v,hideVariantCheckbox:h,hideProductVariants:p,pickerType:g,onInfoIconClick:f,showProductDetailInfoIcon:b}=e,j=t=>{var o,e,c,s,d,r;if(!(null===(e=null===(o=null==l?void 0:l[i])||void 0===o?void 0:o.products)||void 0===e?void 0:e[n]))return!1;return!!(null===(r=null===(d=null===(s=null===(c=null==l?void 0:l[i])||void 0===c?void 0:c.products)||void 0===s?void 0:s[n])||void 0===d?void 0:d.variants)||void 0===r?void 0:r[t])};return t("div",{children:[o(T,{isVariant:!1,data:c,productId:n,collectionId:i,isSelected:!!(null===(y=null===(m=null==l?void 0:l[i])||void 0===m?void 0:m.products)||void 0===y?void 0:y[n]),isPartiallyChecked:a,selectedCollectionsDispatch:s,upliftAdditions:r,viewOnly:d,hideProductCheckbox:u,hideVariantCheckbox:h,hideProductVariants:p,pickerType:g,outOfStockAction:v,onInfoIconClick:f,showProductDetailInfoIcon:b},n),p?null:Object.keys(c.variants||[]).length>1&&Object.keys(c.variants||[]).map((t=>o(T,{isVariant:!0,hideVariantCheckbox:h,data:c.variants[t],variantId:t,productId:n,viewOnly:d,upliftAdditions:r,collectionId:i,isSelected:j(t),selectedCollectionsDispatch:s,outOfStockAction:v,onInfoIconClick:f,showProductDetailInfoIcon:b},t)))]});var m,y},T=i=>{const{isVariant:n,data:c,productId:l,collectionId:s,variantId:d,isSelected:r,selectedCollectionsDispatch:a,viewOnly:g,upliftAdditions:f,isPartiallyChecked:j,hideProductCheckbox:y,outOfStockAction:k,hideVariantCheckbox:O,hideProductVariants:P,pickerType:S,onInfoIconClick:x,showProductDetailInfoIcon:D}=i;return t(E,Object.assign({isVariant:n,onClick:t=>{"PRODUCT"===S&&P&&(t.stopPropagation(),a({type:"reset",data:{}}),f("variantSelected",{productId:l,variantId:d||Object.keys(c.variants)[0],collectionId:s,variant:c}))},isActive:r},{children:[n&&!g&&!O||!n&&!g&&!y?o(h,{isChecked:r,isPartiallyChecked:j||!1,onValueChange:function(t){n?t?f("variantSelected",{productId:l,variantId:d,collectionId:s,variant:c}):a({type:"variantUnselected",data:{productId:l,variantId:d,collectionId:s}}):t?f("productSelected",{productId:l,collectionId:s,product:c}):a({type:"productUnselected",data:{productId:l,collectionId:s}})}}):o(e,{}),o("div",{children:o(b,{width:40,height:40,imageUrl:c.image,alt:"Item",borderRadius:4})}),o(m,Object.assign({variant:"light",body:c.name,placement:"bottom",delay:400},{children:t("div",Object.assign({style:{display:"flex",flexDirection:"column",flex:1}},{children:[t("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},{children:[o(I,Object.assign({numberOfLines:1},{children:c.name})),D&&o(p,{onClick:()=>{null==x||x(c)},Icon:()=>o(v,{width:20,height:20,color:u.content.placeholder})})]})),o(C,{isVariant:n,data:c,outOfStockAction:k})]}))}))]}))};export{T as ProductCard,A as ProductGroup,w as ProductsScreen};
1
+ import{jsxs as t,jsx as o,Fragment as e}from"react/jsx-runtime";import i from"../../assets/icons/arrow_left.svg.js";import n from"../../assets/icons/box.svg.js";import c from"../../assets/icons/search.svg.js";import{cloneDeep as l}from"lodash";import{useContext as r,useRef as s,useState as d,useEffect as a}from"react";import{COLORS as u}from"../../constants/Theme.js";import h from"../../assets/icons/info.svg.js";import{CheckBox as v}from"../checkBox/CheckBox.js";import{IconButton as p}from"../icon-button/IconButton.js";import{Input as g}from"../input/Input.js";import{BikShimmer as m}from"../shimmer/ShimmerComponent/BikShimmer.js";import{ShimmerImage as f}from"../shimmer-image/ShimmerImage.js";import{Spinner as b}from"../spinner/Spinner.js";import{Tooltip as j}from"../tooltips/Tooltip.js";import{BodyCaption as y,TitleRegular as I,BodyPrimary as k}from"../TypographyStyle.js";import{EmptyState as O}from"./emptyState.js";import{ProductPickerTag as C}from"./ProductPickerTag.js";import{CollectionIdContext as P}from"./reducers.js";import{ProductScreenHeader as x,ProductScreenCollectionCardStyle as S,ProductCardStyle as D}from"./style.js";import{OUT_OF_STOCK_ACTION as E}from"./type.js";import{getVariantIdsToFetchAtProductLevel as w,markVariantsAsApprovedProductsLevel as V,liftTheStateUp as A}from"./utility.js";const T=e=>{const{data:h,collectionsDispatch:f,selectedData:j,selectedCollectionsDispatch:k,productFetcher:C,storeId:D,setScreen:T,setSaveDisabled:F,hideInCollectionSearch:B,customCollectionRestriction:U,hideProductCheckbox:L,outOfStockAction:H=E.BLUR,hideVariantCheckbox:J=!1,selectProductsFromCustomCollection:W=!1,pickerType:z,hideProductVariants:K,fbStatusFetcher:M,onInfoIconClick:N,showProductDetailInfoIcon:_}=e,q=r(P),G=s(null),Q=s(0),[X,Y]=d(!1),[Z,$]=d(""),[tt,ot]=d(!1),[et,it]=d(h),nt=s(!1);a((()=>{const t=setTimeout((()=>{Z.length?(ot(!0),e.searchInCollectionFetcher(D,q,Z).then((t=>{const o=l(h);o.products=t,it(o);const e=w(null!=t?t:{},h);rt(e,null!=t?t:{},!0),F(!1),ot(!1)}))):it(h)}),800);return()=>clearTimeout(t)}),[Z]),a((()=>{var t,o,e,i,n,c,l,r;console.log("vj: collectionId change before",h,h.products,null===(o=Object.keys(null!==(t=h.products)&&void 0!==t?t:{}))||void 0===o?void 0:o.length,nt),nt.current=!1,Q.current=Math.floor((null===(i=Object.keys(null!==(e=h.products)&&void 0!==e?e:{}))||void 0===i?void 0:i.length)/10);const s=w(null!==(n=h.products)&&void 0!==n?n:{});rt(s,null!==(c=h.products)&&void 0!==c?c:{}),console.log("vj: collectionId change after",h,h.products,null===(r=Object.keys(null!==(l=h.products)&&void 0!==l?l:{}))||void 0===r?void 0:r.length,nt)}),[q]);const ct=!!U&&h.isSmartCollection,lt=t=>{var o,e,i,n,c,l,r,s;let d=0,a=0;return!!((null===(e=null===(o=null==j?void 0:j[q])||void 0===o?void 0:o.products)||void 0===e?void 0:e[t])&&(null===(c=Object.keys((null===(n=null===(i=null==h?void 0:h.products)||void 0===i?void 0:i[t])||void 0===n?void 0:n.variants)||[]))||void 0===c||c.forEach((()=>a++)),Object.keys((null===(s=null===(r=null===(l=null==j?void 0:j[q])||void 0===l?void 0:l.products)||void 0===r?void 0:r[t])||void 0===s?void 0:s.variants)||[]).forEach((()=>d++)),d>0&&a!==d))};a((()=>{(null==h?void 0:h.products)||st(10)}),[]);const rt=(t,o,e)=>{console.log("fetchFbStatusAndDispatchProducts",{variantIdsToFetchFbStatus:t,fbStatusFetcher:M}),M||(e?V(o,f,q,et,it):V(o,f,q)),t.length>0&&M&&M(D,t).then((t=>{console.log("vj: response",{response:t,products:o});const i=Object.assign({},o);if(Object.keys(o).forEach((e=>{var n,c,l;console.log("vj: response variants",null===(n=null==o?void 0:o[e])||void 0===n?void 0:n.variants),Object.keys(null!==(l=null===(c=null==o?void 0:o[e])||void 0===c?void 0:c.variants)&&void 0!==l?l:{}).forEach((n=>{var c,l;const r=null===(c=null==o?void 0:o[e].variants)||void 0===c?void 0:c[n];console.log("vj: v",{v:r,vId:n,status:t[n],response:t}),r&&"REJECTED"===t[n]?r.fbStatus="REJECTED":r&&"APPROVED"===t[n]&&(r.fbStatus="APPROVED");const s=null===(l=null==i?void 0:i[e])||void 0===l?void 0:l.variants;s&&s[n]&&(s[n]=r)}))})),e){const t=Object.assign({},et);t.products=i,it(t)}else f({type:"productsPaged",data:{collectionId:q,products:i}})})).catch((t=>{e?V(o,f,q,et,it):V(o,f,q)}))};a((()=>{console.log("vj: observertarget",G.current);const t=new IntersectionObserver((t=>{console.log("vj: observertargetinside",t),t[0].isIntersecting&&(console.log("vj: nextPageRef",Q.current,nt),Q.current>=0&&!nt.current&&(F(!0),Y(!0),C(q,D,10,Q.current).then((t=>{if(console.log("vj: fetched products",t,nt,Object.keys(t).length),Object.keys(t).length||(console.log("vj: setHasAllCollectionLoaded ",!0),nt.current=!0),Object.keys(t).length){const o=et;o.products=Object.assign(Object.assign({},et.products),t),it(o);const e=w(t);rt(e,t),Q.current+=1}Y(!1),F(!1)})).catch()))}),{threshold:1});return G.current&&t.observe(G.current),()=>{G.current&&t.unobserve(G.current)}}),[G]);const st=t=>{console.log("vj: getProductsForCollection"),F(!0),ot(!0),C(q,D,t,0).then((o=>{if(Object.keys(o).length||(console.log("vj: setHasAllCollectionLoaded ",!0),nt.current=!0),Object.keys(o).length){it(Object.assign(Object.assign({},et),{products:o})),console.log("vj: next page when products loaded",Q.current);const t=w(o);rt(t,o),Q.current=1}console.log("vj: product data",{productData:o,limit:t,data:h}),t||k({type:"selected",data:{id:q,val:Object.assign(Object.assign({},h),{products:o})}}),F(!1),ot(!1)})).catch()},dt=(t,o)=>{const e=A(o,h);k({type:t,data:Object.assign(Object.assign({},e),{isRestricted:U})})};return t("div",{children:[t(x,{children:[o(p,{Icon:i,height:16,onClick:()=>{T("collections")}}),o(y,Object.assign({style:{color:u.content.secondary}},{children:h.name}))]}),!B&&o("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:o(g,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>tt&&Z.length?o(b,{size:"small",color:u.content.primary}):o(c,{})},id:"listInput",height:"24px",type:"text",value:Z,onChangeText:t=>{t.length&&t.trim().length?$(t):$("")},placeholder:"Search products in this collection..."})})),t("div",{children:[Object.keys((null==et?void 0:et.products)||[]).length>0&&!ct&&!Z.length&&!L&&"-1"!==q&&t(S,{children:[o(v,{isChecked:!!(null==j?void 0:j[q]),isPartiallyChecked:(t=>{var o;let e=0,i=0;if(j[t]){const n=null==h?void 0:h.products;n&&Object.keys(n).forEach((t=>{var o;const i=null===(o=n[t])||void 0===o?void 0:o.variants;i&&Object.keys(i).forEach((t=>e+=1))}));const c=null===(o=j[t])||void 0===o?void 0:o.products;return c&&Object.keys(c).forEach((t=>{var o;const e=null===(o=c[t])||void 0===o?void 0:o.variants;e&&Object.keys(e).forEach((()=>i+=1))})),i>0&&e!==i}return!1})(q),onValueChange:function(t){t?st():k({type:"unselected",data:{id:q}})}}),o("div",Object.assign({style:{width:40,height:40}},{children:o(n,{})})),o(I,{children:"All Products"})]}),Object.keys((null==et?void 0:et.products)||[]).length?Object.keys(et.products||[]).map((t=>o(R,{outOfStockAction:H,collectionId:q,isProductPartiallyChecked:lt(t),productId:t,data:et.products[t],selectedData:j,selectedCollectionsDispatch:k,viewOnly:!W&&!!ct,upliftAdditions:dt,hideProductCheckbox:L,hideVariantCheckbox:J,hideProductVariants:K,pickerType:z,onInfoIconClick:N,showProductDetailInfoIcon:_},t))):tt?[1,2,3,4,5,6,7,8,9,10].map(((t,e)=>o("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:o(m,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),e))):o(O,{title:"No products to show",subtitle:Z.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),o("div",{ref:G})]}),X&&[1,2,3,4,5].map(((t,e)=>o("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:o(m,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),e)))]})},R=e=>{const{collectionId:i,productId:n,data:c,selectedData:l,selectedCollectionsDispatch:r,viewOnly:s,upliftAdditions:d,isProductPartiallyChecked:a,hideProductCheckbox:u,outOfStockAction:h,hideVariantCheckbox:v,hideProductVariants:p,pickerType:g,onInfoIconClick:m,showProductDetailInfoIcon:f}=e,b=t=>{var o,e,c,r,s,d;if(!(null===(e=null===(o=null==l?void 0:l[i])||void 0===o?void 0:o.products)||void 0===e?void 0:e[n]))return!1;return!!(null===(d=null===(s=null===(r=null===(c=null==l?void 0:l[i])||void 0===c?void 0:c.products)||void 0===r?void 0:r[n])||void 0===s?void 0:s.variants)||void 0===d?void 0:d[t])};return t("div",{children:[o(F,{isVariant:!1,data:c,productId:n,collectionId:i,isSelected:!!(null===(y=null===(j=null==l?void 0:l[i])||void 0===j?void 0:j.products)||void 0===y?void 0:y[n]),isPartiallyChecked:a,selectedCollectionsDispatch:r,upliftAdditions:d,viewOnly:s,hideProductCheckbox:u,hideVariantCheckbox:v,hideProductVariants:p,pickerType:g,outOfStockAction:h,onInfoIconClick:m,showProductDetailInfoIcon:f},n),p?null:Object.keys(c.variants||[]).length>1&&Object.keys(c.variants||[]).map((t=>o(F,{isVariant:!0,hideVariantCheckbox:v,data:c.variants[t],variantId:t,productId:n,viewOnly:s,upliftAdditions:d,collectionId:i,isSelected:b(t),selectedCollectionsDispatch:r,outOfStockAction:h,onInfoIconClick:m,showProductDetailInfoIcon:f},t)))]});var j,y},F=i=>{const{isVariant:n,data:c,productId:l,collectionId:r,variantId:s,isSelected:d,selectedCollectionsDispatch:a,viewOnly:g,upliftAdditions:m,isPartiallyChecked:b,hideProductCheckbox:y,outOfStockAction:I,hideVariantCheckbox:O,hideProductVariants:P,pickerType:x,onInfoIconClick:S,showProductDetailInfoIcon:E}=i;return t(D,Object.assign({isVariant:n,onClick:t=>{"PRODUCT"===x&&P&&(t.stopPropagation(),a({type:"reset",data:{}}),m("variantSelected",{productId:l,variantId:s||Object.keys(c.variants)[0],collectionId:r,variant:c}))},isActive:d},{children:[n&&!g&&!O||!n&&!g&&!y?o(v,{isChecked:d,isPartiallyChecked:b||!1,onValueChange:function(t){n?t?m("variantSelected",{productId:l,variantId:s,collectionId:r,variant:c}):a({type:"variantUnselected",data:{productId:l,variantId:s,collectionId:r}}):t?m("productSelected",{productId:l,collectionId:r,product:c}):a({type:"productUnselected",data:{productId:l,collectionId:r}})}}):o(e,{}),o("div",{children:o(f,{width:40,height:40,imageUrl:c.image,alt:"Item",borderRadius:4})}),o(j,Object.assign({variant:"light",body:c.name,placement:"bottom",delay:400},{children:t("div",Object.assign({style:{display:"flex",flexDirection:"column",flex:1}},{children:[t("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},{children:[o(k,Object.assign({numberOfLines:1},{children:c.name})),E&&o(p,{onClick:()=>{null==S||S(c)},Icon:()=>o(h,{width:20,height:20,color:u.content.placeholder})})]})),o(C,{isVariant:n,data:c,outOfStockAction:I})]}))}))]}))};export{F as ProductCard,R as ProductGroup,T as ProductsScreen};
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { Collection, SelectedItems } from '.';
2
+ import { Collection, SearchedItems, SelectedItems } from '.';
3
3
  export interface SelectedCollectionsActions {
4
4
  type: string;
5
5
  data: {
@@ -15,5 +15,9 @@ export interface CollectionsActions {
15
15
  }
16
16
  export declare function collectionsReducer(collections: Collection, action: CollectionsActions): any;
17
17
  export declare function paginationReducer(collections: SelectedItems, action: SelectedCollectionsActions): SelectedItems;
18
- export declare function searchReducer(collections: SelectedItems, action: SelectedCollectionsActions): SelectedItems;
18
+ export interface SearchReducerActions {
19
+ type: string;
20
+ data: SearchedItems;
21
+ }
22
+ export declare function searchReducer(collections: SearchedItems, action: SearchReducerActions): SearchedItems;
19
23
  export declare const CollectionIdContext: import("react").Context<string>;
@@ -1 +1 @@
1
- import{cloneDeep as t}from"lodash";import{createContext as a}from"react";function e(a,e){var o,c,s,d,n,l;let r={},i="",u="",p="";switch(e.type){case"selected":return console.log("vj: selectedColectionsReducer selected",e),r=t(a),e.data.val.isSmartCollection&&(e.data.isRestricted&&(r={}),r.isCustom=!0),r[e.data.id]=e.data.val,r;case"unselected":return r=t(a),(null==r?void 0:r.isCustom)&&(r.isCustom=!1),delete r[e.data.id],r;case"productUnselected":return r=t(a),i=e.data.productId,u=e.data.collectionId,delete r[u].products[i],Object.keys(r[u].products).length||((null==r?void 0:r.isCustom)&&(r.isCustom=!1),delete r[u]),r;case"productSelected":return r=t(a),i=e.data.productId,u=e.data.collectionId,(null===(o=e.data.catalogOnlyData)||void 0===o?void 0:o.isSmartCollection)&&(e.data.isRestricted&&(r={}),r.isCustom=!0),(null==r?void 0:r[u])||(r[u]=e.data.catalogOnlyData,r[u].products={}),r[u].products[i]=e.data.product,r;case"variantSelected":return r=t(a),i=e.data.productId,u=e.data.collectionId,p=e.data.variantId,(null===(c=e.data.catalogOnlyData)||void 0===c?void 0:c.isSmartCollection)&&(e.data.isRestricted&&(r={}),r.isCustom=!0),(null==r?void 0:r[u])||(r[u]=e.data.catalogOnlyData,r[u].products={},r[u].products[i]=e.data.productOnlyData,r[u].products[i].variants={}),(null===(d=null===(s=null==r?void 0:r[u])||void 0===s?void 0:s.products)||void 0===d?void 0:d[i])||((null===(n=null==r?void 0:r[u])||void 0===n?void 0:n.products)||(r[u].products={}),r[u].products[i]=e.data.productOnlyData,r[u].products[i].variants={}),r[u].products[i].variants[p]=e.data.variant,r;case"variantUnselected":return r=t(a),i=e.data.productId,u=e.data.collectionId,p=e.data.variantId,delete r[u].products[i].variants[p],Object.keys(r[u].products[i].variants).length||(delete r[u].products[i],Object.keys(r[u].products).length||((null===(l=r[u])||void 0===l?void 0:l.isSmartCollection)&&(r.isCustom=!1),delete r[u])),r;case"update":default:return a;case"reset":return{}}}function o(t,a){let e={};switch(a.type){case"fetched":return e=Object.assign({},a.data),e;case"productsFetched":return console.log("vj: productsFetched",{collections:t,action:a}),e=Object.assign({},t),e[a.data.collectionId].products=a.data.products,console.log("vj: collectionsCopy",{collectionsCopy:e}),e;case"paged":return console.log("vj: paged",{collections:t,action:a}),e=Object.assign(Object.assign({},t),a.data),e;case"productsPaged":return console.log("vj: pagedProducts",{collections:t,action:a}),e=Object.assign({},t),a.data.collectionId,e[a.data.collectionId].products=Object.assign(Object.assign({},e[a.data.collectionId].products),a.data.products),e;default:return{}}}function c(t,a){let e={};switch(a.type){case"paginate":console.log("vj: paginate",a),e=Object.assign({},t);for(const t in a.data)if(Object.prototype.hasOwnProperty.call(a.data,t)){const o=a.data[t];if(Object.prototype.hasOwnProperty.call(e,t)){const a=e[t];e[t]=Object.assign(Object.assign({},a),{products:Object.assign(Object.assign({},a.products),o.products)})}else e[t]=o}return console.log("vj: collections copy",e),e;case"update":return console.log("vj: update",a),e=Object.assign({},t),console.log("vj: update collection",a),e;case"set":return e=Object.assign(Object.assign({},t),a.data),console.log("vj: update collection",a),e;case"filter":e={};for(const o in t)if(o in a.data){const c=Object.assign({},t[o]),s=a.data[o],d={};for(const t in c.products)if(t in s.products){const a=Object.assign({},c.products[t]),e=s.products[t],o={};for(const t in a.variants)t in e.variants&&(o[t]=Object.assign({},a.variants[t]));Object.keys(o).length>0&&(a.variants=o,d[t]=a)}Object.keys(d).length>0&&(c.products=d,e[o]=c)}return e;default:return t}}function s(t,a){return"set"===a.type?a.data:t}const d=a("");export{d as CollectionIdContext,o as collectionsReducer,c as paginationReducer,s as searchReducer,e as selectedColectionsReducer};
1
+ import{cloneDeep as t}from"lodash";import{createContext as a}from"react";function e(a,e){var s,d,c,o,r,n;let i={},u="",l="",p="";switch(e.type){case"selected":return i=t(a),e.data.val.isSmartCollection&&(e.data.isRestricted&&(i={}),i.isCustom=!0),i[e.data.id]=e.data.val,i;case"unselected":return i=t(a),(null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[e.data.id],i;case"productUnselected":return i=t(a),u=e.data.productId,l=e.data.collectionId,delete i[l].products[u],Object.keys(i[l].products).length||((null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[l]),i;case"productSelected":return i=t(a),u=e.data.productId,l=e.data.collectionId,(null===(s=e.data.catalogOnlyData)||void 0===s?void 0:s.isSmartCollection)&&(e.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[l])||(i[l]=e.data.catalogOnlyData,i[l].products={}),i[l].products[u]=e.data.product,i;case"variantSelected":return i=t(a),u=e.data.productId,l=e.data.collectionId,p=e.data.variantId,(null===(d=e.data.catalogOnlyData)||void 0===d?void 0:d.isSmartCollection)&&(e.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[l])||(i[l]=e.data.catalogOnlyData,i[l].products={},i[l].products[u]=e.data.productOnlyData,i[l].products[u].variants={}),(null===(o=null===(c=null==i?void 0:i[l])||void 0===c?void 0:c.products)||void 0===o?void 0:o[u])||((null===(r=null==i?void 0:i[l])||void 0===r?void 0:r.products)||(i[l].products={}),i[l].products[u]=e.data.productOnlyData,i[l].products[u].variants={}),i[l].products[u].variants[p]=e.data.variant,i;case"variantUnselected":return i=t(a),u=e.data.productId,l=e.data.collectionId,p=e.data.variantId,delete i[l].products[u].variants[p],Object.keys(i[l].products[u].variants).length||(delete i[l].products[u],Object.keys(i[l].products).length||((null===(n=i[l])||void 0===n?void 0:n.isSmartCollection)&&(i.isCustom=!1),delete i[l])),i;case"update":return i=Object.assign({},a),i;case"reset":return{};default:return a}}function s(t,a){let e={};switch(a.type){case"fetched":return e=Object.assign({},a.data),e;case"productsFetched":return e=Object.assign({},t),e[a.data.collectionId].products=a.data.products,e;case"paged":return e=Object.assign(Object.assign({},t),a.data),e;case"productsPaged":return e=Object.assign({},t),e[a.data.collectionId].products=Object.assign(Object.assign({},e[a.data.collectionId].products),a.data.products),e;default:return{}}}function d(t,a){let e={};switch(a.type){case"paginate":console.log("vj: paginate",a),e=Object.assign({},t);for(const t in a.data)if(Object.prototype.hasOwnProperty.call(a.data,t)){const s=a.data[t];if(Object.prototype.hasOwnProperty.call(e,t)){const a=e[t];e[t]=Object.assign(Object.assign({},a),{products:Object.assign(Object.assign({},a.products),s.products)})}else e[t]=s}return e;case"update":return e=Object.assign({},t),e;case"set":return e=Object.assign(Object.assign({},t),a.data),e;case"filter":e={};for(const s in t)if(s in a.data){const d=Object.assign({},t[s]),c=a.data[s],o={};for(const t in d.products)if(t in c.products){const a=Object.assign({},d.products[t]),e=c.products[t],s={};for(const t in a.variants)t in e.variants&&(s[t]=Object.assign({},a.variants[t]));Object.keys(s).length>0&&(a.variants=s,o[t]=a)}Object.keys(o).length>0&&(d.products=o,e[s]=d)}return e;default:return t}}function c(t,a){return"set"===a.type?a.data:t}const o=a("");export{o as CollectionIdContext,s as collectionsReducer,d as paginationReducer,c as searchReducer,e as selectedColectionsReducer};
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" />
2
- import { Collection, FbStatusFetcherReturn, SelectedItems } from '.';
3
- import { SelectedCollectionsActions } from './reducers';
2
+ import { Collection, FbStatusFetcherReturn, SearchedItems, SelectedItems } from '.';
3
+ import { SearchReducerActions, SelectedCollectionsActions } from './reducers';
4
4
  interface SearchScreenInterface {
5
5
  customCollectionRestriction?: boolean;
6
6
  selectedCollections: SelectedItems;
7
- searchedCollections: SelectedItems;
8
- searchedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>;
7
+ searchedCollections: SearchedItems;
8
+ searchedCollectionsDispatch: React.Dispatch<SearchReducerActions>;
9
9
  selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>;
10
10
  setScreen: React.Dispatch<React.SetStateAction<string>>;
11
11
  collections: {
@@ -1 +1 @@
1
- import{jsxs as o,jsx as t,Fragment as e}from"react/jsx-runtime";import i from"../../assets/icons/arrow_left.svg.js";import{useEffect as r}from"react";import{IconButton as c}from"../icon-button/IconButton.js";import{BodyCaption as l}from"../TypographyStyle.js";import{EmptyState as s}from"./emptyState.js";import{ProductGroup as d}from"./productScreen.js";import{SelectedScreenHeader as n}from"./style.js";import{fetchFbStatusCollection as u,liftTheStateUp as a}from"./utility.js";const p=p=>{const{customCollectionRestriction:v,selectedCollections:h,searchedCollections:m,searchedCollectionsDispatch:f,selectedCollectionsDispatch:y,setScreen:j,collections:k,onBackPress:b,hideVariantCheckbox:C,pickerType:O,hideProductVariants:P,hideProductCheckbox:g,storeId:x,fbStatusFetcher:S}=p;r((()=>{u(m,x,f,S,"set")}),[m]);const I=(o,t)=>{var e,i,r,c,l,s,d,n,u;let a=0,p=0;return!!((null===(i=null===(e=null==h?void 0:h[o])||void 0===e?void 0:e.products)||void 0===i?void 0:i[t])&&(null===(s=Object.keys((null===(l=null===(c=null===(r=null==k?void 0:k[o])||void 0===r?void 0:r.products)||void 0===c?void 0:c[t])||void 0===l?void 0:l.variants)||[]))||void 0===s||s.forEach((()=>p++)),Object.keys((null===(u=null===(n=null===(d=null==h?void 0:h[o])||void 0===d?void 0:d.products)||void 0===n?void 0:n[t])||void 0===u?void 0:u.variants)||[]).forEach((()=>a++)),a>0&&p!==a))};return o("div",{children:[o(n,{children:[t(c,{Icon:i,onClick:()=>{j("collections"),b()}}),t(l,{children:"Searched Products"})]}),t("div",{children:Object.keys(m).length?t(e,{children:Object.keys(m).map((o=>{var e;return Object.keys((null===(e=null==m?void 0:m[o])||void 0===e?void 0:e.products)||[]).map((e=>{let i=!1;return(null==m?void 0:m.isCustom)&&(i=!0),t(d,{collectionId:o,upliftAdditions:(t,e)=>((o,t,e)=>{const i=a(e,m[o]);y({type:t,data:Object.assign(Object.assign({},i),{isRestricted:v})})})(o,t,e),productId:e,data:m[o].products[e],isProductPartiallyChecked:I(o,e),selectedData:h,selectedCollectionsDispatch:y,viewOnly:i,hideProductCheckbox:g,hideVariantCheckbox:C,hideProductVariants:P,pickerType:O},e)}))}))}):t(s,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};export{p as SearchScreen};
1
+ import{jsxs as o,jsx as t,Fragment as i}from"react/jsx-runtime";import e from"../../assets/icons/arrow_left.svg.js";import{useEffect as l}from"react";import{IconButton as d}from"../icon-button/IconButton.js";import{BodyCaption as r}from"../TypographyStyle.js";import{EmptyState as c}from"./emptyState.js";import{ProductGroup as s}from"./productScreen.js";import{SelectedScreenHeader as n}from"./style.js";import{fetchFbStatusCollection as u,liftTheStateUp as v}from"./utility.js";const a=a=>{const{customCollectionRestriction:p,selectedCollections:h,searchedCollections:m,searchedCollectionsDispatch:f,selectedCollectionsDispatch:y,setScreen:j,collections:k,onBackPress:b,hideVariantCheckbox:C,pickerType:O,hideProductVariants:P,hideProductCheckbox:g,storeId:x,fbStatusFetcher:S}=a;l((()=>{var o;u(null!==(o=m.products)&&void 0!==o?o:{},x,f,S,"set")}),[null==m?void 0:m.products]);const I=(o,t)=>{var i,e,l,d,r,c,s,n,u;let v=0,a=0;return!!((null===(e=null===(i=null==h?void 0:h[o])||void 0===i?void 0:i.products)||void 0===e?void 0:e[t])&&(null===(c=Object.keys((null===(r=null===(d=null===(l=null==k?void 0:k[o])||void 0===l?void 0:l.products)||void 0===d?void 0:d[t])||void 0===r?void 0:r.variants)||[]))||void 0===c||c.forEach((()=>a++)),Object.keys((null===(u=null===(n=null===(s=null==h?void 0:h[o])||void 0===s?void 0:s.products)||void 0===n?void 0:n[t])||void 0===u?void 0:u.variants)||[]).forEach((()=>v++)),v>0&&a!==v))};return o("div",{children:[o(n,{children:[t(d,{Icon:e,onClick:()=>{j("collections"),b()}}),t(r,{children:"Searched Products"})]}),t("div",{children:Object.keys(null==m?void 0:m.products).length?t(i,{children:Object.keys(null==m?void 0:m.products).map((o=>{var i,e;return Object.keys((null===(e=null===(i=null==m?void 0:m.products)||void 0===i?void 0:i[o])||void 0===e?void 0:e.products)||[]).map((i=>{var e,l;let d=!1;return(null===(e=null==m?void 0:m.products)||void 0===e?void 0:e.isCustom)&&(d=!0),t(s,{collectionId:o,upliftAdditions:(t,i)=>((o,t,i)=>{var e;const l=v(i,null===(e=null==m?void 0:m.products)||void 0===e?void 0:e[o]);y({type:t,data:Object.assign(Object.assign({},l),{isRestricted:p})})})(o,t,i),productId:i,data:(null===(l=null==m?void 0:m.products)||void 0===l?void 0:l[o].products)[i],isProductPartiallyChecked:I(o,i),selectedData:h,selectedCollectionsDispatch:y,viewOnly:d,hideProductCheckbox:g,hideVariantCheckbox:C,hideProductVariants:P,pickerType:O},i)}))}))}):t(c,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};export{a as SearchScreen};
@@ -1,6 +1,13 @@
1
- import { Collection, FbStatusFetcherReturn, SelectedItems } from './modal';
1
+ import { Collection, FbStatusFetcherReturn, Product, SelectedItems } from './modal';
2
+ import { CollectionsActions } from './reducers';
2
3
  export declare const liftTheStateUp: (payload: any, data: any) => any;
3
4
  export declare function paginateSelectedItems(selectedItems: SelectedItems, limit: number, offset: number): {
4
5
  [key: string]: Collection;
5
6
  };
6
7
  export declare const fetchFbStatusCollection: (data: SelectedItems, storeId: string, dispatcher: any, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, dispatchType?: string) => void;
8
+ export declare const getVariantIdsToFetchAtProductLevel: (products: {
9
+ [key: string]: Product;
10
+ }, globalData?: Collection) => string[];
11
+ export declare const markVariantsAsApprovedProductsLevel: (products: {
12
+ [key: string]: Product;
13
+ }, dispatcher: React.Dispatch<CollectionsActions>, collectionId: string, curScreenData?: Collection, setCurScreenData?: React.Dispatch<React.SetStateAction<Collection>>) => void;
@@ -1 +1 @@
1
- import{cloneDeep as o}from"lodash";const t=(t,n)=>{const l=o(n);if(delete l.products,(t=Object.assign(Object.assign({},t),{catalogOnlyData:l})).productId&&n.products){const d=o(n.products[t.productId]);(null==d?void 0:d.variants)&&delete d.variants,t=Object.assign(Object.assign({},t),{catalogOnlyData:l,productOnlyData:d})}return t};function n(o,t,n){var d;const i={};let s=0;console.log("paginated offset",n);for(const c in o)if(Object.prototype.hasOwnProperty.call(o,c)){const v=o[c],a=l(v.products,t,n-s);a&&Object.keys(a).length>0&&(i[c]=Object.assign(Object.assign({},v),{products:a})),s+=Object.keys(null!==(d=v.products)&&void 0!==d?d:{}).length}return i}function l(o,t,n){if(!o)return{};const l=Object.keys(o).slice(n,n+t),d={};return l.forEach((t=>{d[t]=o[t]})),d}const d=(o,t,n)=>{Object.keys(o).forEach((t=>{var n,l;const d=null!==(l=null===(n=o[t])||void 0===n?void 0:n.products)&&void 0!==l?l:{};Object.keys(d).forEach((n=>{var l,d,i,s;const c=null!==(s=null===(i=null===(d=null===(l=o[t])||void 0===l?void 0:l.products)||void 0===d?void 0:d[n])||void 0===i?void 0:i.variants)&&void 0!==s?s:{};Object.keys(c).forEach((l=>{var d,i,s,c;const v=null===(c=null===(s=null===(i=null===(d=o[t])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[l];v&&!v.fbStatus&&(v.fbStatus="APPROVED")}))}))})),t({type:n,data:o})},i=function(o,t,n,l){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";l||d(o,n,i);const s=(o=>{const t=[];return Object.keys(o).forEach((n=>{var l,d;const i=null!==(d=null===(l=o[n])||void 0===l?void 0:l.products)&&void 0!==d?d:{};Object.keys(i).forEach((l=>{var d,i,s,c;const v=null!==(c=null===(s=null===(i=null===(d=o[n])||void 0===d?void 0:d.products)||void 0===i?void 0:i[l])||void 0===s?void 0:s.variants)&&void 0!==c?c:{};Object.keys(v).forEach((d=>{var i,s,c,v;const a=null===(v=null===(c=null===(s=null===(i=o[n])||void 0===i?void 0:i.products)||void 0===s?void 0:s[l])||void 0===c?void 0:c.variants)||void 0===v?void 0:v[d];(null==a?void 0:a.fbStatus)||t.push(d)}))}))})),t})(o);console.log("vj: variantids",s),s.length>0&&l&&l(t,s).then((t=>{const l=Object.assign({},o);Object.keys(l).forEach((o=>{var n,d;const i=null!==(d=null===(n=l[o])||void 0===n?void 0:n.products)&&void 0!==d?d:{};Object.keys(i).forEach((n=>{var d,i,s,c;const v=null!==(c=null===(s=null===(i=null===(d=l[o])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)&&void 0!==c?c:{};Object.keys(v).forEach((d=>{var i,s,c,v;const a=null===(v=null===(c=null===(s=null===(i=l[o])||void 0===i?void 0:i.products)||void 0===s?void 0:s[n])||void 0===c?void 0:c.variants)||void 0===v?void 0:v[d];a&&"REJECTED"===t[d]?a.fbStatus="REJECTED":a&&"APPROVED"===t[d]&&(a.fbStatus="APPROVED")}))}))})),console.log("updated data",l,i),n({type:i,data:l})})).catch((t=>{console.error("Error in fbStatusFetcher",t),d(o,n,i)}))};export{i as fetchFbStatusCollection,t as liftTheStateUp,n as paginateSelectedItems};
1
+ import{cloneDeep as o}from"lodash";const t=(t,l)=>{const n=o(l);if(delete n.products,(t=Object.assign(Object.assign({},t),{catalogOnlyData:n})).productId&&l.products){const d=o(l.products[t.productId]);(null==d?void 0:d.variants)&&delete d.variants,t=Object.assign(Object.assign({},t),{catalogOnlyData:n,productOnlyData:d})}return t};function l(o,t,l){var d;const i={};let v=0;console.log("paginated offset",l);for(const s in o)if(Object.prototype.hasOwnProperty.call(o,s)){const c=o[s],a=n(c.products,t,l-v);a&&Object.keys(a).length>0&&(i[s]=Object.assign(Object.assign({},c),{products:a})),v+=Object.keys(null!==(d=c.products)&&void 0!==d?d:{}).length}return i}function n(o,t,l){if(!o)return{};const n=Object.keys(o).slice(l,l+t),d={};return n.forEach((t=>{d[t]=o[t]})),d}const d=(o,t,l)=>{Object.keys(o).forEach((t=>{var l,n;const d=null!==(n=null===(l=o[t])||void 0===l?void 0:l.products)&&void 0!==n?n:{};Object.keys(d).forEach((l=>{var n,d,i,v;const s=null!==(v=null===(i=null===(d=null===(n=o[t])||void 0===n?void 0:n.products)||void 0===d?void 0:d[l])||void 0===i?void 0:i.variants)&&void 0!==v?v:{};Object.keys(s).forEach((n=>{var d,i,v,s;const c=null===(s=null===(v=null===(i=null===(d=o[t])||void 0===d?void 0:d.products)||void 0===i?void 0:i[l])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[n];c&&!c.fbStatus&&(c.fbStatus="APPROVED")}))}))})),t({type:l,data:o})},i=function(o,t,l,n){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";n||d(o,l,i);const v=(o=>{const t=[];return Object.keys(o).forEach((l=>{var n,d;const i=null!==(d=null===(n=o[l])||void 0===n?void 0:n.products)&&void 0!==d?d:{};Object.keys(i).forEach((n=>{var d,i,v,s;const c=null!==(s=null===(v=null===(i=null===(d=o[l])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(c).forEach((d=>{var i,v,s,c;const a=null===(c=null===(s=null===(v=null===(i=o[l])||void 0===i?void 0:i.products)||void 0===v?void 0:v[n])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[d];(null==a?void 0:a.fbStatus)||t.push(d)}))}))})),t})(o);console.log("vj: variantids",v),v.length>0&&n&&n(t,v).then((t=>{const n=Object.assign({},o);Object.keys(n).forEach((o=>{var l,d;const i=null!==(d=null===(l=n[o])||void 0===l?void 0:l.products)&&void 0!==d?d:{};Object.keys(i).forEach((l=>{var d,i,v,s;const c=null!==(s=null===(v=null===(i=null===(d=n[o])||void 0===d?void 0:d.products)||void 0===i?void 0:i[l])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(c).forEach((d=>{var i,v,s,c;const a=null===(c=null===(s=null===(v=null===(i=n[o])||void 0===i?void 0:i.products)||void 0===v?void 0:v[l])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[d];a&&"REJECTED"===t[d]?a.fbStatus="REJECTED":a&&"APPROVED"===t[d]&&(a.fbStatus="APPROVED")}))}))})),console.log("updated data",n,i),l({type:i,data:n})})).catch((t=>{console.error("Error in fbStatusFetcher",t),d(o,l,i)}))},v=(o,t)=>{const l=[];return Object.keys(null!=o?o:{}).forEach((n=>{var d,i;const v=null!==(i=null===(d=null==o?void 0:o[n])||void 0===d?void 0:d.variants)&&void 0!==i?i:{};Object.keys(v).forEach((d=>{var i,v,s,c,a;let u;u=t?null===(s=null===(v=null===(i=null==t?void 0:t.products)||void 0===i?void 0:i[n])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[d]:null===(a=null===(c=null==o?void 0:o[n])||void 0===c?void 0:c.variants)||void 0===a?void 0:a[d],(null==u?void 0:u.fbStatus)||l.push(d)}))})),l},s=(o,t,l,n,d)=>{const i=Object.assign({},o);if(Object.keys(o).forEach((t=>{var l,n;Object.keys(null!==(n=null===(l=null==o?void 0:o[t])||void 0===l?void 0:l.variants)&&void 0!==n?n:{}).forEach((l=>{var n,d;const v=null===(n=null==o?void 0:o[t].variants)||void 0===n?void 0:n[l];v&&(v.fbStatus="APPROVED");const s=null===(d=null==i?void 0:i[t])||void 0===d?void 0:d.variants;s&&s[l]&&(s[l]=v)}))})),n&&d){const o=Object.assign({},n);o.products=i,d(o)}else t({type:"productsPaged",data:{collectionId:l,products:i}})};export{i as fetchFbStatusCollection,v as getVariantIdsToFetchAtProductLevel,t as liftTheStateUp,s as markVariantsAsApprovedProductsLevel,l as paginateSelectedItems};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.454-beta.ppi-7",
3
+ "version": "0.0.454-beta.ppi-9",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",