@bikdotai/bik-component-library 0.0.656-3 → 0.0.656-5
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/utility.d.ts +2 -4
- package/dist/cjs/components/product-picker-v2/utility.js +1 -1
- package/dist/esm/components/product-picker-v2/modal.js +1 -1
- package/dist/esm/components/product-picker-v2/utility.d.ts +2 -4
- package/dist/esm/components/product-picker-v2/utility.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),o=require("../../assets/icons/search.svg.js"),c=require("react"),r=require("../../constants/Theme.js"),s=require("../../assets/icons/cross.svg.js"),n=require("../button/Button.js"),l=require("../input/Input.js"),i=require("../modals/styledModal.js"),a=require("../spinner/Spinner.js"),d=require("../tag/Tag.js"),u=require("./collectionScreen.js"),h=require("./productInfoOverlay.js"),p=require("./productScreen.js"),S=require("./rearrangeScreen.js"),C=require("./reducers.js"),g=require("./searchScreen.js"),x=require("./selectedScreen.js"),j=require("./style.js"),y=require("./type.js"),m=require("./utility.js");exports.ScreenName=void 0,(e=exports.ScreenName||(exports.ScreenName={})).Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products";exports.ProductPickerModal=e=>{const{storeId:b,selectedItems:f,onClose:v,visible:k,zIndex:I,exactLimit:P,limit:O,hideCollectionCheckbox:F,hideProductCheckbox:R,outOfStockAction:T=y.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:D,selectProductsFromCustomCollection:q,hideSelectionCount:N,title:E,width:A,left:w,renderWithoutModal:B,onClickSave:L,pickerType:M,hideProductVariants:V=!1,startupScreen:z=exports.ScreenName.Collections,rearrangeEnabled:$,selectSingleItem:_=!1,showProductDetails:H,containerStyle:W,crossButtonInsideHeader:G=!1,footerForNonModal:K={},primaryButton:U,secondaryButton:Y,subtitle:J}=e,[Q,X]=c.useReducer(C.collectionsReducer,{}),[Z,ee]=c.useState([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(z)?z:exports.ScreenName.Collections),[te,oe]=c.useState("grid"),[ce,re]=c.useState(""),[se,ne]=c.useState(""),[le,ie]=c.useState(0),[ae,de]=c.useState(!1),[ue,he]=c.useState(0),[pe,Se]=c.useState(""),[Ce,ge]=c.useState(!1),[xe,je]=c.useState(!1),[ye,me]=c.useReducer(C.searchReducer,{collections:{},products:{}}),[be,fe]=c.useReducer(C.selectedColectionsReducer,Object.keys(f).length>0?f:{}),ve=c.useRef(null),[ke,Ie]=c.useState(!1),[Pe,Oe]=c.useState();c.useEffect((()=>{de(!0),je(!0),e.collectionFetcher(le,b).then((e=>{X({type:"fetched",data:(null==e?void 0:e.collections)||{}}),de(!1),ie((e=>e+1)),je(!1)})).catch()}),[]),c.useEffect((()=>{let e=0;V?Object.keys(be||[]).forEach((t=>{var o;Object.keys((null===(o=be[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c;"-1"!==t&&be[-1]&&(null===(c=be[-1].products)||void 0===c?void 0:c[o])||(e+=1)}))})):Object.keys(be||[]).forEach((t=>{var o;Object.keys((null===(o=be[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=be[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),he(e)}),[Q,be,V]),c.useEffect((()=>{se&&(de(!0),e.productFetcher(se,b).then((e=>{Object.keys(e).length&&X({type:"productsFetched",data:{collectionId:se,products:e}}),de(!1)})).catch())}),[se]),c.useEffect((()=>{const t=setTimeout((()=>{"rearrange"!==Z&&(pe.length||"collections"!==Z)&&(pe.length?(ge(!0),e.searchFetcher(b,pe).then((e=>{"collections"in e&&"products"in e?(me({type:"set",data:e}),X({type:"searched",data:e.collections})):(me({type:"set",data:{collections:{},products:e}}),X({type:"searched",data:e})),ee("searchProducts"),de(!1),ge(!1)}))):ee("collections"))}),800);return()=>clearTimeout(t)}),[pe]),c.useEffect((()=>{L&&(e.onAdd(be,ue),Fe())}),[L]),c.useEffect((()=>{_&&Object.keys(be||{}).length&&ue&&(e.onAdd(be,ue),Fe())}),[_,be,ue]);const Fe=()=>{fe({type:"reset",data:{}})},Re=()=>P&&ue>P?t.jsx(d.Tag,{tagText:`You can only select ${P} products`,type:"negative"}):O&&ue>O?t.jsx(d.Tag,{tagText:`You can only select ${O} products`,type:"negative"}):ue>0?t.jsx(n.Button,{onClick:()=>{ee($?exports.ScreenName.RearrangeProducts:exports.ScreenName.SelectedProducts)},buttonText:P?`${ue}/${P} products selected`:`${ue} products selected`,buttonType:["rearrange","view"].includes(Z)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(Z)}):t.jsx(n.Button,{disabled:!0,buttonText:P?`${ue}/${P} products selected`:`${ue} products selected`,buttonType:"tertiaryGray"}),Te=e=>ae?"Loading...":Z===exports.ScreenName.RearrangeProducts?null!=e?e:"Done":null!=e?e:"Add",De=t.jsxs(j.ContainerStyle,Object.assign({style:null!=W?W:{}},{children:[e.postHeader&&t.jsx("div",Object.assign({style:{padding:"0 24px"}},{children:e.postHeader})),!e.hideGlobalSearch&&t.jsx(t.Fragment,{children:("collections"===Z||"searchProducts"===Z)&&t.jsx("div",Object.assign({style:{padding:B?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t.jsx(l.Input,{placeholder:"Search for collections and products, or type a product ID",noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>Ce?t.jsx(a.Spinner,{size:"small",color:r.COLORS.content.primary}):t.jsx(o.default,{})},id:"listInput",height:"24px",type:"text",value:pe,onChangeText:e=>{e.length&&e.trim().length?Se(e):Se("")}})}))}),t.jsxs(j.ScrollContainerStyle,Object.assign({ref:ve,screenName:Z},{children:["collections"===Z&&t.jsx(u.CollectionsScreen,{customCollectionRestriction:e.customCollectionRestriction,dataLoading:xe,collections:Q,selectedCollectionsDispatch:fe,setCollectionId:re,setSelectedCollectionId:ne,setScreen:ee,selectedCollections:be,collectionFetcher:e.collectionFetcher,storeId:b,collectionsDispatch:X,setSaveDisabled:de,pagingControls:{curPage:le,setCurPage:ie},hideCollectionCheckbox:F,renderWithoutModal:B,pickerType:M,scrollContainerRef:ve}),"products"===Z&&ce&&t.jsx(C.CollectionIdContext.Provider,Object.assign({value:ce},{children:t.jsx(p.ProductsScreen,{hideInCollectionSearch:e.hideInCollectionSearch,customCollectionRestriction:e.customCollectionRestriction,productFetcher:e.productFetcher,setScreen:ee,storeId:b,data:Q[ce],collectionsDispatch:X,selectedCollectionsDispatch:fe,selectedData:be,setSaveDisabled:de,searchInCollectionFetcher:e.searchInCollectionFetcher,hideProductCheckbox:R,outOfStockAction:T,hideVariantCheckbox:D,selectProductsFromCustomCollection:q,renderWithoutModal:B,pickerType:M,hideProductVariants:V,fbStatusFetcher:e.fbStatusFetcher,onProductDetailClick:e=>{Ie(!0),Oe(e)},showProductDetailInfoIcon:H,scrollContainerRef:ve})})),"view"===Z&&t.jsx(x.SelectedScreen,{selectedCollections:be||{},selectedCollectionsDispatch:fe,setScreen:ee,collections:Q,hideProductVariants:V,outOfStockAction:T,storeId:b,fbStatusFetcher:e.fbStatusFetcher}),"rearrange"===Z&&t.jsx(S.RearrangeScreen,{selectedCollections:be||{},selectedCollectionsDispatch:fe,setScreen:ee,outOfStockAction:T,rearrangeViewType:"grid"===te?"list":"grid",scrollContainerRef:ve,storeId:b,fbStatusFetcher:e.fbStatusFetcher}),"searchProducts"===Z&&t.jsx(g.SearchScreen,{customCollectionRestriction:e.customCollectionRestriction,selectedCollections:be||{},searchedCollections:ye||{},searchedCollectionsDispatch:me,selectedCollectionsDispatch:fe,setScreen:ee,collections:Q,onBackPress:()=>{Se(""),me({type:"set",data:{collections:{},products:{}}})},pickerType:M,hideProductCheckbox:R,hideProductVariants:V,hideVariantCheckbox:D,storeId:b,fbStatusFetcher:e.fbStatusFetcher,setCollectionId:re,setSelectedCollectionId:ne,renderWithoutModal:B,hideCollectionCheckbox:F,outOfStockAction:T})]}))]}));return t.jsx(t.Fragment,{children:B?t.jsxs(t.Fragment,{children:[De,K.renderFooter?t.jsxs(j.StyledFooterForNonModal,{children:[Re(),t.jsx(n.Button,{buttonText:Te(K.primaryButtonText),disabled:!K.isLoading&&(ae||ue<1||P&&ue<P||!P&&O&&ue>O)||K.primaryButtonDisabled,isLoading:K.isLoading,onClick:()=>{e.onAdd(be,ue),Fe(),ee([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(z)?z:exports.ScreenName.Collections)}})]}):t.jsx(t.Fragment,{}),ke&&Pe?t.jsx(h.ProductInfoOverlay,{productData:Pe,outOfStockAction:T,useDynamicInfoImageSize:e.useDynamicInfoImageSize,onClose:()=>{Ie(!1)}}):t.jsx(t.Fragment,{})]}):t.jsxs(i.StyledModal,Object.assign({zIndex:I,open:k,onClose:()=>{null==v||v(),Fe()},headingTitle:E||("collections"===Z||"products"===Z?"Select Products":"view"===Z?"Selected Products":"searchProducts"===Z?"Searched Results":"rearrange"===Z?"Rearrange Products":void 0),headingSubtitle:J,footerShadow:!0,centralContainerStyles:{width:A||"600px",left:w||"auto"},headerRightCustomElement:G?t.jsx("div",Object.assign({style:{cursor:"pointer",display:"flex"},onClick:v},{children:t.jsx(s.default,{width:20,height:20,color:r.COLORS.content.secondary})})):t.jsx(t.Fragment,{}),footerContainerStyle:e.stickyFooter?{position:"absolute",bottom:0,left:0,width:"100%",zIndex:9,background:r.COLORS.surface.standard}:void 0,primaryButton:U?(t=>Object.assign(Object.assign({},t),{disabled:!t.isLoading&&(ae||ue<1||P&&ue<P||!P&&O&&ue>O)||t.disabled,onClick:()=>{e.onAdd(be,ue),Fe(),ee([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(z)?z:exports.ScreenName.Collections)}}))(U):{buttonText:Te(),disabled:ae||ue<1||P&&ue<P||!P&&O&&ue>O||!1,onClick:()=>{e.onAdd(be,ue),Fe()}},secondaryButton:Y?(t=>Object.assign(Object.assign({},t),{disabled:ae||ue<1||P&&ue<P||!P&&O&&ue>O||!1,onClick:()=>{console.log({selectedCollections:be,collections:Q,searchedCollections:ye});const t=m.updateAllVariantsForSelectedProducts(be,Q);console.log({filteredCollections:t}),e.onAdd(t,ue,!0)}}))(Y):void 0,wrapperStyle:e.stickyFooter?{height:"calc(100vh - 168px)"}:void 0,footerLeftCustomElement:N?t.jsx(t.Fragment,{}):Re(),hideCrossButton:ke||G},{children:[De,ke&&Pe?t.jsx(h.ProductInfoOverlay,{productData:Pe,useDynamicInfoImageSize:e.useDynamicInfoImageSize,outOfStockAction:T,onClose:()=>{Ie(!1)}}):t.jsx(t.Fragment,{})]}))})};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),o=require("../../assets/icons/search.svg.js"),c=require("react"),r=require("../../constants/Theme.js"),s=require("../../assets/icons/cross.svg.js"),n=require("../button/Button.js"),l=require("../input/Input.js"),i=require("../modals/styledModal.js"),a=require("../spinner/Spinner.js"),d=require("../tag/Tag.js"),u=require("./collectionScreen.js"),h=require("./productInfoOverlay.js"),p=require("./productScreen.js"),S=require("./rearrangeScreen.js"),C=require("./reducers.js"),g=require("./searchScreen.js"),x=require("./selectedScreen.js"),j=require("./style.js"),y=require("./type.js"),m=require("./utility.js");exports.ScreenName=void 0,(e=exports.ScreenName||(exports.ScreenName={})).Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products";exports.ProductPickerModal=e=>{const{storeId:b,selectedItems:f,onClose:v,visible:k,zIndex:I,exactLimit:P,limit:O,hideCollectionCheckbox:F,hideProductCheckbox:R,outOfStockAction:T=y.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:D,selectProductsFromCustomCollection:q,hideSelectionCount:N,title:E,width:A,left:w,renderWithoutModal:B,onClickSave:L,pickerType:M,hideProductVariants:V=!1,startupScreen:z=exports.ScreenName.Collections,rearrangeEnabled:$,selectSingleItem:_=!1,showProductDetails:H,containerStyle:W,crossButtonInsideHeader:G=!1,footerForNonModal:K={},primaryButton:U,secondaryButton:Y,subtitle:J}=e,[Q,X]=c.useReducer(C.collectionsReducer,{}),[Z,ee]=c.useState([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(z)?z:exports.ScreenName.Collections),[te,oe]=c.useState("grid"),[ce,re]=c.useState(""),[se,ne]=c.useState(""),[le,ie]=c.useState(0),[ae,de]=c.useState(!1),[ue,he]=c.useState(0),[pe,Se]=c.useState(""),[Ce,ge]=c.useState(!1),[xe,je]=c.useState(!1),[ye,me]=c.useReducer(C.searchReducer,{collections:{},products:{}}),[be,fe]=c.useReducer(C.selectedColectionsReducer,Object.keys(f).length>0?f:{}),ve=c.useRef(null),[ke,Ie]=c.useState(!1),[Pe,Oe]=c.useState();c.useEffect((()=>{de(!0),je(!0),e.collectionFetcher(le,b).then((e=>{X({type:"fetched",data:(null==e?void 0:e.collections)||{}}),de(!1),ie((e=>e+1)),je(!1)})).catch()}),[]),c.useEffect((()=>{let e=0;V?Object.keys(be||[]).forEach((t=>{var o;Object.keys((null===(o=be[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c;"-1"!==t&&be[-1]&&(null===(c=be[-1].products)||void 0===c?void 0:c[o])||(e+=1)}))})):Object.keys(be||[]).forEach((t=>{var o;Object.keys((null===(o=be[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=be[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),he(e)}),[Q,be,V]),c.useEffect((()=>{se&&(de(!0),e.productFetcher(se,b).then((e=>{Object.keys(e).length&&X({type:"productsFetched",data:{collectionId:se,products:e}}),de(!1)})).catch())}),[se]),c.useEffect((()=>{const t=setTimeout((()=>{"rearrange"!==Z&&(pe.length||"collections"!==Z)&&(pe.length?(ge(!0),e.searchFetcher(b,pe).then((e=>{"collections"in e&&"products"in e?(me({type:"set",data:e}),X({type:"searched",data:e.collections})):(me({type:"set",data:{collections:{},products:e}}),X({type:"searched",data:e})),ee("searchProducts"),de(!1),ge(!1)}))):ee("collections"))}),800);return()=>clearTimeout(t)}),[pe]),c.useEffect((()=>{L&&(e.onAdd(be,ue),Fe())}),[L]),c.useEffect((()=>{_&&Object.keys(be||{}).length&&ue&&(e.onAdd(be,ue),Fe())}),[_,be,ue]);const Fe=()=>{fe({type:"reset",data:{}})},Re=()=>P&&ue>P?t.jsx(d.Tag,{tagText:`You can only select ${P} products`,type:"negative"}):O&&ue>O?t.jsx(d.Tag,{tagText:`You can only select ${O} products`,type:"negative"}):ue>0?t.jsx(n.Button,{onClick:()=>{ee($?exports.ScreenName.RearrangeProducts:exports.ScreenName.SelectedProducts)},buttonText:P?`${ue}/${P} products selected`:`${ue} products selected`,buttonType:["rearrange","view"].includes(Z)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(Z)}):t.jsx(n.Button,{disabled:!0,buttonText:P?`${ue}/${P} products selected`:`${ue} products selected`,buttonType:"tertiaryGray"}),Te=e=>ae?"Loading...":Z===exports.ScreenName.RearrangeProducts?null!=e?e:"Done":null!=e?e:"Add",De=t.jsxs(j.ContainerStyle,Object.assign({style:null!=W?W:{}},{children:[e.postHeader&&t.jsx("div",Object.assign({style:{padding:"0 24px"}},{children:e.postHeader})),!e.hideGlobalSearch&&t.jsx(t.Fragment,{children:("collections"===Z||"searchProducts"===Z)&&t.jsx("div",Object.assign({style:{padding:B?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t.jsx(l.Input,{placeholder:"Search for collections and products, or type a product ID",noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>Ce?t.jsx(a.Spinner,{size:"small",color:r.COLORS.content.primary}):t.jsx(o.default,{})},id:"listInput",height:"24px",type:"text",value:pe,onChangeText:e=>{e.length&&e.trim().length?Se(e):Se("")}})}))}),t.jsxs(j.ScrollContainerStyle,Object.assign({ref:ve,screenName:Z},{children:["collections"===Z&&t.jsx(u.CollectionsScreen,{customCollectionRestriction:e.customCollectionRestriction,dataLoading:xe,collections:Q,selectedCollectionsDispatch:fe,setCollectionId:re,setSelectedCollectionId:ne,setScreen:ee,selectedCollections:be,collectionFetcher:e.collectionFetcher,storeId:b,collectionsDispatch:X,setSaveDisabled:de,pagingControls:{curPage:le,setCurPage:ie},hideCollectionCheckbox:F,renderWithoutModal:B,pickerType:M,scrollContainerRef:ve}),"products"===Z&&ce&&t.jsx(C.CollectionIdContext.Provider,Object.assign({value:ce},{children:t.jsx(p.ProductsScreen,{hideInCollectionSearch:e.hideInCollectionSearch,customCollectionRestriction:e.customCollectionRestriction,productFetcher:e.productFetcher,setScreen:ee,storeId:b,data:Q[ce],collectionsDispatch:X,selectedCollectionsDispatch:fe,selectedData:be,setSaveDisabled:de,searchInCollectionFetcher:e.searchInCollectionFetcher,hideProductCheckbox:R,outOfStockAction:T,hideVariantCheckbox:D,selectProductsFromCustomCollection:q,renderWithoutModal:B,pickerType:M,hideProductVariants:V,fbStatusFetcher:e.fbStatusFetcher,onProductDetailClick:e=>{Ie(!0),Oe(e)},showProductDetailInfoIcon:H,scrollContainerRef:ve})})),"view"===Z&&t.jsx(x.SelectedScreen,{selectedCollections:be||{},selectedCollectionsDispatch:fe,setScreen:ee,collections:Q,hideProductVariants:V,outOfStockAction:T,storeId:b,fbStatusFetcher:e.fbStatusFetcher}),"rearrange"===Z&&t.jsx(S.RearrangeScreen,{selectedCollections:be||{},selectedCollectionsDispatch:fe,setScreen:ee,outOfStockAction:T,rearrangeViewType:"grid"===te?"list":"grid",scrollContainerRef:ve,storeId:b,fbStatusFetcher:e.fbStatusFetcher}),"searchProducts"===Z&&t.jsx(g.SearchScreen,{customCollectionRestriction:e.customCollectionRestriction,selectedCollections:be||{},searchedCollections:ye||{},searchedCollectionsDispatch:me,selectedCollectionsDispatch:fe,setScreen:ee,collections:Q,onBackPress:()=>{Se(""),me({type:"set",data:{collections:{},products:{}}})},pickerType:M,hideProductCheckbox:R,hideProductVariants:V,hideVariantCheckbox:D,storeId:b,fbStatusFetcher:e.fbStatusFetcher,setCollectionId:re,setSelectedCollectionId:ne,renderWithoutModal:B,hideCollectionCheckbox:F,outOfStockAction:T})]}))]}));return t.jsx(t.Fragment,{children:B?t.jsxs(t.Fragment,{children:[De,K.renderFooter?t.jsxs(j.StyledFooterForNonModal,{children:[Re(),t.jsx(n.Button,{buttonText:Te(K.primaryButtonText),disabled:!K.isLoading&&(ae||ue<1||P&&ue<P||!P&&O&&ue>O)||K.primaryButtonDisabled,isLoading:K.isLoading,onClick:()=>{e.onAdd(be,ue),Fe(),ee([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(z)?z:exports.ScreenName.Collections)}})]}):t.jsx(t.Fragment,{}),ke&&Pe?t.jsx(h.ProductInfoOverlay,{productData:Pe,outOfStockAction:T,useDynamicInfoImageSize:e.useDynamicInfoImageSize,onClose:()=>{Ie(!1)}}):t.jsx(t.Fragment,{})]}):t.jsxs(i.StyledModal,Object.assign({zIndex:I,open:k,onClose:()=>{null==v||v(),Fe()},headingTitle:E||("collections"===Z||"products"===Z?"Select Products":"view"===Z?"Selected Products":"searchProducts"===Z?"Searched Results":"rearrange"===Z?"Rearrange Products":void 0),headingSubtitle:J,footerShadow:!0,centralContainerStyles:{width:A||"600px",left:w||"auto"},headerRightCustomElement:G?t.jsx("div",Object.assign({style:{cursor:"pointer",display:"flex"},onClick:v},{children:t.jsx(s.default,{width:20,height:20,color:r.COLORS.content.secondary})})):t.jsx(t.Fragment,{}),footerContainerStyle:e.stickyFooter?{position:"absolute",bottom:0,left:0,width:"100%",zIndex:9,background:r.COLORS.surface.standard}:void 0,primaryButton:U?(t=>Object.assign(Object.assign({},t),{disabled:!t.isLoading&&(ae||ue<1||P&&ue<P||!P&&O&&ue>O)||t.disabled,onClick:()=>{e.onAdd(be,ue),Fe(),ee([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(z)?z:exports.ScreenName.Collections)}}))(U):{buttonText:Te(),disabled:ae||ue<1||P&&ue<P||!P&&O&&ue>O||!1,onClick:()=>{e.onAdd(be,ue),Fe()}},secondaryButton:Y?(t=>Object.assign(Object.assign({},t),{disabled:ae||ue<1||P&&ue<P||!P&&O&&ue>O||!1,onClick:()=>{console.log({selectedCollections:be,collections:Q,searchedCollections:ye});const t=m.updateAllVariantsForSelectedProducts(be,Q,ye);console.log({filteredCollections:t}),e.onAdd(t,ue,!0)}}))(Y):void 0,wrapperStyle:e.stickyFooter?{height:"calc(100vh - 168px)"}:void 0,footerLeftCustomElement:N?t.jsx(t.Fragment,{}):Re(),hideCrossButton:ke||G},{children:[De,ke&&Pe?t.jsx(h.ProductInfoOverlay,{productData:Pe,useDynamicInfoImageSize:e.useDynamicInfoImageSize,outOfStockAction:T,onClose:()=>{Ie(!1)}}):t.jsx(t.Fragment,{})]}))})};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Collection, FbStatusFetcherReturn, Product, ProductVariant, SelectedItems } from './modal';
|
|
1
|
+
import { Collection, FbStatusFetcherReturn, Product, ProductVariant, SearchedItems, SelectedItems } from './modal';
|
|
2
2
|
import { CollectionsActions } from './reducers';
|
|
3
3
|
export declare const liftTheStateUp: (payload: any, data: any) => any;
|
|
4
4
|
export declare function paginateSelectedItems(selectedItems: SelectedItems, limit: number, offset: number): {
|
|
@@ -47,6 +47,4 @@ export declare const updateAllVariantsForSelectedProducts: (selectedItems: {
|
|
|
47
47
|
};
|
|
48
48
|
} | undefined;
|
|
49
49
|
};
|
|
50
|
-
}, collections: Collection, searchedProducts:
|
|
51
|
-
products?: Collection;
|
|
52
|
-
}) => Record<string, any>;
|
|
50
|
+
}, collections: Collection, searchedProducts: SearchedItems) => Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("lodash");function l(o,l,t){if(!o)return{};const d=Object.keys(o).slice(t,t+l),i={};return d.forEach((l=>{i[l]=o[l]})),i}const t=(o,l,t)=>{Object.keys(o).forEach((l=>{var t,d;const i=null!==(d=null===(t=o[l])||void 0===t?void 0:t.products)&&void 0!==d?d:{};Object.keys(i).forEach((t=>{var d,i,n,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("lodash");function l(o,l,t){if(!o)return{};const d=Object.keys(o).slice(t,t+l),i={};return d.forEach((l=>{i[l]=o[l]})),i}const t=(o,l,t)=>{Object.keys(o).forEach((l=>{var t,d;const i=null!==(d=null===(t=o[l])||void 0===t?void 0:t.products)&&void 0!==d?d:{};Object.keys(i).forEach((t=>{var d,i,n,v;const s=null!==(v=null===(n=null===(i=null===(d=o[l])||void 0===d?void 0:d.products)||void 0===i?void 0:i[t])||void 0===n?void 0:n.variants)&&void 0!==v?v:{};Object.keys(s).forEach((d=>{var i,n,v,s;const e=null===(s=null===(v=null===(n=null===(i=o[l])||void 0===i?void 0:i.products)||void 0===n?void 0:n[t])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[d];e&&!e.fbStatus&&(e.fbStatus="APPROVED")}))}))})),l({type:t,data:o})};exports.fetchFbStatusCollection=function(o,l,d,i){let n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";i||t(o,d,n);const v=(o=>{const l=[];return Object.keys(o).forEach((t=>{var d,i;const n=null!==(i=null===(d=o[t])||void 0===d?void 0:d.products)&&void 0!==i?i:{};Object.keys(n).forEach((d=>{var i,n,v,s;const e=null!==(s=null===(v=null===(n=null===(i=o[t])||void 0===i?void 0:i.products)||void 0===n?void 0:n[d])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(e).forEach((i=>{var n,v,s,e;const c=null===(e=null===(s=null===(v=null===(n=o[t])||void 0===n?void 0:n.products)||void 0===v?void 0:v[d])||void 0===s?void 0:s.variants)||void 0===e?void 0:e[i];(null==c?void 0:c.fbStatus)||l.push(i)}))}))})),l})(o);v.length>0&&i&&i(l,v).then((l=>{const t=Object.assign({},o);Object.keys(t).forEach((o=>{var d,i;const n=null!==(i=null===(d=t[o])||void 0===d?void 0:d.products)&&void 0!==i?i:{};Object.keys(n).forEach((d=>{var i,n,v,s;const e=null!==(s=null===(v=null===(n=null===(i=t[o])||void 0===i?void 0:i.products)||void 0===n?void 0:n[d])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(e).forEach((i=>{var n,v,s,e;const c=null===(e=null===(s=null===(v=null===(n=t[o])||void 0===n?void 0:n.products)||void 0===v?void 0:v[d])||void 0===s?void 0:s.variants)||void 0===e?void 0:e[i];c&&"REJECTED"===l[i]?c.fbStatus="REJECTED":c&&"APPROVED"===l[i]&&(c.fbStatus="APPROVED")}))}))})),d({type:n,data:t})})).catch((l=>{console.error("Error in fbStatusFetcher",l),t(o,d,n)}))},exports.getVariantIdsToFetchAtProductLevel=(o,l)=>{const t=[];return Object.keys(null!=o?o:{}).forEach((d=>{var i,n;const v=null!==(n=null===(i=null==o?void 0:o[d])||void 0===i?void 0:i.variants)&&void 0!==n?n:{};Object.keys(v).forEach((i=>{var n,v,s,e,c;let u;u=l?null===(s=null===(v=null===(n=null==l?void 0:l.products)||void 0===n?void 0:n[d])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[i]:null===(c=null===(e=null==o?void 0:o[d])||void 0===e?void 0:e.variants)||void 0===c?void 0:c[i],(null==u?void 0:u.fbStatus)||t.push(i)}))})),t},exports.isCollectionPartiallyChecked=function(o,l,t){var d,i,n,v;let s=0,e=0;if(arguments.length>3&&void 0!==arguments[3]&&arguments[3]){const v=null!==(d=null==l?void 0:l.products)&&void 0!==d?d:{};s=Object.keys(v).length;const c=null!==(n=null===(i=t[o])||void 0===i?void 0:i.products)&&void 0!==n?n:{};e=Object.keys(c).length}else if(t[o]){const d=null==l?void 0:l.products;d&&Object.keys(d).forEach((o=>{var l;const t=null===(l=d[o])||void 0===l?void 0:l.variants;t&&Object.keys(t).forEach((o=>s+=1))}));const i=null===(v=t[o])||void 0===v?void 0:v.products;if(i&&Object.keys(i).forEach((o=>{var l;const t=null===(l=i[o])||void 0===l?void 0:l.variants;t&&Object.keys(t).forEach((o=>e+=1))})),s<=0&&e>0)return!1}return e>0&&s!==e},exports.isProductPartiallyChecked=(o,l,t,d,i)=>{var n,v,s,e,c,u,r,a,p,b,O,f,j,h,y,g,E,k,P;let D=0,S=0;if(null===(v=null===(n=null==t?void 0:t[o])||void 0===n?void 0:n.products)||void 0===v?void 0:v[l]){if(i)return!1;const n=(null===(c=null===(e=null===(s=null==t?void 0:t[o])||void 0===s?void 0:s.products)||void 0===e?void 0:e[l])||void 0===c?void 0:c.variants)||[];if(1===Object.keys(n).length)for(const d in n){const i=null===(r=null===(u=null==t?void 0:t[o])||void 0===u?void 0:u.products)||void 0===r?void 0:r[l],n=null===(O=null===(b=null===(p=null===(a=null==t?void 0:t[o])||void 0===a?void 0:a.products)||void 0===p?void 0:p[l])||void 0===b?void 0:b.variants)||void 0===O?void 0:O[d];if(null===(f=null==n?void 0:n.name)||void 0===f?void 0:f.includes(null!==(j=null==i?void 0:i.name)&&void 0!==j?j:""))return!1}if(null===(g=Object.keys((null===(y=null===(h=null==d?void 0:d.products)||void 0===h?void 0:h[l])||void 0===y?void 0:y.variants)||[]))||void 0===g||g.forEach((()=>S++)),Object.keys((null===(P=null===(k=null===(E=null==t?void 0:t[o])||void 0===E?void 0:E.products)||void 0===k?void 0:k[l])||void 0===P?void 0:P.variants)||[]).forEach((()=>D++)),D>0&&S!==D)return!0}return!1},exports.liftTheStateUp=(l,t)=>{const d=o.cloneDeep(t);if(delete d.products,(l=Object.assign(Object.assign({},l),{catalogOnlyData:d})).productId&&t.products){const i=o.cloneDeep(t.products[l.productId]);(null==i?void 0:i.variants)&&delete i.variants,l=Object.assign(Object.assign({},l),{catalogOnlyData:d,productOnlyData:i})}return l},exports.markVariantsAsApprovedProductsLevel=(o,l,t,d,i)=>{const n=Object.assign({},o);if(Object.keys(o).forEach((l=>{var t,d;Object.keys(null!==(d=null===(t=null==o?void 0:o[l])||void 0===t?void 0:t.variants)&&void 0!==d?d:{}).forEach((t=>{var d,i;const v=null===(d=null==o?void 0:o[l].variants)||void 0===d?void 0:d[t];v&&(v.fbStatus="APPROVED");const s=null===(i=null==n?void 0:n[l])||void 0===i?void 0:i.variants;s&&s[t]&&(s[t]=v)}))})),d&&i){const o=Object.assign({},d);o.products=n,i(o),l({type:"productsPaged",data:{collectionId:t,products:n}})}else l({type:"productsPaged",data:{collectionId:t,products:n}})},exports.paginateSelectedItems=function(o,t,d){var i;const n={};let v=0;for(const s in o)if(Object.prototype.hasOwnProperty.call(o,s)){const e=o[s],c=l(e.products,t,d-v);c&&Object.keys(c).length>0&&(n[s]=Object.assign(Object.assign({},e),{products:c})),v+=Object.keys(null!==(i=e.products)&&void 0!==i?i:{}).length}return n},exports.shouldShowVariant=o=>{const l=Object.keys(o.variants||[]);let t=!1;return!(l.length<=1)||(l.forEach((l=>{var d,i;t=null!==(i=null===(d=o.variants)||void 0===d?void 0:d[l].name.includes(o.name))&&void 0!==i&&i})),!t)},exports.updateAllVariantsForSelectedProducts=(l,t,d)=>Object.keys(l).reduce(((i,n)=>{var v;return n in t?(i[n]=Object.assign(Object.assign({},l[n]),{products:Object.keys(null!==(v=l[n].products)&&void 0!==v?v:{}).reduce(((i,v)=>{var s,e,c,u,r,a,p,b,O,f,j,h,y;const g=null===(s=t[n].products)||void 0===s?void 0:s[v],E=null===(c=null===(e=null==d?void 0:d.products)||void 0===e?void 0:e[n].products)||void 0===c?void 0:c[v];return console.log({collectionId:n,productId:v,productInCollection:g,productInCollectionSearched:E,searchedProducts:d,coll:null==d?void 0:d.products,coll1:null===(u=null==d?void 0:d.products)||void 0===u?void 0:u[n],coll3:null===(r=null==d?void 0:d.products)||void 0===r?void 0:r[n].products,coll4:null===(p=null===(a=null==d?void 0:d.products)||void 0===a?void 0:a[n].products)||void 0===p?void 0:p[v]}),g?i[v]=Object.assign(Object.assign({},(null===(b=l[n].products)||void 0===b?void 0:b[v])||{}),{allVariants:o.cloneDeep(g.variants)}):E?(i[v]=Object.assign(Object.assign({},(null===(O=l[n].products)||void 0===O?void 0:O[v])||{}),{allVariants:o.cloneDeep(E.variants)}),console.log({updatedProducts:i,productId:v})):(null===(j=null===(f=l[n].products)||void 0===f?void 0:f[v])||void 0===j?void 0:j.allVariants)&&(i[v]=Object.assign(Object.assign({},(null===(h=l[n].products)||void 0===h?void 0:h[v])||{}),{allVariants:o.cloneDeep(null===(y=l[n].products)||void 0===y?void 0:y[v].allVariants)})),console.log({updatedProducts:i}),i}),{})}),console.log({updatedCollections:i}),i):i}),{});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import c from"../../assets/icons/search.svg.js";import{useReducer as r,useState as s,useRef as i,useEffect as n}from"react";import{COLORS as l}from"../../constants/Theme.js";import d from"../../assets/icons/cross.svg.js";import{Button as a}from"../button/Button.js";import{Input as u}from"../input/Input.js";import{StyledModal as h}from"../modals/styledModal.js";import{Spinner as p}from"../spinner/Spinner.js";import{Tag as m}from"../tag/Tag.js";import{CollectionsScreen as C}from"./collectionScreen.js";import{ProductInfoOverlay as g}from"./productInfoOverlay.js";import{ProductsScreen as f}from"./productScreen.js";import{RearrangeScreen as y}from"./rearrangeScreen.js";import{collectionsReducer as b,searchReducer as S,selectedColectionsReducer as v,CollectionIdContext as k}from"./reducers.js";import{SearchScreen as j}from"./searchScreen.js";import{SelectedScreen as I}from"./selectedScreen.js";import{ContainerStyle as x,ScrollContainerStyle as P,StyledFooterForNonModal as O}from"./style.js";import{OUT_OF_STOCK_ACTION as D}from"./type.js";import{updateAllVariantsForSelectedProducts as F}from"./utility.js";var T;!function(e){e.Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products"}(T||(T={}));const R=R=>{const{storeId:w,selectedItems:A,onClose:B,visible:E,zIndex:L,exactLimit:z,limit:V,hideCollectionCheckbox:$,hideProductCheckbox:M,outOfStockAction:H=D.BLUR,hideVariantCheckbox:W,selectProductsFromCustomCollection:G,hideSelectionCount:N,title:Y,width:K,left:U,renderWithoutModal:q,onClickSave:J,pickerType:Q,hideProductVariants:X=!1,startupScreen:Z=T.Collections,rearrangeEnabled:_,selectSingleItem:ee=!1,showProductDetails:te,containerStyle:oe,crossButtonInsideHeader:ce=!1,footerForNonModal:re={},primaryButton:se,secondaryButton:ie,subtitle:ne}=R,[le,de]=r(b,{}),[ae,ue]=s([T.Collections,T.RearrangeProducts].includes(Z)?Z:T.Collections),[he,pe]=s("grid"),[me,Ce]=s(""),[ge,fe]=s(""),[ye,be]=s(0),[Se,ve]=s(!1),[ke,je]=s(0),[Ie,xe]=s(""),[Pe,Oe]=s(!1),[De,Fe]=s(!1),[Te,Re]=r(S,{collections:{},products:{}}),[we,Ae]=r(v,Object.keys(A).length>0?A:{}),Be=i(null),[Ee,Le]=s(!1),[ze,Ve]=s();n((()=>{ve(!0),Fe(!0),R.collectionFetcher(ye,w).then((e=>{de({type:"fetched",data:(null==e?void 0:e.collections)||{}}),ve(!1),be((e=>e+1)),Fe(!1)})).catch()}),[]),n((()=>{let e=0;X?Object.keys(we||[]).forEach((t=>{var o;Object.keys((null===(o=we[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c;"-1"!==t&&we[-1]&&(null===(c=we[-1].products)||void 0===c?void 0:c[o])||(e+=1)}))})):Object.keys(we||[]).forEach((t=>{var o;Object.keys((null===(o=we[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=we[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),je(e)}),[le,we,X]),n((()=>{ge&&(ve(!0),R.productFetcher(ge,w).then((e=>{Object.keys(e).length&&de({type:"productsFetched",data:{collectionId:ge,products:e}}),ve(!1)})).catch())}),[ge]),n((()=>{const e=setTimeout((()=>{"rearrange"!==ae&&(Ie.length||"collections"!==ae)&&(Ie.length?(Oe(!0),R.searchFetcher(w,Ie).then((e=>{"collections"in e&&"products"in e?(Re({type:"set",data:e}),de({type:"searched",data:e.collections})):(Re({type:"set",data:{collections:{},products:e}}),de({type:"searched",data:e})),ue("searchProducts"),ve(!1),Oe(!1)}))):ue("collections"))}),800);return()=>clearTimeout(e)}),[Ie]),n((()=>{J&&(R.onAdd(we,ke),$e())}),[J]),n((()=>{ee&&Object.keys(we||{}).length&&ke&&(R.onAdd(we,ke),$e())}),[ee,we,ke]);const $e=()=>{Ae({type:"reset",data:{}})},Me=()=>z&&ke>z?t(m,{tagText:`You can only select ${z} products`,type:"negative"}):V&&ke>V?t(m,{tagText:`You can only select ${V} products`,type:"negative"}):t(a,ke>0?{onClick:()=>{ue(_?T.RearrangeProducts:T.SelectedProducts)},buttonText:z?`${ke}/${z} products selected`:`${ke} products selected`,buttonType:["rearrange","view"].includes(ae)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(ae)}:{disabled:!0,buttonText:z?`${ke}/${z} products selected`:`${ke} products selected`,buttonType:"tertiaryGray"}),He=e=>Se?"Loading...":ae===T.RearrangeProducts?null!=e?e:"Done":null!=e?e:"Add",We=e(x,Object.assign({style:null!=oe?oe:{}},{children:[R.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:R.postHeader})),!R.hideGlobalSearch&&t(o,{children:("collections"===ae||"searchProducts"===ae)&&t("div",Object.assign({style:{padding:q?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(u,{placeholder:"Search for collections and products, or type a product ID",noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>Pe?t(p,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:Ie,onChangeText:e=>{e.length&&e.trim().length?xe(e):xe("")}})}))}),e(P,Object.assign({ref:Be,screenName:ae},{children:["collections"===ae&&t(C,{customCollectionRestriction:R.customCollectionRestriction,dataLoading:De,collections:le,selectedCollectionsDispatch:Ae,setCollectionId:Ce,setSelectedCollectionId:fe,setScreen:ue,selectedCollections:we,collectionFetcher:R.collectionFetcher,storeId:w,collectionsDispatch:de,setSaveDisabled:ve,pagingControls:{curPage:ye,setCurPage:be},hideCollectionCheckbox:$,renderWithoutModal:q,pickerType:Q,scrollContainerRef:Be}),"products"===ae&&me&&t(k.Provider,Object.assign({value:me},{children:t(f,{hideInCollectionSearch:R.hideInCollectionSearch,customCollectionRestriction:R.customCollectionRestriction,productFetcher:R.productFetcher,setScreen:ue,storeId:w,data:le[me],collectionsDispatch:de,selectedCollectionsDispatch:Ae,selectedData:we,setSaveDisabled:ve,searchInCollectionFetcher:R.searchInCollectionFetcher,hideProductCheckbox:M,outOfStockAction:H,hideVariantCheckbox:W,selectProductsFromCustomCollection:G,renderWithoutModal:q,pickerType:Q,hideProductVariants:X,fbStatusFetcher:R.fbStatusFetcher,onProductDetailClick:e=>{Le(!0),Ve(e)},showProductDetailInfoIcon:te,scrollContainerRef:Be})})),"view"===ae&&t(I,{selectedCollections:we||{},selectedCollectionsDispatch:Ae,setScreen:ue,collections:le,hideProductVariants:X,outOfStockAction:H,storeId:w,fbStatusFetcher:R.fbStatusFetcher}),"rearrange"===ae&&t(y,{selectedCollections:we||{},selectedCollectionsDispatch:Ae,setScreen:ue,outOfStockAction:H,rearrangeViewType:"grid"===he?"list":"grid",scrollContainerRef:Be,storeId:w,fbStatusFetcher:R.fbStatusFetcher}),"searchProducts"===ae&&t(j,{customCollectionRestriction:R.customCollectionRestriction,selectedCollections:we||{},searchedCollections:Te||{},searchedCollectionsDispatch:Re,selectedCollectionsDispatch:Ae,setScreen:ue,collections:le,onBackPress:()=>{xe(""),Re({type:"set",data:{collections:{},products:{}}})},pickerType:Q,hideProductCheckbox:M,hideProductVariants:X,hideVariantCheckbox:W,storeId:w,fbStatusFetcher:R.fbStatusFetcher,setCollectionId:Ce,setSelectedCollectionId:fe,renderWithoutModal:q,hideCollectionCheckbox:$,outOfStockAction:H})]}))]}));return t(o,{children:q?e(o,{children:[We,re.renderFooter?e(O,{children:[Me(),t(a,{buttonText:He(re.primaryButtonText),disabled:!re.isLoading&&(Se||ke<1||z&&ke<z||!z&&V&&ke>V)||re.primaryButtonDisabled,isLoading:re.isLoading,onClick:()=>{R.onAdd(we,ke),$e(),ue([T.Collections,T.RearrangeProducts].includes(Z)?Z:T.Collections)}})]}):t(o,{}),Ee&&ze?t(g,{productData:ze,outOfStockAction:H,useDynamicInfoImageSize:R.useDynamicInfoImageSize,onClose:()=>{Le(!1)}}):t(o,{})]}):e(h,Object.assign({zIndex:L,open:E,onClose:()=>{null==B||B(),$e()},headingTitle:Y||("collections"===ae||"products"===ae?"Select Products":"view"===ae?"Selected Products":"searchProducts"===ae?"Searched Results":"rearrange"===ae?"Rearrange Products":void 0),headingSubtitle:ne,footerShadow:!0,centralContainerStyles:{width:K||"600px",left:U||"auto"},headerRightCustomElement:ce?t("div",Object.assign({style:{cursor:"pointer",display:"flex"},onClick:B},{children:t(d,{width:20,height:20,color:l.content.secondary})})):t(o,{}),footerContainerStyle:R.stickyFooter?{position:"absolute",bottom:0,left:0,width:"100%",zIndex:9,background:l.surface.standard}:void 0,primaryButton:se?(e=>Object.assign(Object.assign({},e),{disabled:!e.isLoading&&(Se||ke<1||z&&ke<z||!z&&V&&ke>V)||e.disabled,onClick:()=>{R.onAdd(we,ke),$e(),ue([T.Collections,T.RearrangeProducts].includes(Z)?Z:T.Collections)}}))(se):{buttonText:He(),disabled:Se||ke<1||z&&ke<z||!z&&V&&ke>V||!1,onClick:()=>{R.onAdd(we,ke),$e()}},secondaryButton:ie?(e=>Object.assign(Object.assign({},e),{disabled:Se||ke<1||z&&ke<z||!z&&V&&ke>V||!1,onClick:()=>{console.log({selectedCollections:we,collections:le,searchedCollections:Te});const e=F(we,le);console.log({filteredCollections:e}),R.onAdd(e,ke,!0)}}))(ie):void 0,wrapperStyle:R.stickyFooter?{height:"calc(100vh - 168px)"}:void 0,footerLeftCustomElement:N?t(o,{}):Me(),hideCrossButton:Ee||ce},{children:[We,Ee&&ze?t(g,{productData:ze,useDynamicInfoImageSize:R.useDynamicInfoImageSize,outOfStockAction:H,onClose:()=>{Le(!1)}}):t(o,{})]}))})};export{R as ProductPickerModal,T as ScreenName};
|
|
1
|
+
import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import c from"../../assets/icons/search.svg.js";import{useReducer as r,useState as s,useRef as i,useEffect as n}from"react";import{COLORS as l}from"../../constants/Theme.js";import d from"../../assets/icons/cross.svg.js";import{Button as a}from"../button/Button.js";import{Input as u}from"../input/Input.js";import{StyledModal as h}from"../modals/styledModal.js";import{Spinner as p}from"../spinner/Spinner.js";import{Tag as m}from"../tag/Tag.js";import{CollectionsScreen as C}from"./collectionScreen.js";import{ProductInfoOverlay as g}from"./productInfoOverlay.js";import{ProductsScreen as f}from"./productScreen.js";import{RearrangeScreen as y}from"./rearrangeScreen.js";import{collectionsReducer as b,searchReducer as S,selectedColectionsReducer as v,CollectionIdContext as k}from"./reducers.js";import{SearchScreen as j}from"./searchScreen.js";import{SelectedScreen as I}from"./selectedScreen.js";import{ContainerStyle as x,ScrollContainerStyle as P,StyledFooterForNonModal as O}from"./style.js";import{OUT_OF_STOCK_ACTION as D}from"./type.js";import{updateAllVariantsForSelectedProducts as F}from"./utility.js";var T;!function(e){e.Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products"}(T||(T={}));const R=R=>{const{storeId:w,selectedItems:A,onClose:B,visible:E,zIndex:L,exactLimit:z,limit:V,hideCollectionCheckbox:$,hideProductCheckbox:M,outOfStockAction:H=D.BLUR,hideVariantCheckbox:W,selectProductsFromCustomCollection:G,hideSelectionCount:N,title:Y,width:K,left:U,renderWithoutModal:q,onClickSave:J,pickerType:Q,hideProductVariants:X=!1,startupScreen:Z=T.Collections,rearrangeEnabled:_,selectSingleItem:ee=!1,showProductDetails:te,containerStyle:oe,crossButtonInsideHeader:ce=!1,footerForNonModal:re={},primaryButton:se,secondaryButton:ie,subtitle:ne}=R,[le,de]=r(b,{}),[ae,ue]=s([T.Collections,T.RearrangeProducts].includes(Z)?Z:T.Collections),[he,pe]=s("grid"),[me,Ce]=s(""),[ge,fe]=s(""),[ye,be]=s(0),[Se,ve]=s(!1),[ke,je]=s(0),[Ie,xe]=s(""),[Pe,Oe]=s(!1),[De,Fe]=s(!1),[Te,Re]=r(S,{collections:{},products:{}}),[we,Ae]=r(v,Object.keys(A).length>0?A:{}),Be=i(null),[Ee,Le]=s(!1),[ze,Ve]=s();n((()=>{ve(!0),Fe(!0),R.collectionFetcher(ye,w).then((e=>{de({type:"fetched",data:(null==e?void 0:e.collections)||{}}),ve(!1),be((e=>e+1)),Fe(!1)})).catch()}),[]),n((()=>{let e=0;X?Object.keys(we||[]).forEach((t=>{var o;Object.keys((null===(o=we[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c;"-1"!==t&&we[-1]&&(null===(c=we[-1].products)||void 0===c?void 0:c[o])||(e+=1)}))})):Object.keys(we||[]).forEach((t=>{var o;Object.keys((null===(o=we[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=we[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),je(e)}),[le,we,X]),n((()=>{ge&&(ve(!0),R.productFetcher(ge,w).then((e=>{Object.keys(e).length&&de({type:"productsFetched",data:{collectionId:ge,products:e}}),ve(!1)})).catch())}),[ge]),n((()=>{const e=setTimeout((()=>{"rearrange"!==ae&&(Ie.length||"collections"!==ae)&&(Ie.length?(Oe(!0),R.searchFetcher(w,Ie).then((e=>{"collections"in e&&"products"in e?(Re({type:"set",data:e}),de({type:"searched",data:e.collections})):(Re({type:"set",data:{collections:{},products:e}}),de({type:"searched",data:e})),ue("searchProducts"),ve(!1),Oe(!1)}))):ue("collections"))}),800);return()=>clearTimeout(e)}),[Ie]),n((()=>{J&&(R.onAdd(we,ke),$e())}),[J]),n((()=>{ee&&Object.keys(we||{}).length&&ke&&(R.onAdd(we,ke),$e())}),[ee,we,ke]);const $e=()=>{Ae({type:"reset",data:{}})},Me=()=>z&&ke>z?t(m,{tagText:`You can only select ${z} products`,type:"negative"}):V&&ke>V?t(m,{tagText:`You can only select ${V} products`,type:"negative"}):t(a,ke>0?{onClick:()=>{ue(_?T.RearrangeProducts:T.SelectedProducts)},buttonText:z?`${ke}/${z} products selected`:`${ke} products selected`,buttonType:["rearrange","view"].includes(ae)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(ae)}:{disabled:!0,buttonText:z?`${ke}/${z} products selected`:`${ke} products selected`,buttonType:"tertiaryGray"}),He=e=>Se?"Loading...":ae===T.RearrangeProducts?null!=e?e:"Done":null!=e?e:"Add",We=e(x,Object.assign({style:null!=oe?oe:{}},{children:[R.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:R.postHeader})),!R.hideGlobalSearch&&t(o,{children:("collections"===ae||"searchProducts"===ae)&&t("div",Object.assign({style:{padding:q?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(u,{placeholder:"Search for collections and products, or type a product ID",noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>Pe?t(p,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:Ie,onChangeText:e=>{e.length&&e.trim().length?xe(e):xe("")}})}))}),e(P,Object.assign({ref:Be,screenName:ae},{children:["collections"===ae&&t(C,{customCollectionRestriction:R.customCollectionRestriction,dataLoading:De,collections:le,selectedCollectionsDispatch:Ae,setCollectionId:Ce,setSelectedCollectionId:fe,setScreen:ue,selectedCollections:we,collectionFetcher:R.collectionFetcher,storeId:w,collectionsDispatch:de,setSaveDisabled:ve,pagingControls:{curPage:ye,setCurPage:be},hideCollectionCheckbox:$,renderWithoutModal:q,pickerType:Q,scrollContainerRef:Be}),"products"===ae&&me&&t(k.Provider,Object.assign({value:me},{children:t(f,{hideInCollectionSearch:R.hideInCollectionSearch,customCollectionRestriction:R.customCollectionRestriction,productFetcher:R.productFetcher,setScreen:ue,storeId:w,data:le[me],collectionsDispatch:de,selectedCollectionsDispatch:Ae,selectedData:we,setSaveDisabled:ve,searchInCollectionFetcher:R.searchInCollectionFetcher,hideProductCheckbox:M,outOfStockAction:H,hideVariantCheckbox:W,selectProductsFromCustomCollection:G,renderWithoutModal:q,pickerType:Q,hideProductVariants:X,fbStatusFetcher:R.fbStatusFetcher,onProductDetailClick:e=>{Le(!0),Ve(e)},showProductDetailInfoIcon:te,scrollContainerRef:Be})})),"view"===ae&&t(I,{selectedCollections:we||{},selectedCollectionsDispatch:Ae,setScreen:ue,collections:le,hideProductVariants:X,outOfStockAction:H,storeId:w,fbStatusFetcher:R.fbStatusFetcher}),"rearrange"===ae&&t(y,{selectedCollections:we||{},selectedCollectionsDispatch:Ae,setScreen:ue,outOfStockAction:H,rearrangeViewType:"grid"===he?"list":"grid",scrollContainerRef:Be,storeId:w,fbStatusFetcher:R.fbStatusFetcher}),"searchProducts"===ae&&t(j,{customCollectionRestriction:R.customCollectionRestriction,selectedCollections:we||{},searchedCollections:Te||{},searchedCollectionsDispatch:Re,selectedCollectionsDispatch:Ae,setScreen:ue,collections:le,onBackPress:()=>{xe(""),Re({type:"set",data:{collections:{},products:{}}})},pickerType:Q,hideProductCheckbox:M,hideProductVariants:X,hideVariantCheckbox:W,storeId:w,fbStatusFetcher:R.fbStatusFetcher,setCollectionId:Ce,setSelectedCollectionId:fe,renderWithoutModal:q,hideCollectionCheckbox:$,outOfStockAction:H})]}))]}));return t(o,{children:q?e(o,{children:[We,re.renderFooter?e(O,{children:[Me(),t(a,{buttonText:He(re.primaryButtonText),disabled:!re.isLoading&&(Se||ke<1||z&&ke<z||!z&&V&&ke>V)||re.primaryButtonDisabled,isLoading:re.isLoading,onClick:()=>{R.onAdd(we,ke),$e(),ue([T.Collections,T.RearrangeProducts].includes(Z)?Z:T.Collections)}})]}):t(o,{}),Ee&&ze?t(g,{productData:ze,outOfStockAction:H,useDynamicInfoImageSize:R.useDynamicInfoImageSize,onClose:()=>{Le(!1)}}):t(o,{})]}):e(h,Object.assign({zIndex:L,open:E,onClose:()=>{null==B||B(),$e()},headingTitle:Y||("collections"===ae||"products"===ae?"Select Products":"view"===ae?"Selected Products":"searchProducts"===ae?"Searched Results":"rearrange"===ae?"Rearrange Products":void 0),headingSubtitle:ne,footerShadow:!0,centralContainerStyles:{width:K||"600px",left:U||"auto"},headerRightCustomElement:ce?t("div",Object.assign({style:{cursor:"pointer",display:"flex"},onClick:B},{children:t(d,{width:20,height:20,color:l.content.secondary})})):t(o,{}),footerContainerStyle:R.stickyFooter?{position:"absolute",bottom:0,left:0,width:"100%",zIndex:9,background:l.surface.standard}:void 0,primaryButton:se?(e=>Object.assign(Object.assign({},e),{disabled:!e.isLoading&&(Se||ke<1||z&&ke<z||!z&&V&&ke>V)||e.disabled,onClick:()=>{R.onAdd(we,ke),$e(),ue([T.Collections,T.RearrangeProducts].includes(Z)?Z:T.Collections)}}))(se):{buttonText:He(),disabled:Se||ke<1||z&&ke<z||!z&&V&&ke>V||!1,onClick:()=>{R.onAdd(we,ke),$e()}},secondaryButton:ie?(e=>Object.assign(Object.assign({},e),{disabled:Se||ke<1||z&&ke<z||!z&&V&&ke>V||!1,onClick:()=>{console.log({selectedCollections:we,collections:le,searchedCollections:Te});const e=F(we,le,Te);console.log({filteredCollections:e}),R.onAdd(e,ke,!0)}}))(ie):void 0,wrapperStyle:R.stickyFooter?{height:"calc(100vh - 168px)"}:void 0,footerLeftCustomElement:N?t(o,{}):Me(),hideCrossButton:Ee||ce},{children:[We,Ee&&ze?t(g,{productData:ze,useDynamicInfoImageSize:R.useDynamicInfoImageSize,outOfStockAction:H,onClose:()=>{Le(!1)}}):t(o,{})]}))})};export{R as ProductPickerModal,T as ScreenName};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Collection, FbStatusFetcherReturn, Product, ProductVariant, SelectedItems } from './modal';
|
|
1
|
+
import { Collection, FbStatusFetcherReturn, Product, ProductVariant, SearchedItems, SelectedItems } from './modal';
|
|
2
2
|
import { CollectionsActions } from './reducers';
|
|
3
3
|
export declare const liftTheStateUp: (payload: any, data: any) => any;
|
|
4
4
|
export declare function paginateSelectedItems(selectedItems: SelectedItems, limit: number, offset: number): {
|
|
@@ -47,6 +47,4 @@ export declare const updateAllVariantsForSelectedProducts: (selectedItems: {
|
|
|
47
47
|
};
|
|
48
48
|
} | undefined;
|
|
49
49
|
};
|
|
50
|
-
}, collections: Collection, searchedProducts:
|
|
51
|
-
products?: Collection;
|
|
52
|
-
}) => Record<string, any>;
|
|
50
|
+
}, collections: Collection, searchedProducts: SearchedItems) => Record<string, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cloneDeep as o}from"lodash";const l=(l,
|
|
1
|
+
import{cloneDeep as o}from"lodash";const l=(l,d)=>{const i=o(d);if(delete i.products,(l=Object.assign(Object.assign({},l),{catalogOnlyData:i})).productId&&d.products){const n=o(d.products[l.productId]);(null==n?void 0:n.variants)&&delete n.variants,l=Object.assign(Object.assign({},l),{catalogOnlyData:i,productOnlyData:n})}return l};function d(o,l,d){var n;const t={};let v=0;for(const s in o)if(Object.prototype.hasOwnProperty.call(o,s)){const u=o[s],c=i(u.products,l,d-v);c&&Object.keys(c).length>0&&(t[s]=Object.assign(Object.assign({},u),{products:c})),v+=Object.keys(null!==(n=u.products)&&void 0!==n?n:{}).length}return t}function i(o,l,d){if(!o)return{};const i=Object.keys(o).slice(d,d+l),n={};return i.forEach((l=>{n[l]=o[l]})),n}const n=(o,l,d)=>{Object.keys(o).forEach((l=>{var d,i;const n=null!==(i=null===(d=o[l])||void 0===d?void 0:d.products)&&void 0!==i?i:{};Object.keys(n).forEach((d=>{var i,n,t,v;const s=null!==(v=null===(t=null===(n=null===(i=o[l])||void 0===i?void 0:i.products)||void 0===n?void 0:n[d])||void 0===t?void 0:t.variants)&&void 0!==v?v:{};Object.keys(s).forEach((i=>{var n,t,v,s;const u=null===(s=null===(v=null===(t=null===(n=o[l])||void 0===n?void 0:n.products)||void 0===t?void 0:t[d])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[i];u&&!u.fbStatus&&(u.fbStatus="APPROVED")}))}))})),l({type:d,data:o})},t=function(o,l,d,i){let t=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";i||n(o,d,t);const v=(o=>{const l=[];return Object.keys(o).forEach((d=>{var i,n;const t=null!==(n=null===(i=o[d])||void 0===i?void 0:i.products)&&void 0!==n?n:{};Object.keys(t).forEach((i=>{var n,t,v,s;const u=null!==(s=null===(v=null===(t=null===(n=o[d])||void 0===n?void 0:n.products)||void 0===t?void 0:t[i])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(u).forEach((n=>{var t,v,s,u;const c=null===(u=null===(s=null===(v=null===(t=o[d])||void 0===t?void 0:t.products)||void 0===v?void 0:v[i])||void 0===s?void 0:s.variants)||void 0===u?void 0:u[n];(null==c?void 0:c.fbStatus)||l.push(n)}))}))})),l})(o);v.length>0&&i&&i(l,v).then((l=>{const i=Object.assign({},o);Object.keys(i).forEach((o=>{var d,n;const t=null!==(n=null===(d=i[o])||void 0===d?void 0:d.products)&&void 0!==n?n:{};Object.keys(t).forEach((d=>{var n,t,v,s;const u=null!==(s=null===(v=null===(t=null===(n=i[o])||void 0===n?void 0:n.products)||void 0===t?void 0:t[d])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(u).forEach((n=>{var t,v,s,u;const c=null===(u=null===(s=null===(v=null===(t=i[o])||void 0===t?void 0:t.products)||void 0===v?void 0:v[d])||void 0===s?void 0:s.variants)||void 0===u?void 0:u[n];c&&"REJECTED"===l[n]?c.fbStatus="REJECTED":c&&"APPROVED"===l[n]&&(c.fbStatus="APPROVED")}))}))})),d({type:t,data:i})})).catch((l=>{console.error("Error in fbStatusFetcher",l),n(o,d,t)}))},v=(o,l)=>{const d=[];return Object.keys(null!=o?o:{}).forEach((i=>{var n,t;const v=null!==(t=null===(n=null==o?void 0:o[i])||void 0===n?void 0:n.variants)&&void 0!==t?t:{};Object.keys(v).forEach((n=>{var t,v,s,u,c;let r;r=l?null===(s=null===(v=null===(t=null==l?void 0:l.products)||void 0===t?void 0:t[i])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[n]:null===(c=null===(u=null==o?void 0:o[i])||void 0===u?void 0:u.variants)||void 0===c?void 0:c[n],(null==r?void 0:r.fbStatus)||d.push(n)}))})),d},s=(o,l,d,i,n)=>{const t=Object.assign({},o);if(Object.keys(o).forEach((l=>{var d,i;Object.keys(null!==(i=null===(d=null==o?void 0:o[l])||void 0===d?void 0:d.variants)&&void 0!==i?i:{}).forEach((d=>{var i,n;const v=null===(i=null==o?void 0:o[l].variants)||void 0===i?void 0:i[d];v&&(v.fbStatus="APPROVED");const s=null===(n=null==t?void 0:t[l])||void 0===n?void 0:n.variants;s&&s[d]&&(s[d]=v)}))})),i&&n){const o=Object.assign({},i);o.products=t,n(o),l({type:"productsPaged",data:{collectionId:d,products:t}})}else l({type:"productsPaged",data:{collectionId:d,products:t}})},u=o=>{const l=Object.keys(o.variants||[]);let d=!1;return!(l.length<=1)||(l.forEach((l=>{var i,n;d=null!==(n=null===(i=o.variants)||void 0===i?void 0:i[l].name.includes(o.name))&&void 0!==n&&n})),!d)},c=(o,l,d,i,n)=>{var t,v,s,u,c,r,a,e,p,b,O,f,j,h,y,g,E,k,P;let D=0,I=0;if(null===(v=null===(t=null==d?void 0:d[o])||void 0===t?void 0:t.products)||void 0===v?void 0:v[l]){if(n)return!1;const t=(null===(c=null===(u=null===(s=null==d?void 0:d[o])||void 0===s?void 0:s.products)||void 0===u?void 0:u[l])||void 0===c?void 0:c.variants)||[];if(1===Object.keys(t).length)for(const i in t){const n=null===(a=null===(r=null==d?void 0:d[o])||void 0===r?void 0:r.products)||void 0===a?void 0:a[l],t=null===(O=null===(b=null===(p=null===(e=null==d?void 0:d[o])||void 0===e?void 0:e.products)||void 0===p?void 0:p[l])||void 0===b?void 0:b.variants)||void 0===O?void 0:O[i];if(null===(f=null==t?void 0:t.name)||void 0===f?void 0:f.includes(null!==(j=null==n?void 0:n.name)&&void 0!==j?j:""))return!1}if(null===(g=Object.keys((null===(y=null===(h=null==i?void 0:i.products)||void 0===h?void 0:h[l])||void 0===y?void 0:y.variants)||[]))||void 0===g||g.forEach((()=>I++)),Object.keys((null===(P=null===(k=null===(E=null==d?void 0:d[o])||void 0===E?void 0:E.products)||void 0===k?void 0:k[l])||void 0===P?void 0:P.variants)||[]).forEach((()=>D++)),D>0&&I!==D)return!0}return!1},r=function(o,l,d){var i,n,t,v;let s=0,u=0;if(arguments.length>3&&void 0!==arguments[3]&&arguments[3]){const v=null!==(i=null==l?void 0:l.products)&&void 0!==i?i:{};s=Object.keys(v).length;const c=null!==(t=null===(n=d[o])||void 0===n?void 0:n.products)&&void 0!==t?t:{};u=Object.keys(c).length}else if(d[o]){const i=null==l?void 0:l.products;i&&Object.keys(i).forEach((o=>{var l;const d=null===(l=i[o])||void 0===l?void 0:l.variants;d&&Object.keys(d).forEach((o=>s+=1))}));const n=null===(v=d[o])||void 0===v?void 0:v.products;if(n&&Object.keys(n).forEach((o=>{var l;const d=null===(l=n[o])||void 0===l?void 0:l.variants;d&&Object.keys(d).forEach((o=>u+=1))})),s<=0&&u>0)return!1}return u>0&&s!==u},a=(l,d,i)=>Object.keys(l).reduce(((n,t)=>{var v;return t in d?(n[t]=Object.assign(Object.assign({},l[t]),{products:Object.keys(null!==(v=l[t].products)&&void 0!==v?v:{}).reduce(((n,v)=>{var s,u,c,r,a,e,p,b,O,f,j,h,y;const g=null===(s=d[t].products)||void 0===s?void 0:s[v],E=null===(c=null===(u=null==i?void 0:i.products)||void 0===u?void 0:u[t].products)||void 0===c?void 0:c[v];return console.log({collectionId:t,productId:v,productInCollection:g,productInCollectionSearched:E,searchedProducts:i,coll:null==i?void 0:i.products,coll1:null===(r=null==i?void 0:i.products)||void 0===r?void 0:r[t],coll3:null===(a=null==i?void 0:i.products)||void 0===a?void 0:a[t].products,coll4:null===(p=null===(e=null==i?void 0:i.products)||void 0===e?void 0:e[t].products)||void 0===p?void 0:p[v]}),g?n[v]=Object.assign(Object.assign({},(null===(b=l[t].products)||void 0===b?void 0:b[v])||{}),{allVariants:o(g.variants)}):E?(n[v]=Object.assign(Object.assign({},(null===(O=l[t].products)||void 0===O?void 0:O[v])||{}),{allVariants:o(E.variants)}),console.log({updatedProducts:n,productId:v})):(null===(j=null===(f=l[t].products)||void 0===f?void 0:f[v])||void 0===j?void 0:j.allVariants)&&(n[v]=Object.assign(Object.assign({},(null===(h=l[t].products)||void 0===h?void 0:h[v])||{}),{allVariants:o(null===(y=l[t].products)||void 0===y?void 0:y[v].allVariants)})),console.log({updatedProducts:n}),n}),{})}),console.log({updatedCollections:n}),n):n}),{});export{t as fetchFbStatusCollection,v as getVariantIdsToFetchAtProductLevel,r as isCollectionPartiallyChecked,c as isProductPartiallyChecked,l as liftTheStateUp,s as markVariantsAsApprovedProductsLevel,d as paginateSelectedItems,u as shouldShowVariant,a as updateAllVariantsForSelectedProducts};
|