@bikdotai/bik-component-library 0.0.439-beta.ppi-15 → 0.0.439-beta.ppi-17

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,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const Menus: ({
3
2
  displayName: string;
4
3
  key: number;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),r=require("../../assets/icons/search.svg.js"),o=require("react"),c=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"),S=require("./rearrangeScreen.js"),p=require("./reducers.js"),C=require("./searchScreen.js"),x=require("./selectedScreen.js"),g=require("./style.js"),j=require("./type.js"),b=require("./useFetchFbStatus.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:f,onClose:y,visible:P,zIndex:F,minlimit:v,limit:I,hideCollectionCheckbox:k,hideProductCheckbox:O,outOfStockAction:T=j.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:R,selectProductsFromCustomCollection:q,hideSelectionCount:E,title:D,width:w,renderWithoutModal:N,onClickSave:A,pickerType:B,hideProductVariants:M=!1,startupScreen:V=exports.ScreenName.Collections,rearrangeEnabled:L,showProductDetailInfoIcon:_}=e,[$,z]=o.useReducer(p.collectionsReducer,{}),[G,H]=o.useState([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(V)?V: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),[re,oe]=o.useState(0),[ce,se]=o.useState(""),[ne,ie]=o.useState(!1),[le,ae]=o.useState(!1),[de,ue]=o.useState(),[he,Se]=o.useReducer(p.selectedColectionsReducer,Object.keys(f).length>0?f:{}),pe=o.useRef(null),[Ce,xe]=o.useState(!1),[ge,je]=o.useState(),{fetchFbStatus:be}=b.useFetchFbStatusForCollections(he,m,Se,e.fbStatusFetcher,!1);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 r;Object.keys((null===(r=he[t])||void 0===r?void 0:r.products)||[]).forEach((r=>{var o,c;Object.keys((null===(c=null===(o=he[t].products)||void 0===o?void 0:o[r])||void 0===c?void 0:c.variants)||[]).forEach((()=>{e+=1}))}))})),oe(e)})),o.useEffect((()=>{}),[U]),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((()=>{be()}),[he]),o.useEffect((()=>{const t=setTimeout((()=>{"rearrange"!==G&&(ce.length?(ie(!0),e.searchFetcher(m,ce).then((e=>{ue(Object.assign({},e)),H("searchProducts"),te(!1),ie(!1)}))):H("collections"))}),800);return()=>clearTimeout(t)}),[ce]),o.useEffect((()=>{A&&(e.onAdd(he,re),me())}),[A]);const me=()=>{Se({type:"reset",data:{}})},fe=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:N?"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:c.COLORS.content.primary}):t.jsx(r.default,{})},id:"listInput",height:"24px",type:"text",value:ce,onChangeText:e=>{e.length&&e.trim().length?se(e):se("")}})}))}),t.jsxs(g.ScrollContainerStyle,Object.assign({ref:pe},{children:["collections"===G&&t.jsx(d.CollectionsScreen,{customCollectionRestriction:e.customCollectionRestriction,dataLoading:le,collections:$,selectedCollectionsDispatch:Se,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:N,pickerType:B}),"products"===G&&U&&t.jsx(p.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:Se,selectedData:he,setSaveDisabled:te,searchInCollectionFetcher:e.searchInCollectionFetcher,hideProductCheckbox:O,outOfStockAction:T,hideVariantCheckbox:R,selectProductsFromCustomCollection:q,renderWithoutModal:N,pickerType:B,hideProductVariants:M,fbStatusFetcher:e.fbStatusFetcher,onInfoIconClick:e=>{xe(!0),je(e)},showProductDetailInfoIcon:_})})),"view"===G&&t.jsx(x.SelectedScreen,{selectedCollections:he||{},selectedCollectionsDispatch:Se,setScreen:H,collections:$,outOfStockAction:T,storeId:m,fbStatusFetcher:e.fbStatusFetcher}),"rearrange"===G&&t.jsx(S.RearrangeScreen,{selectedCollections:he||{},selectedCollectionsDispatch:Se,setScreen:H,outOfStockAction:T,rearrangeViewType:"grid"===W?"list":"grid",scrollContainerRef:pe,storeId:m,fbStatusFetcher:e.fbStatusFetcher}),"searchProducts"===G&&t.jsx(C.SearchScreen,{customCollectionRestriction:e.customCollectionRestriction,selectedCollections:he||{},searchedCollections:de||{},setSearchedCollections:ue,selectedCollectionsDispatch:Se,setScreen:H,collections:$,onBackPress:()=>{se(""),ue({})},pickerType:B,hideProductCheckbox:O,hideProductVariants:M,hideVariantCheckbox:R,storeId:m,fbStatusFetcher:e.fbStatusFetcher})]}))]});return t.jsx(t.Fragment,{children:N?fe:t.jsxs(i.StyledModal,Object.assign({zIndex:F,open:P,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:w||"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||re<1||v&&re<v||I&&re>I||!1,onClick:()=>{e.onAdd(he,re),me()}},footerLeftCustomElement:E?t.jsx(t.Fragment,{}):v&&re<v?t.jsx(a.Tag,{tagText:`Minimum limit is ${v} products`,type:"negative"}):I&&re>I?t.jsx(a.Tag,{tagText:`You can only select ${I} products`,type:"negative"}):re>0?t.jsx(s.Button,{onClick:()=>{H(L?exports.ScreenName.RearrangeProducts:exports.ScreenName.SelectedProducts)},buttonText:`${re} products selected`,buttonType:["rearrange","view"].includes(G)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(G)}):t.jsx(s.Button,{disabled:!0,buttonText:`${re} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:Ce},{children:[fe,Ce&&ge?t.jsx(u.ProductInfoOverlay,{productData:ge,outOfStockAction:T,onClose:()=>{xe(!1)}}):t.jsx(t.Fragment,{})]}))})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),r=require("../../assets/icons/search.svg.js"),o=require("react"),c=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"),S=require("./rearrangeScreen.js"),p=require("./reducers.js"),C=require("./searchScreen.js"),x=require("./selectedScreen.js"),g=require("./style.js"),j=require("./type.js"),m=require("./useFetchFbStatus.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:b,selectedItems:f,onClose:y,visible:P,zIndex:v,minlimit:F,limit:I,hideCollectionCheckbox:k,hideProductCheckbox:O,outOfStockAction:T=j.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:R,selectProductsFromCustomCollection:q,hideSelectionCount:E,title:D,width:w,renderWithoutModal:N,onClickSave:A,pickerType:B,hideProductVariants:M=!1,startupScreen:V=exports.ScreenName.Collections,rearrangeEnabled:L,showProductDetailInfoIcon:_}=e,[$,z]=o.useReducer(p.collectionsReducer,{}),[G,H]=o.useState([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(V)?V: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),[re,oe]=o.useState(0),[ce,se]=o.useState(""),[ne,ie]=o.useState(!1),[le,ae]=o.useState(!1),[de,ue]=o.useState({}),[he,Se]=o.useReducer(p.selectedColectionsReducer,Object.keys(f).length>0?f:{}),pe=o.useRef(null),[Ce,xe]=o.useState(!1),[ge,je]=o.useState();m.useFetchFbStatusForCollections(he,b,Se,e.fbStatusFetcher,!1),o.useEffect((()=>{te(!0),ae(!0),e.collectionFetcher(X,b).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 r;Object.keys((null===(r=he[t])||void 0===r?void 0:r.products)||[]).forEach((r=>{var o,c;Object.keys((null===(c=null===(o=he[t].products)||void 0===o?void 0:o[r])||void 0===c?void 0:c.variants)||[]).forEach((()=>{e+=1}))}))})),oe(e)})),o.useEffect((()=>{}),[U]),o.useEffect((()=>{J&&(te(!0),e.productFetcher(J,b).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&&(ce.length?(ie(!0),e.searchFetcher(b,ce).then((e=>{ue(Object.assign({},e)),H("searchProducts"),te(!1),ie(!1)}))):H("collections"))}),800);return()=>clearTimeout(t)}),[ce]),o.useEffect((()=>{A&&(e.onAdd(he,re),me())}),[A]);const me=()=>{Se({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:N?"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:c.COLORS.content.primary}):t.jsx(r.default,{})},id:"listInput",height:"24px",type:"text",value:ce,onChangeText:e=>{e.length&&e.trim().length?se(e):se("")}})}))}),t.jsxs(g.ScrollContainerStyle,Object.assign({ref:pe},{children:["collections"===G&&t.jsx(d.CollectionsScreen,{customCollectionRestriction:e.customCollectionRestriction,dataLoading:le,collections:$,selectedCollectionsDispatch:Se,setCollectionId:Y,setSelectedCollectionId:Q,setScreen:H,selectedCollections:he,collectionFetcher:e.collectionFetcher,storeId:b,collectionsDispatch:z,setSaveDisabled:te,pagingControls:{curPage:X,setCurPage:Z},hideCollectionCheckbox:k,renderWithoutModal:N,pickerType:B}),"products"===G&&U&&t.jsx(p.CollectionIdContext.Provider,Object.assign({value:U},{children:t.jsx(h.ProductsScreen,{hideInCollectionSearch:e.hideInCollectionSearch,customCollectionRestriction:e.customCollectionRestriction,productFetcher:e.productFetcher,setScreen:H,storeId:b,data:$[U],collectionsDispatch:z,selectedCollectionsDispatch:Se,selectedData:he,setSaveDisabled:te,searchInCollectionFetcher:e.searchInCollectionFetcher,hideProductCheckbox:O,outOfStockAction:T,hideVariantCheckbox:R,selectProductsFromCustomCollection:q,renderWithoutModal:N,pickerType:B,hideProductVariants:M,fbStatusFetcher:e.fbStatusFetcher,onInfoIconClick:e=>{xe(!0),je(e)},showProductDetailInfoIcon:_})})),"view"===G&&t.jsx(x.SelectedScreen,{selectedCollections:he||{},selectedCollectionsDispatch:Se,setScreen:H,collections:$,outOfStockAction:T,storeId:b,fbStatusFetcher:e.fbStatusFetcher}),"rearrange"===G&&t.jsx(S.RearrangeScreen,{selectedCollections:he||{},selectedCollectionsDispatch:Se,setScreen:H,outOfStockAction:T,rearrangeViewType:"grid"===W?"list":"grid",scrollContainerRef:pe,storeId:b,fbStatusFetcher:e.fbStatusFetcher}),"searchProducts"===G&&t.jsx(C.SearchScreen,{customCollectionRestriction:e.customCollectionRestriction,selectedCollections:he||{},searchedCollections:de||{},setSearchedCollections:ue,selectedCollectionsDispatch:Se,setScreen:H,collections:$,onBackPress:()=>{se(""),ue({})},pickerType:B,hideProductCheckbox:O,hideProductVariants:M,hideVariantCheckbox:R,storeId:b,fbStatusFetcher:e.fbStatusFetcher})]}))]});return t.jsx(t.Fragment,{children:N?be:t.jsxs(i.StyledModal,Object.assign({zIndex:v,open:P,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:w||"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||re<1||F&&re<F||I&&re>I||!1,onClick:()=>{e.onAdd(he,re),me()}},footerLeftCustomElement:E?t.jsx(t.Fragment,{}):F&&re<F?t.jsx(a.Tag,{tagText:`Minimum limit is ${F} products`,type:"negative"}):I&&re>I?t.jsx(a.Tag,{tagText:`You can only select ${I} products`,type:"negative"}):re>0?t.jsx(s.Button,{onClick:()=>{H(L?exports.ScreenName.RearrangeProducts:exports.ScreenName.SelectedProducts)},buttonText:`${re} products selected`,buttonType:["rearrange","view"].includes(G)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(G)}):t.jsx(s.Button,{disabled:!0,buttonText:`${re} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:Ce},{children:[be,Ce&&ge?t.jsx(u.ProductInfoOverlay,{productData:ge,outOfStockAction:T,onClose:()=>{xe(!1)}}):t.jsx(t.Fragment,{})]}))})};
@@ -5,7 +5,7 @@ interface SearchScreenInterface {
5
5
  customCollectionRestriction?: boolean;
6
6
  selectedCollections: SelectedItems;
7
7
  searchedCollections: SelectedItems;
8
- setSearchedCollections: React.Dispatch<React.SetStateAction<SelectedItems | undefined>>;
8
+ setSearchedCollections: React.Dispatch<React.SetStateAction<SelectedItems>>;
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"),s=require("../icon-button/IconButton.js"),r=require("../TypographyStyle.js"),n=require("./emptyState.js"),c=require("./productScreen.js"),i=require("./style.js"),l=require("./utility.js");exports.SelectedScreen=d=>{const{selectedCollections:u,selectedCollectionsDispatch:a,setScreen:v,collections:p,outOfStockAction:j}=d,[g,f]=o.useState({}),b=o.useRef(0),O=o.useRef(null);o.useEffect((()=>{b.current=0;const e=l.paginateSelectedItems(u,10,b.current);console.log("paginated",{paginatedProducts:e,selectedCollections:u}),f(e),b.current+=1}),[]),o.useEffect((()=>{f((e=>{var t,o,s,r,n,c;const i=Object.assign({},e);for(const e in i)if(e in i){const l=i[e],d=u[e],a={};for(const u in l.products)if(u in l.products)if(u in(null!==(t=null==d?void 0:d.products)&&void 0!==t?t:{})){const e=l.products[u],t={};for(const n in e.variants)if(n in e.variants){void 0!==(null===(r=null===(s=null===(o=null==d?void 0:d.products)||void 0===o?void 0:o[u])||void 0===s?void 0:s.variants)||void 0===r?void 0:r[n])&&(t[n]=e.variants[n])}Object.keys(t).length>0&&(a[u]=Object.assign(Object.assign({},e),{variants:t}))}else null===(c=null===(n=null==i?void 0:i[e])||void 0===n?void 0:n.products)||void 0===c||delete c[u];i[e]=Object.assign(Object.assign({},l),{products:a})}return i}))}),[u]),o.useEffect((()=>{console.log("vj: observertarget",O.current);const e=new IntersectionObserver((e=>{if(console.log("vj: observertargetinside",e),e[0].isIntersecting&&(console.log("vj: nextPageRef",b.current),b.current>0)){const e=l.paginateSelectedItems(u,10,b.current);console.log("paginated inside observer target",{paginatedProducts:e,selectedCollections:u,curScreenData:g}),f((t=>{const o=Object.assign({},t);for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const s=e[t];if(Object.prototype.hasOwnProperty.call(o,t)){const e=o[t];o[t]=Object.assign(Object.assign({},e),{products:Object.assign(Object.assign({},e.products),s.products)})}else o[t]=s}return o})),b.current+=1}}),{threshold:1});return O.current&&e.observe(O.current),()=>{O.current&&e.unobserve(O.current)}}),[O,u]);const y=(e,t)=>{var o,s,r,n,c,i,l,d,a;let v=0,j=0;return!!((null===(s=null===(o=null==u?void 0:u[e])||void 0===o?void 0:o.products)||void 0===s?void 0:s[t])&&(null===(i=Object.keys((null===(c=null===(n=null===(r=null==p?void 0:p[e])||void 0===r?void 0:r.products)||void 0===n?void 0:n[t])||void 0===c?void 0:c.variants)||[]))||void 0===i||i.forEach((()=>j++)),Object.keys((null===(a=null===(d=null===(l=null==u?void 0:u[e])||void 0===l?void 0:l.products)||void 0===d?void 0:d[t])||void 0===a?void 0:a.variants)||[]).forEach((()=>v++)),v>0&&j!==v))};return e.jsxs("div",{children:[e.jsxs(i.SelectedScreenHeader,{children:[e.jsx(s.IconButton,{Icon:t.default,onClick:()=>{v("collections")}}),e.jsx(r.BodyCaption,{children:"Selected Products"})]}),e.jsxs("div",{children:[Object.keys(g).length>0?e.jsx(e.Fragment,{children:Object.keys(g).map((t=>{var o;return Object.keys((null===(o=null==g?void 0:g[t])||void 0===o?void 0:o.products)||[]).map((o=>{let s=!1;return(null==g?void 0:g.isCustom)&&(s=!0),e.jsx(c.ProductGroup,{upliftAdditions:null,collectionId:t,productId:o,data:g[t].products[o],isProductPartiallyChecked:y(t,o),selectedData:u,selectedCollectionsDispatch:a,viewOnly:s,outOfStockAction:j},o)}))}))}):e.jsx(n.EmptyState,{title:"No Products Selected",subtitle:"Select products will appear here"}),e.jsx("div",{ref:O})]})]})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),s=require("react"),o=require("../icon-button/IconButton.js"),r=require("../TypographyStyle.js"),n=require("./emptyState.js"),c=require("./productScreen.js"),i=require("./style.js"),l=require("./useFetchFbStatus.js"),u=require("./utility.js");exports.SelectedScreen=d=>{const{selectedCollections:a,selectedCollectionsDispatch:v,setScreen:p,collections:j,outOfStockAction:f,storeId:b,fbStatusFetcher:g}=d,[O,h]=s.useState({}),S=s.useRef(0),y=s.useRef(null),{fetchFbStatus:x}=l.useFetchFbStatusForCollections(O,b,v,g,!1,h);s.useEffect((()=>{x()}),[O]),s.useEffect((()=>{S.current=0;const e=u.paginateSelectedItems(a,10,S.current);console.log("paginated",{paginatedProducts:e,selectedCollections:a}),h(e),S.current+=1}),[]),s.useEffect((()=>{h((e=>{var t,s,o,r,n,c;const i=Object.assign({},e);for(const e in i)if(e in i){const l=i[e],u=a[e],d={};for(const a in l.products)if(a in l.products)if(a in(null!==(t=null==u?void 0:u.products)&&void 0!==t?t:{})){const e=l.products[a],t={};for(const n in e.variants)if(n in e.variants){void 0!==(null===(r=null===(o=null===(s=null==u?void 0:u.products)||void 0===s?void 0:s[a])||void 0===o?void 0:o.variants)||void 0===r?void 0:r[n])&&(t[n]=e.variants[n])}Object.keys(t).length>0&&(d[a]=Object.assign(Object.assign({},e),{variants:t}))}else null===(c=null===(n=null==i?void 0:i[e])||void 0===n?void 0:n.products)||void 0===c||delete c[a];i[e]=Object.assign(Object.assign({},l),{products:d})}return i}))}),[a]),s.useEffect((()=>{console.log("vj: observertarget",y.current);const e=new IntersectionObserver((e=>{if(console.log("vj: observertargetinside",e),e[0].isIntersecting&&(console.log("vj: nextPageRef",S.current),S.current>0)){const e=u.paginateSelectedItems(a,10,S.current);console.log("paginated inside observer target",{paginatedProducts:e,selectedCollections:a,curScreenData:O}),h((t=>{const s=Object.assign({},t);for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const o=e[t];if(Object.prototype.hasOwnProperty.call(s,t)){const e=s[t];s[t]=Object.assign(Object.assign({},e),{products:Object.assign(Object.assign({},e.products),o.products)})}else s[t]=o}return s})),S.current+=1}}),{threshold:1});return y.current&&e.observe(y.current),()=>{y.current&&e.unobserve(y.current)}}),[y,a]);const P=(e,t)=>{var s,o,r,n,c,i,l,u,d;let v=0,p=0;return!!((null===(o=null===(s=null==a?void 0:a[e])||void 0===s?void 0:s.products)||void 0===o?void 0:o[t])&&(null===(i=Object.keys((null===(c=null===(n=null===(r=null==j?void 0:j[e])||void 0===r?void 0:r.products)||void 0===n?void 0:n[t])||void 0===c?void 0:c.variants)||[]))||void 0===i||i.forEach((()=>p++)),Object.keys((null===(d=null===(u=null===(l=null==a?void 0:a[e])||void 0===l?void 0:l.products)||void 0===u?void 0:u[t])||void 0===d?void 0:d.variants)||[]).forEach((()=>v++)),v>0&&p!==v))};return e.jsxs("div",{children:[e.jsxs(i.SelectedScreenHeader,{children:[e.jsx(o.IconButton,{Icon:t.default,onClick:()=>{p("collections")}}),e.jsx(r.BodyCaption,{children:"Selected Products"})]}),e.jsxs("div",{children:[Object.keys(O).length>0?e.jsx(e.Fragment,{children:Object.keys(O).map((t=>{var s;return Object.keys((null===(s=null==O?void 0:O[t])||void 0===s?void 0:s.products)||[]).map((s=>{let o=!1;return(null==O?void 0:O.isCustom)&&(o=!0),e.jsx(c.ProductGroup,{upliftAdditions:null,collectionId:t,productId:s,data:O[t].products[s],isProductPartiallyChecked:P(t,s),selectedData:a,selectedCollectionsDispatch:v,viewOnly:o,outOfStockAction:f},s)}))}))}):e.jsx(n.EmptyState,{title:"No Products Selected",subtitle:"Select products will appear here"}),e.jsx("div",{ref:y})]})]})};
@@ -1,5 +1,5 @@
1
1
  import { FbStatusFetcherReturn, SelectedItems } from './modal';
2
2
  import { SelectedCollectionsActions } from './reducers';
3
- export declare const useFetchFbStatusForCollections: (data: SelectedItems, storeId: string, selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, autoFetch?: boolean, setSearchedCollections?: React.Dispatch<React.SetStateAction<SelectedItems | undefined>>) => {
3
+ export declare const useFetchFbStatusForCollections: (data: SelectedItems, storeId: string, selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, autoFetch?: boolean, setSearchedCollections?: React.Dispatch<React.SetStateAction<SelectedItems>>) => {
4
4
  fetchFbStatus: () => void;
5
5
  };
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const Menus: ({
3
2
  displayName: string;
4
3
  key: number;
@@ -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 i,useEffect as n}from"react";import{COLORS as l}from"../../constants/Theme.js";import{Button as a}from"../button/Button.js";import{Input as d}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,selectedColectionsReducer as S,CollectionIdContext as y}from"./reducers.js";import{SearchScreen as P}from"./searchScreen.js";import{SelectedScreen as v}from"./selectedScreen.js";import{ContainerStyle as j,ScrollContainerStyle as k}from"./style.js";import{OUT_OF_STOCK_ACTION as x}from"./type.js";import{useFetchFbStatusForCollections as I}from"./useFetchFbStatus.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,minlimit:A,limit:V,hideCollectionCheckbox:B,hideProductCheckbox:M,outOfStockAction:L=x.BLUR,hideVariantCheckbox:$,selectProductsFromCustomCollection:z,hideSelectionCount:G,title:H,width:W,renderWithoutModal:K,onClickSave:U,pickerType:Y,hideProductVariants:q=!1,startupScreen:J=F.Collections,rearrangeEnabled:N,showProductDetailInfoIcon:Q}=T,[X,Z]=r(b,{}),[_,ee]=s([F.Collections,F.RearrangeProducts].includes(J)?J:F.Collections),[te,oe]=s("grid"),[ce,re]=s(""),[se,ie]=s(""),[ne,le]=s(0),[ae,de]=s(!1),[ue,he]=s(0),[pe,me]=s(""),[Ce,ge]=s(!1),[fe,be]=s(!1),[Se,ye]=s(),[Pe,ve]=r(S,Object.keys(D).length>0?D:{}),je=i(null),[ke,xe]=s(!1),[Ie,Fe]=s(),{fetchFbStatus:Te}=I(Pe,O,ve,T.fbStatusFetcher,!1);n((()=>{de(!0),be(!0),T.collectionFetcher(ne,O).then((e=>{Z({type:"fetched",data:(null==e?void 0:e.collections)||{}}),de(!1),le((e=>e+1)),be(!1)})).catch()}),[]),n((()=>{let e=0;Object.keys(Pe||[]).forEach((t=>{var o;Object.keys((null===(o=Pe[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=Pe[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),he(e)})),n((()=>{}),[ce]),n((()=>{se&&(de(!0),T.productFetcher(se,O).then((e=>{Object.keys(e).length&&Z({type:"productsFetched",data:{collectionId:se,products:e}}),de(!1)})).catch())}),[se]),n((()=>{Te()}),[Pe]),n((()=>{const e=setTimeout((()=>{"rearrange"!==_&&(pe.length?(ge(!0),T.searchFetcher(O,pe).then((e=>{ye(Object.assign({},e)),ee("searchProducts"),de(!1),ge(!1)}))):ee("collections"))}),800);return()=>clearTimeout(e)}),[pe]),n((()=>{U&&(T.onAdd(Pe,ue),Oe())}),[U]);const Oe=()=>{ve({type:"reset",data:{}})},De=e(j,{children:[T.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:T.postHeader})),!T.hideGlobalSearch&&t(o,{children:("collections"===_||"searchProducts"===_)&&t("div",Object.assign({style:{padding:K?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(d,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>Ce?t(h,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:pe,onChangeText:e=>{e.length&&e.trim().length?me(e):me("")}})}))}),e(k,Object.assign({ref:je},{children:["collections"===_&&t(m,{customCollectionRestriction:T.customCollectionRestriction,dataLoading:fe,collections:X,selectedCollectionsDispatch:ve,setCollectionId:re,setSelectedCollectionId:ie,setScreen:ee,selectedCollections:Pe,collectionFetcher:T.collectionFetcher,storeId:O,collectionsDispatch:Z,setSaveDisabled:de,pagingControls:{curPage:ne,setCurPage:le},hideCollectionCheckbox:B,renderWithoutModal:K,pickerType:Y}),"products"===_&&ce&&t(y.Provider,Object.assign({value:ce},{children:t(g,{hideInCollectionSearch:T.hideInCollectionSearch,customCollectionRestriction:T.customCollectionRestriction,productFetcher:T.productFetcher,setScreen:ee,storeId:O,data:X[ce],collectionsDispatch:Z,selectedCollectionsDispatch:ve,selectedData:Pe,setSaveDisabled:de,searchInCollectionFetcher:T.searchInCollectionFetcher,hideProductCheckbox:M,outOfStockAction:L,hideVariantCheckbox:$,selectProductsFromCustomCollection:z,renderWithoutModal:K,pickerType:Y,hideProductVariants:q,fbStatusFetcher:T.fbStatusFetcher,onInfoIconClick:e=>{xe(!0),Fe(e)},showProductDetailInfoIcon:Q})})),"view"===_&&t(v,{selectedCollections:Pe||{},selectedCollectionsDispatch:ve,setScreen:ee,collections:X,outOfStockAction:L,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"rearrange"===_&&t(f,{selectedCollections:Pe||{},selectedCollectionsDispatch:ve,setScreen:ee,outOfStockAction:L,rearrangeViewType:"grid"===te?"list":"grid",scrollContainerRef:je,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"searchProducts"===_&&t(P,{customCollectionRestriction:T.customCollectionRestriction,selectedCollections:Pe||{},searchedCollections:Se||{},setSearchedCollections:ye,selectedCollectionsDispatch:ve,setScreen:ee,collections:X,onBackPress:()=>{me(""),ye({})},pickerType:Y,hideProductCheckbox:M,hideProductVariants:q,hideVariantCheckbox:$,storeId:O,fbStatusFetcher:T.fbStatusFetcher})]}))]});return t(o,{children:K?De:e(u,Object.assign({zIndex:E,open:w,onClose:()=>{null==R||R(),Oe()},headingTitle:H||("collections"===_||"products"===_?"Select Products":"view"===_?"Selected Products":"searchProducts"===_?"Searched Products":"rearrange"===_?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:W||"600px"},headerRightCustomElement:"rearrange"===_?(console.log("ignore:",oe),t(o,{})):t(o,{}),primaryButton:{buttonText:ae?"Loading...":_===F.RearrangeProducts?"Done":"Add",disabled:ae||ue<1||A&&ue<A||V&&ue>V||!1,onClick:()=>{T.onAdd(Pe,ue),Oe()}},footerLeftCustomElement:G?t(o,{}):A&&ue<A?t(p,{tagText:`Minimum limit is ${A} products`,type:"negative"}):V&&ue>V?t(p,{tagText:`You can only select ${V} products`,type:"negative"}):t(a,ue>0?{onClick:()=>{ee(N?F.RearrangeProducts:F.SelectedProducts)},buttonText:`${ue} products selected`,buttonType:["rearrange","view"].includes(_)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(_)}:{disabled:!0,buttonText:`${ue} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:ke},{children:[De,ke&&Ie?t(C,{productData:Ie,outOfStockAction:L,onClose:()=>{xe(!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 i,useEffect as n}from"react";import{COLORS as l}from"../../constants/Theme.js";import{Button as a}from"../button/Button.js";import{Input as d}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,selectedColectionsReducer as S,CollectionIdContext as y}from"./reducers.js";import{SearchScreen as P}from"./searchScreen.js";import{SelectedScreen as v}from"./selectedScreen.js";import{ContainerStyle as j,ScrollContainerStyle as k}from"./style.js";import{OUT_OF_STOCK_ACTION as x}from"./type.js";import{useFetchFbStatusForCollections as I}from"./useFetchFbStatus.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,minlimit:A,limit:V,hideCollectionCheckbox:B,hideProductCheckbox:M,outOfStockAction:L=x.BLUR,hideVariantCheckbox:$,selectProductsFromCustomCollection:z,hideSelectionCount:G,title:H,width:W,renderWithoutModal:K,onClickSave:U,pickerType:Y,hideProductVariants:q=!1,startupScreen:J=F.Collections,rearrangeEnabled:N,showProductDetailInfoIcon:Q}=T,[X,Z]=r(b,{}),[_,ee]=s([F.Collections,F.RearrangeProducts].includes(J)?J:F.Collections),[te,oe]=s("grid"),[ce,re]=s(""),[se,ie]=s(""),[ne,le]=s(0),[ae,de]=s(!1),[ue,he]=s(0),[pe,me]=s(""),[Ce,ge]=s(!1),[fe,be]=s(!1),[Se,ye]=s({}),[Pe,ve]=r(S,Object.keys(D).length>0?D:{}),je=i(null),[ke,xe]=s(!1),[Ie,Fe]=s();I(Pe,O,ve,T.fbStatusFetcher,!1),n((()=>{de(!0),be(!0),T.collectionFetcher(ne,O).then((e=>{Z({type:"fetched",data:(null==e?void 0:e.collections)||{}}),de(!1),le((e=>e+1)),be(!1)})).catch()}),[]),n((()=>{let e=0;Object.keys(Pe||[]).forEach((t=>{var o;Object.keys((null===(o=Pe[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=Pe[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),he(e)})),n((()=>{}),[ce]),n((()=>{se&&(de(!0),T.productFetcher(se,O).then((e=>{Object.keys(e).length&&Z({type:"productsFetched",data:{collectionId:se,products:e}}),de(!1)})).catch())}),[se]),n((()=>{const e=setTimeout((()=>{"rearrange"!==_&&(pe.length?(ge(!0),T.searchFetcher(O,pe).then((e=>{ye(Object.assign({},e)),ee("searchProducts"),de(!1),ge(!1)}))):ee("collections"))}),800);return()=>clearTimeout(e)}),[pe]),n((()=>{U&&(T.onAdd(Pe,ue),Te())}),[U]);const Te=()=>{ve({type:"reset",data:{}})},Oe=e(j,{children:[T.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:T.postHeader})),!T.hideGlobalSearch&&t(o,{children:("collections"===_||"searchProducts"===_)&&t("div",Object.assign({style:{padding:K?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(d,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>Ce?t(h,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:pe,onChangeText:e=>{e.length&&e.trim().length?me(e):me("")}})}))}),e(k,Object.assign({ref:je},{children:["collections"===_&&t(m,{customCollectionRestriction:T.customCollectionRestriction,dataLoading:fe,collections:X,selectedCollectionsDispatch:ve,setCollectionId:re,setSelectedCollectionId:ie,setScreen:ee,selectedCollections:Pe,collectionFetcher:T.collectionFetcher,storeId:O,collectionsDispatch:Z,setSaveDisabled:de,pagingControls:{curPage:ne,setCurPage:le},hideCollectionCheckbox:B,renderWithoutModal:K,pickerType:Y}),"products"===_&&ce&&t(y.Provider,Object.assign({value:ce},{children:t(g,{hideInCollectionSearch:T.hideInCollectionSearch,customCollectionRestriction:T.customCollectionRestriction,productFetcher:T.productFetcher,setScreen:ee,storeId:O,data:X[ce],collectionsDispatch:Z,selectedCollectionsDispatch:ve,selectedData:Pe,setSaveDisabled:de,searchInCollectionFetcher:T.searchInCollectionFetcher,hideProductCheckbox:M,outOfStockAction:L,hideVariantCheckbox:$,selectProductsFromCustomCollection:z,renderWithoutModal:K,pickerType:Y,hideProductVariants:q,fbStatusFetcher:T.fbStatusFetcher,onInfoIconClick:e=>{xe(!0),Fe(e)},showProductDetailInfoIcon:Q})})),"view"===_&&t(v,{selectedCollections:Pe||{},selectedCollectionsDispatch:ve,setScreen:ee,collections:X,outOfStockAction:L,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"rearrange"===_&&t(f,{selectedCollections:Pe||{},selectedCollectionsDispatch:ve,setScreen:ee,outOfStockAction:L,rearrangeViewType:"grid"===te?"list":"grid",scrollContainerRef:je,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"searchProducts"===_&&t(P,{customCollectionRestriction:T.customCollectionRestriction,selectedCollections:Pe||{},searchedCollections:Se||{},setSearchedCollections:ye,selectedCollectionsDispatch:ve,setScreen:ee,collections:X,onBackPress:()=>{me(""),ye({})},pickerType:Y,hideProductCheckbox:M,hideProductVariants:q,hideVariantCheckbox:$,storeId:O,fbStatusFetcher:T.fbStatusFetcher})]}))]});return t(o,{children:K?Oe:e(u,Object.assign({zIndex:E,open:w,onClose:()=>{null==R||R(),Te()},headingTitle:H||("collections"===_||"products"===_?"Select Products":"view"===_?"Selected Products":"searchProducts"===_?"Searched Products":"rearrange"===_?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:W||"600px"},headerRightCustomElement:"rearrange"===_?(console.log("ignore:",oe),t(o,{})):t(o,{}),primaryButton:{buttonText:ae?"Loading...":_===F.RearrangeProducts?"Done":"Add",disabled:ae||ue<1||A&&ue<A||V&&ue>V||!1,onClick:()=>{T.onAdd(Pe,ue),Te()}},footerLeftCustomElement:G?t(o,{}):A&&ue<A?t(p,{tagText:`Minimum limit is ${A} products`,type:"negative"}):V&&ue>V?t(p,{tagText:`You can only select ${V} products`,type:"negative"}):t(a,ue>0?{onClick:()=>{ee(N?F.RearrangeProducts:F.SelectedProducts)},buttonText:`${ue} products selected`,buttonType:["rearrange","view"].includes(_)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(_)}:{disabled:!0,buttonText:`${ue} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:ke},{children:[Oe,ke&&Ie?t(C,{productData:Ie,outOfStockAction:L,onClose:()=>{xe(!1)}}):t(o,{})]}))})};export{T as ProductPickerModal,F as ScreenName};
@@ -5,7 +5,7 @@ interface SearchScreenInterface {
5
5
  customCollectionRestriction?: boolean;
6
6
  selectedCollections: SelectedItems;
7
7
  searchedCollections: SelectedItems;
8
- setSearchedCollections: React.Dispatch<React.SetStateAction<SelectedItems | undefined>>;
8
+ setSearchedCollections: React.Dispatch<React.SetStateAction<SelectedItems>>;
9
9
  selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>;
10
10
  setScreen: React.Dispatch<React.SetStateAction<string>>;
11
11
  collections: {
@@ -1 +1 @@
1
- import{jsxs as t,jsx as o,Fragment as e}from"react/jsx-runtime";import r from"../../assets/icons/arrow_left.svg.js";import{useState as n,useRef as i,useEffect as s}from"react";import{IconButton as c}from"../icon-button/IconButton.js";import{BodyCaption as l}from"../TypographyStyle.js";import{EmptyState as d}from"./emptyState.js";import{ProductGroup as u}from"./productScreen.js";import{SelectedScreenHeader as a}from"./style.js";import{paginateSelectedItems as v}from"./utility.js";const p=p=>{const{selectedCollections:j,selectedCollectionsDispatch:f,setScreen:g,collections:b,outOfStockAction:O}=p,[m,h]=n({}),y=i(0),k=i(null);s((()=>{y.current=0;const t=v(j,10,y.current);console.log("paginated",{paginatedProducts:t,selectedCollections:j}),h(t),y.current+=1}),[]),s((()=>{h((t=>{var o,e,r,n,i,s;const c=Object.assign({},t);for(const t in c)if(t in c){const l=c[t],d=j[t],u={};for(const a in l.products)if(a in l.products)if(a in(null!==(o=null==d?void 0:d.products)&&void 0!==o?o:{})){const t=l.products[a],o={};for(const i in t.variants)if(i in t.variants){void 0!==(null===(n=null===(r=null===(e=null==d?void 0:d.products)||void 0===e?void 0:e[a])||void 0===r?void 0:r.variants)||void 0===n?void 0:n[i])&&(o[i]=t.variants[i])}Object.keys(o).length>0&&(u[a]=Object.assign(Object.assign({},t),{variants:o}))}else null===(s=null===(i=null==c?void 0:c[t])||void 0===i?void 0:i.products)||void 0===s||delete s[a];c[t]=Object.assign(Object.assign({},l),{products:u})}return c}))}),[j]),s((()=>{console.log("vj: observertarget",k.current);const t=new IntersectionObserver((t=>{if(console.log("vj: observertargetinside",t),t[0].isIntersecting&&(console.log("vj: nextPageRef",y.current),y.current>0)){const t=v(j,10,y.current);console.log("paginated inside observer target",{paginatedProducts:t,selectedCollections:j,curScreenData:m}),h((o=>{const e=Object.assign({},o);for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)){const r=t[o];if(Object.prototype.hasOwnProperty.call(e,o)){const t=e[o];e[o]=Object.assign(Object.assign({},t),{products:Object.assign(Object.assign({},t.products),r.products)})}else e[o]=r}return e})),y.current+=1}}),{threshold:1});return k.current&&t.observe(k.current),()=>{k.current&&t.unobserve(k.current)}}),[k,j]);const S=(t,o)=>{var e,r,n,i,s,c,l,d,u;let a=0,v=0;return!!((null===(r=null===(e=null==j?void 0:j[t])||void 0===e?void 0:e.products)||void 0===r?void 0:r[o])&&(null===(c=Object.keys((null===(s=null===(i=null===(n=null==b?void 0:b[t])||void 0===n?void 0:n.products)||void 0===i?void 0:i[o])||void 0===s?void 0:s.variants)||[]))||void 0===c||c.forEach((()=>v++)),Object.keys((null===(u=null===(d=null===(l=null==j?void 0:j[t])||void 0===l?void 0:l.products)||void 0===d?void 0:d[o])||void 0===u?void 0:u.variants)||[]).forEach((()=>a++)),a>0&&v!==a))};return t("div",{children:[t(a,{children:[o(c,{Icon:r,onClick:()=>{g("collections")}}),o(l,{children:"Selected Products"})]}),t("div",{children:[Object.keys(m).length>0?o(e,{children:Object.keys(m).map((t=>{var e;return Object.keys((null===(e=null==m?void 0:m[t])||void 0===e?void 0:e.products)||[]).map((e=>{let r=!1;return(null==m?void 0:m.isCustom)&&(r=!0),o(u,{upliftAdditions:null,collectionId:t,productId:e,data:m[t].products[e],isProductPartiallyChecked:S(t,e),selectedData:j,selectedCollectionsDispatch:f,viewOnly:r,outOfStockAction:O},e)}))}))}):o(d,{title:"No Products Selected",subtitle:"Select products will appear here"}),o("div",{ref:k})]})]})};export{p as SelectedScreen};
1
+ import{jsxs as t,jsx as o,Fragment as e}from"react/jsx-runtime";import r from"../../assets/icons/arrow_left.svg.js";import{useState as n,useRef as s,useEffect as i}from"react";import{IconButton as c}from"../icon-button/IconButton.js";import{BodyCaption as l}from"../TypographyStyle.js";import{EmptyState as d}from"./emptyState.js";import{ProductGroup as u}from"./productScreen.js";import{SelectedScreenHeader as a}from"./style.js";import{useFetchFbStatusForCollections as v}from"./useFetchFbStatus.js";import{paginateSelectedItems as p}from"./utility.js";const f=f=>{const{selectedCollections:j,selectedCollectionsDispatch:b,setScreen:g,collections:m,outOfStockAction:O,storeId:h,fbStatusFetcher:y}=f,[S,k]=n({}),P=s(0),C=s(null),{fetchFbStatus:I}=v(S,h,b,y,!1,k);i((()=>{I()}),[S]),i((()=>{P.current=0;const t=p(j,10,P.current);console.log("paginated",{paginatedProducts:t,selectedCollections:j}),k(t),P.current+=1}),[]),i((()=>{k((t=>{var o,e,r,n,s,i;const c=Object.assign({},t);for(const t in c)if(t in c){const l=c[t],d=j[t],u={};for(const a in l.products)if(a in l.products)if(a in(null!==(o=null==d?void 0:d.products)&&void 0!==o?o:{})){const t=l.products[a],o={};for(const s in t.variants)if(s in t.variants){void 0!==(null===(n=null===(r=null===(e=null==d?void 0:d.products)||void 0===e?void 0:e[a])||void 0===r?void 0:r.variants)||void 0===n?void 0:n[s])&&(o[s]=t.variants[s])}Object.keys(o).length>0&&(u[a]=Object.assign(Object.assign({},t),{variants:o}))}else null===(i=null===(s=null==c?void 0:c[t])||void 0===s?void 0:s.products)||void 0===i||delete i[a];c[t]=Object.assign(Object.assign({},l),{products:u})}return c}))}),[j]),i((()=>{console.log("vj: observertarget",C.current);const t=new IntersectionObserver((t=>{if(console.log("vj: observertargetinside",t),t[0].isIntersecting&&(console.log("vj: nextPageRef",P.current),P.current>0)){const t=p(j,10,P.current);console.log("paginated inside observer target",{paginatedProducts:t,selectedCollections:j,curScreenData:S}),k((o=>{const e=Object.assign({},o);for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)){const r=t[o];if(Object.prototype.hasOwnProperty.call(e,o)){const t=e[o];e[o]=Object.assign(Object.assign({},t),{products:Object.assign(Object.assign({},t.products),r.products)})}else e[o]=r}return e})),P.current+=1}}),{threshold:1});return C.current&&t.observe(C.current),()=>{C.current&&t.unobserve(C.current)}}),[C,j]);const w=(t,o)=>{var e,r,n,s,i,c,l,d,u;let a=0,v=0;return!!((null===(r=null===(e=null==j?void 0:j[t])||void 0===e?void 0:e.products)||void 0===r?void 0:r[o])&&(null===(c=Object.keys((null===(i=null===(s=null===(n=null==m?void 0:m[t])||void 0===n?void 0:n.products)||void 0===s?void 0:s[o])||void 0===i?void 0:i.variants)||[]))||void 0===c||c.forEach((()=>v++)),Object.keys((null===(u=null===(d=null===(l=null==j?void 0:j[t])||void 0===l?void 0:l.products)||void 0===d?void 0:d[o])||void 0===u?void 0:u.variants)||[]).forEach((()=>a++)),a>0&&v!==a))};return t("div",{children:[t(a,{children:[o(c,{Icon:r,onClick:()=>{g("collections")}}),o(l,{children:"Selected Products"})]}),t("div",{children:[Object.keys(S).length>0?o(e,{children:Object.keys(S).map((t=>{var e;return Object.keys((null===(e=null==S?void 0:S[t])||void 0===e?void 0:e.products)||[]).map((e=>{let r=!1;return(null==S?void 0:S.isCustom)&&(r=!0),o(u,{upliftAdditions:null,collectionId:t,productId:e,data:S[t].products[e],isProductPartiallyChecked:w(t,e),selectedData:j,selectedCollectionsDispatch:b,viewOnly:r,outOfStockAction:O},e)}))}))}):o(d,{title:"No Products Selected",subtitle:"Select products will appear here"}),o("div",{ref:C})]})]})};export{f as SelectedScreen};
@@ -1,5 +1,5 @@
1
1
  import { FbStatusFetcherReturn, SelectedItems } from './modal';
2
2
  import { SelectedCollectionsActions } from './reducers';
3
- export declare const useFetchFbStatusForCollections: (data: SelectedItems, storeId: string, selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, autoFetch?: boolean, setSearchedCollections?: React.Dispatch<React.SetStateAction<SelectedItems | undefined>>) => {
3
+ export declare const useFetchFbStatusForCollections: (data: SelectedItems, storeId: string, selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, autoFetch?: boolean, setSearchedCollections?: React.Dispatch<React.SetStateAction<SelectedItems>>) => {
4
4
  fetchFbStatus: () => void;
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.439-beta.ppi-15",
3
+ "version": "0.0.439-beta.ppi-17",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",