@bikdotai/bik-component-library 0.0.439-beta.ppi-36 → 0.0.439-beta.ppis-10

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 +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,{})]}))})};
@@ -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]);const y=o.useMemo((()=>e=>{f((t=>Object.assign(Object.assign({},t),e)))}),[]);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});const t=g;for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const s=e[o];if(Object.prototype.hasOwnProperty.call(t,o)){const e=t[o];t[o]=Object.assign(Object.assign({},e),{products:Object.assign(Object.assign({},e.products),s.products)})}else t[o]=s}y(t),b.current+=1}}),{threshold:1});return O.current&&e.observe(O.current),()=>{O.current&&e.unobserve(O.current)}}),[O,u,g]);const h=(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:h(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 copy.js"),u=require("./utility.js");exports.SelectedScreen=d=>{const{selectedCollections:a,selectedCollectionsDispatch:v,setScreen:p,collections:j,outOfStockAction:b,storeId:f,fbStatusFetcher:g}=d,[O,h]=s.useState({}),S=s.useRef(0),y=s.useRef(null);s.useEffect((()=>{S.current=0;const e=u.paginateSelectedItems(a,10,S.current);console.log("paginated",{paginatedProducts:e,selectedCollections:a}),h(e),l.fetchFbStatus(e,f,h,g),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})),l.fetchFbStatus(O,f,h,g)}),[a]);const x=s.useMemo((()=>e=>{h((t=>Object.assign(Object.assign({},t),e)))}),[]);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});const t=O;for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)){const o=e[s];if(Object.prototype.hasOwnProperty.call(t,s)){const e=t[s];t[s]=Object.assign(Object.assign({},e),{products:Object.assign(Object.assign({},e.products),o.products)})}else t[s]=o}x(t),l.fetchFbStatus(t,f,h,g),S.current+=1}}),{threshold:1});return y.current&&e.observe(y.current),()=>{y.current&&e.unobserve(y.current)}}),[y,a,O]);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:b},s)}))}))}):e.jsx(n.EmptyState,{title:"No Products Selected",subtitle:"Select products will appear here"}),e.jsx("div",{ref:y})]})]})};
@@ -1,3 +1,2 @@
1
1
  import { FbStatusFetcherReturn, SelectedItems } from './modal';
2
- import { SelectedCollectionsActions } from './reducers';
3
- export declare const fetchFbStatus: (data: SelectedItems, storeId: string, selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, autoFetch?: boolean, setSearchedCollections?: React.Dispatch<React.SetStateAction<SelectedItems>>) => void;
2
+ export declare const fetchFbStatus: (data: SelectedItems, storeId: string, setCurScreenData: React.Dispatch<React.SetStateAction<SelectedItems>>, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined) => void;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("react");exports.fetchFbStatus=(v,i,l,d)=>{if(!d){const o=v;Object.keys(o).forEach((v=>{var i,l;const d=null!==(l=null===(i=o[v])||void 0===i?void 0:i.products)&&void 0!==l?l:{};Object.keys(d).forEach((i=>{var l,d,n,t;const s=null!==(t=null===(n=null===(d=null===(l=o[v])||void 0===l?void 0:l.products)||void 0===d?void 0:d[i])||void 0===n?void 0:n.variants)&&void 0!==t?t:{};Object.keys(s).forEach((l=>{var d,n,t,s;const c=null===(s=null===(t=null===(n=null===(d=o[v])||void 0===d?void 0:d.products)||void 0===n?void 0:n[i])||void 0===t?void 0:t.variants)||void 0===s?void 0:s[l];c&&(c.fbStatus="APPROVED")}))}))})),l(o)}const n=(o=>{const v=[];return Object.keys(o).forEach((i=>{var l,d;const n=null!==(d=null===(l=o[i])||void 0===l?void 0:l.products)&&void 0!==d?d:{};Object.keys(n).forEach((l=>{var d,n,t,s;const c=null!==(s=null===(t=null===(n=null===(d=o[i])||void 0===d?void 0:d.products)||void 0===n?void 0:n[l])||void 0===t?void 0:t.variants)&&void 0!==s?s:{};Object.keys(c).forEach((d=>{var n,t,s,c;const u=null===(c=null===(s=null===(t=null===(n=o[i])||void 0===n?void 0:n.products)||void 0===t?void 0:t[l])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[d];(null==u?void 0:u.fbStatus)||v.push(d)}))}))})),v})(v);console.log("vj: variantids",n),n.length>0&&d&&d(i,n).then((i=>{const d=Object.assign({},v);Object.keys(d).forEach((o=>{var v,l;const n=null!==(l=null===(v=d[o])||void 0===v?void 0:v.products)&&void 0!==l?l:{};Object.keys(n).forEach((v=>{var l,n,t,s;const c=null!==(s=null===(t=null===(n=null===(l=d[o])||void 0===l?void 0:l.products)||void 0===n?void 0:n[v])||void 0===t?void 0:t.variants)&&void 0!==s?s:{};Object.keys(c).forEach((l=>{var n,t,s,c;const u=null===(c=null===(s=null===(t=null===(n=d[o])||void 0===n?void 0:n.products)||void 0===t?void 0:t[v])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[l];u&&"REJECTED"===i[l]?u.fbStatus="REJECTED":u&&"APPROVED"===i[l]&&(u.fbStatus="APPROVED")}))}))})),console.log("variantids",d);o.useMemo((()=>()=>{l((o=>Object.assign(Object.assign({},o),d)))}),[])()})).catch((o=>{const i=Object.assign({},v);Object.keys(i).forEach((o=>{var v,l;const d=null!==(l=null===(v=i[o])||void 0===v?void 0:v.products)&&void 0!==l?l:{};Object.keys(d).forEach((v=>{var l,d,n,t;const s=null!==(t=null===(n=null===(d=null===(l=i[o])||void 0===l?void 0:l.products)||void 0===d?void 0:d[v])||void 0===n?void 0:n.variants)&&void 0!==t?t:{};Object.keys(s).forEach((l=>{var d,n,t,s;const c=null===(s=null===(t=null===(n=null===(d=i[o])||void 0===d?void 0:d.products)||void 0===n?void 0:n[v])||void 0===t?void 0:t.variants)||void 0===s?void 0:s[l];c&&(c.fbStatus="APPROVED")}))}))})),console.log("vj: variantids",i),l(i)}))};
@@ -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};
@@ -1 +1 @@
1
- import{jsxs as t,jsx as o,Fragment as e}from"react/jsx-runtime";import n from"../../assets/icons/arrow_left.svg.js";import{useState as r,useRef as s,useEffect as i,useMemo as c}from"react";import{IconButton as l}from"../icon-button/IconButton.js";import{BodyCaption as d}from"../TypographyStyle.js";import{EmptyState as u}from"./emptyState.js";import{ProductGroup as a}from"./productScreen.js";import{SelectedScreenHeader as v}from"./style.js";import{paginateSelectedItems as p}from"./utility.js";const j=j=>{const{selectedCollections:g,selectedCollectionsDispatch:f,setScreen:b,collections:O,outOfStockAction:m}=j,[h,y]=r({}),k=s(0),S=s(null);i((()=>{k.current=0;const t=p(g,10,k.current);console.log("paginated",{paginatedProducts:t,selectedCollections:g}),y(t),k.current+=1}),[]),i((()=>{y((t=>{var o,e,n,r,s,i;const c=Object.assign({},t);for(const t in c)if(t in c){const l=c[t],d=g[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===(r=null===(n=null===(e=null==d?void 0:d.products)||void 0===e?void 0:e[a])||void 0===n?void 0:n.variants)||void 0===r?void 0:r[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}))}),[g]);const P=c((()=>t=>{y((o=>Object.assign(Object.assign({},o),t)))}),[]);i((()=>{console.log("vj: observertarget",S.current);const t=new IntersectionObserver((t=>{if(console.log("vj: observertargetinside",t),t[0].isIntersecting&&(console.log("vj: nextPageRef",k.current),k.current>0)){const t=p(g,10,k.current);console.log("paginated inside observer target",{paginatedProducts:t,selectedCollections:g,curScreenData:h});const o=h;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const n=t[e];if(Object.prototype.hasOwnProperty.call(o,e)){const t=o[e];o[e]=Object.assign(Object.assign({},t),{products:Object.assign(Object.assign({},t.products),n.products)})}else o[e]=n}P(o),k.current+=1}}),{threshold:1});return S.current&&t.observe(S.current),()=>{S.current&&t.unobserve(S.current)}}),[S,g,h]);const C=(t,o)=>{var e,n,r,s,i,c,l,d,u;let a=0,v=0;return!!((null===(n=null===(e=null==g?void 0:g[t])||void 0===e?void 0:e.products)||void 0===n?void 0:n[o])&&(null===(c=Object.keys((null===(i=null===(s=null===(r=null==O?void 0:O[t])||void 0===r?void 0:r.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==g?void 0:g[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(v,{children:[o(l,{Icon:n,onClick:()=>{b("collections")}}),o(d,{children:"Selected Products"})]}),t("div",{children:[Object.keys(h).length>0?o(e,{children:Object.keys(h).map((t=>{var e;return Object.keys((null===(e=null==h?void 0:h[t])||void 0===e?void 0:e.products)||[]).map((e=>{let n=!1;return(null==h?void 0:h.isCustom)&&(n=!0),o(a,{upliftAdditions:null,collectionId:t,productId:e,data:h[t].products[e],isProductPartiallyChecked:C(t,e),selectedData:g,selectedCollectionsDispatch:f,viewOnly:n,outOfStockAction:m},e)}))}))}):o(u,{title:"No Products Selected",subtitle:"Select products will appear here"}),o("div",{ref:S})]})]})};export{j 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 c,useMemo as i}from"react";import{IconButton as l}from"../icon-button/IconButton.js";import{BodyCaption as d}from"../TypographyStyle.js";import{EmptyState as u}from"./emptyState.js";import{ProductGroup as a}from"./productScreen.js";import{SelectedScreenHeader as v}from"./style.js";import{fetchFbStatus as p}from"./useFetchFbStatus copy.js";import{paginateSelectedItems as j}from"./utility.js";const f=f=>{const{selectedCollections:b,selectedCollectionsDispatch:g,setScreen:m,collections:O,outOfStockAction:h,storeId:y,fbStatusFetcher:S}=f,[k,P]=n({}),C=s(0),I=s(null);c((()=>{C.current=0;const t=j(b,10,C.current);console.log("paginated",{paginatedProducts:t,selectedCollections:b}),P(t),p(t,y,P,S),C.current+=1}),[]),c((()=>{P((t=>{var o,e,r,n,s,c;const i=Object.assign({},t);for(const t in i)if(t in i){const l=i[t],d=b[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===(c=null===(s=null==i?void 0:i[t])||void 0===s?void 0:s.products)||void 0===c||delete c[a];i[t]=Object.assign(Object.assign({},l),{products:u})}return i})),p(k,y,P,S)}),[b]);const w=i((()=>t=>{P((o=>Object.assign(Object.assign({},o),t)))}),[]);c((()=>{console.log("vj: observertarget",I.current);const t=new IntersectionObserver((t=>{if(console.log("vj: observertargetinside",t),t[0].isIntersecting&&(console.log("vj: nextPageRef",C.current),C.current>0)){const t=j(b,10,C.current);console.log("paginated inside observer target",{paginatedProducts:t,selectedCollections:b,curScreenData:k});const o=k;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const r=t[e];if(Object.prototype.hasOwnProperty.call(o,e)){const t=o[e];o[e]=Object.assign(Object.assign({},t),{products:Object.assign(Object.assign({},t.products),r.products)})}else o[e]=r}w(o),p(o,y,P,S),C.current+=1}}),{threshold:1});return I.current&&t.observe(I.current),()=>{I.current&&t.unobserve(I.current)}}),[I,b,k]);const D=(t,o)=>{var e,r,n,s,c,i,l,d,u;let a=0,v=0;return!!((null===(r=null===(e=null==b?void 0:b[t])||void 0===e?void 0:e.products)||void 0===r?void 0:r[o])&&(null===(i=Object.keys((null===(c=null===(s=null===(n=null==O?void 0:O[t])||void 0===n?void 0:n.products)||void 0===s?void 0:s[o])||void 0===c?void 0:c.variants)||[]))||void 0===i||i.forEach((()=>v++)),Object.keys((null===(u=null===(d=null===(l=null==b?void 0:b[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(v,{children:[o(l,{Icon:r,onClick:()=>{m("collections")}}),o(d,{children:"Selected Products"})]}),t("div",{children:[Object.keys(k).length>0?o(e,{children:Object.keys(k).map((t=>{var e;return Object.keys((null===(e=null==k?void 0:k[t])||void 0===e?void 0:e.products)||[]).map((e=>{let r=!1;return(null==k?void 0:k.isCustom)&&(r=!0),o(a,{upliftAdditions:null,collectionId:t,productId:e,data:k[t].products[e],isProductPartiallyChecked:D(t,e),selectedData:b,selectedCollectionsDispatch:g,viewOnly:r,outOfStockAction:h},e)}))}))}):o(u,{title:"No Products Selected",subtitle:"Select products will appear here"}),o("div",{ref:I})]})]})};export{f as SelectedScreen};
@@ -1,3 +1,2 @@
1
1
  import { FbStatusFetcherReturn, SelectedItems } from './modal';
2
- import { SelectedCollectionsActions } from './reducers';
3
- export declare const fetchFbStatus: (data: SelectedItems, storeId: string, selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, autoFetch?: boolean, setSearchedCollections?: React.Dispatch<React.SetStateAction<SelectedItems>>) => void;
2
+ export declare const fetchFbStatus: (data: SelectedItems, storeId: string, setCurScreenData: React.Dispatch<React.SetStateAction<SelectedItems>>, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined) => void;
@@ -0,0 +1 @@
1
+ import{useMemo as o}from"react";const v=(v,i,l,d)=>{if(!d){const o=v;Object.keys(o).forEach((v=>{var i,l;const d=null!==(l=null===(i=o[v])||void 0===i?void 0:i.products)&&void 0!==l?l:{};Object.keys(d).forEach((i=>{var l,d,n,t;const s=null!==(t=null===(n=null===(d=null===(l=o[v])||void 0===l?void 0:l.products)||void 0===d?void 0:d[i])||void 0===n?void 0:n.variants)&&void 0!==t?t:{};Object.keys(s).forEach((l=>{var d,n,t,s;const c=null===(s=null===(t=null===(n=null===(d=o[v])||void 0===d?void 0:d.products)||void 0===n?void 0:n[i])||void 0===t?void 0:t.variants)||void 0===s?void 0:s[l];c&&(c.fbStatus="APPROVED")}))}))})),l(o)}const n=(o=>{const v=[];return Object.keys(o).forEach((i=>{var l,d;const n=null!==(d=null===(l=o[i])||void 0===l?void 0:l.products)&&void 0!==d?d:{};Object.keys(n).forEach((l=>{var d,n,t,s;const c=null!==(s=null===(t=null===(n=null===(d=o[i])||void 0===d?void 0:d.products)||void 0===n?void 0:n[l])||void 0===t?void 0:t.variants)&&void 0!==s?s:{};Object.keys(c).forEach((d=>{var n,t,s,c;const u=null===(c=null===(s=null===(t=null===(n=o[i])||void 0===n?void 0:n.products)||void 0===t?void 0:t[l])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[d];(null==u?void 0:u.fbStatus)||v.push(d)}))}))})),v})(v);console.log("vj: variantids",n),n.length>0&&d&&d(i,n).then((i=>{const d=Object.assign({},v);Object.keys(d).forEach((o=>{var v,l;const n=null!==(l=null===(v=d[o])||void 0===v?void 0:v.products)&&void 0!==l?l:{};Object.keys(n).forEach((v=>{var l,n,t,s;const c=null!==(s=null===(t=null===(n=null===(l=d[o])||void 0===l?void 0:l.products)||void 0===n?void 0:n[v])||void 0===t?void 0:t.variants)&&void 0!==s?s:{};Object.keys(c).forEach((l=>{var n,t,s,c;const u=null===(c=null===(s=null===(t=null===(n=d[o])||void 0===n?void 0:n.products)||void 0===t?void 0:t[v])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[l];u&&"REJECTED"===i[l]?u.fbStatus="REJECTED":u&&"APPROVED"===i[l]&&(u.fbStatus="APPROVED")}))}))})),console.log("variantids",d);o((()=>()=>{l((o=>Object.assign(Object.assign({},o),d)))}),[])()})).catch((o=>{const i=Object.assign({},v);Object.keys(i).forEach((o=>{var v,l;const d=null!==(l=null===(v=i[o])||void 0===v?void 0:v.products)&&void 0!==l?l:{};Object.keys(d).forEach((v=>{var l,d,n,t;const s=null!==(t=null===(n=null===(d=null===(l=i[o])||void 0===l?void 0:l.products)||void 0===d?void 0:d[v])||void 0===n?void 0:n.variants)&&void 0!==t?t:{};Object.keys(s).forEach((l=>{var d,n,t,s;const c=null===(s=null===(t=null===(n=null===(d=i[o])||void 0===d?void 0:d.products)||void 0===n?void 0:n[v])||void 0===t?void 0:t.variants)||void 0===s?void 0:s[l];c&&(c.fbStatus="APPROVED")}))}))})),console.log("vj: variantids",i),l(i)}))};export{v as fetchFbStatus};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.439-beta.ppi-36",
3
+ "version": "0.0.439-beta.ppis-10",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",