@bikdotai/bik-component-library 0.0.455-beta.ppi-30 → 0.0.455-beta.ppif-1
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/ProductPickerTag.d.ts +11 -0
- package/dist/cjs/components/product-picker-v2/helpers/ProductHelper.d.ts +3 -0
- package/dist/cjs/components/product-picker-v2/modal.js +1 -1
- package/dist/cjs/components/product-picker-v2/productInfoOverlay.d.ts +6 -0
- package/dist/cjs/components/product-picker-v2/productInfoOverlay.js +1 -1
- package/dist/cjs/components/product-picker-v2/productScreen.js +1 -1
- package/dist/cjs/components/product-picker-v2/reducers.d.ts +18 -0
- package/dist/cjs/components/product-picker-v2/reducers.js +1 -1
- package/dist/cjs/components/product-picker-v2/searchScreen.js +1 -1
- package/dist/cjs/components/product-picker-v2/selectedScreen.js +1 -1
- package/dist/cjs/components/product-picker-v2/utility.d.ts +18 -0
- package/dist/cjs/components/product-picker-v2/utility.js +1 -1
- package/dist/esm/components/product-picker-v2/ProductPickerTag.d.ts +11 -0
- package/dist/esm/components/product-picker-v2/helpers/ProductHelper.d.ts +3 -0
- package/dist/esm/components/product-picker-v2/modal.js +1 -1
- package/dist/esm/components/product-picker-v2/productInfoOverlay.d.ts +6 -0
- package/dist/esm/components/product-picker-v2/productInfoOverlay.js +1 -1
- package/dist/esm/components/product-picker-v2/productScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/reducers.d.ts +18 -0
- package/dist/esm/components/product-picker-v2/reducers.js +1 -1
- package/dist/esm/components/product-picker-v2/searchScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/selectedScreen.js +1 -1
- package/dist/esm/components/product-picker-v2/utility.d.ts +18 -0
- package/dist/esm/components/product-picker-v2/utility.js +1 -1
- package/package.json +1 -1
|
@@ -5,4 +5,15 @@ export type ProductPickerTagType = {
|
|
|
5
5
|
data: Product | ProductVariant;
|
|
6
6
|
outOfStockAction?: OUT_OF_STOCK_ACTION;
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Used in Product Screen, Search Screen, Selected Screen and Rearrange Screen.
|
|
10
|
+
* Wherever product card is shown, we use this component.
|
|
11
|
+
*
|
|
12
|
+
* New logic: When product has only one variant and variant name is same as product name,
|
|
13
|
+
* we consider that a variant and do operations as variant.
|
|
14
|
+
*
|
|
15
|
+
* Note: If there is no Fb rejected tag in the variant, we show a shimmer,
|
|
16
|
+
* meanwhile hit the API to get FB status.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
8
19
|
export declare const ProductPickerTag: (props: ProductPickerTagType) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -32,6 +32,9 @@ export declare class ProductHelper {
|
|
|
32
32
|
* @param outOfStockAction
|
|
33
33
|
*/
|
|
34
34
|
static getProductLabels(productVariant: Product | ProductVariant, outOfStockAction?: OUT_OF_STOCK_ACTION): string | null;
|
|
35
|
+
/**
|
|
36
|
+
* For FB Rejected returns 'negative', for rest returns 'warning'
|
|
37
|
+
*/
|
|
35
38
|
static getTagType: (tagText: string) => TagType;
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
@@ -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("../button/Button.js"),n=require("../input/Input.js"),l=require("../modals/styledModal.js"),i=require("../spinner/Spinner.js"),a=require("../tag/Tag.js"),d=require("./collectionScreen.js"),u=require("./productInfoOverlay.js"),h=require("./productScreen.js"),p=require("./rearrangeScreen.js"),S=require("./reducers.js"),C=require("./searchScreen.js"),x=require("./selectedScreen.js"),g=require("./style.js"),j=require("./type.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:y,selectedItems:b,onClose:f,visible:m,zIndex:v,exactLimit:P,limit:I,hideCollectionCheckbox:k,hideProductCheckbox:F,outOfStockAction:O=j.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:R,selectProductsFromCustomCollection:T,hideSelectionCount:q,title:D,width:E,renderWithoutModal:w,onClickSave:N,pickerType:A,hideProductVariants:B=!1,startupScreen:M=exports.ScreenName.Collections,rearrangeEnabled:$,selectSingleItem:L=!1,showProductDetailInfoIcon:V}=e,[_,z]=c.useReducer(S.collectionsReducer,{}),[W,G]=c.useState([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(M)?M:exports.ScreenName.Collections),[H,K]=c.useState("grid"),[U,Y]=c.useState(""),[J,Q]=c.useState(""),[X,Z]=c.useState(0),[ee,te]=c.useState(!1),[oe,ce]=c.useState(0),[re,se]=c.useState(""),[ne,le]=c.useState(!1),[ie,ae]=c.useState(!1),[de,ue]=c.useReducer(S.searchReducer,{collections:{},products:{}}),[he,pe]=c.useReducer(S.selectedColectionsReducer,Object.keys(b).length>0?b:{}),Se=c.useRef(null),[Ce,xe]=c.useState(!1),[ge,je]=c.useState();c.useEffect((()=>{te(!0),ae(!0),e.collectionFetcher(X,y).then((e=>{z({type:"fetched",data:(null==e?void 0:e.collections)||{}}),te(!1),Z((e=>e+1)),ae(!1)})).catch()}),[]),c.useEffect((()=>{let e=0;Object.keys(he||[]).forEach((t=>{var o;Object.keys((null===(o=he[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=he[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),ce(e)})),c.useEffect((()=>{J&&(te(!0),e.productFetcher(J,y).then((e=>{Object.keys(e).length&&z({type:"productsFetched",data:{collectionId:J,products:e}}),te(!1)})).catch())}),[J]),c.useEffect((()=>{const t=setTimeout((()=>{"rearrange"!==W&&(re.length?(le(!0),e.searchFetcher(y,re).then((e=>{"collections"in e&&"products"in e?(ue({type:"set",data:e}),z({type:"searched",data:e.collections})):ue({type:"set",data:{collections:{},products:e}}),G("searchProducts"),te(!1),le(!1)}))):G("collections"))}),800);return()=>clearTimeout(t)}),[re]),c.useEffect((()=>{N&&(e.onAdd(he,oe),ye())}),[N]),c.useEffect((()=>{L&&Object.keys(he||{}).length&&oe&&(e.onAdd(he,oe),ye())}),[L,he,oe]);const ye=()=>{pe({type:"reset",data:{}})},be=t.jsxs(g.ContainerStyle,{children:[e.postHeader&&t.jsx("div",Object.assign({style:{padding:"0 24px"}},{children:e.postHeader})),!e.hideGlobalSearch&&t.jsx(t.Fragment,{children:("collections"===W||"searchProducts"===W)&&t.jsx("div",Object.assign({style:{padding:w?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t.jsx(n.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>ne?t.jsx(i.Spinner,{size:"small",color:r.COLORS.content.primary}):t.jsx(o.default,{})},id:"listInput",height:"24px",type:"text",value:re,onChangeText:e=>{e.length&&e.trim().length?se(e):se("")}})}))}),t.jsxs(g.ScrollContainerStyle,Object.assign({ref:Se},{children:["collections"===W&&t.jsx(d.CollectionsScreen,{customCollectionRestriction:e.customCollectionRestriction,dataLoading:ie,collections:_,selectedCollectionsDispatch:pe,setCollectionId:Y,setSelectedCollectionId:Q,setScreen:G,selectedCollections:he,collectionFetcher:e.collectionFetcher,storeId:y,collectionsDispatch:z,setSaveDisabled:te,pagingControls:{curPage:X,setCurPage:Z},hideCollectionCheckbox:k,renderWithoutModal:w,pickerType:A}),"products"===W&&U&&t.jsx(S.CollectionIdContext.Provider,Object.assign({value:U},{children:t.jsx(h.ProductsScreen,{hideInCollectionSearch:e.hideInCollectionSearch,customCollectionRestriction:e.customCollectionRestriction,productFetcher:e.productFetcher,setScreen:G,storeId:y,data:_[U],collectionsDispatch:z,selectedCollectionsDispatch:pe,selectedData:he,setSaveDisabled:te,searchInCollectionFetcher:e.searchInCollectionFetcher,hideProductCheckbox:F,outOfStockAction:O,hideVariantCheckbox:R,selectProductsFromCustomCollection:T,renderWithoutModal:w,pickerType:A,hideProductVariants:B,fbStatusFetcher:e.fbStatusFetcher,onInfoIconClick:e=>{xe(!0),je(e)},showProductDetailInfoIcon:V})})),"view"===W&&t.jsx(x.SelectedScreen,{selectedCollections:he||{},selectedCollectionsDispatch:pe,setScreen:G,collections:_,outOfStockAction:O,storeId:y,fbStatusFetcher:e.fbStatusFetcher}),"rearrange"===W&&t.jsx(p.RearrangeScreen,{selectedCollections:he||{},selectedCollectionsDispatch:pe,setScreen:G,outOfStockAction:O,rearrangeViewType:"grid"===H?"list":"grid",scrollContainerRef:Se,storeId:y,fbStatusFetcher:e.fbStatusFetcher}),"searchProducts"===W&&t.jsx(C.SearchScreen,{customCollectionRestriction:e.customCollectionRestriction,selectedCollections:he||{},searchedCollections:de||{},searchedCollectionsDispatch:ue,selectedCollectionsDispatch:pe,setScreen:G,collections:_,onBackPress:()=>{se(""),ue({type:"set",data:{collections:{},products:{}}})},pickerType:A,hideProductCheckbox:F,hideProductVariants:B,hideVariantCheckbox:R,storeId:y,fbStatusFetcher:e.fbStatusFetcher,setCollectionId:Y,setSelectedCollectionId:Q,renderWithoutModal:w,hideCollectionCheckbox:k})]}))]});return t.jsx(t.Fragment,{children:w?be:t.jsxs(l.StyledModal,Object.assign({zIndex:v,open:m,onClose:()=>{null==f||f(),ye()},headingTitle:D||("collections"===W||"products"===W?"Select Products":"view"===W?"Selected Products":"searchProducts"===W?"Searched Products":"rearrange"===W?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:E||"600px"},headerRightCustomElement:"rearrange"===W?(console.log("ignore:",K),t.jsx(t.Fragment,{})):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:{buttonText:ee?"Loading...":W===exports.ScreenName.RearrangeProducts?"Done":"Add",disabled:ee||oe<1||P&&oe<P||!P&&I&&oe>I||!1,onClick:()=>{e.onAdd(he,oe),ye()}},wrapperStyle:e.stickyFooter?{height:"calc(100vh - 168px)"}:void 0,footerLeftCustomElement:q?t.jsx(t.Fragment,{}):P&&oe>P?t.jsx(a.Tag,{tagText:`You can only select ${P} products`,type:"negative"}):I&&oe>I?t.jsx(a.Tag,{tagText:`You can only select ${I} products`,type:"negative"}):oe>0?t.jsx(s.Button,{onClick:()=>{G($?exports.ScreenName.RearrangeProducts:exports.ScreenName.SelectedProducts)},buttonText:P?`${oe}/${P} products selected`:`${oe} products selected`,buttonType:["rearrange","view"].includes(W)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(W)}):t.jsx(s.Button,{disabled:!0,buttonText:P?`${oe}/${P} products selected`:`${oe} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:Ce},{children:[be,Ce&&ge?t.jsx(u.ProductInfoOverlay,{productData:ge,outOfStockAction:O,onClose:()=>{xe(!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("../button/Button.js"),n=require("../input/Input.js"),l=require("../modals/styledModal.js"),i=require("../spinner/Spinner.js"),a=require("../tag/Tag.js"),d=require("./collectionScreen.js"),u=require("./productInfoOverlay.js"),h=require("./productScreen.js"),p=require("./rearrangeScreen.js"),S=require("./reducers.js"),C=require("./searchScreen.js"),x=require("./selectedScreen.js"),g=require("./style.js"),j=require("./type.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:y,selectedItems:b,onClose:f,visible:m,zIndex:v,exactLimit:P,limit:I,hideCollectionCheckbox:k,hideProductCheckbox:F,outOfStockAction:O=j.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:R,selectProductsFromCustomCollection:T,hideSelectionCount:q,title:D,width:E,renderWithoutModal:w,onClickSave:N,pickerType:A,hideProductVariants:B=!1,startupScreen:M=exports.ScreenName.Collections,rearrangeEnabled:$,selectSingleItem:L=!1,showProductDetailInfoIcon:V}=e,[_,z]=c.useReducer(S.collectionsReducer,{}),[W,G]=c.useState([exports.ScreenName.Collections,exports.ScreenName.RearrangeProducts].includes(M)?M:exports.ScreenName.Collections),[H,K]=c.useState("grid"),[U,Y]=c.useState(""),[J,Q]=c.useState(""),[X,Z]=c.useState(0),[ee,te]=c.useState(!1),[oe,ce]=c.useState(0),[re,se]=c.useState(""),[ne,le]=c.useState(!1),[ie,ae]=c.useState(!1),[de,ue]=c.useReducer(S.searchReducer,{collections:{},products:{}}),[he,pe]=c.useReducer(S.selectedColectionsReducer,Object.keys(b).length>0?b:{}),Se=c.useRef(null),[Ce,xe]=c.useState(!1),[ge,je]=c.useState();c.useEffect((()=>{te(!0),ae(!0),e.collectionFetcher(X,y).then((e=>{z({type:"fetched",data:(null==e?void 0:e.collections)||{}}),te(!1),Z((e=>e+1)),ae(!1)})).catch()}),[]),c.useEffect((()=>{let e=0;Object.keys(he||[]).forEach((t=>{var o;Object.keys((null===(o=he[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=he[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),ce(e)})),c.useEffect((()=>{J&&(te(!0),e.productFetcher(J,y).then((e=>{Object.keys(e).length&&z({type:"productsFetched",data:{collectionId:J,products:e}}),te(!1)})).catch())}),[J]),c.useEffect((()=>{const t=setTimeout((()=>{"rearrange"!==W&&(re.length?(le(!0),e.searchFetcher(y,re).then((e=>{"collections"in e&&"products"in e?(ue({type:"set",data:e}),z({type:"searched",data:e.collections})):(ue({type:"set",data:{collections:{},products:e}}),z({type:"searched",data:e})),G("searchProducts"),te(!1),le(!1)}))):G("collections"))}),800);return()=>clearTimeout(t)}),[re]),c.useEffect((()=>{N&&(e.onAdd(he,oe),ye())}),[N]),c.useEffect((()=>{L&&Object.keys(he||{}).length&&oe&&(e.onAdd(he,oe),ye())}),[L,he,oe]);const ye=()=>{pe({type:"reset",data:{}})},be=t.jsxs(g.ContainerStyle,{children:[e.postHeader&&t.jsx("div",Object.assign({style:{padding:"0 24px"}},{children:e.postHeader})),!e.hideGlobalSearch&&t.jsx(t.Fragment,{children:("collections"===W||"searchProducts"===W)&&t.jsx("div",Object.assign({style:{padding:w?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t.jsx(n.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>ne?t.jsx(i.Spinner,{size:"small",color:r.COLORS.content.primary}):t.jsx(o.default,{})},id:"listInput",height:"24px",type:"text",value:re,onChangeText:e=>{e.length&&e.trim().length?se(e):se("")}})}))}),t.jsxs(g.ScrollContainerStyle,Object.assign({ref:Se},{children:["collections"===W&&t.jsx(d.CollectionsScreen,{customCollectionRestriction:e.customCollectionRestriction,dataLoading:ie,collections:_,selectedCollectionsDispatch:pe,setCollectionId:Y,setSelectedCollectionId:Q,setScreen:G,selectedCollections:he,collectionFetcher:e.collectionFetcher,storeId:y,collectionsDispatch:z,setSaveDisabled:te,pagingControls:{curPage:X,setCurPage:Z},hideCollectionCheckbox:k,renderWithoutModal:w,pickerType:A}),"products"===W&&U&&t.jsx(S.CollectionIdContext.Provider,Object.assign({value:U},{children:t.jsx(h.ProductsScreen,{hideInCollectionSearch:e.hideInCollectionSearch,customCollectionRestriction:e.customCollectionRestriction,productFetcher:e.productFetcher,setScreen:G,storeId:y,data:_[U],collectionsDispatch:z,selectedCollectionsDispatch:pe,selectedData:he,setSaveDisabled:te,searchInCollectionFetcher:e.searchInCollectionFetcher,hideProductCheckbox:F,outOfStockAction:O,hideVariantCheckbox:R,selectProductsFromCustomCollection:T,renderWithoutModal:w,pickerType:A,hideProductVariants:B,fbStatusFetcher:e.fbStatusFetcher,onInfoIconClick:e=>{xe(!0),je(e)},showProductDetailInfoIcon:V})})),"view"===W&&t.jsx(x.SelectedScreen,{selectedCollections:he||{},selectedCollectionsDispatch:pe,setScreen:G,collections:_,outOfStockAction:O,storeId:y,fbStatusFetcher:e.fbStatusFetcher}),"rearrange"===W&&t.jsx(p.RearrangeScreen,{selectedCollections:he||{},selectedCollectionsDispatch:pe,setScreen:G,outOfStockAction:O,rearrangeViewType:"grid"===H?"list":"grid",scrollContainerRef:Se,storeId:y,fbStatusFetcher:e.fbStatusFetcher}),"searchProducts"===W&&t.jsx(C.SearchScreen,{customCollectionRestriction:e.customCollectionRestriction,selectedCollections:he||{},searchedCollections:de||{},searchedCollectionsDispatch:ue,selectedCollectionsDispatch:pe,setScreen:G,collections:_,onBackPress:()=>{se(""),ue({type:"set",data:{collections:{},products:{}}})},pickerType:A,hideProductCheckbox:F,hideProductVariants:B,hideVariantCheckbox:R,storeId:y,fbStatusFetcher:e.fbStatusFetcher,setCollectionId:Y,setSelectedCollectionId:Q,renderWithoutModal:w,hideCollectionCheckbox:k})]}))]});return t.jsx(t.Fragment,{children:w?be:t.jsxs(l.StyledModal,Object.assign({zIndex:v,open:m,onClose:()=>{null==f||f(),ye()},headingTitle:D||("collections"===W||"products"===W?"Select Products":"view"===W?"Selected Products":"searchProducts"===W?"Searched Products":"rearrange"===W?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:E||"600px"},headerRightCustomElement:"rearrange"===W?(console.log("ignore:",K),t.jsx(t.Fragment,{})):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:{buttonText:ee?"Loading...":W===exports.ScreenName.RearrangeProducts?"Done":"Add",disabled:ee||oe<1||P&&oe<P||!P&&I&&oe>I||!1,onClick:()=>{e.onAdd(he,oe),ye()}},wrapperStyle:e.stickyFooter?{height:"calc(100vh - 168px)"}:void 0,footerLeftCustomElement:q?t.jsx(t.Fragment,{}):P&&oe>P?t.jsx(a.Tag,{tagText:`You can only select ${P} products`,type:"negative"}):I&&oe>I?t.jsx(a.Tag,{tagText:`You can only select ${I} products`,type:"negative"}):oe>0?t.jsx(s.Button,{onClick:()=>{G($?exports.ScreenName.RearrangeProducts:exports.ScreenName.SelectedProducts)},buttonText:P?`${oe}/${P} products selected`:`${oe} products selected`,buttonType:["rearrange","view"].includes(W)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(W)}):t.jsx(s.Button,{disabled:!0,buttonText:P?`${oe}/${P} products selected`:`${oe} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:Ce},{children:[be,Ce&&ge?t.jsx(u.ProductInfoOverlay,{productData:ge,outOfStockAction:O,onClose:()=>{xe(!1)}}):t.jsx(t.Fragment,{})]}))})};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Product, ProductVariant } from './modal';
|
|
2
2
|
import { OUT_OF_STOCK_ACTION } from './type';
|
|
3
|
+
/**
|
|
4
|
+
* When user presses i icon on a product, we show the overlay.
|
|
5
|
+
* In case of a product, contains products image, product name & description
|
|
6
|
+
* In case of a variant, contains variant image, variant name,
|
|
7
|
+
* description as product name, variant tag
|
|
8
|
+
*/
|
|
3
9
|
export declare const ProductInfoOverlay: (props: {
|
|
4
10
|
productData: Product | ProductVariant;
|
|
5
11
|
onClose: () => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("styled-components"),o=require("../../constants/Theme.js"),r=require("../../assets/icons/cross.svg.js"),i=require("../icon-button/IconButton.js"),a=require("../shimmer-image/ShimmerImage.js"),s=require("../TypographyStyle.js"),d=require("./ProductPickerTag.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=n(t);const c=t=>{var o;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("styled-components"),o=require("../../constants/Theme.js"),r=require("../../assets/icons/cross.svg.js"),i=require("../icon-button/IconButton.js"),a=require("../shimmer-image/ShimmerImage.js"),s=require("../TypographyStyle.js"),d=require("./ProductPickerTag.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=n(t);const c=t=>{var o;const r=void 0===t.productData.variants;return e.jsxs(f,{children:[e.jsx(g,{children:e.jsx(a.ShimmerImage,{imageUrl:t.productData.image,width:"200px",height:200,borderRadius:4})}),e.jsxs(h,{children:[e.jsx(s.TitleSmall,Object.assign({style:{display:"flex"}},{children:t.productData.name})),e.jsx(s.BodyCaption,{style:{display:"flex",flexDirection:"column"},dangerouslySetInnerHTML:{__html:null!==(o=t.productData.description)&&void 0!==o?o:""}}),e.jsx(d.ProductPickerTag,{isVariant:r,data:t.productData,outOfStockAction:t.outOfStockAction})]})]})},u=l.default.div`
|
|
2
2
|
display: flex;
|
|
3
3
|
flex: 1;
|
|
4
4
|
background: rgba(0, 0, 0, 0.5);
|
|
@@ -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"),i=require("lodash"),n=require("react"),s=require("../../constants/Theme.js"),r=require("../../assets/icons/info.svg.js"),l=require("../checkBox/CheckBox.js"),d=require("../icon-button/IconButton.js"),a=require("../input/Input.js"),u=require("../shimmer/ShimmerComponent/BikShimmer.js"),h=require("../shimmer-image/ShimmerImage.js"),v=require("../spinner/Spinner.js"),p=require("../tooltips/Tooltip.js"),j=require("../TypographyStyle.js"),g=require("./emptyState.js"),b=require("./ProductPickerTag.js"),f=require("./reducers.js"),x=require("./style.js"),y=require("./type.js"),I=require("./utility.js");const k=t=>{const{collectionId:o,productId:c,data:i,selectedData:n,selectedCollectionsDispatch:s,viewOnly:r,upliftAdditions:l,isProductPartiallyChecked:d,hideProductCheckbox:a,outOfStockAction:u,hideVariantCheckbox:h,hideProductVariants:v,pickerType:p,onInfoIconClick:j,showProductDetailInfoIcon:g}=t,b=e=>{var t,i,s,r,l,d;if(!(null===(i=null===(t=null==n?void 0:n[o])||void 0===t?void 0:t.products)||void 0===i?void 0:i[c]))return!1;return!!(null===(d=null===(l=null===(r=null===(s=null==n?void 0:n[o])||void 0===s?void 0:s.products)||void 0===r?void 0:r[c])||void 0===l?void 0:l.variants)||void 0===d?void 0:d[e])};return e.jsxs("div",{children:[e.jsx(O,{isVariant:!1,data:i,productId:c,collectionId:o,isSelected:!!(null===(x=null===(f=null==n?void 0:n[o])||void 0===f?void 0:f.products)||void 0===x?void 0:x[c]),isPartiallyChecked:d,selectedCollectionsDispatch:s,upliftAdditions:l,viewOnly:r,hideProductCheckbox:a,hideVariantCheckbox:h,hideProductVariants:v,pickerType:p,outOfStockAction:u,onInfoIconClick:j,showProductDetailInfoIcon:g},c),v?null:(()=>{const e=Object.keys(i.variants||[]);let t=!1;return!(e.length<=1)||(e.forEach((e=>{var o,c;t=null!==(c=null===(o=i.variants)||void 0===o?void 0:o[e].name.includes(i.name))&&void 0!==c&&c})),!t)})()&&Object.keys(i.variants||[]).map((t=>e.jsx(O,{isVariant:!0,hideVariantCheckbox:h,data:i.variants[t],variantId:t,productId:c,viewOnly:r,upliftAdditions:l,collectionId:o,isSelected:b(t),selectedCollectionsDispatch:s,outOfStockAction:u,onInfoIconClick:j,showProductDetailInfoIcon:g},t)))]});var f,x},O=t=>{const{isVariant:o,data:c,productId:i,collectionId:n,variantId:a,isSelected:u,selectedCollectionsDispatch:v,viewOnly:g,upliftAdditions:f,isPartiallyChecked:y,hideProductCheckbox:I,outOfStockAction:k,hideVariantCheckbox:O,hideProductVariants:C,pickerType:m,onInfoIconClick:P,showProductDetailInfoIcon:S}=t;return e.jsxs(x.ProductCardStyle,Object.assign({isVariant:o,onClick:e=>{"PRODUCT"===m&&C&&(e.stopPropagation(),v({type:"reset",data:{}}),f("variantSelected",{productId:i,variantId:a||Object.keys(c.variants)[0],collectionId:n,variant:c}))},isActive:u},{children:[o&&!g&&!O||!o&&!g&&!I?e.jsx(l.CheckBox,{isChecked:u,isPartiallyChecked:y||!1,onValueChange:function(e){o?e?f("variantSelected",{productId:i,variantId:a,collectionId:n,variant:c}):v({type:"variantUnselected",data:{productId:i,variantId:a,collectionId:n}}):e?f("productSelected",{productId:i,collectionId:n,product:c}):v({type:"productUnselected",data:{productId:i,collectionId:n}})}}):e.jsx(e.Fragment,{}),e.jsx("div",{children:e.jsx(h.ShimmerImage,{width:40,height:40,imageUrl:c.image,alt:"Item",borderRadius:4})}),e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",flex:1}},{children:[e.jsxs("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},{children:[e.jsx(p.Tooltip,Object.assign({variant:"light",body:c.name,placement:"bottom",delay:400},{children:e.jsx(j.BodyPrimary,Object.assign({numberOfLines:1},{children:c.name}))})),S&&e.jsx(d.IconButton,{onClick:()=>{null==P||P(c)},Icon:()=>e.jsx(r.default,{width:20,height:20,color:s.COLORS.content.placeholder})})]})),e.jsx(b.ProductPickerTag,{isVariant:o,data:c,outOfStockAction:k})]}))]}))};exports.ProductCard=O,exports.ProductGroup=k,exports.ProductsScreen=r=>{const{data:h,collectionsDispatch:p,selectedData:b,selectedCollectionsDispatch:O,productFetcher:C,storeId:m,setScreen:P,setSaveDisabled:S,hideInCollectionSearch:A,customCollectionRestriction:E,hideProductCheckbox:T,outOfStockAction:V=y.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:D=!1,selectProductsFromCustomCollection:w=!1,pickerType:q,hideProductVariants:R,fbStatusFetcher:B,onInfoIconClick:F,showProductDetailInfoIcon:L}=r,U=n.useContext(f.CollectionIdContext),_=n.useRef(null),H=n.useRef(0),[J,K]=n.useState(!1),[M,N]=n.useState(""),[W,z]=n.useState(!1),[G,Q]=n.useState(h),X=n.useRef(!1);n.useEffect((()=>{const e=setTimeout((()=>{M.length?(z(!0),r.searchInCollectionFetcher(m,U,M).then((e=>{const t=i.cloneDeep(h);t.products=e,Q(t);const o=I.getVariantIdsToFetchAtProductLevel(null!=e?e:{});$(o,null!=e?e:{},!0),S(!1),z(!1)}))):Q(h)}),800);return()=>clearTimeout(e)}),[M]),n.useEffect((()=>{var e,t,o,c,i,n,s,r;console.log("vj: collectionId change before",h,h.products,null===(t=Object.keys(null!==(e=h.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length,X),X.current=!1,H.current=Math.floor((null===(c=Object.keys(null!==(o=h.products)&&void 0!==o?o:{}))||void 0===c?void 0:c.length)/10);const l=I.getVariantIdsToFetchAtProductLevel(null!==(i=h.products)&&void 0!==i?i:{});$(l,null!==(n=h.products)&&void 0!==n?n:{}),console.log("vj: collectionId change after",h,h.products,null===(r=Object.keys(null!==(s=h.products)&&void 0!==s?s:{}))||void 0===r?void 0:r.length,X)}),[U]);const Y=!!E&&h.isSmartCollection,Z=e=>{var t,o,c,i,n,s,r,l;let d=0,a=0;return!!((null===(o=null===(t=null==b?void 0:b[U])||void 0===t?void 0:t.products)||void 0===o?void 0:o[e])&&(null===(n=Object.keys((null===(i=null===(c=null==G?void 0:G.products)||void 0===c?void 0:c[e])||void 0===i?void 0:i.variants)||[]))||void 0===n||n.forEach((()=>a++)),Object.keys((null===(l=null===(r=null===(s=null==b?void 0:b[U])||void 0===s?void 0:s.products)||void 0===r?void 0:r[e])||void 0===l?void 0:l.variants)||[]).forEach((()=>d++)),d>0&&a!==d))};n.useEffect((()=>{(null==h?void 0:h.products)||ee(10)}),[]);const $=(e,t,o)=>{console.log("fetchFbStatusAndDispatchProducts",{variantIdsToFetchFbStatus:e,fbStatusFetcher:B}),B||(o?I.markVariantsAsApprovedProductsLevel(t,p,U,G,Q):I.markVariantsAsApprovedProductsLevel(t,p,U)),e.length>0&&B&&B(m,e).then((e=>{const c=Object.assign({},t);Object.keys(t).forEach((o=>{var i,n;Object.keys(null!==(n=null===(i=null==t?void 0:t[o])||void 0===i?void 0:i.variants)&&void 0!==n?n:{}).forEach((i=>{var n,s;const r=null===(n=null==t?void 0:t[o].variants)||void 0===n?void 0:n[i];r&&"REJECTED"===e[i]?r.fbStatus="REJECTED":r&&"APPROVED"===e[i]&&(r.fbStatus="APPROVED");const l=null===(s=null==c?void 0:c[o])||void 0===s?void 0:s.variants;l&&l[i]&&(l[i]=r)}))})),o?(Q((e=>{const t=Object.assign({},e);return t.products=c,t})),p({type:"productsPaged",data:{collectionId:U,products:c}})):p({type:"productsPaged",data:{collectionId:U,products:c}})})).catch((e=>{o?I.markVariantsAsApprovedProductsLevel(t,p,U,G,Q):I.markVariantsAsApprovedProductsLevel(t,p,U)}))};n.useEffect((()=>{console.log("vj: observertarget",_.current);const e=new IntersectionObserver((e=>{console.log("vj: observertargetinside",e),e[0].isIntersecting&&(console.log("vj: nextPageRef",H.current,X),H.current>=0&&!X.current&&!M&&(S(!0),K(!0),C(U,m,10,H.current).then((e=>{if(console.log("vj: fetched products",e,X,Object.keys(e).length),Object.keys(e).length||(console.log("vj: setHasAllCollectionLoaded ",!0),X.current=!0),Object.keys(e).length){const t=G;t.products=Object.assign(Object.assign({},G.products),e),Q(t);const o=I.getVariantIdsToFetchAtProductLevel(e);$(o,e),H.current+=1}K(!1),S(!1)})).catch()))}),{threshold:1});return _.current&&e.observe(_.current),()=>{_.current&&e.unobserve(_.current)}}),[_,M]);const ee=e=>{console.log("vj: getProductsForCollection"),S(!0),z(!0),C(U,m,e,0).then((t=>{if(Object.keys(t).length||(console.log("vj: setHasAllCollectionLoaded ",!0),X.current=!0),Object.keys(t).length){Q(Object.assign(Object.assign({},G),{products:t})),console.log("vj: next page when products loaded",H.current);const e=I.getVariantIdsToFetchAtProductLevel(t);$(e,t),H.current=1}console.log("vj: product data",{productData:t,limit:e,data:h}),e||O({type:"selected",data:{id:U,val:Object.assign(Object.assign({},h),{products:t})}}),S(!1),z(!1)})).catch()},te=(e,t)=>{const o=I.liftTheStateUp(t,h);O({type:e,data:Object.assign(Object.assign({},o),{isRestricted:E})})};return e.jsxs("div",{children:[e.jsxs(x.ProductScreenHeader,{children:[e.jsx(d.IconButton,{Icon:t.default,height:16,onClick:()=>{P("collections")}}),e.jsx(j.BodyCaption,Object.assign({style:{color:s.COLORS.content.secondary}},{children:h.name}))]}),!A&&e.jsx("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(a.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>W&&M.length?e.jsx(v.Spinner,{size:"small",color:s.COLORS.content.primary}):e.jsx(c.default,{})},id:"listInput",height:"24px",type:"text",value:M,onChangeText:e=>{e.length&&e.trim().length?N(e):N("")},placeholder:"Search products in this collection..."})})),e.jsxs("div",{children:[Object.keys((null==G?void 0:G.products)||[]).length>0&&!Y&&!M.length&&!T&&"-1"!==U&&e.jsxs(x.ProductScreenCollectionCardStyle,{children:[e.jsx(l.CheckBox,{isChecked:!!(null==b?void 0:b[U]),isPartiallyChecked:(e=>{var t;let o=0,c=0;if(b[e]){const i=null==h?void 0:h.products;i&&Object.keys(i).forEach((e=>{var t;const c=null===(t=i[e])||void 0===t?void 0:t.variants;c&&Object.keys(c).forEach((e=>o+=1))}));const n=null===(t=b[e])||void 0===t?void 0:t.products;return n&&Object.keys(n).forEach((e=>{var t;const o=null===(t=n[e])||void 0===t?void 0:t.variants;o&&Object.keys(o).forEach((()=>c+=1))})),c>0&&o!==c}return!1})(U),onValueChange:function(e){e?ee():O({type:"unselected",data:{id:U}})}}),e.jsx("div",Object.assign({style:{width:40,height:40}},{children:e.jsx(o.default,{})})),e.jsx(j.TitleRegular,{children:"All Products"})]}),Object.keys((null==G?void 0:G.products)||[]).length?Object.keys(G.products||[]).map((t=>e.jsx(k,{outOfStockAction:V,collectionId:U,isProductPartiallyChecked:Z(t),productId:t,data:G.products[t],selectedData:b,selectedCollectionsDispatch:O,viewOnly:!w&&!!Y,upliftAdditions:te,hideProductCheckbox:T,hideVariantCheckbox:D,hideProductVariants:R,pickerType:q,onInfoIconClick:F,showProductDetailInfoIcon:L},t))):W?[1,2,3,4,5,6,7,8,9,10].map(((t,o)=>e.jsx("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),o))):e.jsx(g.EmptyState,{title:"No products to show",subtitle:M.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),e.jsx("div",{ref:_})]}),J&&[1,2,3,4,5].map(((t,o)=>e.jsx("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),o)))]})};
|
|
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"),i=require("../../assets/icons/search.svg.js"),n=require("lodash"),c=require("react"),r=require("../../constants/Theme.js"),s=require("../../assets/icons/info.svg.js"),d=require("../checkBox/CheckBox.js"),l=require("../icon-button/IconButton.js"),a=require("../input/Input.js"),u=require("../shimmer/ShimmerComponent/BikShimmer.js"),v=require("../shimmer-image/ShimmerImage.js"),h=require("../spinner/Spinner.js"),p=require("../tooltips/Tooltip.js"),j=require("../TypographyStyle.js"),f=require("./emptyState.js"),g=require("./ProductPickerTag.js"),x=require("./reducers.js"),y=require("./style.js"),I=require("./type.js"),k=require("./utility.js");const b=t=>{const{collectionId:o,productId:i,data:n,selectedData:c,selectedCollectionsDispatch:r,viewOnly:s,upliftAdditions:d,isProductPartiallyChecked:l,hideProductCheckbox:a,outOfStockAction:u,hideVariantCheckbox:v,hideProductVariants:h,pickerType:p,onInfoIconClick:j,showProductDetailInfoIcon:f}=t,g=e=>{var t,n,r,s,d,l;if(!(null===(n=null===(t=null==c?void 0:c[o])||void 0===t?void 0:t.products)||void 0===n?void 0:n[i]))return!1;return!!(null===(l=null===(d=null===(s=null===(r=null==c?void 0:c[o])||void 0===r?void 0:r.products)||void 0===s?void 0:s[i])||void 0===d?void 0:d.variants)||void 0===l?void 0:l[e])};return e.jsxs("div",{children:[e.jsx(O,{isVariant:!1,data:n,productId:i,collectionId:o,isSelected:!!(null===(y=null===(x=null==c?void 0:c[o])||void 0===x?void 0:x.products)||void 0===y?void 0:y[i]),isPartiallyChecked:l,selectedCollectionsDispatch:r,upliftAdditions:d,viewOnly:s,hideProductCheckbox:a,hideVariantCheckbox:v,hideProductVariants:h,pickerType:p,outOfStockAction:u,onInfoIconClick:j,showProductDetailInfoIcon:f},i),h?null:(()=>{const e=Object.keys(n.variants||[]);let t=!1;return!(e.length<=1)||(e.forEach((e=>{var o,i;t=null!==(i=null===(o=n.variants)||void 0===o?void 0:o[e].name.includes(n.name))&&void 0!==i&&i})),!t)})()&&Object.keys(n.variants||[]).map((t=>e.jsx(O,{isVariant:!0,hideVariantCheckbox:v,data:n.variants[t],variantId:t,productId:i,viewOnly:s,upliftAdditions:d,collectionId:o,isSelected:g(t),selectedCollectionsDispatch:r,outOfStockAction:u,onInfoIconClick:j,showProductDetailInfoIcon:f},t)))]});var x,y},O=t=>{const{isVariant:o,data:i,productId:n,collectionId:c,variantId:a,isSelected:u,selectedCollectionsDispatch:h,viewOnly:f,upliftAdditions:x,isPartiallyChecked:I,hideProductCheckbox:k,outOfStockAction:b,hideVariantCheckbox:O,hideProductVariants:C,pickerType:m,onInfoIconClick:P,showProductDetailInfoIcon:S}=t;return e.jsxs(y.ProductCardStyle,Object.assign({isVariant:o,onClick:e=>{"PRODUCT"===m&&C&&(e.stopPropagation(),h({type:"reset",data:{}}),x("variantSelected",{productId:n,variantId:a||Object.keys(i.variants)[0],collectionId:c,variant:i}))},isActive:u},{children:[o&&!f&&!O||!o&&!f&&!k?e.jsx(d.CheckBox,{isChecked:u,isPartiallyChecked:I||!1,onValueChange:function(e){o?e?x("variantSelected",{productId:n,variantId:a,collectionId:c,variant:i}):h({type:"variantUnselected",data:{productId:n,variantId:a,collectionId:c}}):e?x("productSelected",{productId:n,collectionId:c,product:i}):h({type:"productUnselected",data:{productId:n,collectionId:c}})}}):e.jsx(e.Fragment,{}),e.jsx("div",{children:e.jsx(v.ShimmerImage,{width:40,height:40,imageUrl:i.image,alt:"Item",borderRadius:4})}),e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",flex:1}},{children:[e.jsxs("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},{children:[e.jsx(p.Tooltip,Object.assign({variant:"light",body:i.name,placement:"bottom",delay:400},{children:e.jsx(j.BodyPrimary,Object.assign({numberOfLines:1},{children:i.name}))})),S&&e.jsx(l.IconButton,{onClick:()=>{null==P||P(i)},Icon:()=>e.jsx(s.default,{width:20,height:20,color:r.COLORS.content.placeholder})})]})),e.jsx(g.ProductPickerTag,{isVariant:o,data:i,outOfStockAction:b})]}))]}))};exports.ProductCard=O,exports.ProductGroup=b,exports.ProductsScreen=s=>{const{data:v,collectionsDispatch:p,selectedData:g,selectedCollectionsDispatch:O,productFetcher:C,storeId:m,setScreen:P,setSaveDisabled:S,hideInCollectionSearch:E,customCollectionRestriction:A,hideProductCheckbox:T,outOfStockAction:V=I.OUT_OF_STOCK_ACTION.BLUR,hideVariantCheckbox:D=!1,selectProductsFromCustomCollection:q=!1,pickerType:w,hideProductVariants:B,fbStatusFetcher:R,onInfoIconClick:L,showProductDetailInfoIcon:F}=s,U=c.useContext(x.CollectionIdContext),_=c.useRef(null),H=c.useRef(0),[J,K]=c.useState(!1),[M,N]=c.useState(""),[W,z]=c.useState(!1),[G,Q]=c.useState(v),X=c.useRef(!1);c.useEffect((()=>{const e=setTimeout((()=>{M.length?(z(!0),s.searchInCollectionFetcher(m,U,M).then((e=>{const t=n.cloneDeep(v);t.products=e,Q(t);const o=k.getVariantIdsToFetchAtProductLevel(null!=e?e:{});$(o,null!=e?e:{},!0),S(!1),z(!1)}))):Q(v)}),800);return()=>clearTimeout(e)}),[M]),c.useEffect((()=>{var e,t,o,i;X.current=!1,H.current=Math.floor((null===(t=Object.keys(null!==(e=v.products)&&void 0!==e?e:{}))||void 0===t?void 0:t.length)/10);const n=k.getVariantIdsToFetchAtProductLevel(null!==(o=v.products)&&void 0!==o?o:{});$(n,null!==(i=v.products)&&void 0!==i?i:{})}),[U]);const Y=!!A&&v.isSmartCollection,Z=e=>{var t,o,i,n,c,r,s,d,l,a,u,v,h,p,j,f,x,y,I;let k=0,b=0;if(null===(o=null===(t=null==g?void 0:g[U])||void 0===t?void 0:t.products)||void 0===o?void 0:o[e]){const t=(null===(c=null===(n=null===(i=null==g?void 0:g[U])||void 0===i?void 0:i.products)||void 0===n?void 0:n[e])||void 0===c?void 0:c.variants)||[];if(1===Object.keys(t).length)for(const o in t){const t=null===(s=null===(r=null==g?void 0:g[U])||void 0===r?void 0:r.products)||void 0===s?void 0:s[e],i=null===(u=null===(a=null===(l=null===(d=null==g?void 0:g[U])||void 0===d?void 0:d.products)||void 0===l?void 0:l[e])||void 0===a?void 0:a.variants)||void 0===u?void 0:u[o];if(null===(v=null==i?void 0:i.name)||void 0===v?void 0:v.includes(null!==(h=null==t?void 0:t.name)&&void 0!==h?h:""))return!1}if(null===(f=Object.keys((null===(j=null===(p=null==G?void 0:G.products)||void 0===p?void 0:p[e])||void 0===j?void 0:j.variants)||[]))||void 0===f||f.forEach((()=>b++)),Object.keys((null===(I=null===(y=null===(x=null==g?void 0:g[U])||void 0===x?void 0:x.products)||void 0===y?void 0:y[e])||void 0===I?void 0:I.variants)||[]).forEach((()=>k++)),k>0&&b!==k)return!0}return!1};c.useEffect((()=>{(null==v?void 0:v.products)||ee(10)}),[]);const $=(e,t,o)=>{R||(o?k.markVariantsAsApprovedProductsLevel(t,p,U,G,Q):k.markVariantsAsApprovedProductsLevel(t,p,U)),e.length>0&&R&&R(m,e).then((e=>{const i=Object.assign({},t);Object.keys(t).forEach((o=>{var n,c;Object.keys(null!==(c=null===(n=null==t?void 0:t[o])||void 0===n?void 0:n.variants)&&void 0!==c?c:{}).forEach((n=>{var c,r;const s=null===(c=null==t?void 0:t[o].variants)||void 0===c?void 0:c[n];s&&"REJECTED"===e[n]?s.fbStatus="REJECTED":s&&"APPROVED"===e[n]&&(s.fbStatus="APPROVED");const d=null===(r=null==i?void 0:i[o])||void 0===r?void 0:r.variants;d&&d[n]&&(d[n]=s)}))})),o?(Q((e=>{const t=Object.assign({},e);return t.products=i,t})),p({type:"productsPaged",data:{collectionId:U,products:i}})):p({type:"productsPaged",data:{collectionId:U,products:i}})})).catch((e=>{o?k.markVariantsAsApprovedProductsLevel(t,p,U,G,Q):k.markVariantsAsApprovedProductsLevel(t,p,U)}))};c.useEffect((()=>{const e=new IntersectionObserver((e=>{e[0].isIntersecting&&H.current>=0&&!X.current&&!M&&(S(!0),K(!0),C(U,m,10,H.current).then((e=>{if(Object.keys(e).length||(X.current=!0),Object.keys(e).length){const t=G;t.products=Object.assign(Object.assign({},G.products),e),Q(t);const o=k.getVariantIdsToFetchAtProductLevel(e);$(o,e),H.current+=1}K(!1),S(!1)})).catch())}),{threshold:1});return _.current&&e.observe(_.current),()=>{_.current&&e.unobserve(_.current)}}),[_,M]);const ee=e=>{S(!0),z(!0),C(U,m,e,0).then((t=>{if(Object.keys(t).length||(X.current=!0),Object.keys(t).length){Q(Object.assign(Object.assign({},G),{products:t}));const e=k.getVariantIdsToFetchAtProductLevel(t);$(e,t),H.current=1}e||O({type:"selected",data:{id:U,val:Object.assign(Object.assign({},v),{products:t})}}),S(!1),z(!1)})).catch()},te=(e,t)=>{const o=k.liftTheStateUp(t,v);O({type:e,data:Object.assign(Object.assign({},o),{isRestricted:A})})};return e.jsxs("div",{children:[e.jsxs(y.ProductScreenHeader,{children:[e.jsx(l.IconButton,{Icon:t.default,height:16,onClick:()=>{P("collections")}}),e.jsx(j.BodyCaption,Object.assign({style:{color:r.COLORS.content.secondary}},{children:v.name}))]}),!E&&e.jsx("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(a.Input,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>W&&M.length?e.jsx(h.Spinner,{size:"small",color:r.COLORS.content.primary}):e.jsx(i.default,{})},id:"listInput",height:"24px",type:"text",value:M,onChangeText:e=>{e.length&&e.trim().length?N(e):N("")},placeholder:"Search products in this collection..."})})),e.jsxs("div",{children:[Object.keys((null==G?void 0:G.products)||[]).length>0&&!Y&&!M.length&&!T&&"-1"!==U&&e.jsxs(y.ProductScreenCollectionCardStyle,{children:[e.jsx(d.CheckBox,{isChecked:!!(null==g?void 0:g[U]),isPartiallyChecked:(e=>{var t;let o=0,i=0;if(g[e]){const n=null==v?void 0:v.products;n&&Object.keys(n).forEach((e=>{var t;const i=null===(t=n[e])||void 0===t?void 0:t.variants;i&&Object.keys(i).forEach((e=>o+=1))}));const c=null===(t=g[e])||void 0===t?void 0:t.products;return c&&Object.keys(c).forEach((e=>{var t;const o=null===(t=c[e])||void 0===t?void 0:t.variants;o&&Object.keys(o).forEach((()=>i+=1))})),i>0&&o!==i}return!1})(U),onValueChange:function(e){e?ee():O({type:"unselected",data:{id:U}})}}),e.jsx("div",Object.assign({style:{width:40,height:40}},{children:e.jsx(o.default,{})})),e.jsx(j.TitleRegular,{children:"All Products"})]}),Object.keys((null==G?void 0:G.products)||[]).length?Object.keys(G.products||[]).map((t=>e.jsx(b,{outOfStockAction:V,collectionId:U,isProductPartiallyChecked:Z(t),productId:t,data:G.products[t],selectedData:g,selectedCollectionsDispatch:O,viewOnly:!q&&!!Y,upliftAdditions:te,hideProductCheckbox:T,hideVariantCheckbox:D,hideProductVariants:B,pickerType:w,onInfoIconClick:L,showProductDetailInfoIcon:F},t))):W?[1,2,3,4,5,6,7,8,9,10].map(((t,o)=>e.jsx("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),o))):e.jsx(f.EmptyState,{title:"No products to show",subtitle:M.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."}),e.jsx("div",{ref:_})]}),J&&[1,2,3,4,5].map(((t,o)=>e.jsx("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:e.jsx(u.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),o)))]})};
|
|
@@ -14,10 +14,28 @@ export interface CollectionsActions {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
export declare function collectionsReducer(collections: Collection, action: CollectionsActions): any;
|
|
17
|
+
/**
|
|
18
|
+
* Pagination reducer used in selected screen.
|
|
19
|
+
* Used for local pagination.
|
|
20
|
+
*
|
|
21
|
+
* Actions used:
|
|
22
|
+
* paginate -> Checks if the products of the collection is already displayed, if yes addes the products, if no adds the entire collection
|
|
23
|
+
* update -> triggers a re-render.
|
|
24
|
+
* set -> adds the data to existing collections.
|
|
25
|
+
* filter -> When user unselects a product in selected screen, we filter out the selected data and show only unselected data.
|
|
26
|
+
*/
|
|
17
27
|
export declare function paginationReducer(collections: SelectedItems, action: SelectedCollectionsActions): SelectedItems;
|
|
18
28
|
export interface SearchReducerActions {
|
|
19
29
|
type: string;
|
|
20
30
|
data: SearchedItems;
|
|
21
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Data used in search screen.
|
|
34
|
+
* To display both collections and products.
|
|
35
|
+
*
|
|
36
|
+
* Actions:
|
|
37
|
+
* set -> no change and sets the data.
|
|
38
|
+
* setProducts -> keeps the collection from search as-is and sets only products
|
|
39
|
+
*/
|
|
22
40
|
export declare function searchReducer(searchedItems: SearchedItems, action: SearchReducerActions): SearchedItems;
|
|
23
41
|
export declare const CollectionIdContext: import("react").Context<string>;
|
|
@@ -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;case"productsPaged":return a=Object.assign({},t),a[e.data.collectionId].products=Object.assign(Object.assign({},a[e.data.collectionId].products),e.data.products),a;case"searched":a=Object.assign({},t);for(const t in e.data)t in a||(a[t]=e.data[t]);return a;default:return{}}},exports.paginationReducer=function(t,e){let a={};switch(e.type){case"paginate":
|
|
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;case"productsPaged":return a=Object.assign({},t),a[e.data.collectionId].products=Object.assign(Object.assign({},a[e.data.collectionId].products),e.data.products),a;case"searched":a=Object.assign({},t);for(const t in e.data)t in a||(a[t]=e.data[t]);return a;default:return{}}},exports.paginationReducer=function(t,e){let a={};switch(e.type){case"paginate":a=Object.assign({},t);for(const t in e.data)if(Object.prototype.hasOwnProperty.call(e.data,t)){const s=e.data[t];if(Object.prototype.hasOwnProperty.call(a,t)){const e=a[t];a[t]=Object.assign(Object.assign({},e),{products:Object.assign(Object.assign({},e.products),s.products)})}else a[t]=s}return a;case"update":return a=Object.assign({},t),a;case"set":return a=Object.assign(Object.assign({},t),e.data),a;case"filter":a={};for(const s in t)if(s in e.data){const c=Object.assign({},t[s]),d=e.data[s],o={};for(const t in c.products)if(t in d.products){const e=Object.assign({},c.products[t]),a=d.products[t],s={};for(const t in e.variants)t in a.variants&&(s[t]=Object.assign({},e.variants[t]));Object.keys(s).length>0&&(e.variants=s,o[t]=e)}Object.keys(o).length>0&&(c.products=o,a[s]=c)}return a;default:return t}},exports.searchReducer=function(t,e){let a={collections:{},products:{}};switch(e.type){case"set":return e.data;case"setProducts":return a=Object.assign({},t),a.products=e.data,a;default:return t}},exports.selectedColectionsReducer=function(e,a){var s,c,d,o,r,n;let i={},u="",l="",p="";switch(a.type){case"selected":return i=t.cloneDeep(e),a.data.val.isSmartCollection&&(a.data.isRestricted&&(i={}),i.isCustom=!0),i[a.data.id]=a.data.val,i;case"unselected":return i=t.cloneDeep(e),(null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[a.data.id],i;case"productUnselected":return i=t.cloneDeep(e),u=a.data.productId,l=a.data.collectionId,delete i[l].products[u],Object.keys(i[l].products).length||((null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[l]),i;case"productSelected":return i=t.cloneDeep(e),u=a.data.productId,l=a.data.collectionId,(null===(s=a.data.catalogOnlyData)||void 0===s?void 0:s.isSmartCollection)&&(a.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[l])||(i[l]=a.data.catalogOnlyData,i[l].products={}),i[l].products[u]=a.data.product,i;case"variantSelected":return i=t.cloneDeep(e),u=a.data.productId,l=a.data.collectionId,p=a.data.variantId,(null===(c=a.data.catalogOnlyData)||void 0===c?void 0:c.isSmartCollection)&&(a.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[l])||(i[l]=a.data.catalogOnlyData,i[l].products={},i[l].products[u]=a.data.productOnlyData,i[l].products[u].variants={}),(null===(o=null===(d=null==i?void 0:i[l])||void 0===d?void 0:d.products)||void 0===o?void 0:o[u])||((null===(r=null==i?void 0:i[l])||void 0===r?void 0:r.products)||(i[l].products={}),i[l].products[u]=a.data.productOnlyData,i[l].products[u].variants={}),i[l].products[u].variants[p]=a.data.variant,i;case"variantUnselected":return i=t.cloneDeep(e),u=a.data.productId,l=a.data.collectionId,p=a.data.variantId,delete i[l].products[u].variants[p],Object.keys(i[l].products[u].variants).length||(delete i[l].products[u],Object.keys(i[l].products).length||((null===(n=i[l])||void 0===n?void 0:n.isSmartCollection)&&(i.isCustom=!1),delete i[l])),i;case"update":return i=Object.assign({},e),i;case"reset":return{};default:return e}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),o=require("../../assets/icons/arrow_left.svg.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),o=require("../../assets/icons/arrow_left.svg.js"),l=require("react"),t=require("../icon-button/IconButton.js"),i=require("../TypographyStyle.js"),d=require("./collectionScreen.js"),c=require("./emptyState.js"),n=require("./productScreen.js"),s=require("./style.js"),r=require("./utility.js");exports.SearchScreen=u=>{const{customCollectionRestriction:v,selectedCollections:a,searchedCollections:h,searchedCollectionsDispatch:p,selectedCollectionsDispatch:j,setScreen:C,collections:y,onBackPress:k,hideVariantCheckbox:b,pickerType:f,hideProductVariants:x,hideProductCheckbox:S,storeId:O,fbStatusFetcher:m,setCollectionId:P,setSelectedCollectionId:g,hideCollectionCheckbox:I,renderWithoutModal:q}=u;l.useEffect((()=>{var e;r.fetchFbStatusCollection(null!==(e=h.products)&&void 0!==e?e:{},O,p,m,"setProducts")}),[null==h?void 0:h.products]);const E=!!v&&(null==a?void 0:a.isCustom),D=e=>{var o,l;let t=0,i=0;if(a[e]){const d=null===(o=y[e])||void 0===o?void 0:o.products;d&&Object.keys(d).forEach((e=>{var o;const l=null===(o=d[e])||void 0===o?void 0:o.variants;l&&Object.keys(l).forEach((e=>t+=1))}));const c=null===(l=a[e])||void 0===l?void 0:l.products;return c&&Object.keys(c).forEach((e=>{var o;const l=null===(o=c[e])||void 0===o?void 0:o.variants;l&&Object.keys(l).forEach((e=>i+=1))})),!(t<=0&&i>0)&&(i>0&&t!==i)}return!1},F=(e,o)=>{var l,t,i,d,c,n,s,r,u,v,p,j,C,y,k,b,f,x,S,O,m;let P=0,g=0;if(null===(t=null===(l=null==a?void 0:a[e])||void 0===l?void 0:l.products)||void 0===t?void 0:t[o]){const l=(null===(c=null===(d=null===(i=null==a?void 0:a[e])||void 0===i?void 0:i.products)||void 0===d?void 0:d[o])||void 0===c?void 0:c.variants)||[];if(1===Object.keys(l).length)for(const t in l){const l=null===(s=null===(n=null==a?void 0:a[e])||void 0===n?void 0:n.products)||void 0===s?void 0:s[o],i=null===(p=null===(v=null===(u=null===(r=null==a?void 0:a[e])||void 0===r?void 0:r.products)||void 0===u?void 0:u[o])||void 0===v?void 0:v.variants)||void 0===p?void 0:p[t];if(null===(j=null==i?void 0:i.name)||void 0===j?void 0:j.includes(null!==(C=null==l?void 0:l.name)&&void 0!==C?C:""))return!1}if(null===(x=Object.keys((null===(f=null===(b=null===(k=null===(y=h.products)||void 0===y?void 0:y[e])||void 0===k?void 0:k.products)||void 0===b?void 0:b[o])||void 0===f?void 0:f.variants)||[]))||void 0===x||x.forEach((()=>g++)),Object.keys((null===(m=null===(O=null===(S=null==a?void 0:a[e])||void 0===S?void 0:S.products)||void 0===O?void 0:O[o])||void 0===m?void 0:m.variants)||[]).forEach((()=>P++)),P>0&&g!==P)return!0}return!1};return e.jsxs("div",{children:[e.jsxs(s.SelectedScreenHeader,{children:[e.jsx(t.IconButton,{Icon:o.default,onClick:()=>{C("collections"),k()}}),e.jsx(i.BodyCaption,{children:"Searched Products"})]}),e.jsx("div",{children:Object.keys(null==h?void 0:h.products).length||Object.keys(null==h?void 0:h.collections).length?e.jsxs(e.Fragment,{children:[e.jsx(e.Fragment,{children:Object.keys(null==h?void 0:h.collections).map((o=>e.jsx(d.CollectionCard,{customCollectionRestriction:v,data:null==y?void 0:y[o],isDisabled:E&&!(null==a?void 0:a[o]),isChecked:!!(null==a?void 0:a[o]),isPartiallyChecked:D(o),selectedCollectionsDispatch:j,setCollectionId:P,setSelectedCollectionId:g,setScreen:C,id:o,hideCollectionCheckbox:I||"-1"===o,selectedCollections:a,renderWithoutModal:q,pickerType:f,usedInSearch:!0},o)))}),e.jsx(e.Fragment,{children:Object.keys(null==h?void 0:h.products).map((o=>{var l,t;return Object.keys((null===(t=null===(l=null==h?void 0:h.products)||void 0===l?void 0:l[o])||void 0===t?void 0:t.products)||[]).map((l=>{var t,i;let d=!1;return(null===(t=null==h?void 0:h.products)||void 0===t?void 0:t.isCustom)&&(d=!0),e.jsx(n.ProductGroup,{collectionId:o,upliftAdditions:(e,l)=>((e,o,l)=>{var t;const i=r.liftTheStateUp(l,null===(t=null==h?void 0:h.products)||void 0===t?void 0:t[e]);j({type:o,data:Object.assign(Object.assign({},i),{isRestricted:v})})})(o,e,l),productId:l,data:(null===(i=null==h?void 0:h.products)||void 0===i?void 0:i[o].products)[l],isProductPartiallyChecked:F(o,l),selectedData:a,selectedCollectionsDispatch:j,viewOnly:d,hideProductCheckbox:S,hideVariantCheckbox:b,hideProductVariants:x,pickerType:f},l)}))}))})]}):e.jsx(c.EmptyState,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};
|
|
@@ -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"),
|
|
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("react"),l=require("../icon-button/IconButton.js"),i=require("../TypographyStyle.js"),r=require("./emptyState.js"),n=require("./productScreen.js"),d=require("./reducers.js"),u=require("./style.js"),c=require("./utility.js");exports.SelectedScreen=s=>{const{selectedCollections:v,selectedCollectionsDispatch:a,setScreen:p,collections:f,outOfStockAction:j,storeId:y,fbStatusFetcher:h}=s,S=o.useRef(0),b=o.useRef(null),[x,g]=o.useReducer(d.paginationReducer,{});o.useEffect((()=>{S.current=0;const e=c.paginateSelectedItems(v,10,0);g({type:"paginate",data:e}),c.fetchFbStatusCollection(e,y,g,h,"set"),S.current+=1}),[]),o.useEffect((()=>{g({type:"filter",data:v})}),[v]),o.useEffect((()=>{const e=new IntersectionObserver((e=>{if(e[0].isIntersecting&&S.current>0){const e=c.paginateSelectedItems(v,10,S.current);g({type:"paginate",data:e}),c.fetchFbStatusCollection(e,y,g,h,"update"),S.current+=1}}),{threshold:1});return b.current&&e.observe(b.current),()=>{b.current&&e.unobserve(b.current)}}),[b,v]);const m=(e,t)=>{var o,l,i,r,n,d,u,c,s,a,p,j,y,h,S,b,x,g,m,O;let k=0,q=0;if(null===(l=null===(o=null==v?void 0:v[e])||void 0===o?void 0:o.products)||void 0===l?void 0:l[t]){const o=(null===(n=null===(r=null===(i=null==v?void 0:v[e])||void 0===i?void 0:i.products)||void 0===r?void 0:r[t])||void 0===n?void 0:n.variants)||[];if(1===Object.keys(o).length)for(const l in o){const o=null===(u=null===(d=null==v?void 0:v[e])||void 0===d?void 0:d.products)||void 0===u?void 0:u[t],i=null===(p=null===(a=null===(s=null===(c=null==v?void 0:v[e])||void 0===c?void 0:c.products)||void 0===s?void 0:s[t])||void 0===a?void 0:a.variants)||void 0===p?void 0:p[l];if(null===(j=null==i?void 0:i.name)||void 0===j?void 0:j.includes(null!==(y=null==o?void 0:o.name)&&void 0!==y?y:""))return!1}if(null===(x=Object.keys((null===(b=null===(S=null===(h=null==f?void 0:f[e])||void 0===h?void 0:h.products)||void 0===S?void 0:S[t])||void 0===b?void 0:b.variants)||[]))||void 0===x||x.forEach((()=>q++)),Object.keys((null===(O=null===(m=null===(g=null==v?void 0:v[e])||void 0===g?void 0:g.products)||void 0===m?void 0:m[t])||void 0===O?void 0:O.variants)||[]).forEach((()=>k++)),k>0&&q!==k)return!0}return!1};return e.jsxs("div",{children:[e.jsxs(u.SelectedScreenHeader,{children:[e.jsx(l.IconButton,{Icon:t.default,onClick:()=>{p("collections")}}),e.jsx(i.BodyCaption,{children:"Selected Products"})]}),e.jsxs("div",{children:[Object.keys(x).length>0?e.jsx(e.Fragment,{children:Object.keys(x).map((t=>{var o;return Object.keys((null===(o=null==x?void 0:x[t])||void 0===o?void 0:o.products)||[]).map((o=>{let l=!1;return(null==v?void 0:v.isCustom)&&(l=!0),e.jsx(n.ProductGroup,{upliftAdditions:null,collectionId:t,productId:o,data:x[t].products[o],isProductPartiallyChecked:m(t,o),selectedData:v,selectedCollectionsDispatch:a,viewOnly:l,outOfStockAction:j},o)}))}))}):e.jsx(r.EmptyState,{title:"No Products Selected",subtitle:"Select products will appear here"}),e.jsx("div",{ref:b})]})]})};
|
|
@@ -4,10 +4,28 @@ export declare const liftTheStateUp: (payload: any, data: any) => any;
|
|
|
4
4
|
export declare function paginateSelectedItems(selectedItems: SelectedItems, limit: number, offset: number): {
|
|
5
5
|
[key: string]: Collection;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* 3 scenarios.
|
|
9
|
+
* 1. If no api is provided -> marks everything as approved.
|
|
10
|
+
* 2. If api is success -> sets the status
|
|
11
|
+
* 3. If api is failure -> marks everything as approved.
|
|
12
|
+
*
|
|
13
|
+
* We first get the variant ids to fetch and only if we have variant ids, we call api.
|
|
14
|
+
*/
|
|
7
15
|
export declare const fetchFbStatusCollection: (data: SelectedItems, storeId: string, dispatcher: any, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, dispatchType?: string) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Instead of collection level, we do it product level.
|
|
18
|
+
*
|
|
19
|
+
* For more info refer @function getVariantIdsToFetch
|
|
20
|
+
*/
|
|
8
21
|
export declare const getVariantIdsToFetchAtProductLevel: (products: {
|
|
9
22
|
[key: string]: Product;
|
|
10
23
|
}, globalData?: Collection) => string[];
|
|
24
|
+
/**
|
|
25
|
+
* Instead of collection level, we do it product level.
|
|
26
|
+
*
|
|
27
|
+
* For more info refer @function markVariantsAsApproved
|
|
28
|
+
*/
|
|
11
29
|
export declare const markVariantsAsApprovedProductsLevel: (products: {
|
|
12
30
|
[key: string]: Product;
|
|
13
31
|
}, dispatcher: React.Dispatch<CollectionsActions>, collectionId: string, curScreenData?: Collection, setCurScreenData?: React.Dispatch<React.SetStateAction<Collection>>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("lodash");function t(o,t,l){if(!o)return{};const n=Object.keys(o).slice(l,l+t),d={};return n.forEach((t=>{d[t]=o[t]})),d}const l=(o,t,l)=>{Object.keys(o).forEach((t=>{var l,n;const d=null!==(n=null===(l=o[t])||void 0===l?void 0:l.products)&&void 0!==n?n:{};Object.keys(d).forEach((l=>{var n,d,i,s;const e=null!==(s=null===(i=null===(d=null===(n=o[t])||void 0===n?void 0:n.products)||void 0===d?void 0:d[l])||void 0===i?void 0:i.variants)&&void 0!==s?s:{};Object.keys(e).forEach((n=>{var d,i,s,e;const v=null===(e=null===(s=null===(i=null===(d=o[t])||void 0===d?void 0:d.products)||void 0===i?void 0:i[l])||void 0===s?void 0:s.variants)||void 0===e?void 0:e[n];v&&!v.fbStatus&&(v.fbStatus="APPROVED")}))}))})),t({type:l,data:o})};exports.fetchFbStatusCollection=function(o,t,n,d){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";d||l(o,n,i);const s=(o=>{const t=[];return Object.keys(o).forEach((l=>{var n,d;const i=null!==(d=null===(n=o[l])||void 0===n?void 0:n.products)&&void 0!==d?d:{};Object.keys(i).forEach((n=>{var d,i,s,e;const v=null!==(e=null===(s=null===(i=null===(d=o[l])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)&&void 0!==e?e:{};Object.keys(v).forEach((d=>{var i,s,e,v;const c=null===(v=null===(e=null===(s=null===(i=o[l])||void 0===i?void 0:i.products)||void 0===s?void 0:s[n])||void 0===e?void 0:e.variants)||void 0===v?void 0:v[d];(null==c?void 0:c.fbStatus)||t.push(d)}))}))})),t})(o);
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("lodash");function t(o,t,l){if(!o)return{};const n=Object.keys(o).slice(l,l+t),d={};return n.forEach((t=>{d[t]=o[t]})),d}const l=(o,t,l)=>{Object.keys(o).forEach((t=>{var l,n;const d=null!==(n=null===(l=o[t])||void 0===l?void 0:l.products)&&void 0!==n?n:{};Object.keys(d).forEach((l=>{var n,d,i,s;const e=null!==(s=null===(i=null===(d=null===(n=o[t])||void 0===n?void 0:n.products)||void 0===d?void 0:d[l])||void 0===i?void 0:i.variants)&&void 0!==s?s:{};Object.keys(e).forEach((n=>{var d,i,s,e;const v=null===(e=null===(s=null===(i=null===(d=o[t])||void 0===d?void 0:d.products)||void 0===i?void 0:i[l])||void 0===s?void 0:s.variants)||void 0===e?void 0:e[n];v&&!v.fbStatus&&(v.fbStatus="APPROVED")}))}))})),t({type:l,data:o})};exports.fetchFbStatusCollection=function(o,t,n,d){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";d||l(o,n,i);const s=(o=>{const t=[];return Object.keys(o).forEach((l=>{var n,d;const i=null!==(d=null===(n=o[l])||void 0===n?void 0:n.products)&&void 0!==d?d:{};Object.keys(i).forEach((n=>{var d,i,s,e;const v=null!==(e=null===(s=null===(i=null===(d=o[l])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)&&void 0!==e?e:{};Object.keys(v).forEach((d=>{var i,s,e,v;const c=null===(v=null===(e=null===(s=null===(i=o[l])||void 0===i?void 0:i.products)||void 0===s?void 0:s[n])||void 0===e?void 0:e.variants)||void 0===v?void 0:v[d];(null==c?void 0:c.fbStatus)||t.push(d)}))}))})),t})(o);s.length>0&&d&&d(t,s).then((t=>{const l=Object.assign({},o);Object.keys(l).forEach((o=>{var n,d;const i=null!==(d=null===(n=l[o])||void 0===n?void 0:n.products)&&void 0!==d?d:{};Object.keys(i).forEach((n=>{var d,i,s,e;const v=null!==(e=null===(s=null===(i=null===(d=l[o])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)&&void 0!==e?e:{};Object.keys(v).forEach((d=>{var i,s,e,v;const c=null===(v=null===(e=null===(s=null===(i=l[o])||void 0===i?void 0:i.products)||void 0===s?void 0:s[n])||void 0===e?void 0:e.variants)||void 0===v?void 0:v[d];c&&"REJECTED"===t[d]?c.fbStatus="REJECTED":c&&"APPROVED"===t[d]&&(c.fbStatus="APPROVED")}))}))})),n({type:i,data:l})})).catch((t=>{console.error("Error in fbStatusFetcher",t),l(o,n,i)}))},exports.getVariantIdsToFetchAtProductLevel=(o,t)=>{const l=[];return Object.keys(null!=o?o:{}).forEach((n=>{var d,i;const s=null!==(i=null===(d=null==o?void 0:o[n])||void 0===d?void 0:d.variants)&&void 0!==i?i:{};Object.keys(s).forEach((d=>{var i,s,e,v,c;let a;a=t?null===(e=null===(s=null===(i=null==t?void 0:t.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)||void 0===e?void 0:e[d]:null===(c=null===(v=null==o?void 0:o[n])||void 0===v?void 0:v.variants)||void 0===c?void 0:c[d],(null==a?void 0:a.fbStatus)||l.push(d)}))})),l},exports.liftTheStateUp=(t,l)=>{const n=o.cloneDeep(l);if(delete n.products,(t=Object.assign(Object.assign({},t),{catalogOnlyData:n})).productId&&l.products){const d=o.cloneDeep(l.products[t.productId]);(null==d?void 0:d.variants)&&delete d.variants,t=Object.assign(Object.assign({},t),{catalogOnlyData:n,productOnlyData:d})}return t},exports.markVariantsAsApprovedProductsLevel=(o,t,l,n,d)=>{const i=Object.assign({},o);if(Object.keys(o).forEach((t=>{var l,n;Object.keys(null!==(n=null===(l=null==o?void 0:o[t])||void 0===l?void 0:l.variants)&&void 0!==n?n:{}).forEach((l=>{var n,d;const s=null===(n=null==o?void 0:o[t].variants)||void 0===n?void 0:n[l];s&&(s.fbStatus="APPROVED");const e=null===(d=null==i?void 0:i[t])||void 0===d?void 0:d.variants;e&&e[l]&&(e[l]=s)}))})),n&&d){const o=Object.assign({},n);o.products=i,d(o),t({type:"productsPaged",data:{collectionId:l,products:i}})}else t({type:"productsPaged",data:{collectionId:l,products:i}})},exports.paginateSelectedItems=function(o,l,n){var d;const i={};let s=0;for(const e in o)if(Object.prototype.hasOwnProperty.call(o,e)){const v=o[e],c=t(v.products,l,n-s);c&&Object.keys(c).length>0&&(i[e]=Object.assign(Object.assign({},v),{products:c})),s+=Object.keys(null!==(d=v.products)&&void 0!==d?d:{}).length}return i};
|
|
@@ -5,4 +5,15 @@ export type ProductPickerTagType = {
|
|
|
5
5
|
data: Product | ProductVariant;
|
|
6
6
|
outOfStockAction?: OUT_OF_STOCK_ACTION;
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Used in Product Screen, Search Screen, Selected Screen and Rearrange Screen.
|
|
10
|
+
* Wherever product card is shown, we use this component.
|
|
11
|
+
*
|
|
12
|
+
* New logic: When product has only one variant and variant name is same as product name,
|
|
13
|
+
* we consider that a variant and do operations as variant.
|
|
14
|
+
*
|
|
15
|
+
* Note: If there is no Fb rejected tag in the variant, we show a shimmer,
|
|
16
|
+
* meanwhile hit the API to get FB status.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
8
19
|
export declare const ProductPickerTag: (props: ProductPickerTagType) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -32,6 +32,9 @@ export declare class ProductHelper {
|
|
|
32
32
|
* @param outOfStockAction
|
|
33
33
|
*/
|
|
34
34
|
static getProductLabels(productVariant: Product | ProductVariant, outOfStockAction?: OUT_OF_STOCK_ACTION): string | null;
|
|
35
|
+
/**
|
|
36
|
+
* For FB Rejected returns 'negative', for rest returns 'warning'
|
|
37
|
+
*/
|
|
35
38
|
static getTagType: (tagText: string) => TagType;
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
@@ -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{Button as d}from"../button/Button.js";import{Input as a}from"../input/Input.js";import{StyledModal as
|
|
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{Button as d}from"../button/Button.js";import{Input as a}from"../input/Input.js";import{StyledModal as h}from"../modals/styledModal.js";import{Spinner as u}from"../spinner/Spinner.js";import{Tag as p}from"../tag/Tag.js";import{CollectionsScreen as m}from"./collectionScreen.js";import{ProductInfoOverlay as C}from"./productInfoOverlay.js";import{ProductsScreen as g}from"./productScreen.js";import{RearrangeScreen as f}from"./rearrangeScreen.js";import{collectionsReducer as b,searchReducer as y,selectedColectionsReducer as S,CollectionIdContext as v}from"./reducers.js";import{SearchScreen as k}from"./searchScreen.js";import{SelectedScreen as x}from"./selectedScreen.js";import{ContainerStyle as P,ScrollContainerStyle as I}from"./style.js";import{OUT_OF_STOCK_ACTION as j}from"./type.js";var F;!function(e){e.Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products"}(F||(F={}));const T=T=>{const{storeId:O,selectedItems:D,onClose:w,visible:R,zIndex:E,exactLimit:A,limit:$,hideCollectionCheckbox:V,hideProductCheckbox:B,outOfStockAction:L=j.BLUR,hideVariantCheckbox:M,selectProductsFromCustomCollection:z,hideSelectionCount:W,title:G,width:H,renderWithoutModal:Y,onClickSave:K,pickerType:U,hideProductVariants:q=!1,startupScreen:J=F.Collections,rearrangeEnabled:N,selectSingleItem:Q=!1,showProductDetailInfoIcon:X}=T,[Z,_]=r(b,{}),[ee,te]=s([F.Collections,F.RearrangeProducts].includes(J)?J:F.Collections),[oe,ce]=s("grid"),[re,se]=s(""),[ie,ne]=s(""),[le,de]=s(0),[ae,he]=s(!1),[ue,pe]=s(0),[me,Ce]=s(""),[ge,fe]=s(!1),[be,ye]=s(!1),[Se,ve]=r(y,{collections:{},products:{}}),[ke,xe]=r(S,Object.keys(D).length>0?D:{}),Pe=i(null),[Ie,je]=s(!1),[Fe,Te]=s();n((()=>{he(!0),ye(!0),T.collectionFetcher(le,O).then((e=>{_({type:"fetched",data:(null==e?void 0:e.collections)||{}}),he(!1),de((e=>e+1)),ye(!1)})).catch()}),[]),n((()=>{let e=0;Object.keys(ke||[]).forEach((t=>{var o;Object.keys((null===(o=ke[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=ke[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),pe(e)})),n((()=>{ie&&(he(!0),T.productFetcher(ie,O).then((e=>{Object.keys(e).length&&_({type:"productsFetched",data:{collectionId:ie,products:e}}),he(!1)})).catch())}),[ie]),n((()=>{const e=setTimeout((()=>{"rearrange"!==ee&&(me.length?(fe(!0),T.searchFetcher(O,me).then((e=>{"collections"in e&&"products"in e?(ve({type:"set",data:e}),_({type:"searched",data:e.collections})):(ve({type:"set",data:{collections:{},products:e}}),_({type:"searched",data:e})),te("searchProducts"),he(!1),fe(!1)}))):te("collections"))}),800);return()=>clearTimeout(e)}),[me]),n((()=>{K&&(T.onAdd(ke,ue),Oe())}),[K]),n((()=>{Q&&Object.keys(ke||{}).length&&ue&&(T.onAdd(ke,ue),Oe())}),[Q,ke,ue]);const Oe=()=>{xe({type:"reset",data:{}})},De=e(P,{children:[T.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:T.postHeader})),!T.hideGlobalSearch&&t(o,{children:("collections"===ee||"searchProducts"===ee)&&t("div",Object.assign({style:{padding:Y?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(a,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>ge?t(u,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:me,onChangeText:e=>{e.length&&e.trim().length?Ce(e):Ce("")}})}))}),e(I,Object.assign({ref:Pe},{children:["collections"===ee&&t(m,{customCollectionRestriction:T.customCollectionRestriction,dataLoading:be,collections:Z,selectedCollectionsDispatch:xe,setCollectionId:se,setSelectedCollectionId:ne,setScreen:te,selectedCollections:ke,collectionFetcher:T.collectionFetcher,storeId:O,collectionsDispatch:_,setSaveDisabled:he,pagingControls:{curPage:le,setCurPage:de},hideCollectionCheckbox:V,renderWithoutModal:Y,pickerType:U}),"products"===ee&&re&&t(v.Provider,Object.assign({value:re},{children:t(g,{hideInCollectionSearch:T.hideInCollectionSearch,customCollectionRestriction:T.customCollectionRestriction,productFetcher:T.productFetcher,setScreen:te,storeId:O,data:Z[re],collectionsDispatch:_,selectedCollectionsDispatch:xe,selectedData:ke,setSaveDisabled:he,searchInCollectionFetcher:T.searchInCollectionFetcher,hideProductCheckbox:B,outOfStockAction:L,hideVariantCheckbox:M,selectProductsFromCustomCollection:z,renderWithoutModal:Y,pickerType:U,hideProductVariants:q,fbStatusFetcher:T.fbStatusFetcher,onInfoIconClick:e=>{je(!0),Te(e)},showProductDetailInfoIcon:X})})),"view"===ee&&t(x,{selectedCollections:ke||{},selectedCollectionsDispatch:xe,setScreen:te,collections:Z,outOfStockAction:L,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"rearrange"===ee&&t(f,{selectedCollections:ke||{},selectedCollectionsDispatch:xe,setScreen:te,outOfStockAction:L,rearrangeViewType:"grid"===oe?"list":"grid",scrollContainerRef:Pe,storeId:O,fbStatusFetcher:T.fbStatusFetcher}),"searchProducts"===ee&&t(k,{customCollectionRestriction:T.customCollectionRestriction,selectedCollections:ke||{},searchedCollections:Se||{},searchedCollectionsDispatch:ve,selectedCollectionsDispatch:xe,setScreen:te,collections:Z,onBackPress:()=>{Ce(""),ve({type:"set",data:{collections:{},products:{}}})},pickerType:U,hideProductCheckbox:B,hideProductVariants:q,hideVariantCheckbox:M,storeId:O,fbStatusFetcher:T.fbStatusFetcher,setCollectionId:se,setSelectedCollectionId:ne,renderWithoutModal:Y,hideCollectionCheckbox:V})]}))]});return t(o,{children:Y?De:e(h,Object.assign({zIndex:E,open:R,onClose:()=>{null==w||w(),Oe()},headingTitle:G||("collections"===ee||"products"===ee?"Select Products":"view"===ee?"Selected Products":"searchProducts"===ee?"Searched Products":"rearrange"===ee?"Rearrange Products":void 0),footerShadow:!0,centralContainerStyles:{width:H||"600px"},headerRightCustomElement:"rearrange"===ee?(console.log("ignore:",ce),t(o,{})):t(o,{}),footerContainerStyle:T.stickyFooter?{position:"absolute",bottom:0,left:0,width:"100%",zIndex:9,background:l.surface.standard}:void 0,primaryButton:{buttonText:ae?"Loading...":ee===F.RearrangeProducts?"Done":"Add",disabled:ae||ue<1||A&&ue<A||!A&&$&&ue>$||!1,onClick:()=>{T.onAdd(ke,ue),Oe()}},wrapperStyle:T.stickyFooter?{height:"calc(100vh - 168px)"}:void 0,footerLeftCustomElement:W?t(o,{}):A&&ue>A?t(p,{tagText:`You can only select ${A} products`,type:"negative"}):$&&ue>$?t(p,{tagText:`You can only select ${$} products`,type:"negative"}):t(d,ue>0?{onClick:()=>{te(N?F.RearrangeProducts:F.SelectedProducts)},buttonText:A?`${ue}/${A} products selected`:`${ue} products selected`,buttonType:["rearrange","view"].includes(ee)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(ee)}:{disabled:!0,buttonText:A?`${ue}/${A} products selected`:`${ue} products selected`,buttonType:"tertiaryGray"}),hideCrossButton:Ie},{children:[De,Ie&&Fe?t(C,{productData:Fe,outOfStockAction:L,onClose:()=>{je(!1)}}):t(o,{})]}))})};export{T as ProductPickerModal,F as ScreenName};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Product, ProductVariant } from './modal';
|
|
2
2
|
import { OUT_OF_STOCK_ACTION } from './type';
|
|
3
|
+
/**
|
|
4
|
+
* When user presses i icon on a product, we show the overlay.
|
|
5
|
+
* In case of a product, contains products image, product name & description
|
|
6
|
+
* In case of a variant, contains variant image, variant name,
|
|
7
|
+
* description as product name, variant tag
|
|
8
|
+
*/
|
|
3
9
|
export declare const ProductInfoOverlay: (props: {
|
|
4
10
|
productData: Product | ProductVariant;
|
|
5
11
|
onClose: () => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{jsxs as o,jsx as t}from"react/jsx-runtime";import i from"styled-components";import{COLORS as r}from"../../constants/Theme.js";import e from"../../assets/icons/cross.svg.js";import{IconButton as a}from"../icon-button/IconButton.js";import{ShimmerImage as
|
|
1
|
+
import{jsxs as o,jsx as t}from"react/jsx-runtime";import i from"styled-components";import{COLORS as r}from"../../constants/Theme.js";import e from"../../assets/icons/cross.svg.js";import{IconButton as a}from"../icon-button/IconButton.js";import{ShimmerImage as n}from"../shimmer-image/ShimmerImage.js";import{TitleSmall as d,BodyCaption as s}from"../TypographyStyle.js";import{ProductPickerTag as c}from"./ProductPickerTag.js";const l=i=>o(m,{children:[t(u,{}),t(x,{children:t(a,{className:"close-button",onClick:i.onClose,Icon:e,width:20,height:20})}),t(p,{productData:i.productData,outOfStockAction:i.outOfStockAction})]}),p=i=>{var r;const e=void 0===i.productData.variants;return o(f,{children:[t(g,{children:t(n,{imageUrl:i.productData.image,width:"200px",height:200,borderRadius:4})}),o(h,{children:[t(d,Object.assign({style:{display:"flex"}},{children:i.productData.name})),t(s,{style:{display:"flex",flexDirection:"column"},dangerouslySetInnerHTML:{__html:null!==(r=i.productData.description)&&void 0!==r?r:""}}),t(c,{isVariant:e,data:i.productData,outOfStockAction:i.outOfStockAction})]})]})},m=i.div`
|
|
2
2
|
display: flex;
|
|
3
3
|
flex: 1;
|
|
4
4
|
background: rgba(0, 0, 0, 0.5);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as t,jsx as o,Fragment as e}from"react/jsx-runtime";import i from"../../assets/icons/arrow_left.svg.js";import c from"../../assets/icons/box.svg.js";import n from"../../assets/icons/search.svg.js";import{cloneDeep as l}from"lodash";import{useContext as r,useRef as s,useState as d,useEffect as a}from"react";import{COLORS as u}from"../../constants/Theme.js";import h from"../../assets/icons/info.svg.js";import{CheckBox as v}from"../checkBox/CheckBox.js";import{IconButton as p}from"../icon-button/IconButton.js";import{Input as m}from"../input/Input.js";import{BikShimmer as g}from"../shimmer/ShimmerComponent/BikShimmer.js";import{ShimmerImage as f}from"../shimmer-image/ShimmerImage.js";import{Spinner as b}from"../spinner/Spinner.js";import{Tooltip as j}from"../tooltips/Tooltip.js";import{BodyCaption as y,TitleRegular as I,BodyPrimary as k}from"../TypographyStyle.js";import{EmptyState as O}from"./emptyState.js";import{ProductPickerTag as C}from"./ProductPickerTag.js";import{CollectionIdContext as P}from"./reducers.js";import{ProductScreenHeader as x,ProductScreenCollectionCardStyle as S,ProductCardStyle as E}from"./style.js";import{OUT_OF_STOCK_ACTION as D}from"./type.js";import{getVariantIdsToFetchAtProductLevel as w,markVariantsAsApprovedProductsLevel as V,liftTheStateUp as A}from"./utility.js";const T=e=>{const{data:h,collectionsDispatch:f,selectedData:j,selectedCollectionsDispatch:k,productFetcher:C,storeId:E,setScreen:T,setSaveDisabled:F,hideInCollectionSearch:B,customCollectionRestriction:U,hideProductCheckbox:L,outOfStockAction:H=D.BLUR,hideVariantCheckbox:J=!1,selectProductsFromCustomCollection:W=!1,pickerType:z,hideProductVariants:K,fbStatusFetcher:M,onInfoIconClick:N,showProductDetailInfoIcon:_}=e,q=r(P),G=s(null),Q=s(0),[X,Y]=d(!1),[Z,$]=d(""),[tt,ot]=d(!1),[et,it]=d(h),ct=s(!1);a((()=>{const t=setTimeout((()=>{Z.length?(ot(!0),e.searchInCollectionFetcher(E,q,Z).then((t=>{const o=l(h);o.products=t,it(o);const e=w(null!=t?t:{});rt(e,null!=t?t:{},!0),F(!1),ot(!1)}))):it(h)}),800);return()=>clearTimeout(t)}),[Z]),a((()=>{var t,o,e,i,c,n,l,r;console.log("vj: collectionId change before",h,h.products,null===(o=Object.keys(null!==(t=h.products)&&void 0!==t?t:{}))||void 0===o?void 0:o.length,ct),ct.current=!1,Q.current=Math.floor((null===(i=Object.keys(null!==(e=h.products)&&void 0!==e?e:{}))||void 0===i?void 0:i.length)/10);const s=w(null!==(c=h.products)&&void 0!==c?c:{});rt(s,null!==(n=h.products)&&void 0!==n?n:{}),console.log("vj: collectionId change after",h,h.products,null===(r=Object.keys(null!==(l=h.products)&&void 0!==l?l:{}))||void 0===r?void 0:r.length,ct)}),[q]);const nt=!!U&&h.isSmartCollection,lt=t=>{var o,e,i,c,n,l,r,s;let d=0,a=0;return!!((null===(e=null===(o=null==j?void 0:j[q])||void 0===o?void 0:o.products)||void 0===e?void 0:e[t])&&(null===(n=Object.keys((null===(c=null===(i=null==et?void 0:et.products)||void 0===i?void 0:i[t])||void 0===c?void 0:c.variants)||[]))||void 0===n||n.forEach((()=>a++)),Object.keys((null===(s=null===(r=null===(l=null==j?void 0:j[q])||void 0===l?void 0:l.products)||void 0===r?void 0:r[t])||void 0===s?void 0:s.variants)||[]).forEach((()=>d++)),d>0&&a!==d))};a((()=>{(null==h?void 0:h.products)||st(10)}),[]);const rt=(t,o,e)=>{console.log("fetchFbStatusAndDispatchProducts",{variantIdsToFetchFbStatus:t,fbStatusFetcher:M}),M||(e?V(o,f,q,et,it):V(o,f,q)),t.length>0&&M&&M(E,t).then((t=>{const i=Object.assign({},o);Object.keys(o).forEach((e=>{var c,n;Object.keys(null!==(n=null===(c=null==o?void 0:o[e])||void 0===c?void 0:c.variants)&&void 0!==n?n:{}).forEach((c=>{var n,l;const r=null===(n=null==o?void 0:o[e].variants)||void 0===n?void 0:n[c];r&&"REJECTED"===t[c]?r.fbStatus="REJECTED":r&&"APPROVED"===t[c]&&(r.fbStatus="APPROVED");const s=null===(l=null==i?void 0:i[e])||void 0===l?void 0:l.variants;s&&s[c]&&(s[c]=r)}))})),e?(it((t=>{const o=Object.assign({},t);return o.products=i,o})),f({type:"productsPaged",data:{collectionId:q,products:i}})):f({type:"productsPaged",data:{collectionId:q,products:i}})})).catch((t=>{e?V(o,f,q,et,it):V(o,f,q)}))};a((()=>{console.log("vj: observertarget",G.current);const t=new IntersectionObserver((t=>{console.log("vj: observertargetinside",t),t[0].isIntersecting&&(console.log("vj: nextPageRef",Q.current,ct),Q.current>=0&&!ct.current&&!Z&&(F(!0),Y(!0),C(q,E,10,Q.current).then((t=>{if(console.log("vj: fetched products",t,ct,Object.keys(t).length),Object.keys(t).length||(console.log("vj: setHasAllCollectionLoaded ",!0),ct.current=!0),Object.keys(t).length){const o=et;o.products=Object.assign(Object.assign({},et.products),t),it(o);const e=w(t);rt(e,t),Q.current+=1}Y(!1),F(!1)})).catch()))}),{threshold:1});return G.current&&t.observe(G.current),()=>{G.current&&t.unobserve(G.current)}}),[G,Z]);const st=t=>{console.log("vj: getProductsForCollection"),F(!0),ot(!0),C(q,E,t,0).then((o=>{if(Object.keys(o).length||(console.log("vj: setHasAllCollectionLoaded ",!0),ct.current=!0),Object.keys(o).length){it(Object.assign(Object.assign({},et),{products:o})),console.log("vj: next page when products loaded",Q.current);const t=w(o);rt(t,o),Q.current=1}console.log("vj: product data",{productData:o,limit:t,data:h}),t||k({type:"selected",data:{id:q,val:Object.assign(Object.assign({},h),{products:o})}}),F(!1),ot(!1)})).catch()},dt=(t,o)=>{const e=A(o,h);k({type:t,data:Object.assign(Object.assign({},e),{isRestricted:U})})};return t("div",{children:[t(x,{children:[o(p,{Icon:i,height:16,onClick:()=>{T("collections")}}),o(y,Object.assign({style:{color:u.content.secondary}},{children:h.name}))]}),!B&&o("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:o(m,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>tt&&Z.length?o(b,{size:"small",color:u.content.primary}):o(n,{})},id:"listInput",height:"24px",type:"text",value:Z,onChangeText:t=>{t.length&&t.trim().length?$(t):$("")},placeholder:"Search products in this collection..."})})),t("div",{children:[Object.keys((null==et?void 0:et.products)||[]).length>0&&!nt&&!Z.length&&!L&&"-1"!==q&&t(S,{children:[o(v,{isChecked:!!(null==j?void 0:j[q]),isPartiallyChecked:(t=>{var o;let e=0,i=0;if(j[t]){const c=null==h?void 0:h.products;c&&Object.keys(c).forEach((t=>{var o;const i=null===(o=c[t])||void 0===o?void 0:o.variants;i&&Object.keys(i).forEach((t=>e+=1))}));const n=null===(o=j[t])||void 0===o?void 0:o.products;return n&&Object.keys(n).forEach((t=>{var o;const e=null===(o=n[t])||void 0===o?void 0:o.variants;e&&Object.keys(e).forEach((()=>i+=1))})),i>0&&e!==i}return!1})(q),onValueChange:function(t){t?st():k({type:"unselected",data:{id:q}})}}),o("div",Object.assign({style:{width:40,height:40}},{children:o(c,{})})),o(I,{children:"All Products"})]}),Object.keys((null==et?void 0:et.products)||[]).length?Object.keys(et.products||[]).map((t=>o(R,{outOfStockAction:H,collectionId:q,isProductPartiallyChecked:lt(t),productId:t,data:et.products[t],selectedData:j,selectedCollectionsDispatch:k,viewOnly:!W&&!!nt,upliftAdditions:dt,hideProductCheckbox:L,hideVariantCheckbox:J,hideProductVariants:K,pickerType:z,onInfoIconClick:N,showProductDetailInfoIcon:_},t))):tt?[1,2,3,4,5,6,7,8,9,10].map(((t,e)=>o("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:o(g,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),e))):o(O,{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."}),o("div",{ref:G})]}),X&&[1,2,3,4,5].map(((t,e)=>o("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:o(g,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),e)))]})},R=e=>{const{collectionId:i,productId:c,data:n,selectedData:l,selectedCollectionsDispatch:r,viewOnly:s,upliftAdditions:d,isProductPartiallyChecked:a,hideProductCheckbox:u,outOfStockAction:h,hideVariantCheckbox:v,hideProductVariants:p,pickerType:m,onInfoIconClick:g,showProductDetailInfoIcon:f}=e,b=t=>{var o,e,n,r,s,d;if(!(null===(e=null===(o=null==l?void 0:l[i])||void 0===o?void 0:o.products)||void 0===e?void 0:e[c]))return!1;return!!(null===(d=null===(s=null===(r=null===(n=null==l?void 0:l[i])||void 0===n?void 0:n.products)||void 0===r?void 0:r[c])||void 0===s?void 0:s.variants)||void 0===d?void 0:d[t])};return t("div",{children:[o(F,{isVariant:!1,data:n,productId:c,collectionId:i,isSelected:!!(null===(y=null===(j=null==l?void 0:l[i])||void 0===j?void 0:j.products)||void 0===y?void 0:y[c]),isPartiallyChecked:a,selectedCollectionsDispatch:r,upliftAdditions:d,viewOnly:s,hideProductCheckbox:u,hideVariantCheckbox:v,hideProductVariants:p,pickerType:m,outOfStockAction:h,onInfoIconClick:g,showProductDetailInfoIcon:f},c),p?null:(()=>{const t=Object.keys(n.variants||[]);let o=!1;return!(t.length<=1)||(t.forEach((t=>{var e,i;o=null!==(i=null===(e=n.variants)||void 0===e?void 0:e[t].name.includes(n.name))&&void 0!==i&&i})),!o)})()&&Object.keys(n.variants||[]).map((t=>o(F,{isVariant:!0,hideVariantCheckbox:v,data:n.variants[t],variantId:t,productId:c,viewOnly:s,upliftAdditions:d,collectionId:i,isSelected:b(t),selectedCollectionsDispatch:r,outOfStockAction:h,onInfoIconClick:g,showProductDetailInfoIcon:f},t)))]});var j,y},F=i=>{const{isVariant:c,data:n,productId:l,collectionId:r,variantId:s,isSelected:d,selectedCollectionsDispatch:a,viewOnly:m,upliftAdditions:g,isPartiallyChecked:b,hideProductCheckbox:y,outOfStockAction:I,hideVariantCheckbox:O,hideProductVariants:P,pickerType:x,onInfoIconClick:S,showProductDetailInfoIcon:D}=i;return t(E,Object.assign({isVariant:c,onClick:t=>{"PRODUCT"===x&&P&&(t.stopPropagation(),a({type:"reset",data:{}}),g("variantSelected",{productId:l,variantId:s||Object.keys(n.variants)[0],collectionId:r,variant:n}))},isActive:d},{children:[c&&!m&&!O||!c&&!m&&!y?o(v,{isChecked:d,isPartiallyChecked:b||!1,onValueChange:function(t){c?t?g("variantSelected",{productId:l,variantId:s,collectionId:r,variant:n}):a({type:"variantUnselected",data:{productId:l,variantId:s,collectionId:r}}):t?g("productSelected",{productId:l,collectionId:r,product:n}):a({type:"productUnselected",data:{productId:l,collectionId:r}})}}):o(e,{}),o("div",{children:o(f,{width:40,height:40,imageUrl:n.image,alt:"Item",borderRadius:4})}),t("div",Object.assign({style:{display:"flex",flexDirection:"column",flex:1}},{children:[t("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},{children:[o(j,Object.assign({variant:"light",body:n.name,placement:"bottom",delay:400},{children:o(k,Object.assign({numberOfLines:1},{children:n.name}))})),D&&o(p,{onClick:()=>{null==S||S(n)},Icon:()=>o(h,{width:20,height:20,color:u.content.placeholder})})]})),o(C,{isVariant:c,data:n,outOfStockAction:I})]}))]}))};export{F as ProductCard,R as ProductGroup,T as ProductsScreen};
|
|
1
|
+
import{jsxs as t,jsx as o,Fragment as e}from"react/jsx-runtime";import i 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 l}from"lodash";import{useContext as r,useRef as d,useState as s,useEffect as a}from"react";import{COLORS as u}from"../../constants/Theme.js";import v from"../../assets/icons/info.svg.js";import{CheckBox as h}from"../checkBox/CheckBox.js";import{IconButton as p}from"../icon-button/IconButton.js";import{Input as m}from"../input/Input.js";import{BikShimmer as f}from"../shimmer/ShimmerComponent/BikShimmer.js";import{ShimmerImage as b}from"../shimmer-image/ShimmerImage.js";import{Spinner as g}from"../spinner/Spinner.js";import{Tooltip as y}from"../tooltips/Tooltip.js";import{BodyCaption as k,TitleRegular as I,BodyPrimary as j}from"../TypographyStyle.js";import{EmptyState as O}from"./emptyState.js";import{ProductPickerTag as C}from"./ProductPickerTag.js";import{CollectionIdContext as P}from"./reducers.js";import{ProductScreenHeader as x,ProductScreenCollectionCardStyle as E,ProductCardStyle as S}from"./style.js";import{OUT_OF_STOCK_ACTION as D}from"./type.js";import{getVariantIdsToFetchAtProductLevel as w,markVariantsAsApprovedProductsLevel as V,liftTheStateUp as T}from"./utility.js";const A=e=>{const{data:v,collectionsDispatch:b,selectedData:y,selectedCollectionsDispatch:j,productFetcher:C,storeId:S,setScreen:A,setSaveDisabled:B,hideInCollectionSearch:U,customCollectionRestriction:F,hideProductCheckbox:J,outOfStockAction:L=D.BLUR,hideVariantCheckbox:W=!1,selectProductsFromCustomCollection:z=!1,pickerType:H,hideProductVariants:K,fbStatusFetcher:M,onInfoIconClick:N,showProductDetailInfoIcon:_}=e,q=r(P),G=d(null),Q=d(0),[X,Y]=s(!1),[Z,$]=s(""),[tt,ot]=s(!1),[et,it]=s(v),nt=d(!1);a((()=>{const t=setTimeout((()=>{Z.length?(ot(!0),e.searchInCollectionFetcher(S,q,Z).then((t=>{const o=l(v);o.products=t,it(o);const e=w(null!=t?t:{});rt(e,null!=t?t:{},!0),B(!1),ot(!1)}))):it(v)}),800);return()=>clearTimeout(t)}),[Z]),a((()=>{var t,o,e,i;nt.current=!1,Q.current=Math.floor((null===(o=Object.keys(null!==(t=v.products)&&void 0!==t?t:{}))||void 0===o?void 0:o.length)/10);const n=w(null!==(e=v.products)&&void 0!==e?e:{});rt(n,null!==(i=v.products)&&void 0!==i?i:{})}),[q]);const ct=!!F&&v.isSmartCollection,lt=t=>{var o,e,i,n,c,l,r,d,s,a,u,v,h,p,m,f,b,g,k;let I=0,j=0;if(null===(e=null===(o=null==y?void 0:y[q])||void 0===o?void 0:o.products)||void 0===e?void 0:e[t]){const o=(null===(c=null===(n=null===(i=null==y?void 0:y[q])||void 0===i?void 0:i.products)||void 0===n?void 0:n[t])||void 0===c?void 0:c.variants)||[];if(1===Object.keys(o).length)for(const e in o){const o=null===(r=null===(l=null==y?void 0:y[q])||void 0===l?void 0:l.products)||void 0===r?void 0:r[t],i=null===(u=null===(a=null===(s=null===(d=null==y?void 0:y[q])||void 0===d?void 0:d.products)||void 0===s?void 0:s[t])||void 0===a?void 0:a.variants)||void 0===u?void 0:u[e];if(null===(v=null==i?void 0:i.name)||void 0===v?void 0:v.includes(null!==(h=null==o?void 0:o.name)&&void 0!==h?h:""))return!1}if(null===(f=Object.keys((null===(m=null===(p=null==et?void 0:et.products)||void 0===p?void 0:p[t])||void 0===m?void 0:m.variants)||[]))||void 0===f||f.forEach((()=>j++)),Object.keys((null===(k=null===(g=null===(b=null==y?void 0:y[q])||void 0===b?void 0:b.products)||void 0===g?void 0:g[t])||void 0===k?void 0:k.variants)||[]).forEach((()=>I++)),I>0&&j!==I)return!0}return!1};a((()=>{(null==v?void 0:v.products)||dt(10)}),[]);const rt=(t,o,e)=>{M||(e?V(o,b,q,et,it):V(o,b,q)),t.length>0&&M&&M(S,t).then((t=>{const i=Object.assign({},o);Object.keys(o).forEach((e=>{var n,c;Object.keys(null!==(c=null===(n=null==o?void 0:o[e])||void 0===n?void 0:n.variants)&&void 0!==c?c:{}).forEach((n=>{var c,l;const r=null===(c=null==o?void 0:o[e].variants)||void 0===c?void 0:c[n];r&&"REJECTED"===t[n]?r.fbStatus="REJECTED":r&&"APPROVED"===t[n]&&(r.fbStatus="APPROVED");const d=null===(l=null==i?void 0:i[e])||void 0===l?void 0:l.variants;d&&d[n]&&(d[n]=r)}))})),e?(it((t=>{const o=Object.assign({},t);return o.products=i,o})),b({type:"productsPaged",data:{collectionId:q,products:i}})):b({type:"productsPaged",data:{collectionId:q,products:i}})})).catch((t=>{e?V(o,b,q,et,it):V(o,b,q)}))};a((()=>{const t=new IntersectionObserver((t=>{t[0].isIntersecting&&Q.current>=0&&!nt.current&&!Z&&(B(!0),Y(!0),C(q,S,10,Q.current).then((t=>{if(Object.keys(t).length||(nt.current=!0),Object.keys(t).length){const o=et;o.products=Object.assign(Object.assign({},et.products),t),it(o);const e=w(t);rt(e,t),Q.current+=1}Y(!1),B(!1)})).catch())}),{threshold:1});return G.current&&t.observe(G.current),()=>{G.current&&t.unobserve(G.current)}}),[G,Z]);const dt=t=>{B(!0),ot(!0),C(q,S,t,0).then((o=>{if(Object.keys(o).length||(nt.current=!0),Object.keys(o).length){it(Object.assign(Object.assign({},et),{products:o}));const t=w(o);rt(t,o),Q.current=1}t||j({type:"selected",data:{id:q,val:Object.assign(Object.assign({},v),{products:o})}}),B(!1),ot(!1)})).catch()},st=(t,o)=>{const e=T(o,v);j({type:t,data:Object.assign(Object.assign({},e),{isRestricted:F})})};return t("div",{children:[t(x,{children:[o(p,{Icon:i,height:16,onClick:()=>{A("collections")}}),o(k,Object.assign({style:{color:u.content.secondary}},{children:v.name}))]}),!U&&o("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:o(m,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>tt&&Z.length?o(g,{size:"small",color:u.content.primary}):o(c,{})},id:"listInput",height:"24px",type:"text",value:Z,onChangeText:t=>{t.length&&t.trim().length?$(t):$("")},placeholder:"Search products in this collection..."})})),t("div",{children:[Object.keys((null==et?void 0:et.products)||[]).length>0&&!ct&&!Z.length&&!J&&"-1"!==q&&t(E,{children:[o(h,{isChecked:!!(null==y?void 0:y[q]),isPartiallyChecked:(t=>{var o;let e=0,i=0;if(y[t]){const n=null==v?void 0:v.products;n&&Object.keys(n).forEach((t=>{var o;const i=null===(o=n[t])||void 0===o?void 0:o.variants;i&&Object.keys(i).forEach((t=>e+=1))}));const c=null===(o=y[t])||void 0===o?void 0:o.products;return c&&Object.keys(c).forEach((t=>{var o;const e=null===(o=c[t])||void 0===o?void 0:o.variants;e&&Object.keys(e).forEach((()=>i+=1))})),i>0&&e!==i}return!1})(q),onValueChange:function(t){t?dt():j({type:"unselected",data:{id:q}})}}),o("div",Object.assign({style:{width:40,height:40}},{children:o(n,{})})),o(I,{children:"All Products"})]}),Object.keys((null==et?void 0:et.products)||[]).length?Object.keys(et.products||[]).map((t=>o(R,{outOfStockAction:L,collectionId:q,isProductPartiallyChecked:lt(t),productId:t,data:et.products[t],selectedData:y,selectedCollectionsDispatch:j,viewOnly:!z&&!!ct,upliftAdditions:st,hideProductCheckbox:J,hideVariantCheckbox:W,hideProductVariants:K,pickerType:H,onInfoIconClick:N,showProductDetailInfoIcon:_},t))):tt?[1,2,3,4,5,6,7,8,9,10].map(((t,e)=>o("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:o(f,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),e))):o(O,{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."}),o("div",{ref:G})]}),X&&[1,2,3,4,5].map(((t,e)=>o("div",Object.assign({style:{borderBottom:"1px solid #E0E0E0"}},{children:o(f,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]})}),e)))]})},R=e=>{const{collectionId:i,productId:n,data:c,selectedData:l,selectedCollectionsDispatch:r,viewOnly:d,upliftAdditions:s,isProductPartiallyChecked:a,hideProductCheckbox:u,outOfStockAction:v,hideVariantCheckbox:h,hideProductVariants:p,pickerType:m,onInfoIconClick:f,showProductDetailInfoIcon:b}=e,g=t=>{var o,e,c,r,d,s;if(!(null===(e=null===(o=null==l?void 0:l[i])||void 0===o?void 0:o.products)||void 0===e?void 0:e[n]))return!1;return!!(null===(s=null===(d=null===(r=null===(c=null==l?void 0:l[i])||void 0===c?void 0:c.products)||void 0===r?void 0:r[n])||void 0===d?void 0:d.variants)||void 0===s?void 0:s[t])};return t("div",{children:[o(B,{isVariant:!1,data:c,productId:n,collectionId:i,isSelected:!!(null===(k=null===(y=null==l?void 0:l[i])||void 0===y?void 0:y.products)||void 0===k?void 0:k[n]),isPartiallyChecked:a,selectedCollectionsDispatch:r,upliftAdditions:s,viewOnly:d,hideProductCheckbox:u,hideVariantCheckbox:h,hideProductVariants:p,pickerType:m,outOfStockAction:v,onInfoIconClick:f,showProductDetailInfoIcon:b},n),p?null:(()=>{const t=Object.keys(c.variants||[]);let o=!1;return!(t.length<=1)||(t.forEach((t=>{var e,i;o=null!==(i=null===(e=c.variants)||void 0===e?void 0:e[t].name.includes(c.name))&&void 0!==i&&i})),!o)})()&&Object.keys(c.variants||[]).map((t=>o(B,{isVariant:!0,hideVariantCheckbox:h,data:c.variants[t],variantId:t,productId:n,viewOnly:d,upliftAdditions:s,collectionId:i,isSelected:g(t),selectedCollectionsDispatch:r,outOfStockAction:v,onInfoIconClick:f,showProductDetailInfoIcon:b},t)))]});var y,k},B=i=>{const{isVariant:n,data:c,productId:l,collectionId:r,variantId:d,isSelected:s,selectedCollectionsDispatch:a,viewOnly:m,upliftAdditions:f,isPartiallyChecked:g,hideProductCheckbox:k,outOfStockAction:I,hideVariantCheckbox:O,hideProductVariants:P,pickerType:x,onInfoIconClick:E,showProductDetailInfoIcon:D}=i;return t(S,Object.assign({isVariant:n,onClick:t=>{"PRODUCT"===x&&P&&(t.stopPropagation(),a({type:"reset",data:{}}),f("variantSelected",{productId:l,variantId:d||Object.keys(c.variants)[0],collectionId:r,variant:c}))},isActive:s},{children:[n&&!m&&!O||!n&&!m&&!k?o(h,{isChecked:s,isPartiallyChecked:g||!1,onValueChange:function(t){n?t?f("variantSelected",{productId:l,variantId:d,collectionId:r,variant:c}):a({type:"variantUnselected",data:{productId:l,variantId:d,collectionId:r}}):t?f("productSelected",{productId:l,collectionId:r,product:c}):a({type:"productUnselected",data:{productId:l,collectionId:r}})}}):o(e,{}),o("div",{children:o(b,{width:40,height:40,imageUrl:c.image,alt:"Item",borderRadius:4})}),t("div",Object.assign({style:{display:"flex",flexDirection:"column",flex:1}},{children:[t("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between"}},{children:[o(y,Object.assign({variant:"light",body:c.name,placement:"bottom",delay:400},{children:o(j,Object.assign({numberOfLines:1},{children:c.name}))})),D&&o(p,{onClick:()=>{null==E||E(c)},Icon:()=>o(v,{width:20,height:20,color:u.content.placeholder})})]})),o(C,{isVariant:n,data:c,outOfStockAction:I})]}))]}))};export{B as ProductCard,R as ProductGroup,A as ProductsScreen};
|
|
@@ -14,10 +14,28 @@ export interface CollectionsActions {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
export declare function collectionsReducer(collections: Collection, action: CollectionsActions): any;
|
|
17
|
+
/**
|
|
18
|
+
* Pagination reducer used in selected screen.
|
|
19
|
+
* Used for local pagination.
|
|
20
|
+
*
|
|
21
|
+
* Actions used:
|
|
22
|
+
* paginate -> Checks if the products of the collection is already displayed, if yes addes the products, if no adds the entire collection
|
|
23
|
+
* update -> triggers a re-render.
|
|
24
|
+
* set -> adds the data to existing collections.
|
|
25
|
+
* filter -> When user unselects a product in selected screen, we filter out the selected data and show only unselected data.
|
|
26
|
+
*/
|
|
17
27
|
export declare function paginationReducer(collections: SelectedItems, action: SelectedCollectionsActions): SelectedItems;
|
|
18
28
|
export interface SearchReducerActions {
|
|
19
29
|
type: string;
|
|
20
30
|
data: SearchedItems;
|
|
21
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Data used in search screen.
|
|
34
|
+
* To display both collections and products.
|
|
35
|
+
*
|
|
36
|
+
* Actions:
|
|
37
|
+
* set -> no change and sets the data.
|
|
38
|
+
* setProducts -> keeps the collection from search as-is and sets only products
|
|
39
|
+
*/
|
|
22
40
|
export declare function searchReducer(searchedItems: SearchedItems, action: SearchReducerActions): SearchedItems;
|
|
23
41
|
export declare const CollectionIdContext: import("react").Context<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cloneDeep as t}from"lodash";import{createContext as a}from"react";function e(a,e){var s,c,d,o,n
|
|
1
|
+
import{cloneDeep as t}from"lodash";import{createContext as a}from"react";function e(a,e){var s,c,d,r,o,n;let i={},u="",l="",p="";switch(e.type){case"selected":return i=t(a),e.data.val.isSmartCollection&&(e.data.isRestricted&&(i={}),i.isCustom=!0),i[e.data.id]=e.data.val,i;case"unselected":return i=t(a),(null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[e.data.id],i;case"productUnselected":return i=t(a),u=e.data.productId,l=e.data.collectionId,delete i[l].products[u],Object.keys(i[l].products).length||((null==i?void 0:i.isCustom)&&(i.isCustom=!1),delete i[l]),i;case"productSelected":return i=t(a),u=e.data.productId,l=e.data.collectionId,(null===(s=e.data.catalogOnlyData)||void 0===s?void 0:s.isSmartCollection)&&(e.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[l])||(i[l]=e.data.catalogOnlyData,i[l].products={}),i[l].products[u]=e.data.product,i;case"variantSelected":return i=t(a),u=e.data.productId,l=e.data.collectionId,p=e.data.variantId,(null===(c=e.data.catalogOnlyData)||void 0===c?void 0:c.isSmartCollection)&&(e.data.isRestricted&&(i={}),i.isCustom=!0),(null==i?void 0:i[l])||(i[l]=e.data.catalogOnlyData,i[l].products={},i[l].products[u]=e.data.productOnlyData,i[l].products[u].variants={}),(null===(r=null===(d=null==i?void 0:i[l])||void 0===d?void 0:d.products)||void 0===r?void 0:r[u])||((null===(o=null==i?void 0:i[l])||void 0===o?void 0:o.products)||(i[l].products={}),i[l].products[u]=e.data.productOnlyData,i[l].products[u].variants={}),i[l].products[u].variants[p]=e.data.variant,i;case"variantUnselected":return i=t(a),u=e.data.productId,l=e.data.collectionId,p=e.data.variantId,delete i[l].products[u].variants[p],Object.keys(i[l].products[u].variants).length||(delete i[l].products[u],Object.keys(i[l].products).length||((null===(n=i[l])||void 0===n?void 0:n.isSmartCollection)&&(i.isCustom=!1),delete i[l])),i;case"update":return i=Object.assign({},a),i;case"reset":return{};default:return a}}function s(t,a){let e={};switch(a.type){case"fetched":return e=Object.assign({},a.data),e;case"productsFetched":return e=Object.assign({},t),e[a.data.collectionId].products=a.data.products,e;case"paged":return e=Object.assign(Object.assign({},t),a.data),e;case"productsPaged":return e=Object.assign({},t),e[a.data.collectionId].products=Object.assign(Object.assign({},e[a.data.collectionId].products),a.data.products),e;case"searched":e=Object.assign({},t);for(const t in a.data)t in e||(e[t]=a.data[t]);return e;default:return{}}}function c(t,a){let e={};switch(a.type){case"paginate":e=Object.assign({},t);for(const t in a.data)if(Object.prototype.hasOwnProperty.call(a.data,t)){const s=a.data[t];if(Object.prototype.hasOwnProperty.call(e,t)){const a=e[t];e[t]=Object.assign(Object.assign({},a),{products:Object.assign(Object.assign({},a.products),s.products)})}else e[t]=s}return e;case"update":return e=Object.assign({},t),e;case"set":return e=Object.assign(Object.assign({},t),a.data),e;case"filter":e={};for(const s in t)if(s in a.data){const c=Object.assign({},t[s]),d=a.data[s],r={};for(const t in c.products)if(t in d.products){const a=Object.assign({},c.products[t]),e=d.products[t],s={};for(const t in a.variants)t in e.variants&&(s[t]=Object.assign({},a.variants[t]));Object.keys(s).length>0&&(a.variants=s,r[t]=a)}Object.keys(r).length>0&&(c.products=r,e[s]=c)}return e;default:return t}}function d(t,a){let e={collections:{},products:{}};switch(a.type){case"set":return a.data;case"setProducts":return e=Object.assign({},t),e.products=a.data,e;default:return t}}const r=a("");export{r as CollectionIdContext,s as collectionsReducer,c as paginationReducer,d as searchReducer,e as selectedColectionsReducer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as o,jsx as
|
|
1
|
+
import{jsxs as o,jsx as i,Fragment as l}from"react/jsx-runtime";import t from"../../assets/icons/arrow_left.svg.js";import{useEffect as e}from"react";import{IconButton as d}from"../icon-button/IconButton.js";import{BodyCaption as c}from"../TypographyStyle.js";import{CollectionCard as n}from"./collectionScreen.js";import{EmptyState as r}from"./emptyState.js";import{ProductGroup as s}from"./productScreen.js";import{SelectedScreenHeader as u}from"./style.js";import{fetchFbStatusCollection as v,liftTheStateUp as a}from"./utility.js";const p=p=>{const{customCollectionRestriction:h,selectedCollections:m,searchedCollections:f,searchedCollectionsDispatch:k,selectedCollectionsDispatch:C,setScreen:y,collections:b,onBackPress:j,hideVariantCheckbox:O,pickerType:S,hideProductVariants:I,hideProductCheckbox:P,storeId:g,fbStatusFetcher:x,setCollectionId:D,setSelectedCollectionId:E,hideCollectionCheckbox:T,renderWithoutModal:V}=p;e((()=>{var o;v(null!==(o=f.products)&&void 0!==o?o:{},g,k,x,"setProducts")}),[null==f?void 0:f.products]);const w=!!h&&(null==m?void 0:m.isCustom),R=o=>{var i,l;let t=0,e=0;if(m[o]){const d=null===(i=b[o])||void 0===i?void 0:i.products;d&&Object.keys(d).forEach((o=>{var i;const l=null===(i=d[o])||void 0===i?void 0:i.variants;l&&Object.keys(l).forEach((o=>t+=1))}));const c=null===(l=m[o])||void 0===l?void 0:l.products;return c&&Object.keys(c).forEach((o=>{var i;const l=null===(i=c[o])||void 0===i?void 0:i.variants;l&&Object.keys(l).forEach((o=>e+=1))})),!(t<=0&&e>0)&&(e>0&&t!==e)}return!1},W=(o,i)=>{var l,t,e,d,c,n,r,s,u,v,a,p,h,k,C,y,b,j,O,S,I;let P=0,g=0;if(null===(t=null===(l=null==m?void 0:m[o])||void 0===l?void 0:l.products)||void 0===t?void 0:t[i]){const l=(null===(c=null===(d=null===(e=null==m?void 0:m[o])||void 0===e?void 0:e.products)||void 0===d?void 0:d[i])||void 0===c?void 0:c.variants)||[];if(1===Object.keys(l).length)for(const t in l){const l=null===(r=null===(n=null==m?void 0:m[o])||void 0===n?void 0:n.products)||void 0===r?void 0:r[i],e=null===(a=null===(v=null===(u=null===(s=null==m?void 0:m[o])||void 0===s?void 0:s.products)||void 0===u?void 0:u[i])||void 0===v?void 0:v.variants)||void 0===a?void 0:a[t];if(null===(p=null==e?void 0:e.name)||void 0===p?void 0:p.includes(null!==(h=null==l?void 0:l.name)&&void 0!==h?h:""))return!1}if(null===(j=Object.keys((null===(b=null===(y=null===(C=null===(k=f.products)||void 0===k?void 0:k[o])||void 0===C?void 0:C.products)||void 0===y?void 0:y[i])||void 0===b?void 0:b.variants)||[]))||void 0===j||j.forEach((()=>g++)),Object.keys((null===(I=null===(S=null===(O=null==m?void 0:m[o])||void 0===O?void 0:O.products)||void 0===S?void 0:S[i])||void 0===I?void 0:I.variants)||[]).forEach((()=>P++)),P>0&&g!==P)return!0}return!1};return o("div",{children:[o(u,{children:[i(d,{Icon:t,onClick:()=>{y("collections"),j()}}),i(c,{children:"Searched Products"})]}),i("div",{children:Object.keys(null==f?void 0:f.products).length||Object.keys(null==f?void 0:f.collections).length?o(l,{children:[i(l,{children:Object.keys(null==f?void 0:f.collections).map((o=>i(n,{customCollectionRestriction:h,data:null==b?void 0:b[o],isDisabled:w&&!(null==m?void 0:m[o]),isChecked:!!(null==m?void 0:m[o]),isPartiallyChecked:R(o),selectedCollectionsDispatch:C,setCollectionId:D,setSelectedCollectionId:E,setScreen:y,id:o,hideCollectionCheckbox:T||"-1"===o,selectedCollections:m,renderWithoutModal:V,pickerType:S,usedInSearch:!0},o)))}),i(l,{children:Object.keys(null==f?void 0:f.products).map((o=>{var l,t;return Object.keys((null===(t=null===(l=null==f?void 0:f.products)||void 0===l?void 0:l[o])||void 0===t?void 0:t.products)||[]).map((l=>{var t,e;let d=!1;return(null===(t=null==f?void 0:f.products)||void 0===t?void 0:t.isCustom)&&(d=!0),i(s,{collectionId:o,upliftAdditions:(i,l)=>((o,i,l)=>{var t;const e=a(l,null===(t=null==f?void 0:f.products)||void 0===t?void 0:t[o]);C({type:i,data:Object.assign(Object.assign({},e),{isRestricted:h})})})(o,i,l),productId:l,data:(null===(e=null==f?void 0:f.products)||void 0===e?void 0:e[o].products)[l],isProductPartiallyChecked:W(o,l),selectedData:m,selectedCollectionsDispatch:C,viewOnly:d,hideProductCheckbox:P,hideVariantCheckbox:O,hideProductVariants:I,pickerType:S},l)}))}))})]}):i(r,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};export{p as SearchScreen};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as
|
|
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{useRef as l,useReducer as r,useEffect as n}from"react";import{IconButton as d}from"../icon-button/IconButton.js";import{BodyCaption as c}from"../TypographyStyle.js";import{EmptyState as u}from"./emptyState.js";import{ProductGroup as s}from"./productScreen.js";import{paginationReducer as v}from"./reducers.js";import{SelectedScreenHeader as a}from"./style.js";import{paginateSelectedItems as p,fetchFbStatusCollection as m}from"./utility.js";const f=f=>{const{selectedCollections:h,selectedCollectionsDispatch:y,setScreen:j,collections:b,outOfStockAction:k,storeId:O,fbStatusFetcher:S}=f,g=l(0),I=l(null),[C,w]=r(v,{});n((()=>{g.current=0;const o=p(h,10,0);w({type:"paginate",data:o}),m(o,O,w,S,"set"),g.current+=1}),[]),n((()=>{w({type:"filter",data:h})}),[h]),n((()=>{const o=new IntersectionObserver((o=>{if(o[0].isIntersecting&&g.current>0){const o=p(h,10,g.current);w({type:"paginate",data:o}),m(o,O,w,S,"update"),g.current+=1}}),{threshold:1});return I.current&&o.observe(I.current),()=>{I.current&&o.unobserve(I.current)}}),[I,h]);const P=(o,t)=>{var e,i,l,r,n,d,c,u,s,v,a,p,m,f,y,j,k,O,S,g;let I=0,C=0;if(null===(i=null===(e=null==h?void 0:h[o])||void 0===e?void 0:e.products)||void 0===i?void 0:i[t]){const e=(null===(n=null===(r=null===(l=null==h?void 0:h[o])||void 0===l?void 0:l.products)||void 0===r?void 0:r[t])||void 0===n?void 0:n.variants)||[];if(1===Object.keys(e).length)for(const i in e){const e=null===(c=null===(d=null==h?void 0:h[o])||void 0===d?void 0:d.products)||void 0===c?void 0:c[t],l=null===(a=null===(v=null===(s=null===(u=null==h?void 0:h[o])||void 0===u?void 0:u.products)||void 0===s?void 0:s[t])||void 0===v?void 0:v.variants)||void 0===a?void 0:a[i];if(null===(p=null==l?void 0:l.name)||void 0===p?void 0:p.includes(null!==(m=null==e?void 0:e.name)&&void 0!==m?m:""))return!1}if(null===(k=Object.keys((null===(j=null===(y=null===(f=null==b?void 0:b[o])||void 0===f?void 0:f.products)||void 0===y?void 0:y[t])||void 0===j?void 0:j.variants)||[]))||void 0===k||k.forEach((()=>C++)),Object.keys((null===(g=null===(S=null===(O=null==h?void 0:h[o])||void 0===O?void 0:O.products)||void 0===S?void 0:S[t])||void 0===g?void 0:g.variants)||[]).forEach((()=>I++)),I>0&&C!==I)return!0}return!1};return o("div",{children:[o(a,{children:[t(d,{Icon:i,onClick:()=>{j("collections")}}),t(c,{children:"Selected Products"})]}),o("div",{children:[Object.keys(C).length>0?t(e,{children:Object.keys(C).map((o=>{var e;return Object.keys((null===(e=null==C?void 0:C[o])||void 0===e?void 0:e.products)||[]).map((e=>{let i=!1;return(null==h?void 0:h.isCustom)&&(i=!0),t(s,{upliftAdditions:null,collectionId:o,productId:e,data:C[o].products[e],isProductPartiallyChecked:P(o,e),selectedData:h,selectedCollectionsDispatch:y,viewOnly:i,outOfStockAction:k},e)}))}))}):t(u,{title:"No Products Selected",subtitle:"Select products will appear here"}),t("div",{ref:I})]})]})};export{f as SelectedScreen};
|
|
@@ -4,10 +4,28 @@ export declare const liftTheStateUp: (payload: any, data: any) => any;
|
|
|
4
4
|
export declare function paginateSelectedItems(selectedItems: SelectedItems, limit: number, offset: number): {
|
|
5
5
|
[key: string]: Collection;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* 3 scenarios.
|
|
9
|
+
* 1. If no api is provided -> marks everything as approved.
|
|
10
|
+
* 2. If api is success -> sets the status
|
|
11
|
+
* 3. If api is failure -> marks everything as approved.
|
|
12
|
+
*
|
|
13
|
+
* We first get the variant ids to fetch and only if we have variant ids, we call api.
|
|
14
|
+
*/
|
|
7
15
|
export declare const fetchFbStatusCollection: (data: SelectedItems, storeId: string, dispatcher: any, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, dispatchType?: string) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Instead of collection level, we do it product level.
|
|
18
|
+
*
|
|
19
|
+
* For more info refer @function getVariantIdsToFetch
|
|
20
|
+
*/
|
|
8
21
|
export declare const getVariantIdsToFetchAtProductLevel: (products: {
|
|
9
22
|
[key: string]: Product;
|
|
10
23
|
}, globalData?: Collection) => string[];
|
|
24
|
+
/**
|
|
25
|
+
* Instead of collection level, we do it product level.
|
|
26
|
+
*
|
|
27
|
+
* For more info refer @function markVariantsAsApproved
|
|
28
|
+
*/
|
|
11
29
|
export declare const markVariantsAsApprovedProductsLevel: (products: {
|
|
12
30
|
[key: string]: Product;
|
|
13
31
|
}, dispatcher: React.Dispatch<CollectionsActions>, collectionId: string, curScreenData?: Collection, setCurScreenData?: React.Dispatch<React.SetStateAction<Collection>>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cloneDeep as o}from"lodash";const t=(t,l)=>{const n=o(l);if(delete n.products,(t=Object.assign(Object.assign({},t),{catalogOnlyData:n})).productId&&l.products){const d=o(l.products[t.productId]);(null==d?void 0:d.variants)&&delete d.variants,t=Object.assign(Object.assign({},t),{catalogOnlyData:n,productOnlyData:d})}return t};function l(o,t,l){var d;const i={};let
|
|
1
|
+
import{cloneDeep as o}from"lodash";const t=(t,l)=>{const n=o(l);if(delete n.products,(t=Object.assign(Object.assign({},t),{catalogOnlyData:n})).productId&&l.products){const d=o(l.products[t.productId]);(null==d?void 0:d.variants)&&delete d.variants,t=Object.assign(Object.assign({},t),{catalogOnlyData:n,productOnlyData:d})}return t};function l(o,t,l){var d;const i={};let v=0;for(const s in o)if(Object.prototype.hasOwnProperty.call(o,s)){const c=o[s],a=n(c.products,t,l-v);a&&Object.keys(a).length>0&&(i[s]=Object.assign(Object.assign({},c),{products:a})),v+=Object.keys(null!==(d=c.products)&&void 0!==d?d:{}).length}return i}function n(o,t,l){if(!o)return{};const n=Object.keys(o).slice(l,l+t),d={};return n.forEach((t=>{d[t]=o[t]})),d}const d=(o,t,l)=>{Object.keys(o).forEach((t=>{var l,n;const d=null!==(n=null===(l=o[t])||void 0===l?void 0:l.products)&&void 0!==n?n:{};Object.keys(d).forEach((l=>{var n,d,i,v;const s=null!==(v=null===(i=null===(d=null===(n=o[t])||void 0===n?void 0:n.products)||void 0===d?void 0:d[l])||void 0===i?void 0:i.variants)&&void 0!==v?v:{};Object.keys(s).forEach((n=>{var d,i,v,s;const c=null===(s=null===(v=null===(i=null===(d=o[t])||void 0===d?void 0:d.products)||void 0===i?void 0:i[l])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[n];c&&!c.fbStatus&&(c.fbStatus="APPROVED")}))}))})),t({type:l,data:o})},i=function(o,t,l,n){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";n||d(o,l,i);const v=(o=>{const t=[];return Object.keys(o).forEach((l=>{var n,d;const i=null!==(d=null===(n=o[l])||void 0===n?void 0:n.products)&&void 0!==d?d:{};Object.keys(i).forEach((n=>{var d,i,v,s;const c=null!==(s=null===(v=null===(i=null===(d=o[l])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(c).forEach((d=>{var i,v,s,c;const a=null===(c=null===(s=null===(v=null===(i=o[l])||void 0===i?void 0:i.products)||void 0===v?void 0:v[n])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[d];(null==a?void 0:a.fbStatus)||t.push(d)}))}))})),t})(o);v.length>0&&n&&n(t,v).then((t=>{const n=Object.assign({},o);Object.keys(n).forEach((o=>{var l,d;const i=null!==(d=null===(l=n[o])||void 0===l?void 0:l.products)&&void 0!==d?d:{};Object.keys(i).forEach((l=>{var d,i,v,s;const c=null!==(s=null===(v=null===(i=null===(d=n[o])||void 0===d?void 0:d.products)||void 0===i?void 0:i[l])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(c).forEach((d=>{var i,v,s,c;const a=null===(c=null===(s=null===(v=null===(i=n[o])||void 0===i?void 0:i.products)||void 0===v?void 0:v[l])||void 0===s?void 0:s.variants)||void 0===c?void 0:c[d];a&&"REJECTED"===t[d]?a.fbStatus="REJECTED":a&&"APPROVED"===t[d]&&(a.fbStatus="APPROVED")}))}))})),l({type:i,data:n})})).catch((t=>{console.error("Error in fbStatusFetcher",t),d(o,l,i)}))},v=(o,t)=>{const l=[];return Object.keys(null!=o?o:{}).forEach((n=>{var d,i;const v=null!==(i=null===(d=null==o?void 0:o[n])||void 0===d?void 0:d.variants)&&void 0!==i?i:{};Object.keys(v).forEach((d=>{var i,v,s,c,a;let u;u=t?null===(s=null===(v=null===(i=null==t?void 0:t.products)||void 0===i?void 0:i[n])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[d]:null===(a=null===(c=null==o?void 0:o[n])||void 0===c?void 0:c.variants)||void 0===a?void 0:a[d],(null==u?void 0:u.fbStatus)||l.push(d)}))})),l},s=(o,t,l,n,d)=>{const i=Object.assign({},o);if(Object.keys(o).forEach((t=>{var l,n;Object.keys(null!==(n=null===(l=null==o?void 0:o[t])||void 0===l?void 0:l.variants)&&void 0!==n?n:{}).forEach((l=>{var n,d;const v=null===(n=null==o?void 0:o[t].variants)||void 0===n?void 0:n[l];v&&(v.fbStatus="APPROVED");const s=null===(d=null==i?void 0:i[t])||void 0===d?void 0:d.variants;s&&s[l]&&(s[l]=v)}))})),n&&d){const o=Object.assign({},n);o.products=i,d(o),t({type:"productsPaged",data:{collectionId:l,products:i}})}else t({type:"productsPaged",data:{collectionId:l,products:i}})};export{i as fetchFbStatusCollection,v as getVariantIdsToFetchAtProductLevel,t as liftTheStateUp,s as markVariantsAsApprovedProductsLevel,l as paginateSelectedItems};
|