@bikdotai/bik-component-library 0.0.469-beta.pp-7 → 0.0.469-beta.pp-8

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=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),r=require("../../assets/icons/box.svg.js"),c=require("../../assets/icons/search.svg.js"),o=require("lodash"),s=require("react"),n=require("../../constants/Theme.js"),i=require("../checkBox/CheckBox.js"),l=require("../icon-button/IconButton.js"),d=require("../input/Input.js"),u=require("../spinner/Spinner.js"),a=require("../TypographyStyle.js"),h=require("./emptyState.js"),p=require("./product.js"),v=require("./ProductPickerShimmer.js"),j=require("./reducers.js"),g=require("./style.js"),y=require("./type.js"),P=require("./utility.js");exports.ProductsScreen=f=>{const{data:C,collectionsDispatch:k,selectedData:x,selectedCollectionsDispatch:O,productFetcher:b,storeId:S,setScreen:m,setSaveDisabled:I,hideInCollectionSearch:E,customCollectionRestriction:A,hideProductCheckbox:q,outOfStockAction:T=y.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:R=!1,selectProductsFromCustomCollection:D=!1,pickerType:L,hideProductVariants:V,fbStatusFetcher:F,onProductDetailClick:w,showProductDetailInfoIcon:B,scrollContainerRef:_}=f,H=s.useContext(j.CollectionIdContext),U=s.useRef(null),J=s.useRef(0),K=s.useRef(!1),[M,N]=s.useState(!(null==C?void 0:C.products)),[W,z]=s.useState(""),[G,Q]=s.useState(!1),[X,Y]=s.useState(C),Z=s.useRef(!1);s.useEffect((()=>{const e=setTimeout((()=>{W.length?(Q(!0),f.searchInCollectionFetcher(S,H,W).then((e=>{const t=o.cloneDeep(C);t.products=e,Y(t);const r=P.getVariantIdsToFetchAtProductLevel(null!=e?e:{});te(r,null!=e?e:{},!0),I(!1),Q(!1)}))):Y(C)}),800);return()=>clearTimeout(e)}),[W]),s.useEffect((()=>{var e;return null===(e=null==_?void 0:_.current)||void 0===e||e.addEventListener("scroll",$),()=>{var e;null===(e=null==_?void 0:_.current)||void 0===e||e.removeEventListener("scroll",$)}}),[]);const $=()=>{if(!_||!(null==_?void 0:_.current))return;console.log("handlescroll called",{scrollContainerRef:_,hasAllProductsLoaded:Z,isLoading:M,isFetchingRef:K});const{scrollTop:e,clientHeight:t,scrollHeight:r}=_.current;e+t>=r-20&&!Z.current&&!K.current&&(console.log("scrolling"),I(!0),N(!0),K.current=!0,b(H,S,10,J.current).then((e=>{if(Object.keys(e).length||(Z.current=!0),Object.keys(e).length){const t=X;t.products=Object.assign(Object.assign({},X.products),e),Y(t);const r=P.getVariantIdsToFetchAtProductLevel(e);te(r,e),J.current+=1}K.current=!0,N(!1),I(!1)})).catch())};s.useEffect((()=>{var e,t,r,c;Z.current=!1,J.current=Math.floor((null===(t=Object.keys(null!==(e=C.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length)/10);const o=P.getVariantIdsToFetchAtProductLevel(null!==(r=C.products)&&void 0!==r?r:{});te(o,null!==(c=C.products)&&void 0!==c?c:{})}),[H]);const ee=!!A&&C.isSmartCollection;s.useEffect((()=>{(null==C?void 0:C.products)||re(10)}),[]);const te=(e,t,r)=>{F||(r?P.markVariantsAsApprovedProductsLevel(t,k,H,X,Y):P.markVariantsAsApprovedProductsLevel(t,k,H)),e.length>0&&F&&F(S,e).then((e=>{const c=Object.assign({},t);Object.keys(t).forEach((r=>{var o,s;Object.keys(null!==(s=null===(o=null==t?void 0:t[r])||void 0===o?void 0:o.variants)&&void 0!==s?s:{}).forEach((o=>{var s,n;const i=null===(s=null==t?void 0:t[r].variants)||void 0===s?void 0:s[o];i&&"REJECTED"===e[o]?i.fbStatus="REJECTED":i&&"APPROVED"===e[o]&&(i.fbStatus="APPROVED");const l=null===(n=null==c?void 0:c[r])||void 0===n?void 0:n.variants;l&&l[o]&&(l[o]=i)}))})),r?(Y((e=>{const t=Object.assign({},e);return t.products=c,t})),k({type:"productsPaged",data:{collectionId:H,products:c}})):k({type:"productsPaged",data:{collectionId:H,products:c}})})).catch((e=>{r?P.markVariantsAsApprovedProductsLevel(t,k,H,X,Y):P.markVariantsAsApprovedProductsLevel(t,k,H)}))},re=e=>{I(!0),Q(!0),b(H,S,e,0).then((t=>{if(Object.keys(t).length||(Z.current=!0),Object.keys(t).length){Y(Object.assign(Object.assign({},X),{products:t}));const e=P.getVariantIdsToFetchAtProductLevel(t);te(e,t),J.current=1}e||O({type:"selected",data:{id:H,val:Object.assign(Object.assign({},C),{products:t})}}),I(!1),Q(!1),N(!1)})).catch()},ce=(e,t)=>{const r=P.liftTheStateUp(t,C);O({type:e,data:Object.assign(Object.assign({},r),{isRestricted:A})})};return e.jsxs("div",{children:[e.jsxs(g.ProductScreenHeader,{children:[e.jsx(l.IconButton,{Icon:t.default,height:16,onClick:()=>{m("collections")}}),e.jsx(a.BodyCaption,Object.assign({style:{color:n.COLORS.content.secondary}},{children:C.name}))]}),!E&&e.jsx("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(d.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>G&&W.length?e.jsx(u.Spinner,{size:"small",color:n.COLORS.content.primary}):e.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:W,onChangeText:e=>{e.length&&e.trim().length?z(e):z("")},placeholder:"Search products in this collection..."})})),e.jsxs("div",{children:[Object.keys((null==X?void 0:X.products)||[]).length>0&&!ee&&!W.length&&!q&&"-1"!==H&&e.jsxs(g.ProductScreenCollectionCardStyle,{children:[e.jsx(i.CheckBox,{isChecked:!!(null==x?void 0:x[H]),isPartiallyChecked:P.isCollectionPartiallyChecked(H,X,x,V),onValueChange:function(e){e?re():O({type:"unselected",data:{id:H}})}}),e.jsx("div",Object.assign({style:{width:40,height:40}},{children:e.jsx(r.default,{})})),e.jsx(a.TitleRegular,{children:"All Products"})]}),Object.keys((null==X?void 0:X.products)||[]).length?Object.keys(X.products||[]).map((t=>e.jsx(p.ProductGroup,{outOfStockAction:T,collectionId:H,isProductPartiallyChecked:P.isProductPartiallyChecked(H,t,x,X,V),productId:t,data:X.products[t],selectedData:x,selectedCollectionsDispatch:O,viewOnly:!D&&!!ee,upliftAdditions:ce,hideProductCheckbox:q,hideVariantCheckbox:R,hideProductVariants:V,pickerType:L,onProductDetailClick:w,showProductDetailInfoIcon:B},t))):G?e.jsx(v.ProductPickerShimmer,{limit:10}):e.jsx(h.EmptyState,{title:"No products to show",subtitle:W.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),e.jsx("div",{ref:U})]}),M&&e.jsx(v.ProductPickerShimmer,{})]})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),r=require("../../assets/icons/box.svg.js"),c=require("../../assets/icons/search.svg.js"),o=require("lodash"),s=require("react"),n=require("../../constants/Theme.js"),i=require("../checkBox/CheckBox.js"),l=require("../icon-button/IconButton.js"),d=require("../input/Input.js"),u=require("../spinner/Spinner.js"),a=require("../TypographyStyle.js"),h=require("./emptyState.js"),p=require("./product.js"),v=require("./ProductPickerShimmer.js"),j=require("./reducers.js"),g=require("./style.js"),y=require("./type.js"),P=require("./utility.js");exports.ProductsScreen=f=>{const{data:C,collectionsDispatch:k,selectedData:x,selectedCollectionsDispatch:O,productFetcher:b,storeId:S,setScreen:m,setSaveDisabled:I,hideInCollectionSearch:E,customCollectionRestriction:A,hideProductCheckbox:q,outOfStockAction:T=y.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:R=!1,selectProductsFromCustomCollection:D=!1,pickerType:L,hideProductVariants:V,fbStatusFetcher:F,onProductDetailClick:w,showProductDetailInfoIcon:B,scrollContainerRef:_}=f,H=s.useContext(j.CollectionIdContext),U=s.useRef(null),J=s.useRef(0),K=s.useRef(!1),[M,N]=s.useState(!(null==C?void 0:C.products)),[W,z]=s.useState(""),[G,Q]=s.useState(!1),[X,Y]=s.useState(C),Z=s.useRef(!1);s.useEffect((()=>{const e=setTimeout((()=>{W.length?(Q(!0),f.searchInCollectionFetcher(S,H,W).then((e=>{const t=o.cloneDeep(C);t.products=e,Y(t);const r=P.getVariantIdsToFetchAtProductLevel(null!=e?e:{});te(r,null!=e?e:{},!0),I(!1),Q(!1)}))):Y(C)}),800);return()=>clearTimeout(e)}),[W]),s.useEffect((()=>{var e;return null===(e=null==_?void 0:_.current)||void 0===e||e.addEventListener("scroll",$),()=>{var e;null===(e=null==_?void 0:_.current)||void 0===e||e.removeEventListener("scroll",$)}}),[]);const $=()=>{if(!_||!(null==_?void 0:_.current))return;console.log("handlescroll called",{scrollContainerRef:_,hasAllProductsLoaded:Z,isLoading:M,isFetchingRef:K});const{scrollTop:e,clientHeight:t,scrollHeight:r}=_.current;e+t>=r-20&&!Z.current&&!K.current&&(console.log("scrolling"),I(!0),N(!0),K.current=!0,b(H,S,10,J.current).then((e=>{if(Object.keys(e).length||(Z.current=!0),Object.keys(e).length){const t=X;t.products=Object.assign(Object.assign({},X.products),e),Y(t);const r=P.getVariantIdsToFetchAtProductLevel(e);te(r,e),J.current+=1}K.current=!1,N(!1),I(!1)})).catch())};s.useEffect((()=>{var e,t,r,c;Z.current=!1,J.current=Math.floor((null===(t=Object.keys(null!==(e=C.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length)/10);const o=P.getVariantIdsToFetchAtProductLevel(null!==(r=C.products)&&void 0!==r?r:{});te(o,null!==(c=C.products)&&void 0!==c?c:{})}),[H]);const ee=!!A&&C.isSmartCollection;s.useEffect((()=>{(null==C?void 0:C.products)||re(10)}),[]);const te=(e,t,r)=>{F||(r?P.markVariantsAsApprovedProductsLevel(t,k,H,X,Y):P.markVariantsAsApprovedProductsLevel(t,k,H)),e.length>0&&F&&F(S,e).then((e=>{const c=Object.assign({},t);Object.keys(t).forEach((r=>{var o,s;Object.keys(null!==(s=null===(o=null==t?void 0:t[r])||void 0===o?void 0:o.variants)&&void 0!==s?s:{}).forEach((o=>{var s,n;const i=null===(s=null==t?void 0:t[r].variants)||void 0===s?void 0:s[o];i&&"REJECTED"===e[o]?i.fbStatus="REJECTED":i&&"APPROVED"===e[o]&&(i.fbStatus="APPROVED");const l=null===(n=null==c?void 0:c[r])||void 0===n?void 0:n.variants;l&&l[o]&&(l[o]=i)}))})),r?(Y((e=>{const t=Object.assign({},e);return t.products=c,t})),k({type:"productsPaged",data:{collectionId:H,products:c}})):k({type:"productsPaged",data:{collectionId:H,products:c}})})).catch((e=>{r?P.markVariantsAsApprovedProductsLevel(t,k,H,X,Y):P.markVariantsAsApprovedProductsLevel(t,k,H)}))},re=e=>{I(!0),Q(!0),b(H,S,e,0).then((t=>{if(Object.keys(t).length||(Z.current=!0),Object.keys(t).length){Y(Object.assign(Object.assign({},X),{products:t}));const e=P.getVariantIdsToFetchAtProductLevel(t);te(e,t),J.current=1}e||O({type:"selected",data:{id:H,val:Object.assign(Object.assign({},C),{products:t})}}),I(!1),Q(!1),N(!1)})).catch()},ce=(e,t)=>{const r=P.liftTheStateUp(t,C);O({type:e,data:Object.assign(Object.assign({},r),{isRestricted:A})})};return e.jsxs("div",{children:[e.jsxs(g.ProductScreenHeader,{children:[e.jsx(l.IconButton,{Icon:t.default,height:16,onClick:()=>{m("collections")}}),e.jsx(a.BodyCaption,Object.assign({style:{color:n.COLORS.content.secondary}},{children:C.name}))]}),!E&&e.jsx("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(d.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>G&&W.length?e.jsx(u.Spinner,{size:"small",color:n.COLORS.content.primary}):e.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:W,onChangeText:e=>{e.length&&e.trim().length?z(e):z("")},placeholder:"Search products in this collection..."})})),e.jsxs("div",{children:[Object.keys((null==X?void 0:X.products)||[]).length>0&&!ee&&!W.length&&!q&&"-1"!==H&&e.jsxs(g.ProductScreenCollectionCardStyle,{children:[e.jsx(i.CheckBox,{isChecked:!!(null==x?void 0:x[H]),isPartiallyChecked:P.isCollectionPartiallyChecked(H,X,x,V),onValueChange:function(e){e?re():O({type:"unselected",data:{id:H}})}}),e.jsx("div",Object.assign({style:{width:40,height:40}},{children:e.jsx(r.default,{})})),e.jsx(a.TitleRegular,{children:"All Products"})]}),Object.keys((null==X?void 0:X.products)||[]).length?Object.keys(X.products||[]).map((t=>e.jsx(p.ProductGroup,{outOfStockAction:T,collectionId:H,isProductPartiallyChecked:P.isProductPartiallyChecked(H,t,x,X,V),productId:t,data:X.products[t],selectedData:x,selectedCollectionsDispatch:O,viewOnly:!D&&!!ee,upliftAdditions:ce,hideProductCheckbox:q,hideVariantCheckbox:R,hideProductVariants:V,pickerType:L,onProductDetailClick:w,showProductDetailInfoIcon:B},t))):G?e.jsx(v.ProductPickerShimmer,{limit:10}):e.jsx(h.EmptyState,{title:"No products to show",subtitle:W.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),e.jsx("div",{ref:U})]}),M&&e.jsx(v.ProductPickerShimmer,{})]})};
@@ -1 +1 @@
1
- import{jsxs as t,jsx as e}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import c from"../../assets/icons/box.svg.js";import r from"../../assets/icons/search.svg.js";import{cloneDeep as n}from"lodash";import{useContext as i,useRef as s,useState as l,useEffect as d}from"react";import{COLORS as a}from"../../constants/Theme.js";import{CheckBox as u}from"../checkBox/CheckBox.js";import{IconButton as h}from"../icon-button/IconButton.js";import{Input as p}from"../input/Input.js";import{Spinner as m}from"../spinner/Spinner.js";import{BodyCaption as g,TitleRegular as v}from"../TypographyStyle.js";import{EmptyState as f}from"./emptyState.js";import{ProductGroup as j}from"./product.js";import{ProductPickerShimmer as y}from"./ProductPickerShimmer.js";import{CollectionIdContext as b}from"./reducers.js";import{ProductScreenHeader as k,ProductScreenCollectionCardStyle as O}from"./style.js";import{OUT_OF_STOCK_ACTION as C}from"./type.js";import{getVariantIdsToFetchAtProductLevel as P,markVariantsAsApprovedProductsLevel as E,isCollectionPartiallyChecked as I,isProductPartiallyChecked as D,liftTheStateUp as x}from"./utility.js";const S=S=>{const{data:R,collectionsDispatch:T,selectedData:w,selectedCollectionsDispatch:A,productFetcher:V,storeId:B,setScreen:F,setSaveDisabled:L,hideInCollectionSearch:H,customCollectionRestriction:J,hideProductCheckbox:W,outOfStockAction:z=C.BLUR,hideVariantCheckbox:K=!1,selectProductsFromCustomCollection:M=!1,pickerType:N,hideProductVariants:U,fbStatusFetcher:_,onProductDetailClick:q,showProductDetailInfoIcon:G,scrollContainerRef:Q}=S,X=i(b),Y=s(null),Z=s(0),$=s(!1),[tt,et]=l(!(null==R?void 0:R.products)),[ot,ct]=l(""),[rt,nt]=l(!1),[it,st]=l(R),lt=s(!1);d((()=>{const t=setTimeout((()=>{ot.length?(nt(!0),S.searchInCollectionFetcher(B,X,ot).then((t=>{const e=n(R);e.products=t,st(e);const o=P(null!=t?t:{});ut(o,null!=t?t:{},!0),L(!1),nt(!1)}))):st(R)}),800);return()=>clearTimeout(t)}),[ot]),d((()=>{var t;return null===(t=null==Q?void 0:Q.current)||void 0===t||t.addEventListener("scroll",dt),()=>{var t;null===(t=null==Q?void 0:Q.current)||void 0===t||t.removeEventListener("scroll",dt)}}),[]);const dt=()=>{if(!Q||!(null==Q?void 0:Q.current))return;console.log("handlescroll called",{scrollContainerRef:Q,hasAllProductsLoaded:lt,isLoading:tt,isFetchingRef:$});const{scrollTop:t,clientHeight:e,scrollHeight:o}=Q.current;t+e>=o-20&&!lt.current&&!$.current&&(console.log("scrolling"),L(!0),et(!0),$.current=!0,V(X,B,10,Z.current).then((t=>{if(Object.keys(t).length||(lt.current=!0),Object.keys(t).length){const e=it;e.products=Object.assign(Object.assign({},it.products),t),st(e);const o=P(t);ut(o,t),Z.current+=1}$.current=!0,et(!1),L(!1)})).catch())};d((()=>{var t,e,o,c;lt.current=!1,Z.current=Math.floor((null===(e=Object.keys(null!==(t=R.products)&&void 0!==t?t:{}))||void 0===e?void 0:e.length)/10);const r=P(null!==(o=R.products)&&void 0!==o?o:{});ut(r,null!==(c=R.products)&&void 0!==c?c:{})}),[X]);const at=!!J&&R.isSmartCollection;d((()=>{(null==R?void 0:R.products)||ht(10)}),[]);const ut=(t,e,o)=>{_||(o?E(e,T,X,it,st):E(e,T,X)),t.length>0&&_&&_(B,t).then((t=>{const c=Object.assign({},e);Object.keys(e).forEach((o=>{var r,n;Object.keys(null!==(n=null===(r=null==e?void 0:e[o])||void 0===r?void 0:r.variants)&&void 0!==n?n:{}).forEach((r=>{var n,i;const s=null===(n=null==e?void 0:e[o].variants)||void 0===n?void 0:n[r];s&&"REJECTED"===t[r]?s.fbStatus="REJECTED":s&&"APPROVED"===t[r]&&(s.fbStatus="APPROVED");const l=null===(i=null==c?void 0:c[o])||void 0===i?void 0:i.variants;l&&l[r]&&(l[r]=s)}))})),o?(st((t=>{const e=Object.assign({},t);return e.products=c,e})),T({type:"productsPaged",data:{collectionId:X,products:c}})):T({type:"productsPaged",data:{collectionId:X,products:c}})})).catch((t=>{o?E(e,T,X,it,st):E(e,T,X)}))},ht=t=>{L(!0),nt(!0),V(X,B,t,0).then((e=>{if(Object.keys(e).length||(lt.current=!0),Object.keys(e).length){st(Object.assign(Object.assign({},it),{products:e}));const t=P(e);ut(t,e),Z.current=1}t||A({type:"selected",data:{id:X,val:Object.assign(Object.assign({},R),{products:e})}}),L(!1),nt(!1),et(!1)})).catch()},pt=(t,e)=>{const o=x(e,R);A({type:t,data:Object.assign(Object.assign({},o),{isRestricted:J})})};return t("div",{children:[t(k,{children:[e(h,{Icon:o,height:16,onClick:()=>{F("collections")}}),e(g,Object.assign({style:{color:a.content.secondary}},{children:R.name}))]}),!H&&e("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e(p,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>rt&&ot.length?e(m,{size:"small",color:a.content.primary}):e(r,{})},id:"listInput",height:"24px",type:"text",value:ot,onChangeText:t=>{t.length&&t.trim().length?ct(t):ct("")},placeholder:"Search products in this collection..."})})),t("div",{children:[Object.keys((null==it?void 0:it.products)||[]).length>0&&!at&&!ot.length&&!W&&"-1"!==X&&t(O,{children:[e(u,{isChecked:!!(null==w?void 0:w[X]),isPartiallyChecked:I(X,it,w,U),onValueChange:function(t){t?ht():A({type:"unselected",data:{id:X}})}}),e("div",Object.assign({style:{width:40,height:40}},{children:e(c,{})})),e(v,{children:"All Products"})]}),Object.keys((null==it?void 0:it.products)||[]).length?Object.keys(it.products||[]).map((t=>e(j,{outOfStockAction:z,collectionId:X,isProductPartiallyChecked:D(X,t,w,it,U),productId:t,data:it.products[t],selectedData:w,selectedCollectionsDispatch:A,viewOnly:!M&&!!at,upliftAdditions:pt,hideProductCheckbox:W,hideVariantCheckbox:K,hideProductVariants:U,pickerType:N,onProductDetailClick:q,showProductDetailInfoIcon:G},t))):rt?e(y,{limit:10}):e(f,{title:"No products to show",subtitle:ot.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),e("div",{ref:Y})]}),tt&&e(y,{})]})};export{S as ProductsScreen};
1
+ import{jsxs as t,jsx as e}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import c from"../../assets/icons/box.svg.js";import r from"../../assets/icons/search.svg.js";import{cloneDeep as n}from"lodash";import{useContext as i,useRef as s,useState as l,useEffect as d}from"react";import{COLORS as a}from"../../constants/Theme.js";import{CheckBox as u}from"../checkBox/CheckBox.js";import{IconButton as h}from"../icon-button/IconButton.js";import{Input as p}from"../input/Input.js";import{Spinner as m}from"../spinner/Spinner.js";import{BodyCaption as g,TitleRegular as v}from"../TypographyStyle.js";import{EmptyState as f}from"./emptyState.js";import{ProductGroup as j}from"./product.js";import{ProductPickerShimmer as y}from"./ProductPickerShimmer.js";import{CollectionIdContext as b}from"./reducers.js";import{ProductScreenHeader as k,ProductScreenCollectionCardStyle as O}from"./style.js";import{OUT_OF_STOCK_ACTION as C}from"./type.js";import{getVariantIdsToFetchAtProductLevel as P,markVariantsAsApprovedProductsLevel as E,isCollectionPartiallyChecked as I,isProductPartiallyChecked as D,liftTheStateUp as x}from"./utility.js";const S=S=>{const{data:R,collectionsDispatch:T,selectedData:w,selectedCollectionsDispatch:A,productFetcher:V,storeId:B,setScreen:F,setSaveDisabled:L,hideInCollectionSearch:H,customCollectionRestriction:J,hideProductCheckbox:W,outOfStockAction:z=C.BLUR,hideVariantCheckbox:K=!1,selectProductsFromCustomCollection:M=!1,pickerType:N,hideProductVariants:U,fbStatusFetcher:_,onProductDetailClick:q,showProductDetailInfoIcon:G,scrollContainerRef:Q}=S,X=i(b),Y=s(null),Z=s(0),$=s(!1),[tt,et]=l(!(null==R?void 0:R.products)),[ot,ct]=l(""),[rt,nt]=l(!1),[it,st]=l(R),lt=s(!1);d((()=>{const t=setTimeout((()=>{ot.length?(nt(!0),S.searchInCollectionFetcher(B,X,ot).then((t=>{const e=n(R);e.products=t,st(e);const o=P(null!=t?t:{});ut(o,null!=t?t:{},!0),L(!1),nt(!1)}))):st(R)}),800);return()=>clearTimeout(t)}),[ot]),d((()=>{var t;return null===(t=null==Q?void 0:Q.current)||void 0===t||t.addEventListener("scroll",dt),()=>{var t;null===(t=null==Q?void 0:Q.current)||void 0===t||t.removeEventListener("scroll",dt)}}),[]);const dt=()=>{if(!Q||!(null==Q?void 0:Q.current))return;console.log("handlescroll called",{scrollContainerRef:Q,hasAllProductsLoaded:lt,isLoading:tt,isFetchingRef:$});const{scrollTop:t,clientHeight:e,scrollHeight:o}=Q.current;t+e>=o-20&&!lt.current&&!$.current&&(console.log("scrolling"),L(!0),et(!0),$.current=!0,V(X,B,10,Z.current).then((t=>{if(Object.keys(t).length||(lt.current=!0),Object.keys(t).length){const e=it;e.products=Object.assign(Object.assign({},it.products),t),st(e);const o=P(t);ut(o,t),Z.current+=1}$.current=!1,et(!1),L(!1)})).catch())};d((()=>{var t,e,o,c;lt.current=!1,Z.current=Math.floor((null===(e=Object.keys(null!==(t=R.products)&&void 0!==t?t:{}))||void 0===e?void 0:e.length)/10);const r=P(null!==(o=R.products)&&void 0!==o?o:{});ut(r,null!==(c=R.products)&&void 0!==c?c:{})}),[X]);const at=!!J&&R.isSmartCollection;d((()=>{(null==R?void 0:R.products)||ht(10)}),[]);const ut=(t,e,o)=>{_||(o?E(e,T,X,it,st):E(e,T,X)),t.length>0&&_&&_(B,t).then((t=>{const c=Object.assign({},e);Object.keys(e).forEach((o=>{var r,n;Object.keys(null!==(n=null===(r=null==e?void 0:e[o])||void 0===r?void 0:r.variants)&&void 0!==n?n:{}).forEach((r=>{var n,i;const s=null===(n=null==e?void 0:e[o].variants)||void 0===n?void 0:n[r];s&&"REJECTED"===t[r]?s.fbStatus="REJECTED":s&&"APPROVED"===t[r]&&(s.fbStatus="APPROVED");const l=null===(i=null==c?void 0:c[o])||void 0===i?void 0:i.variants;l&&l[r]&&(l[r]=s)}))})),o?(st((t=>{const e=Object.assign({},t);return e.products=c,e})),T({type:"productsPaged",data:{collectionId:X,products:c}})):T({type:"productsPaged",data:{collectionId:X,products:c}})})).catch((t=>{o?E(e,T,X,it,st):E(e,T,X)}))},ht=t=>{L(!0),nt(!0),V(X,B,t,0).then((e=>{if(Object.keys(e).length||(lt.current=!0),Object.keys(e).length){st(Object.assign(Object.assign({},it),{products:e}));const t=P(e);ut(t,e),Z.current=1}t||A({type:"selected",data:{id:X,val:Object.assign(Object.assign({},R),{products:e})}}),L(!1),nt(!1),et(!1)})).catch()},pt=(t,e)=>{const o=x(e,R);A({type:t,data:Object.assign(Object.assign({},o),{isRestricted:J})})};return t("div",{children:[t(k,{children:[e(h,{Icon:o,height:16,onClick:()=>{F("collections")}}),e(g,Object.assign({style:{color:a.content.secondary}},{children:R.name}))]}),!H&&e("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e(p,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>rt&&ot.length?e(m,{size:"small",color:a.content.primary}):e(r,{})},id:"listInput",height:"24px",type:"text",value:ot,onChangeText:t=>{t.length&&t.trim().length?ct(t):ct("")},placeholder:"Search products in this collection..."})})),t("div",{children:[Object.keys((null==it?void 0:it.products)||[]).length>0&&!at&&!ot.length&&!W&&"-1"!==X&&t(O,{children:[e(u,{isChecked:!!(null==w?void 0:w[X]),isPartiallyChecked:I(X,it,w,U),onValueChange:function(t){t?ht():A({type:"unselected",data:{id:X}})}}),e("div",Object.assign({style:{width:40,height:40}},{children:e(c,{})})),e(v,{children:"All Products"})]}),Object.keys((null==it?void 0:it.products)||[]).length?Object.keys(it.products||[]).map((t=>e(j,{outOfStockAction:z,collectionId:X,isProductPartiallyChecked:D(X,t,w,it,U),productId:t,data:it.products[t],selectedData:w,selectedCollectionsDispatch:A,viewOnly:!M&&!!at,upliftAdditions:pt,hideProductCheckbox:W,hideVariantCheckbox:K,hideProductVariants:U,pickerType:N,onProductDetailClick:q,showProductDetailInfoIcon:G},t))):rt?e(y,{limit:10}):e(f,{title:"No products to show",subtitle:ot.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),e("div",{ref:Y})]}),tt&&e(y,{})]})};export{S as ProductsScreen};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.469-beta.pp-7",
3
+ "version": "0.0.469-beta.pp-8",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",