@bikdotai/bik-component-library 0.0.548-beta.0 → 0.0.548-beta.2

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