@bikdotai/bik-component-library 0.0.159-beta.10 → 0.0.159-beta.12
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.
- package/dist/cjs/components/product-picker-v2/modal.js +1 -1
- package/dist/cjs/components/product-picker-v2/productScreen.js +1 -1
- package/dist/cjs/components/product-picker-v2/reducers.js +1 -1
- package/dist/cjs/components/product-picker-v2/searchScreen.d.ts +1 -0
- package/dist/cjs/components/product-picker-v2/searchScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/modal.js +1 -1
- package/dist/esm/components/product-picker-v2/productScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/reducers.js +1 -1
- package/dist/esm/components/product-picker-v2/searchScreen.d.ts +1 -0
- package/dist/esm/components/product-picker-v2/searchScreen.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/search.svg.js"),c=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/search.svg.js"),c=require("react"),o=require("../../constants/Theme.js"),s=require("../button/Button.js"),r=require("../input/Input.js"),l=require("../modals/styledModal.js"),n=require("../spinner/Spinner.js"),i=require("../tag/Tag.js"),d=require("./collectionScreen.js"),a=require("./productScreen.js"),u=require("./reducers.js"),h=require("./searchScreen.js"),p=require("./selectedScreen.js"),S=require("./style.js");exports.ProductPickerModal=j=>{const{storeId:C,selectedItems:x,onClose:v,visible:g,zIndex:y,limit:b}=j,[m,f]=c.useReducer(u.collectionsReducer,{}),[I,q]=c.useState("collections"),[P,T]=c.useState(""),[E,F]=c.useState(0),[O,R]=c.useState(!1),[k,D]=c.useState(0),[B,w]=c.useState(""),[L,M]=c.useState(!1),[z,G]=c.useState(!1),[$,A]=c.useState(),[_,H]=c.useReducer(u.selectedColectionsReducer,Object.keys(x).length>0?x:{});c.useEffect((()=>{R(!0),G(!0),j.collectionFetcher(E,C).then((e=>{f({type:"fetched",data:(null==e?void 0:e.collections)||{}}),R(!1),F((e=>e+1)),G(!1)})).catch()}),[]),c.useEffect((()=>{let e=0;Object.keys(_||[]).forEach((t=>{var c;Object.keys((null===(c=_[t])||void 0===c?void 0:c.products)||[]).forEach((c=>{var o,s;Object.keys((null===(s=null===(o=_[t].products)||void 0===o?void 0:o[c])||void 0===s?void 0:s.variants)||[]).forEach((()=>{e+=1}))}))})),D(e)})),c.useEffect((()=>{var e;P&&!(null===(e=null==m?void 0:m[P])||void 0===e?void 0:e.products)&&(R(!0),j.productFetcher(P,C).then((e=>{Object.keys(e).length&&f({type:"productsFetched",data:{collectionId:P,products:e}}),R(!1)})).catch())}),[P]),c.useEffect((()=>{const e=setTimeout((()=>{B.length&&(M(!0),j.searchFetcher(C,B).then((e=>{A(e),q("searchProducts"),R(!1),M(!1)})))}),800);return()=>clearTimeout(e)}),[B]);const Y=()=>{H({type:"reset",data:{}})};return e.jsx(l.StyledModal,Object.assign({zIndex:y,open:g,onClose:()=>{v(),Y()},headingTitle:"collections"===I||"products"===I?"Select Products":"view"===I?"Selected Products":"searchProducts"===I?"Searched Products":void 0,footerShadow:!0,centralContainerStyles:{width:"480px"},primaryButton:{buttonText:O?"Loading...":"Add",disabled:O||b&&k>b||!1,onClick:()=>{j.onAdd(_,k),Y()}},footerLeftCustomElement:b&&k>b?e.jsx(i.Tag,{tagText:`You can only select ${b} products`,type:"negative"}):k>0?e.jsx(s.Button,{onClick:()=>{q("view")},buttonText:`${k} products selected`,buttonType:"tertiaryGray"}):e.jsx(s.Button,{disabled:!0,buttonText:`${k} products selected`,buttonType:"tertiaryGray"})},{children:e.jsxs(S.ContainerStyle,{children:[!j.hideGlobalSearch&&e.jsx(e.Fragment,{children:("collections"===I||"searchProducts"===I)&&e.jsx("div",Object.assign({style:{padding:16,paddingTop:0,height:"60px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(r.Input,{noErrorHint:!0,rightIcon:{icon:()=>L?e.jsx(n.Spinner,{size:"small",color:o.COLORS.content.primary}):e.jsx(t.default,{})},id:"listInput",height:"24px",type:"text",value:B,onChangeText:e=>{e.length&&e.trim().length&&w(e)},placeholder:"Search products..."})}))}),e.jsxs(S.ScrollContainerStyle,{children:["collections"===I&&e.jsx(d.CollectionsScreen,{customCollectionRestriction:j.customCollectionRestriction,dataLoading:z,collections:m,selectedCollectionsDispatch:H,setCollectionId:T,setScreen:q,selectedCollections:_,collectionFetcher:j.collectionFetcher,storeId:C,collectionsDispatch:f,setSaveDisabled:R,pagingControls:{curPage:E,setCurPage:F}}),"products"===I&&P&&e.jsx(u.CollectionIdContext.Provider,Object.assign({value:P},{children:e.jsx(a.ProductsScreen,{hideInCollectionSearch:j.hideInCollectionSearch,customCollectionRestriction:j.customCollectionRestriction,productFetcher:j.productFetcher,setScreen:q,storeId:C,data:m[P],collectionsDispatch:f,selectedCollectionsDispatch:H,selectedData:_,setSaveDisabled:R,searchInCollectionFetcher:j.searchInCollectionFetcher})})),"view"===I&&e.jsx(p.SelectedScreen,{selectedCollections:_||{},selectedCollectionsDispatch:H,setScreen:q,collections:m}),"searchProducts"===I&&e.jsx(h.SearchScreen,{customCollectionRestriction:j.customCollectionRestriction,selectedCollections:_||{},searchedCollections:$||{},selectedCollectionsDispatch:H,setScreen:q,collections:m,onBackPress:()=>{w(""),A({})}})]})]})}))};
|
|
@@ -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"),i=require("../../assets/icons/box.svg.js"),o=require("../../assets/icons/search.svg.js"),s=require("lodash"),l=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../assets/icons/arrow_left.svg.js"),i=require("../../assets/icons/box.svg.js"),o=require("../../assets/icons/search.svg.js"),s=require("lodash"),l=require("react"),c=require("../../constants/Theme.js"),d=require("../checkBox/CheckBox.js"),r=require("../icon-button/IconButton.js"),n=require("../input/Input.js"),a=require("../shimmer/ShimmerComponent/BikShimmer.js"),u=require("../shimmer-image/ShimmerImage.js"),h=require("../spinner/Spinner.js"),v=require("../TypographyStyle.js"),p=require("./collectionScreen.js"),j=require("./emptyState.js"),x=require("./reducers.js"),y=require("./style.js"),g=require("./utility.js");const m=t=>{const{collectionId:i,productId:o,data:s,selectedData:l,selectedCollectionsDispatch:c,viewOnly:d,upliftAdditions:r,isProductPartiallyChecked:n}=t,a=e=>{var t,s,c,d,r,n;if(!(null===(s=null===(t=null==l?void 0:l[i])||void 0===t?void 0:t.products)||void 0===s?void 0:s[o]))return!1;return!!(null===(n=null===(r=null===(d=null===(c=null==l?void 0:l[i])||void 0===c?void 0:c.products)||void 0===d?void 0:d[o])||void 0===r?void 0:r.variants)||void 0===n?void 0:n[e])};return e.jsxs("div",{children:[e.jsx(I,{isVariant:!1,data:s,productId:o,collectionId:i,isSelected:!!(null===(h=null===(u=null==l?void 0:l[i])||void 0===u?void 0:u.products)||void 0===h?void 0:h[o]),isPartiallyChecked:n,selectedCollectionsDispatch:c,upliftAdditions:r,viewOnly:d},o),Object.keys(s.variants||[]).map((t=>e.jsx(I,{isVariant:!0,data:s.variants[t],variantId:t,productId:o,viewOnly:d,upliftAdditions:r,collectionId:i,isSelected:a(t),selectedCollectionsDispatch:c},t)))]});var u,h},I=t=>{const{isVariant:i,data:o,productId:s,collectionId:l,variantId:c,isSelected:r,selectedCollectionsDispatch:n,viewOnly:a,upliftAdditions:h,isPartiallyChecked:j}=t;return e.jsxs(y.ProductCardStyle,Object.assign({isVariant:i},{children:[a?e.jsx(e.Fragment,{}):e.jsx(d.CheckBox,{isChecked:r,isPartiallyChecked:j||!1,onValueChange:function(e){i?e?h("variantSelected",{productId:s,variantId:c,collectionId:l,variant:o}):n({type:"variantUnselected",data:{productId:s,variantId:c,collectionId:l}}):e?h("productSelected",{productId:s,collectionId:l,product:o}):n({type:"productUnselected",data:{productId:s,collectionId:l}})}}),e.jsx("div",{children:e.jsx(u.ShimmerImage,{width:40,height:40,imageUrl:o.image,alt:"Item",borderRadius:4})}),e.jsx(v.TitleRegular,{children:p.truncate(o.name,40,!0)})]}))};exports.ProductCard=I,exports.ProductGroup=m,exports.ProductsScreen=u=>{const p=l.useContext(x.CollectionIdContext),{data:I,collectionsDispatch:C,selectedData:S,selectedCollectionsDispatch:f,productFetcher:O,storeId:b,setScreen:k,setSaveDisabled:q,hideInCollectionSearch:E,customCollectionRestriction:P}=u,[D,w]=l.useState(""),[B,T]=l.useState(!1),[R,A]=l.useState(I);l.useEffect((()=>{const e=setTimeout((()=>{D.length?(T(!0),u.searchInCollectionFetcher(b,p,D).then((e=>{var t;const i=s.cloneDeep(I);i.products={};for(const o of e)(null===(t=null==I?void 0:I.products)||void 0===t?void 0:t[o])&&(i.products[o]=I.products[o]);A(i),q(!1),T(!1)}))):A(I)}),800);return()=>clearTimeout(e)}),[D]);const V=!!P&&I.isSmartCollection,F=e=>{var t,i,o,s,l,c,d,r;let n=0,a=0;return!!((null===(i=null===(t=null==S?void 0:S[p])||void 0===t?void 0:t.products)||void 0===i?void 0:i[e])&&(null===(l=Object.keys((null===(s=null===(o=null==I?void 0:I.products)||void 0===o?void 0:o[e])||void 0===s?void 0:s.variants)||[]))||void 0===l||l.forEach((()=>a++)),Object.keys((null===(r=null===(d=null===(c=null==S?void 0:S[p])||void 0===c?void 0:c.products)||void 0===d?void 0:d[e])||void 0===r?void 0:r.variants)||[]).forEach((()=>n++)),n>0&&a!==n))};l.useEffect((()=>{(null==I?void 0:I.products)||U()}),[]);const U=()=>{q(!0),T(!0),O(p,b).then((e=>{Object.keys(e).length&&(C({type:"productsFetched",data:{collectionId:p,products:e}}),A(Object.assign(Object.assign({},R),{products:e}))),q(!1),T(!1)})).catch()},_=(e,t)=>{const i=g.liftTheStateUp(t,I);f({type:e,data:Object.assign(Object.assign({},i),{isRestricted:P})})};return e.jsxs("div",{children:[e.jsxs(y.ProductScreenHeader,{children:[e.jsx(r.IconButton,{Icon:t.default,height:16,onClick:()=>{k("collections")}}),e.jsx(v.BodyCaption,Object.assign({style:{color:c.COLORS.content.secondary}},{children:I.name}))]}),!E&&e.jsx("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(n.Input,{noErrorHint:!0,rightIcon:{icon:()=>B&&D.length?e.jsx(h.Spinner,{size:"small",color:c.COLORS.content.primary}):e.jsx(o.default,{})},id:"listInput",height:"24px",type:"text",value:D,onChangeText:e=>{e.length&&e.trim().length&&w(e)},placeholder:"Search products in this collection..."})})),e.jsxs("div",{children:[Object.keys((null==R?void 0:R.products)||[]).length>0&&!V&&!D.length&&e.jsxs(y.ProductScreenCollectionCardStyle,{children:[e.jsx(d.CheckBox,{isChecked:!!(null==S?void 0:S[p]),isPartiallyChecked:(e=>{var t;let i=0,o=0;if(S[e]){const s=null==I?void 0:I.products;s&&Object.keys(s).forEach((e=>{var t;const o=null===(t=s[e])||void 0===t?void 0:t.variants;o&&Object.keys(o).forEach((e=>i+=1))}));const l=null===(t=S[e])||void 0===t?void 0:t.products;return l&&Object.keys(l).forEach((e=>{var t;const i=null===(t=l[e])||void 0===t?void 0:t.variants;i&&Object.keys(i).forEach((e=>o+=1))})),o>0&&i!==o}return!1})(p),onValueChange:function(e){f(e?{type:"selected",data:{id:p,val:I}}:{type:"unselected",data:{id:p}})}}),e.jsx("div",Object.assign({style:{width:40,height:40}},{children:e.jsx(i.default,{})})),e.jsx(v.TitleRegular,{children:"All Products"})]}),Object.keys((null==R?void 0:R.products)||[]).length?Object.keys(R.products||[]).map((t=>e.jsx(m,{collectionId:p,isProductPartiallyChecked:F(t),productId:t,data:R.products[t],selectedData:S,selectedCollectionsDispatch:f,viewOnly:!!V,upliftAdditions:_},t))):B?[1,2,3,4,5,6,7,8,9,10].map(((t,i)=>e.jsx("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(a.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),i))):e.jsx(j.EmptyState,{title:"No products to show",subtitle:D.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})]})]})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("lodash");const e=require("react").createContext("");exports.CollectionIdContext=e,exports.collectionsReducer=function(t,e){let a={};switch(e.type){case"fetched":return a=Object.assign({},e.data),a;case"productsFetched":return a=Object.assign({},t),a[e.data.collectionId].products=e.data.products,a;case"paged":return a=Object.assign(Object.assign({},t),e.data),a;default:return{}}},exports.selectedColectionsReducer=function(e,a){var d,o,c,l,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("lodash");const e=require("react").createContext("");exports.CollectionIdContext=e,exports.collectionsReducer=function(t,e){let a={};switch(e.type){case"fetched":return a=Object.assign({},e.data),a;case"productsFetched":return a=Object.assign({},t),a[e.data.collectionId].products=e.data.products,a;case"paged":return a=Object.assign(Object.assign({},t),e.data),a;default:return{}}},exports.selectedColectionsReducer=function(e,a){var d,o,c,s,l,r;let n={},u="",i="",p="";switch(a.type){case"selected":return n=t.cloneDeep(e),a.data.val.isSmartCollection&&(a.data.isRestricted&&(n={}),n.isCustom=!0),n[a.data.id]=a.data.val,n;case"unselected":return n=t.cloneDeep(e),(null==n?void 0:n.isCustom)&&(n.isCustom=!1),delete n[a.data.id],n;case"productUnselected":return n=t.cloneDeep(e),u=a.data.productId,i=a.data.collectionId,delete n[i].products[u],Object.keys(n[i].products).length||((null==n?void 0:n.isCustom)&&(n.isCustom=!1),delete n[i]),n;case"productSelected":return n=t.cloneDeep(e),u=a.data.productId,i=a.data.collectionId,(null===(d=a.data.catalogOnlyData)||void 0===d?void 0:d.isSmartCollection)&&(a.data.isRestricted&&(n={}),n.isCustom=!0),(null==n?void 0:n[i])||(n[i]=a.data.catalogOnlyData,n[i].products={}),n[i].products[u]=a.data.product,n;case"variantSelected":return n=t.cloneDeep(e),u=a.data.productId,i=a.data.collectionId,p=a.data.variantId,(null===(o=a.data.catalogOnlyData)||void 0===o?void 0:o.isSmartCollection)&&(a.data.isRestricted&&(n={}),n.isCustom=!0),(null==n?void 0:n[i])||(n[i]=a.data.catalogOnlyData,n[i].products={},n[i].products[u]=a.data.productOnlyData,n[i].products[u].variants={}),(null===(s=null===(c=null==n?void 0:n[i])||void 0===c?void 0:c.products)||void 0===s?void 0:s[u])||((null===(l=null==n?void 0:n[i])||void 0===l?void 0:l.products)||(n[i].products={}),n[i].products[u]=a.data.productOnlyData,n[i].products[u].variants={}),n[i].products[u].variants[p]=a.data.variant,n;case"variantUnselected":return n=t.cloneDeep(e),u=a.data.productId,i=a.data.collectionId,p=a.data.variantId,delete n[i].products[u].variants[p],Object.keys(n[i].products[u].variants).length||(delete n[i].products[u],Object.keys(n[i].products).length||((null===(r=n[i])||void 0===r?void 0:r.isSmartCollection)&&(n.isCustom=!1),delete n[i])),n;case"reset":return{};default:return e}};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Collection, SelectedItems } from '.';
|
|
3
3
|
import { SelectedCollectionsActions } from './reducers';
|
|
4
4
|
interface SearchScreenInterface {
|
|
5
|
+
customCollectionRestriction?: boolean;
|
|
5
6
|
selectedCollections: SelectedItems;
|
|
6
7
|
searchedCollections: SelectedItems;
|
|
7
8
|
selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>;
|
|
@@ -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("../icon-button/IconButton.js"),
|
|
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("../icon-button/IconButton.js"),i=require("../TypographyStyle.js"),l=require("./emptyState.js"),s=require("./productScreen.js"),r=require("./style.js"),c=require("./utility.js");exports.SearchScreen=d=>{const{customCollectionRestriction:n,selectedCollections:u,searchedCollections:a,selectedCollectionsDispatch:v,setScreen:j,collections:p,onBackPress:h}=d,y=(e,t)=>{var o,i,l,s,r,c,d,n,a;let v=0,j=0;return!!((null===(i=null===(o=null==u?void 0:u[e])||void 0===o?void 0:o.products)||void 0===i?void 0:i[t])&&(null===(c=Object.keys((null===(r=null===(s=null===(l=null==p?void 0:p[e])||void 0===l?void 0:l.products)||void 0===s?void 0:s[t])||void 0===r?void 0:r.variants)||[]))||void 0===c||c.forEach((()=>j++)),Object.keys((null===(a=null===(n=null===(d=null==u?void 0:u[e])||void 0===d?void 0:d.products)||void 0===n?void 0:n[t])||void 0===a?void 0:a.variants)||[]).forEach((()=>v++)),v>0&&j!==v))};return e.jsxs("div",{children:[e.jsxs(r.SelectedScreenHeader,{children:[e.jsx(o.IconButton,{Icon:t.default,onClick:()=>{j("collections"),h()}}),e.jsx(i.BodyCaption,{children:"Searched Products"})]}),e.jsx("div",{children:Object.keys(a).length?e.jsx(e.Fragment,{children:Object.keys(a).map((t=>{var o;return Object.keys((null===(o=null==a?void 0:a[t])||void 0===o?void 0:o.products)||[]).map((o=>{let i=!1;return(null==a?void 0:a.isCustom)&&(i=!0),e.jsx(s.ProductGroup,{collectionId:t,upliftAdditions:(e,o)=>((e,t,o)=>{const i=c.liftTheStateUp(o,a[e]);v({type:t,data:Object.assign(Object.assign({},i),{isRestricted:n})})})(t,e,o),productId:o,data:a[t].products[o],isProductPartiallyChecked:y(t,o),selectedData:u,selectedCollectionsDispatch:v,viewOnly:i},o)}))}))}):e.jsx(l.EmptyState,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as o}from"react/jsx-runtime";import c from"../../assets/icons/search.svg.js";import{useReducer as s,useState as r,useEffect as l}from"react";import{COLORS as i}from"../../constants/Theme.js";import{Button as n}from"../button/Button.js";import{Input as d}from"../input/Input.js";import{StyledModal as a}from"../modals/styledModal.js";import{Spinner as h}from"../spinner/Spinner.js";import{Tag as p}from"../tag/Tag.js";import{CollectionsScreen as u}from"./collectionScreen.js";import{ProductsScreen as m}from"./productScreen.js";import{collectionsReducer as
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as o}from"react/jsx-runtime";import c from"../../assets/icons/search.svg.js";import{useReducer as s,useState as r,useEffect as l}from"react";import{COLORS as i}from"../../constants/Theme.js";import{Button as n}from"../button/Button.js";import{Input as d}from"../input/Input.js";import{StyledModal as a}from"../modals/styledModal.js";import{Spinner as h}from"../spinner/Spinner.js";import{Tag as p}from"../tag/Tag.js";import{CollectionsScreen as u}from"./collectionScreen.js";import{ProductsScreen as m}from"./productScreen.js";import{collectionsReducer as C,selectedColectionsReducer as v,CollectionIdContext as g}from"./reducers.js";import{SearchScreen as y}from"./searchScreen.js";import{SelectedScreen as f}from"./selectedScreen.js";import{ContainerStyle as j,ScrollContainerStyle as b}from"./style.js";const S=S=>{const{storeId:I,selectedItems:x,onClose:T,visible:P,zIndex:F,limit:D}=S,[k,E]=s(C,{}),[O,R]=r("collections"),[w,B]=r(""),[z,G]=r(0),[L,$]=r(!1),[A,H]=r(0),[M,Y]=r(""),[q,J]=r(!1),[K,N]=r(!1),[Q,U]=r(),[V,W]=s(v,Object.keys(x).length>0?x:{});l((()=>{$(!0),N(!0),S.collectionFetcher(z,I).then((e=>{E({type:"fetched",data:(null==e?void 0:e.collections)||{}}),$(!1),G((e=>e+1)),N(!1)})).catch()}),[]),l((()=>{let e=0;Object.keys(V||[]).forEach((t=>{var o;Object.keys((null===(o=V[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,s;Object.keys((null===(s=null===(c=V[t].products)||void 0===c?void 0:c[o])||void 0===s?void 0:s.variants)||[]).forEach((()=>{e+=1}))}))})),H(e)})),l((()=>{var e;w&&!(null===(e=null==k?void 0:k[w])||void 0===e?void 0:e.products)&&($(!0),S.productFetcher(w,I).then((e=>{Object.keys(e).length&&E({type:"productsFetched",data:{collectionId:w,products:e}}),$(!1)})).catch())}),[w]),l((()=>{const e=setTimeout((()=>{M.length&&(J(!0),S.searchFetcher(I,M).then((e=>{U(e),R("searchProducts"),$(!1),J(!1)})))}),800);return()=>clearTimeout(e)}),[M]);const X=()=>{W({type:"reset",data:{}})};return e(a,Object.assign({zIndex:F,open:P,onClose:()=>{T(),X()},headingTitle:"collections"===O||"products"===O?"Select Products":"view"===O?"Selected Products":"searchProducts"===O?"Searched Products":void 0,footerShadow:!0,centralContainerStyles:{width:"480px"},primaryButton:{buttonText:L?"Loading...":"Add",disabled:L||D&&A>D||!1,onClick:()=>{S.onAdd(V,A),X()}},footerLeftCustomElement:D&&A>D?e(p,{tagText:`You can only select ${D} products`,type:"negative"}):e(n,A>0?{onClick:()=>{R("view")},buttonText:`${A} products selected`,buttonType:"tertiaryGray"}:{disabled:!0,buttonText:`${A} products selected`,buttonType:"tertiaryGray"})},{children:t(j,{children:[!S.hideGlobalSearch&&e(o,{children:("collections"===O||"searchProducts"===O)&&e("div",Object.assign({style:{padding:16,paddingTop:0,height:"60px",borderBottom:"1px solid #E0E0E0"}},{children:e(d,{noErrorHint:!0,rightIcon:{icon:()=>q?e(h,{size:"small",color:i.content.primary}):e(c,{})},id:"listInput",height:"24px",type:"text",value:M,onChangeText:e=>{e.length&&e.trim().length&&Y(e)},placeholder:"Search products..."})}))}),t(b,{children:["collections"===O&&e(u,{customCollectionRestriction:S.customCollectionRestriction,dataLoading:K,collections:k,selectedCollectionsDispatch:W,setCollectionId:B,setScreen:R,selectedCollections:V,collectionFetcher:S.collectionFetcher,storeId:I,collectionsDispatch:E,setSaveDisabled:$,pagingControls:{curPage:z,setCurPage:G}}),"products"===O&&w&&e(g.Provider,Object.assign({value:w},{children:e(m,{hideInCollectionSearch:S.hideInCollectionSearch,customCollectionRestriction:S.customCollectionRestriction,productFetcher:S.productFetcher,setScreen:R,storeId:I,data:k[w],collectionsDispatch:E,selectedCollectionsDispatch:W,selectedData:V,setSaveDisabled:$,searchInCollectionFetcher:S.searchInCollectionFetcher})})),"view"===O&&e(f,{selectedCollections:V||{},selectedCollectionsDispatch:W,setScreen:R,collections:k}),"searchProducts"===O&&e(y,{customCollectionRestriction:S.customCollectionRestriction,selectedCollections:V||{},searchedCollections:Q||{},selectedCollectionsDispatch:W,setScreen:R,collections:k,onBackPress:()=>{Y(""),U({})}})]})]})}))};export{S as ProductPickerModal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as t,jsx as
|
|
1
|
+
import{jsxs as t,jsx as e,Fragment as o}from"react/jsx-runtime";import i from"../../assets/icons/arrow_left.svg.js";import l from"../../assets/icons/box.svg.js";import d from"../../assets/icons/search.svg.js";import{cloneDeep as c}from"lodash";import{useContext as n,useState as r,useEffect as s}from"react";import{COLORS as a}from"../../constants/Theme.js";import{CheckBox as u}from"../checkBox/CheckBox.js";import{IconButton as p}from"../icon-button/IconButton.js";import{Input as v}from"../input/Input.js";import{BikShimmer as h}from"../shimmer/ShimmerComponent/BikShimmer.js";import{ShimmerImage as m}from"../shimmer-image/ShimmerImage.js";import{Spinner as y}from"../spinner/Spinner.js";import{BodyCaption as f,TitleRegular as g}from"../TypographyStyle.js";import{truncate as j}from"./collectionScreen.js";import{EmptyState as I}from"./emptyState.js";import{CollectionIdContext as b}from"./reducers.js";import{ProductScreenHeader as O,ProductScreenCollectionCardStyle as k,ProductCardStyle as C}from"./style.js";import{liftTheStateUp as S}from"./utility.js";const x=o=>{const m=n(b),{data:j,collectionsDispatch:C,selectedData:x,selectedCollectionsDispatch:w,productFetcher:D,storeId:P,setScreen:A,setSaveDisabled:B,hideInCollectionSearch:T,customCollectionRestriction:V}=o,[F,R]=r(""),[U,W]=r(!1),[z,H]=r(j);s((()=>{const t=setTimeout((()=>{F.length?(W(!0),o.searchInCollectionFetcher(P,m,F).then((t=>{var e;const o=c(j);o.products={};for(const i of t)(null===(e=null==j?void 0:j.products)||void 0===e?void 0:e[i])&&(o.products[i]=j.products[i]);H(o),B(!1),W(!1)}))):H(j)}),800);return()=>clearTimeout(t)}),[F]);const N=!!V&&j.isSmartCollection,_=t=>{var e,o,i,l,d,c,n,r;let s=0,a=0;return!!((null===(o=null===(e=null==x?void 0:x[m])||void 0===e?void 0:e.products)||void 0===o?void 0:o[t])&&(null===(d=Object.keys((null===(l=null===(i=null==j?void 0:j.products)||void 0===i?void 0:i[t])||void 0===l?void 0:l.variants)||[]))||void 0===d||d.forEach((()=>a++)),Object.keys((null===(r=null===(n=null===(c=null==x?void 0:x[m])||void 0===c?void 0:c.products)||void 0===n?void 0:n[t])||void 0===r?void 0:r.variants)||[]).forEach((()=>s++)),s>0&&a!==s))};s((()=>{(null==j?void 0:j.products)||q()}),[]);const q=()=>{B(!0),W(!0),D(m,P).then((t=>{Object.keys(t).length&&(C({type:"productsFetched",data:{collectionId:m,products:t}}),H(Object.assign(Object.assign({},z),{products:t}))),B(!1),W(!1)})).catch()},G=(t,e)=>{const o=S(e,j);w({type:t,data:Object.assign(Object.assign({},o),{isRestricted:V})})};return t("div",{children:[t(O,{children:[e(p,{Icon:i,height:16,onClick:()=>{A("collections")}}),e(f,Object.assign({style:{color:a.content.secondary}},{children:j.name}))]}),!T&&e("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e(v,{noErrorHint:!0,rightIcon:{icon:()=>U&&F.length?e(y,{size:"small",color:a.content.primary}):e(d,{})},id:"listInput",height:"24px",type:"text",value:F,onChangeText:t=>{t.length&&t.trim().length&&R(t)},placeholder:"Search products in this collection..."})})),t("div",{children:[Object.keys((null==z?void 0:z.products)||[]).length>0&&!N&&!F.length&&t(k,{children:[e(u,{isChecked:!!(null==x?void 0:x[m]),isPartiallyChecked:(t=>{var e;let o=0,i=0;if(x[t]){const l=null==j?void 0:j.products;l&&Object.keys(l).forEach((t=>{var e;const i=null===(e=l[t])||void 0===e?void 0:e.variants;i&&Object.keys(i).forEach((t=>o+=1))}));const d=null===(e=x[t])||void 0===e?void 0:e.products;return d&&Object.keys(d).forEach((t=>{var e;const o=null===(e=d[t])||void 0===e?void 0:e.variants;o&&Object.keys(o).forEach((t=>i+=1))})),i>0&&o!==i}return!1})(m),onValueChange:function(t){w(t?{type:"selected",data:{id:m,val:j}}:{type:"unselected",data:{id:m}})}}),e("div",Object.assign({style:{width:40,height:40}},{children:e(l,{})})),e(g,{children:"All Products"})]}),Object.keys((null==z?void 0:z.products)||[]).length?Object.keys(z.products||[]).map((t=>e(E,{collectionId:m,isProductPartiallyChecked:_(t),productId:t,data:z.products[t],selectedData:x,selectedCollectionsDispatch:w,viewOnly:!!N,upliftAdditions:G},t))):U?[1,2,3,4,5,6,7,8,9,10].map(((t,o)=>e("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e(h,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),o))):e(I,{title:"No products to show",subtitle:F.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})]})]})},E=o=>{const{collectionId:i,productId:l,data:d,selectedData:c,selectedCollectionsDispatch:n,viewOnly:r,upliftAdditions:s,isProductPartiallyChecked:a}=o,u=t=>{var e,o,d,n,r,s;if(!(null===(o=null===(e=null==c?void 0:c[i])||void 0===e?void 0:e.products)||void 0===o?void 0:o[l]))return!1;return!!(null===(s=null===(r=null===(n=null===(d=null==c?void 0:c[i])||void 0===d?void 0:d.products)||void 0===n?void 0:n[l])||void 0===r?void 0:r.variants)||void 0===s?void 0:s[t])};return t("div",{children:[e(w,{isVariant:!1,data:d,productId:l,collectionId:i,isSelected:!!(null===(v=null===(p=null==c?void 0:c[i])||void 0===p?void 0:p.products)||void 0===v?void 0:v[l]),isPartiallyChecked:a,selectedCollectionsDispatch:n,upliftAdditions:s,viewOnly:r},l),Object.keys(d.variants||[]).map((t=>e(w,{isVariant:!0,data:d.variants[t],variantId:t,productId:l,viewOnly:r,upliftAdditions:s,collectionId:i,isSelected:u(t),selectedCollectionsDispatch:n},t)))]});var p,v},w=i=>{const{isVariant:l,data:d,productId:c,collectionId:n,variantId:r,isSelected:s,selectedCollectionsDispatch:a,viewOnly:p,upliftAdditions:v,isPartiallyChecked:h}=i;return t(C,Object.assign({isVariant:l},{children:[p?e(o,{}):e(u,{isChecked:s,isPartiallyChecked:h||!1,onValueChange:function(t){l?t?v("variantSelected",{productId:c,variantId:r,collectionId:n,variant:d}):a({type:"variantUnselected",data:{productId:c,variantId:r,collectionId:n}}):t?v("productSelected",{productId:c,collectionId:n,product:d}):a({type:"productUnselected",data:{productId:c,collectionId:n}})}}),e("div",{children:e(m,{width:40,height:40,imageUrl:d.image,alt:"Item",borderRadius:4})}),e(g,{children:j(d.name,40,!0)})]}))};export{w as ProductCard,E as ProductGroup,x as ProductsScreen};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cloneDeep as t}from"lodash";import{createContext as a}from"react";function d(a,d){var e,o,c,s,r,l;let
|
|
1
|
+
import{cloneDeep as t}from"lodash";import{createContext as a}from"react";function d(a,d){var e,o,c,s,r,l;let i={},u="",n="",p="";switch(d.type){case"selected":return i=t(a),d.data.val.isSmartCollection&&(d.data.isRestricted&&(i={}),i.isCustom=!0),i[d.data.id]=d.data.val,i;case"unselected":return i=t(a),(null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[d.data.id],i;case"productUnselected":return i=t(a),u=d.data.productId,n=d.data.collectionId,delete i[n].products[u],Object.keys(i[n].products).length||((null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[n]),i;case"productSelected":return i=t(a),u=d.data.productId,n=d.data.collectionId,(null===(e=d.data.catalogOnlyData)||void 0===e?void 0:e.isSmartCollection)&&(d.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[n])||(i[n]=d.data.catalogOnlyData,i[n].products={}),i[n].products[u]=d.data.product,i;case"variantSelected":return i=t(a),u=d.data.productId,n=d.data.collectionId,p=d.data.variantId,(null===(o=d.data.catalogOnlyData)||void 0===o?void 0:o.isSmartCollection)&&(d.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[n])||(i[n]=d.data.catalogOnlyData,i[n].products={},i[n].products[u]=d.data.productOnlyData,i[n].products[u].variants={}),(null===(s=null===(c=null==i?void 0:i[n])||void 0===c?void 0:c.products)||void 0===s?void 0:s[u])||((null===(r=null==i?void 0:i[n])||void 0===r?void 0:r.products)||(i[n].products={}),i[n].products[u]=d.data.productOnlyData,i[n].products[u].variants={}),i[n].products[u].variants[p]=d.data.variant,i;case"variantUnselected":return i=t(a),u=d.data.productId,n=d.data.collectionId,p=d.data.variantId,delete i[n].products[u].variants[p],Object.keys(i[n].products[u].variants).length||(delete i[n].products[u],Object.keys(i[n].products).length||((null===(l=i[n])||void 0===l?void 0:l.isSmartCollection)&&(i.isCustom=!1),delete i[n])),i;case"reset":return{};default:return a}}function e(t,a){let d={};switch(a.type){case"fetched":return d=Object.assign({},a.data),d;case"productsFetched":return d=Object.assign({},t),d[a.data.collectionId].products=a.data.products,d;case"paged":return d=Object.assign(Object.assign({},t),a.data),d;default:return{}}}const o=a("");export{o as CollectionIdContext,e as collectionsReducer,d as selectedColectionsReducer};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Collection, SelectedItems } from '.';
|
|
3
3
|
import { SelectedCollectionsActions } from './reducers';
|
|
4
4
|
interface SearchScreenInterface {
|
|
5
|
+
customCollectionRestriction?: boolean;
|
|
5
6
|
selectedCollections: SelectedItems;
|
|
6
7
|
searchedCollections: SelectedItems;
|
|
7
8
|
selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as o,jsx as t,Fragment as e}from"react/jsx-runtime";import
|
|
1
|
+
import{jsxs as o,jsx as t,Fragment as e}from"react/jsx-runtime";import i from"../../assets/icons/arrow_left.svg.js";import{IconButton as l}from"../icon-button/IconButton.js";import{BodyCaption as r}from"../TypographyStyle.js";import{EmptyState as s}from"./emptyState.js";import{ProductGroup as c}from"./productScreen.js";import{SelectedScreenHeader as d}from"./style.js";import{liftTheStateUp as n}from"./utility.js";const u=u=>{const{customCollectionRestriction:v,selectedCollections:a,searchedCollections:p,selectedCollectionsDispatch:m,setScreen:h,collections:f,onBackPress:j}=u,y=(o,t)=>{var e,i,l,r,s,c,d,n,u;let v=0,p=0;return!!((null===(i=null===(e=null==a?void 0:a[o])||void 0===e?void 0:e.products)||void 0===i?void 0:i[t])&&(null===(c=Object.keys((null===(s=null===(r=null===(l=null==f?void 0:f[o])||void 0===l?void 0:l.products)||void 0===r?void 0:r[t])||void 0===s?void 0:s.variants)||[]))||void 0===c||c.forEach((()=>p++)),Object.keys((null===(u=null===(n=null===(d=null==a?void 0:a[o])||void 0===d?void 0:d.products)||void 0===n?void 0:n[t])||void 0===u?void 0:u.variants)||[]).forEach((()=>v++)),v>0&&p!==v))};return o("div",{children:[o(d,{children:[t(l,{Icon:i,onClick:()=>{h("collections"),j()}}),t(r,{children:"Searched Products"})]}),t("div",{children:Object.keys(p).length?t(e,{children:Object.keys(p).map((o=>{var e;return Object.keys((null===(e=null==p?void 0:p[o])||void 0===e?void 0:e.products)||[]).map((e=>{let i=!1;return(null==p?void 0:p.isCustom)&&(i=!0),t(c,{collectionId:o,upliftAdditions:(t,e)=>((o,t,e)=>{const i=n(e,p[o]);m({type:t,data:Object.assign(Object.assign({},i),{isRestricted:v})})})(o,t,e),productId:e,data:p[o].products[e],isProductPartiallyChecked:y(o,e),selectedData:a,selectedCollectionsDispatch:m,viewOnly:i},e)}))}))}):t(s,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};export{u as SearchScreen};
|