@bikdotai/bik-component-library 0.0.469-beta.pp-9 → 0.0.469-beta.pp-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,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -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=C=>{const{data:f,collectionsDispatch:k,selectedData:O,selectedCollectionsDispatch:b,productFetcher:x,storeId:S,setScreen:m,setSaveDisabled:I,hideInCollectionSearch:E,customCollectionRestriction:A,hideProductCheckbox:q,outOfStockAction:T=y.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:D=!1,selectProductsFromCustomCollection:R=!1,pickerType:L,hideProductVariants:V,fbStatusFetcher:F,onProductDetailClick:w,showProductDetailInfoIcon:B,scrollContainerRef:_}=C,H=s.useContext(j.CollectionIdContext),U=s.useRef(0),J=s.useRef(!1),[K,M]=s.useState(!(null==f?void 0:f.products)),[N,W]=s.useState(""),[z,G]=s.useState(!1),[Q,X]=s.useState(f),Y=s.useRef(!1);s.useEffect((()=>{const e=setTimeout((()=>{N.length?(G(!0),C.searchInCollectionFetcher(S,H,N).then((e=>{const t=o.cloneDeep(f);t.products=e,X(t);const r=P.getVariantIdsToFetchAtProductLevel(null!=e?e:{});ee(r,null!=e?e:{},!0),I(!1),G(!1)}))):X(f)}),800);return()=>clearTimeout(e)}),[N]);const Z=()=>{if(!_||!(null==_?void 0:_.current))return;console.log("handlescroll called",{scrollContainerRef:_,hasAllProductsLoaded:Y,isLoading:K,isFetchingRef:J});const{scrollTop:e,clientHeight:t,scrollHeight:r}=_.current;e+t>=r-20&&!Y.current&&!J.current&&(I(!0),M(!0),J.current=!0,x(H,S,10,U.current).then((e=>{if(Object.keys(e).length||(Y.current=!0),Object.keys(e).length){const t=Q;t.products=Object.assign(Object.assign({},Q.products),e),X(t);const r=P.getVariantIdsToFetchAtProductLevel(e);ee(r,e),U.current+=1}J.current=!1,M(!1),I(!1)})).catch())};s.useEffect((()=>{var e;return null===(e=null==_?void 0:_.current)||void 0===e||e.addEventListener("scroll",Z),()=>{var e;null===(e=null==_?void 0:_.current)||void 0===e||e.removeEventListener("scroll",Z)}}),[]),s.useEffect((()=>{var e,t,r,c;Y.current=!1,U.current=Math.floor((null===(t=Object.keys(null!==(e=f.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length)/10);const o=P.getVariantIdsToFetchAtProductLevel(null!==(r=f.products)&&void 0!==r?r:{});ee(o,null!==(c=f.products)&&void 0!==c?c:{})}),[H]);const $=!!A&&f.isSmartCollection;s.useEffect((()=>{(null==f?void 0:f.products)||te(10)}),[]);const ee=(e,t,r)=>{F||(r?P.markVariantsAsApprovedProductsLevel(t,k,H,Q,X):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?(X((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,Q,X):P.markVariantsAsApprovedProductsLevel(t,k,H)}))},te=e=>{I(!0),G(!0),x(H,S,e,0).then((t=>{if(Object.keys(t).length||(Y.current=!0),Object.keys(t).length){X(Object.assign(Object.assign({},Q),{products:t}));const e=P.getVariantIdsToFetchAtProductLevel(t);ee(e,t),U.current=1}e||b({type:"selected",data:{id:H,val:Object.assign(Object.assign({},f),{products:t})}}),I(!1),G(!1),M(!1)})).catch()},re=(e,t)=>{const r=P.liftTheStateUp(t,f);b({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:f.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:()=>z&&N.length?e.jsx(u.Spinner,{size:"small",color:n.COLORS.content.primary}):e.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:N,onChangeText:e=>{e.length&&e.trim().length?W(e):W("")},placeholder:"Search products in this collection..."})})),e.jsxs("div",{children:[Object.keys((null==Q?void 0:Q.products)||[]).length>0&&!$&&!N.length&&!q&&"-1"!==H&&e.jsxs(g.ProductScreenCollectionCardStyle,{children:[e.jsx(i.CheckBox,{isChecked:!!(null==O?void 0:O[H]),isPartiallyChecked:P.isCollectionPartiallyChecked(H,Q,O,V),onValueChange:function(e){e?te():b({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==Q?void 0:Q.products)||[]).length?Object.keys(Q.products||[]).map((t=>e.jsx(p.ProductGroup,{outOfStockAction:T,collectionId:H,isProductPartiallyChecked:P.isProductPartiallyChecked(H,t,O,Q,V),productId:t,data:Q.products[t],selectedData:O,selectedCollectionsDispatch:b,viewOnly:!R&&!!$,upliftAdditions:re,hideProductCheckbox:q,hideVariantCheckbox:D,hideProductVariants:V,pickerType:L,onProductDetailClick:w,showProductDetailInfoIcon:B},t))):z?e.jsx(v.ProductPickerShimmer,{limit:10}):e.jsx(h.EmptyState,{title:"No products to show",subtitle:N.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})]}),K&&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=C=>{const{data:f,collectionsDispatch:k,selectedData:O,selectedCollectionsDispatch:b,productFetcher:x,storeId:S,setScreen:m,setSaveDisabled:I,hideInCollectionSearch:E,customCollectionRestriction:A,hideProductCheckbox:q,outOfStockAction:T=y.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:D=!1,selectProductsFromCustomCollection:R=!1,pickerType:L,hideProductVariants:V,fbStatusFetcher:F,onProductDetailClick:w,showProductDetailInfoIcon:B,scrollContainerRef:_}=C,H=s.useContext(j.CollectionIdContext),U=s.useRef(0),J=s.useRef(!1),[K,M]=s.useState(!(null==f?void 0:f.products)),[N,W]=s.useState(""),[z,G]=s.useState(!1),[Q,X]=s.useState(f),Y=s.useRef(!1);s.useEffect((()=>{const e=setTimeout((()=>{N.length?(G(!0),C.searchInCollectionFetcher(S,H,N).then((e=>{const t=o.cloneDeep(f);t.products=e,X(t);const r=P.getVariantIdsToFetchAtProductLevel(null!=e?e:{});ee(r,null!=e?e:{},!0),I(!1),G(!1)}))):X(f)}),800);return()=>clearTimeout(e)}),[N]);const Z=()=>{if(console.log("handlescroll called",{scrollContainerRef:_,hasAllProductsLoaded:Y,isLoading:K,isFetchingRef:J}),!_||!(null==_?void 0:_.current))return;const{scrollTop:e,clientHeight:t,scrollHeight:r}=_.current;e+t>=r-20&&!Y.current&&!J.current&&(I(!0),M(!0),J.current=!0,x(H,S,10,U.current).then((e=>{if(Object.keys(e).length||(Y.current=!0),Object.keys(e).length){const t=Q;t.products=Object.assign(Object.assign({},Q.products),e),X(t);const r=P.getVariantIdsToFetchAtProductLevel(e);ee(r,e),U.current+=1}J.current=!1,M(!1),I(!1)})).catch())};s.useEffect((()=>{var e;return null===(e=null==_?void 0:_.current)||void 0===e||e.addEventListener("scroll",Z),()=>{var e;null===(e=null==_?void 0:_.current)||void 0===e||e.removeEventListener("scroll",Z)}}),[]),s.useEffect((()=>{var e,t,r,c;Y.current=!1,U.current=Math.floor((null===(t=Object.keys(null!==(e=f.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length)/10);const o=P.getVariantIdsToFetchAtProductLevel(null!==(r=f.products)&&void 0!==r?r:{});ee(o,null!==(c=f.products)&&void 0!==c?c:{})}),[H]);const $=!!A&&f.isSmartCollection;s.useEffect((()=>{(null==f?void 0:f.products)||te(10)}),[]);const ee=(e,t,r)=>{F||(r?P.markVariantsAsApprovedProductsLevel(t,k,H,Q,X):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?(X((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,Q,X):P.markVariantsAsApprovedProductsLevel(t,k,H)}))},te=e=>{I(!0),G(!0),x(H,S,e,0).then((t=>{if(Object.keys(t).length||(Y.current=!0),Object.keys(t).length){X(Object.assign(Object.assign({},Q),{products:t}));const e=P.getVariantIdsToFetchAtProductLevel(t);ee(e,t),U.current=1}e||b({type:"selected",data:{id:H,val:Object.assign(Object.assign({},f),{products:t})}}),I(!1),G(!1),M(!1)})).catch()},re=(e,t)=>{const r=P.liftTheStateUp(t,f);b({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:f.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:()=>z&&N.length?e.jsx(u.Spinner,{size:"small",color:n.COLORS.content.primary}):e.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:N,onChangeText:e=>{e.length&&e.trim().length?W(e):W("")},placeholder:"Search products in this collection..."})})),e.jsxs("div",{children:[Object.keys((null==Q?void 0:Q.products)||[]).length>0&&!$&&!N.length&&!q&&"-1"!==H&&e.jsxs(g.ProductScreenCollectionCardStyle,{children:[e.jsx(i.CheckBox,{isChecked:!!(null==O?void 0:O[H]),isPartiallyChecked:P.isCollectionPartiallyChecked(H,Q,O,V),onValueChange:function(e){e?te():b({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==Q?void 0:Q.products)||[]).length?Object.keys(Q.products||[]).map((t=>e.jsx(p.ProductGroup,{outOfStockAction:T,collectionId:H,isProductPartiallyChecked:P.isProductPartiallyChecked(H,t,O,Q,V),productId:t,data:Q.products[t],selectedData:O,selectedCollectionsDispatch:b,viewOnly:!R&&!!$,upliftAdditions:re,hideProductCheckbox:q,hideVariantCheckbox:D,hideProductVariants:V,pickerType:L,onProductDetailClick:w,showProductDetailInfoIcon:B},t))):z?e.jsx(v.ProductPickerShimmer,{limit:10}):e.jsx(h.EmptyState,{title:"No products to show",subtitle:N.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})]}),K&&e.jsx(v.ProductPickerShimmer,{})]})};
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -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(0),Z=s(!1),[$,tt]=l(!(null==R?void 0:R.products)),[et,ot]=l(""),[ct,rt]=l(!1),[nt,it]=l(R),st=s(!1);d((()=>{const t=setTimeout((()=>{et.length?(rt(!0),S.searchInCollectionFetcher(B,X,et).then((t=>{const e=n(R);e.products=t,it(e);const o=P(null!=t?t:{});at(o,null!=t?t:{},!0),L(!1),rt(!1)}))):it(R)}),800);return()=>clearTimeout(t)}),[et]);const lt=()=>{if(!Q||!(null==Q?void 0:Q.current))return;console.log("handlescroll called",{scrollContainerRef:Q,hasAllProductsLoaded:st,isLoading:$,isFetchingRef:Z});const{scrollTop:t,clientHeight:e,scrollHeight:o}=Q.current;t+e>=o-20&&!st.current&&!Z.current&&(L(!0),tt(!0),Z.current=!0,V(X,B,10,Y.current).then((t=>{if(Object.keys(t).length||(st.current=!0),Object.keys(t).length){const e=nt;e.products=Object.assign(Object.assign({},nt.products),t),it(e);const o=P(t);at(o,t),Y.current+=1}Z.current=!1,tt(!1),L(!1)})).catch())};d((()=>{var t;return null===(t=null==Q?void 0:Q.current)||void 0===t||t.addEventListener("scroll",lt),()=>{var t;null===(t=null==Q?void 0:Q.current)||void 0===t||t.removeEventListener("scroll",lt)}}),[]),d((()=>{var t,e,o,c;st.current=!1,Y.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:{});at(r,null!==(c=R.products)&&void 0!==c?c:{})}),[X]);const dt=!!J&&R.isSmartCollection;d((()=>{(null==R?void 0:R.products)||ut(10)}),[]);const at=(t,e,o)=>{_||(o?E(e,T,X,nt,it):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?(it((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,nt,it):E(e,T,X)}))},ut=t=>{L(!0),rt(!0),V(X,B,t,0).then((e=>{if(Object.keys(e).length||(st.current=!0),Object.keys(e).length){it(Object.assign(Object.assign({},nt),{products:e}));const t=P(e);at(t,e),Y.current=1}t||A({type:"selected",data:{id:X,val:Object.assign(Object.assign({},R),{products:e})}}),L(!1),rt(!1),tt(!1)})).catch()},ht=(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:()=>ct&&et.length?e(m,{size:"small",color:a.content.primary}):e(r,{})},id:"listInput",height:"24px",type:"text",value:et,onChangeText:t=>{t.length&&t.trim().length?ot(t):ot("")},placeholder:"Search products in this collection..."})})),t("div",{children:[Object.keys((null==nt?void 0:nt.products)||[]).length>0&&!dt&&!et.length&&!W&&"-1"!==X&&t(O,{children:[e(u,{isChecked:!!(null==w?void 0:w[X]),isPartiallyChecked:I(X,nt,w,U),onValueChange:function(t){t?ut():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==nt?void 0:nt.products)||[]).length?Object.keys(nt.products||[]).map((t=>e(j,{outOfStockAction:z,collectionId:X,isProductPartiallyChecked:D(X,t,w,nt,U),productId:t,data:nt.products[t],selectedData:w,selectedCollectionsDispatch:A,viewOnly:!M&&!!dt,upliftAdditions:ht,hideProductCheckbox:W,hideVariantCheckbox:K,hideProductVariants:U,pickerType:N,onProductDetailClick:q,showProductDetailInfoIcon:G},t))):ct?e(y,{limit:10}):e(f,{title:"No products to show",subtitle:et.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})]}),$&&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(0),Z=s(!1),[$,tt]=l(!(null==R?void 0:R.products)),[et,ot]=l(""),[ct,rt]=l(!1),[nt,it]=l(R),st=s(!1);d((()=>{const t=setTimeout((()=>{et.length?(rt(!0),S.searchInCollectionFetcher(B,X,et).then((t=>{const e=n(R);e.products=t,it(e);const o=P(null!=t?t:{});at(o,null!=t?t:{},!0),L(!1),rt(!1)}))):it(R)}),800);return()=>clearTimeout(t)}),[et]);const lt=()=>{if(console.log("handlescroll called",{scrollContainerRef:Q,hasAllProductsLoaded:st,isLoading:$,isFetchingRef:Z}),!Q||!(null==Q?void 0:Q.current))return;const{scrollTop:t,clientHeight:e,scrollHeight:o}=Q.current;t+e>=o-20&&!st.current&&!Z.current&&(L(!0),tt(!0),Z.current=!0,V(X,B,10,Y.current).then((t=>{if(Object.keys(t).length||(st.current=!0),Object.keys(t).length){const e=nt;e.products=Object.assign(Object.assign({},nt.products),t),it(e);const o=P(t);at(o,t),Y.current+=1}Z.current=!1,tt(!1),L(!1)})).catch())};d((()=>{var t;return null===(t=null==Q?void 0:Q.current)||void 0===t||t.addEventListener("scroll",lt),()=>{var t;null===(t=null==Q?void 0:Q.current)||void 0===t||t.removeEventListener("scroll",lt)}}),[]),d((()=>{var t,e,o,c;st.current=!1,Y.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:{});at(r,null!==(c=R.products)&&void 0!==c?c:{})}),[X]);const dt=!!J&&R.isSmartCollection;d((()=>{(null==R?void 0:R.products)||ut(10)}),[]);const at=(t,e,o)=>{_||(o?E(e,T,X,nt,it):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?(it((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,nt,it):E(e,T,X)}))},ut=t=>{L(!0),rt(!0),V(X,B,t,0).then((e=>{if(Object.keys(e).length||(st.current=!0),Object.keys(e).length){it(Object.assign(Object.assign({},nt),{products:e}));const t=P(e);at(t,e),Y.current=1}t||A({type:"selected",data:{id:X,val:Object.assign(Object.assign({},R),{products:e})}}),L(!1),rt(!1),tt(!1)})).catch()},ht=(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:()=>ct&&et.length?e(m,{size:"small",color:a.content.primary}):e(r,{})},id:"listInput",height:"24px",type:"text",value:et,onChangeText:t=>{t.length&&t.trim().length?ot(t):ot("")},placeholder:"Search products in this collection..."})})),t("div",{children:[Object.keys((null==nt?void 0:nt.products)||[]).length>0&&!dt&&!et.length&&!W&&"-1"!==X&&t(O,{children:[e(u,{isChecked:!!(null==w?void 0:w[X]),isPartiallyChecked:I(X,nt,w,U),onValueChange:function(t){t?ut():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==nt?void 0:nt.products)||[]).length?Object.keys(nt.products||[]).map((t=>e(j,{outOfStockAction:z,collectionId:X,isProductPartiallyChecked:D(X,t,w,nt,U),productId:t,data:nt.products[t],selectedData:w,selectedCollectionsDispatch:A,viewOnly:!M&&!!dt,upliftAdditions:ht,hideProductCheckbox:W,hideVariantCheckbox:K,hideProductVariants:U,pickerType:N,onProductDetailClick:q,showProductDetailInfoIcon:G},t))):ct?e(y,{limit:10}):e(f,{title:"No products to show",subtitle:et.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})]}),$&&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-9",
3
+ "version": "0.0.469-beta.pp-10",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",