@bikdotai/bik-component-library 0.0.665-beta.0.1 → 0.0.665-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/components/analytics-chips-and-dropdowns/chart/Pie/PieChartAnalytics.js +1 -1
  2. package/dist/cjs/components/discount-modal/DiscountModal.d.ts +0 -2
  3. package/dist/cjs/components/discount-modal/DiscountModal.js +1 -1
  4. package/dist/cjs/components/discount-modal/DynamicCoupon/DynamicCoupon.js +1 -1
  5. package/dist/cjs/components/product-picker-v2/collectionScreen.d.ts +1 -3
  6. package/dist/cjs/components/product-picker-v2/collectionScreen.js +1 -1
  7. package/dist/cjs/components/product-picker-v2/modal.d.ts +5 -7
  8. package/dist/cjs/components/product-picker-v2/modal.js +1 -1
  9. package/dist/cjs/components/product-picker-v2/productScreen.d.ts +3 -5
  10. package/dist/cjs/components/product-picker-v2/productScreen.js +1 -1
  11. package/dist/cjs/components/product-picker-v2/rearrangeScreen.d.ts +1 -3
  12. package/dist/cjs/components/product-picker-v2/rearrangeScreen.js +1 -1
  13. package/dist/cjs/components/product-picker-v2/reducers.js +1 -1
  14. package/dist/cjs/components/product-picker-v2/searchScreen.d.ts +1 -3
  15. package/dist/cjs/components/product-picker-v2/searchScreen.js +1 -1
  16. package/dist/cjs/components/product-picker-v2/selectedScreen.d.ts +1 -3
  17. package/dist/cjs/components/product-picker-v2/selectedScreen.js +1 -1
  18. package/dist/cjs/components/product-picker-v2/utility.d.ts +1 -2
  19. package/dist/cjs/components/product-picker-v2/utility.js +1 -1
  20. package/dist/esm/components/analytics-chips-and-dropdowns/chart/Pie/PieChartAnalytics.js +1 -1
  21. package/dist/esm/components/discount-modal/DiscountModal.d.ts +0 -2
  22. package/dist/esm/components/discount-modal/DiscountModal.js +1 -1
  23. package/dist/esm/components/discount-modal/DynamicCoupon/DynamicCoupon.js +1 -1
  24. package/dist/esm/components/product-picker-v2/collectionScreen.d.ts +1 -3
  25. package/dist/esm/components/product-picker-v2/collectionScreen.js +1 -1
  26. package/dist/esm/components/product-picker-v2/modal.d.ts +5 -7
  27. package/dist/esm/components/product-picker-v2/modal.js +1 -1
  28. package/dist/esm/components/product-picker-v2/productScreen.d.ts +3 -5
  29. package/dist/esm/components/product-picker-v2/productScreen.js +1 -1
  30. package/dist/esm/components/product-picker-v2/rearrangeScreen.d.ts +1 -3
  31. package/dist/esm/components/product-picker-v2/rearrangeScreen.js +1 -1
  32. package/dist/esm/components/product-picker-v2/reducers.js +1 -1
  33. package/dist/esm/components/product-picker-v2/searchScreen.d.ts +1 -3
  34. package/dist/esm/components/product-picker-v2/searchScreen.js +1 -1
  35. package/dist/esm/components/product-picker-v2/selectedScreen.d.ts +1 -3
  36. package/dist/esm/components/product-picker-v2/selectedScreen.js +1 -1
  37. package/dist/esm/components/product-picker-v2/utility.d.ts +1 -2
  38. package/dist/esm/components/product-picker-v2/utility.js +1 -1
  39. package/package.json +2 -2
  40. package/dist/cjs/_virtual/bik-store.js +0 -1
  41. package/dist/cjs/node_modules/@bikdotai/bik-models/growth/models/bik-store.js +0 -1
  42. package/dist/esm/_virtual/bik-store.js +0 -1
  43. package/dist/esm/node_modules/@bikdotai/bik-models/growth/models/bik-store.js +0 -1
@@ -1 +1 @@
1
- import{__rest as e}from"../../../_virtual/_tslib.js";import{jsxs as i,jsx as t,Fragment as o}from"react/jsx-runtime";import n from"../../../assets/icons/info.svg.js";import{Alert as l}from"../../alerts/Alert.js";import{ALERT_TYPES as s,CONTENT_POSITION as r}from"../../alerts/AlertHelper.js";import{Button as a}from"../../button/Button.js";import{CheckBox as d}from"../../checkBox/CheckBox.js";import"../../../node_modules/@bikdotai/bik-models/growth/models/bik-store.js";import"react";import{DISCOUNT_APPLIES_TO as c,OFFER_APPLIES_TO as u,DISCOUNT_TYPES as p,COUPON_EXPIRATION as m,DISCOUNT_VALUE_TYPES as v,DISCOUNT_TARGET_TYPES as C,DISCOUNT_TARGET_SELECTION as E}from"../type.js";import"../../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../../dropdown/Dropdown.js";import"../../dropdown/ChipDropdown.js";import"../../zeroState/ZeroState.js";import{BodySecondary as D,TitleRegular as g,TitleSmall as T}from"../../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../../constants/Theme.js";import"../../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../../list-item/ListItem.js";import"../../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../../icon-button/IconButton.js";import{Input as y}from"../../input/Input.js";import P from"../../../assets/icons/cross.svg.js";import"../../dropdown/MenuItem/MenuItem.js";import"../../modals/styledModal.js";import"../../../node_modules/lodash.debounce/index.js";import"../../bik-layout/CommonStyles.js";import"../../product-picker/ProductPicker.styled.js";import"../../../utils/DateUtils.js";import"../../tag/Tag.js";import"../../tooltips/Tooltip.js";import"../../product-picker-v2/modal.js";import"../../variable-picker-v3/model.js";import"../../modals/modal.styled.js";import O from"../../../assets/icons/plus.svg.js";import"../../accordion/Accordion.style.js";import"../../accordion/AccordionArrow.js";import"../../switch/Switch.js";import"../../variable-picker-v3/NoResult.js";import"../../variable-picker-v3/styles.js";import"lodash";import{DynamicCouponContainer as I}from"../DiscountModal.styled.js";import{CouponExpiration as j}from"../CouponExpiration/CouponExpiration.js";import{RadioButton as V}from"../../radioButton/RadioButton.js";import S from"../../../assets/icons/cubeIcon.svg.js";import f from"../../../assets/icons/delete.svg.js";import x from"../../../assets/icons/edit.svg.js";import{DiscountOptionsContainer as R,DiscountDetailsOption as _,AddProductButtonsContainer as A,ProductCollectionCard as N,CubeIconContainer as w,IconContainer as L,ProductVariableCard as F}from"./DynamicCoupon.styled.js";import q from"./MinimumRequirementComponent.js";import k from"./ZeroState.js";var U;!function(e){e.ENTITLED="entitled",e.PREREQUISITE="prerequisite"}(U||(U={}));const B=B=>{var M,G,Q,Y,X,$,W,z;const Z=[{selected:B.discountCouponAppliesTo===c.ENTIRE_ORDER,label:"Entire Order",value:c.ENTIRE_ORDER},{selected:B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS,label:"Specific Product",value:c.SPECIFIC_PRODUCTS},{selected:B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:c.SPECIFIC_COLLECTIONS}],H=[{selected:B.offerAppliesToBuy===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToBuy===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],J=[{selected:B.offerAppliesToGet===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToGet===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],K=(e,d,u)=>{var p,m,v,C,E,b,g,y,I,j,V,R;let _=[],q=[],k={},M={};B.useNewPicker?(k=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,M=null!==(p=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==p?p:[],(null==k?void 0:k.isCustom)&&delete k.isCustom,(null==M?void 0:M.isCustom)&&delete M.isCustom,Object.values(k).forEach((e=>{Object.keys(e.products).forEach((i=>{_.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(M).forEach((e=>{"isCustom"!==e&&q.push({id:e,name:M[e].name,image:M[e].image})}))):(_=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,q=null!==(m=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==m?m:[]);const G=[null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidProductSelection,null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidProductVariableSelection,null===(E=B.dynamicDiscountValidationError)||void 0===E?void 0:E.inValidCollectionSelection],Q=[null===(b=B.dynamicDiscountValidationError)||void 0===b?void 0:b.inValidBuyXCollectionSelection,null===(g=B.dynamicDiscountValidationError)||void 0===g?void 0:g.inValidBuyXProductSelection,null===(y=B.dynamicDiscountValidationError)||void 0===y?void 0:y.inValidBuyXProductVariableSelection],Y=[null===(I=B.dynamicDiscountValidationError)||void 0===I?void 0:I.inValidGetYCollectionSelection,null===(j=B.dynamicDiscountValidationError)||void 0===j?void 0:j.inValidGetYProductSelection,null===(V=B.dynamicDiscountValidationError)||void 0===V?void 0:V.inValidGetYProductVariableSelection];let X=!1;return"couponAppliesTo"===u&&(X=G.some(Boolean)),"buyX"===u&&(X=Q.some(Boolean)),"getY"===u&&(X=Y.some(Boolean)),i(o,{children:[i("div",Object.assign({style:{display:"flex",gap:18}},{children:[e===c.SPECIFIC_PRODUCTS&&0===_.length&&(d===U.ENTITLED&&!B.entitledProductVariable||d===U.PREREQUISITE&&!B.preRequisiteProductVariable)&&!(null==q?void 0:q.length)&&i(A,{children:[t("div",Object.assign({style:{width:B.isProductVariableSupported?"284px":"300px",display:"flex"}},{children:t(a,{buttonText:"Add Product(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductPickerOpen(d)},error:X})})),B.isProductVariableSupported&&B.productVariableList&&i(o,{children:[t(D,Object.assign({color:h.colorsV2.content.placeholder},{children:"OR"})),t(a,{buttonText:"Add Product(s) Variable",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductVariablePickerOpen(d)},error:X})]})]}),e===c.SPECIFIC_COLLECTIONS&&0===q.length&&!(null==_?void 0:_.length)&&t("div",Object.assign({style:{width:"300px",display:"flex"}},{children:t(a,{buttonText:"Add collection(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsCollectionPickerOpen(d)},style:{marginTop:"16px"},error:X})}))]})),X&&t("div",Object.assign({style:{margin:"8px 0 0"}},{children:t(l,{type:s.NEGATIVE,text:"Required Field",contentPosition:r.START,icon:()=>t(n,{width:16,height:16,color:h.colorsV2.content.negative})})})),_.length||q.length?i("div",{children:[t(D,Object.assign({style:{margin:"8px 0"}},{children:e===c.SPECIFIC_COLLECTIONS?"Collection(s)":"Product(s)"})),i(N,{children:[t(w,{children:t(S,{width:20,height:20,color:h.colorsV2.content.secondary})}),i(T,{children:[e===c.SPECIFIC_PRODUCTS?_.length:q.length," ",e===c.SPECIFIC_PRODUCTS?"Product(s)":"Collection(s)"," ","added"]}),i("div",Object.assign({style:{display:"flex",gap:4}},{children:[t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?B.setIsProductPickerOpen(d):B.setIsCollectionPickerOpen(d)}},{children:t(x,{width:24,height:24,color:h.colorsV2.content.placeholder})})),t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?d===U.ENTITLED?B.setEntitledProducts([]):B.setPrerequisiteProducts([]):d===U.ENTITLED?B.setEntitledCollections([]):B.setPrerequisiteCollections([])}},{children:t(f,{width:24,height:24,color:h.colorsV2.content.placeholder})}))]}))]})]}):d===U.ENTITLED&&B.entitledProductVariable?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.entitledProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setEntitledProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):d===U.PREREQUISITE&&(null===(R=B.preRequisiteProductVariable)||void 0===R?void 0:R.displayName)?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.preRequisiteProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setPreRequisiteProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):t(o,{children:" "})]})},ee=(e,o)=>{var n,l,s,r,a,d,p,m,v,C;let E=[],g=[],h={},P={};B.useNewPicker?(h=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,P=null!==(n=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==n?n:[],(null==h?void 0:h.isCustom)&&delete h.isCustom,(null==P?void 0:P.isCustom)&&delete P.isCustom,Object.values(h).forEach((e=>{Object.keys(e.products).forEach((i=>{E.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(P).forEach((e=>{"isCustom"!==e&&g.push({id:e,name:P[e].name,image:P[e].image})}))):(E=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,g=null!==(l=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==l?l:[]);const O=e===U.PREREQUISITE?B.offerAppliesToBuy:B.offerAppliesToGet,I=e===U.PREREQUISITE?U.PREREQUISITE:U.ENTITLED,j=O===u.SPECIFIC_PRODUCTS?c.SPECIFIC_PRODUCTS:c.SPECIFIC_COLLECTIONS;return i("div",{children:[t(T,Object.assign({style:{marginBottom:16}},{children:e===U.PREREQUISITE?"Customer buys":"Customer gets"})),i("div",Object.assign({style:{display:"flex"}},{children:[!o&&t("div",{children:i("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:e===U.ENTITLED?null!==(r=null===(s=B.discountData.entitledQuantity)||void 0===s?void 0:s.toString())&&void 0!==r?r:"":null!==(d=null===(a=B.discountData.prerequisiteQuantity)||void 0===a?void 0:a.toString())&&void 0!==d?d:"",type:"number",onChangeText:i=>{e===U.ENTITLED?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledQuantity:parseInt(i)})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteQuantity:parseInt(i)}))},labelText:"Quantity of products",placeholder:"Eg. 2",width:"300px",errorMessage:e===U.PREREQUISITE&&(null===(p=B.dynamicDiscountValidationError)||void 0===p?void 0:p.inValidBuyXValue)||e===U.ENTITLED&&(null===(m=B.dynamicDiscountValidationError)||void 0===m?void 0:m.inValidGetYValue)?"Required Field":"",state:e===U.PREREQUISITE&&(null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidBuyXValue)||e===U.ENTITLED&&(null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidGetYValue)?"invalid":"none"})})),t("div",{className:"input__wrapper"})]}))}),i("div",{children:[t(D,Object.assign({style:{marginBottom:8}},{children:"Any items from"})),e===U.PREREQUISITE&&t(b,{width:"244px",options:H,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToBuy(e.value),B.setPrerequisiteProducts([]),B.setPrerequisiteCollections([]),B.setPreRequisiteProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidBuyXCollectionSelection:!1,inValidBuyXProductSelection:!1,inValidBuyXProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.entitledCollections,prerequisiteCollections:{}},productsConf:{entitledProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.entitledProducts,prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,prerequisiteProductVariable:{}}}))}}),e===U.ENTITLED&&t(b,{width:"244px",options:J,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToGet(e.value),B.setEntitledProducts([]),B.setEntitledCollections([]),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidGetYCollectionSelection:!1,inValidGetYProductSelection:!1,inValidGetYProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledCollectionIds:[],entitledProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.prerequisiteCollections},productsConf:{entitledProducts:{},prerequisiteProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.prerequisiteProducts},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.prerequisiteProductVariable}}))}})]})]})),K(j,I,e===U.PREREQUISITE?"buyX":"getY")]})};return i(I,{children:[i("div",{children:[i("div",Object.assign({style:{display:"flex",gap:16}},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(M=B.discountData.title)&&void 0!==M?M:"",onChangeText:e=>{var i;B.setDiscountData(Object.assign(Object.assign({},B.discountData),{title:null!==(i=null==e?void 0:e.trim())&&void 0!==i?i:""}))},maxCharLimit:30,labelText:"Discount Coupon Title",placeholder:`Eg. “Flat ${null!==(G=B.currency)&&void 0!==G?G:""} 15 Off”`,hintText:"Will be same for everyone. Can’t be changed later",width:"300px",isRequired:!0,errorMessage:(null===(Q=B.dynamicDiscountValidationError)||void 0===Q?void 0:Q.invalidCouponTitle)?"Required Field":"",state:(null===(Y=B.dynamicDiscountValidationError)||void 0===Y?void 0:Y.invalidCouponTitle)?"invalid":"none"})})),!B.hideProbability&&t(y,{value:null!==($=null===(X=B.discountData.probability)||void 0===X?void 0:X.toString())&&void 0!==$?$:"",type:"number",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{probability:e.startsWith(".")?parseFloat(parseFloat(`0${e}`).toFixed(2)):parseFloat(parseFloat(e).toFixed(2))}))},labelText:"Probability of getting coupon ",hintText:"Enter a decimal value between 0-1",placeholder:"Eg. 0.5",maxCharLimit:4,width:"300px",isRequired:!0,errorMessage:(null===(W=B.dynamicDiscountValidationError)||void 0===W?void 0:W.inValidProbability)?"Required Field":"",state:(null===(z=B.dynamicDiscountValidationError)||void 0===z?void 0:z.inValidProbability)?"invalid":"none"})]})),t("div",{style:{height:"1px",width:"100%",background:h.colorsV2.stroke.primary,margin:"24px 0 8px"}})]}),B.allowStaticCoupon&&t((()=>i("div",{children:[t(g,{children:"Discount Details"}),t(R,{children:B.discountDetailsOptions.map((t=>{return i(_,Object.assign({selected:B.selectedDiscountDetails.id===t.id,onClick:()=>(i=>{if(B.selectedDiscountDetails.id!==i.id)if(B.resetValidationErrors(),B.setValidationErrorMessage(""),B.setDiscountCouponAppliesTo(c.ENTIRE_ORDER),B.setSelectedDiscountDetails(i),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0})),B.setPreRequisiteProductVariable(void 0),B.setEntitledProductVariable(void 0),["percentage","amount"].includes(i.value)){B.onChangeCouponType({label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER});const t=Object.assign(Object.assign({},B.discountData),{valueType:"percentage"===i.value?v.PERCENTAGE:v.FIXED_AMOUNT,value:void 0,targetType:C.LINE_ITEM,targetSelection:E.ALL,entitledCollectionIds:[],entitledProductIds:[],prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:{}},productsConf:{entitledProducts:{},prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:{}}}),o=e(t,["entitledQuantity","prerequisiteQuantity"]);B.setDiscountData(o)}else B.onChangeCouponType({label:i.label,selected:!0,value:i.value})})(t)},{children:[t.icon((o=t.id,B.selectedDiscountDetails.id===o?h.colorsV2.stroke.brand:h.colorsV2.text.secondary)),t.label]}),t.id);var o}))})]})),{}),(B.selectedCouponType===p.AMOUNT_OFF_ORDER||B.selectedCouponType===p.AMOUNT_OFF_PRODUCTS)&&(()=>{var e,n,l,s,r,a;return i(o,{children:[t("div",Object.assign({className:"input__rows"},{children:t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(l=null===(n=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===n?void 0:n.toString())&&void 0!==l?l:"",labelText:"Discount amount",type:"number",width:"300px",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},placeholder:"15",prefixText:B.discountData.valueType===v.FIXED_AMOUNT?null!==(s=B.currency)&&void 0!==s?s:"":void 0,suffixText:B.discountData.valueType===v.PERCENTAGE?"%":void 0,errorMessage:(null===(r=B.dynamicDiscountValidationError)||void 0===r?void 0:r.inValidDiscountAmount)?"Required Field":"",state:(null===(a=B.dynamicDiscountValidationError)||void 0===a?void 0:a.inValidDiscountAmount)?"invalid":"none"})}))})),t("div",Object.assign({style:{paddingTop:"24px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:i("div",Object.assign({className:"input__wrapper"},{children:[t(g,Object.assign({style:{marginBottom:10}},{children:"Applies to"})),t("div",Object.assign({style:{display:"flex",flexGrow:0,flexShrink:0,flexBasis:"auto"}},{children:t(b,{width:"300px",options:Z,placement:"bottom-start",onSelect:e=>{const i="value"in e&&e.value===c.ENTIRE_ORDER?{label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER}:{label:"Amount off on products",selected:!0,value:p.AMOUNT_OFF_PRODUCTS};B.onChangeCouponType(i),B.setDiscountCouponAppliesTo(e.value),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidProductVariableSelection:!1,inValidProductSelection:!1,inValidCollectionSelection:!1})))}})})),(B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS||B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS)&&K(B.discountCouponAppliesTo,U.ENTITLED,"couponAppliesTo")]}))}))]})})(),B.selectedCouponType===p.BUY_X_GET_Y&&(()=>{var e,o,n,l,s;return i(I,Object.assign({style:{border:`1px solid ${h.colorsV2.stroke.primary}`,padding:"16px",borderRadius:"4px",margin:0}},{children:[ee(U.PREREQUISITE),t("div",{style:{width:"100%",height:"1px",backgroundColor:h.colorsV2.stroke.primary,margin:"8px 0"}}),ee(U.ENTITLED),t(D,Object.assign({style:{marginTop:"8px"}},{children:"At a discounted value"})),t("div",{children:t(V,{label:"Free",isActive:100===B.discountData.value,onValueChange:e=>{e?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:100})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}})}),i("div",Object.assign({style:{display:"flex",flexDirection:"column"}},{children:[t(V,{label:"Percentage off",isActive:100!==B.discountData.value,onValueChange:()=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}}),100!==B.discountData.value&&t("div",Object.assign({style:{marginTop:8}},{children:t(y,{value:null!==(n=null===(o=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===o?void 0:o.toString())&&void 0!==n?n:"",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Eg. 50",suffixText:"%",width:"300px",errorMessage:(null===(l=B.dynamicDiscountValidationError)||void 0===l?void 0:l.inValidDiscountAmount)?"Required Field":"",state:(null===(s=B.dynamicDiscountValidationError)||void 0===s?void 0:s.inValidDiscountAmount)?"invalid":"none"})}))]}))]}))})(),!B.selectedCouponType&&t(k,{}),B.allowStaticCoupon&&B.selectedCouponType!==p.BUY_X_GET_Y&&t("div",Object.assign({style:{padding:"24px 0 16px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:t(q,{selectedMinimumRequirement:B.selectedMinimumRequirement,setSelectedMinimumRequirement:B.setSelectedMinimumRequirement,discountData:B.discountData,setDiscountData:B.setDiscountData,currency:B.currency,dynamicDiscountValidationError:B.dynamicDiscountValidationError})})),B.selectedCouponType&&!B.hideExpiration&&i("div",Object.assign({style:{padding:B.selectedCouponType!==p.BUY_X_GET_Y?"24px 0 16px":"8px 0",borderTop:B.selectedCouponType!==p.BUY_X_GET_Y?`1px solid ${h.colorsV2.stroke.primary}`:"none"}},{children:[t(d,{label:"Add expiration",isDisabled:!!B.makeExpiryMandatory,isChecked:B.isAddExpirationChecked,onValueChange:e=>{B.setIsAddExpirationChecked(e),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{expireAfter:void 0,expireAt:void 0})),B.setSelectedExpiration(m.DYNAMIC_EXPIRATION)},boldOnChecked:!0,labelSize:"DEFAULT"}),t(D,Object.assign({style:{color:h.colorsV2.text.secondary,marginLeft:28}},{children:"Make coupon only valid till a certain time"})),B.isAddExpirationChecked&&t(j,{discountData:B.discountData,setDiscountData:B.setDiscountData,isAddExpirationChecked:B.isAddExpirationChecked,inValidCouponExpiry:B.dynamicDiscountValidationError.inValidCouponExpiry,selectedExpiration:B.selectedExpiration,setSelectedExpiration:B.setSelectedExpiration})]}))]})};export{U as DISCOUNT_PRODUCTS,B as default};
1
+ import{__rest as e}from"../../../_virtual/_tslib.js";import{jsxs as i,jsx as t,Fragment as o}from"react/jsx-runtime";import n from"../../../assets/icons/info.svg.js";import{Alert as l}from"../../alerts/Alert.js";import{ALERT_TYPES as s,CONTENT_POSITION as r}from"../../alerts/AlertHelper.js";import{Button as a}from"../../button/Button.js";import{CheckBox as d}from"../../checkBox/CheckBox.js";import"react";import{DISCOUNT_APPLIES_TO as c,OFFER_APPLIES_TO as u,DISCOUNT_TYPES as p,COUPON_EXPIRATION as m,DISCOUNT_VALUE_TYPES as v,DISCOUNT_TARGET_TYPES as C,DISCOUNT_TARGET_SELECTION as E}from"../type.js";import"../../dropdown/DropdownPopover/index.js";import{Dropdown as b}from"../../dropdown/Dropdown.js";import"../../dropdown/ChipDropdown.js";import"../../zeroState/ZeroState.js";import{BodySecondary as D,TitleRegular as g,TitleSmall as T}from"../../TypographyStyle.js";import{DEFAULT_THEME as h}from"../../../constants/Theme.js";import"../../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../../list-item/ListItem.js";import"../../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../../icon-button/IconButton.js";import{Input as y}from"../../input/Input.js";import P from"../../../assets/icons/cross.svg.js";import"../../dropdown/MenuItem/MenuItem.js";import"../../modals/styledModal.js";import"../../../node_modules/lodash.debounce/index.js";import"../../bik-layout/CommonStyles.js";import"../../product-picker/ProductPicker.styled.js";import"../../../utils/DateUtils.js";import"../../tag/Tag.js";import"../../tooltips/Tooltip.js";import"../../product-picker-v2/modal.js";import"../../variable-picker-v3/model.js";import"../../modals/modal.styled.js";import O from"../../../assets/icons/plus.svg.js";import"../../accordion/Accordion.style.js";import"../../accordion/AccordionArrow.js";import"../../switch/Switch.js";import"../../variable-picker-v3/NoResult.js";import"../../variable-picker-v3/styles.js";import"lodash";import{DynamicCouponContainer as I}from"../DiscountModal.styled.js";import{CouponExpiration as j}from"../CouponExpiration/CouponExpiration.js";import{RadioButton as V}from"../../radioButton/RadioButton.js";import S from"../../../assets/icons/cubeIcon.svg.js";import f from"../../../assets/icons/delete.svg.js";import x from"../../../assets/icons/edit.svg.js";import{DiscountOptionsContainer as R,DiscountDetailsOption as _,AddProductButtonsContainer as A,ProductCollectionCard as N,CubeIconContainer as w,IconContainer as L,ProductVariableCard as F}from"./DynamicCoupon.styled.js";import q from"./MinimumRequirementComponent.js";import k from"./ZeroState.js";var U;!function(e){e.ENTITLED="entitled",e.PREREQUISITE="prerequisite"}(U||(U={}));const B=B=>{var M,G,Q,Y,X,$,W,z;const Z=[{selected:B.discountCouponAppliesTo===c.ENTIRE_ORDER,label:"Entire Order",value:c.ENTIRE_ORDER},{selected:B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS,label:"Specific Product",value:c.SPECIFIC_PRODUCTS},{selected:B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:c.SPECIFIC_COLLECTIONS}],H=[{selected:B.offerAppliesToBuy===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToBuy===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],J=[{selected:B.offerAppliesToGet===u.SPECIFIC_PRODUCTS,label:"Specific Product",value:u.SPECIFIC_PRODUCTS},{selected:B.offerAppliesToGet===u.SPECIFIC_COLLECTIONS,label:"Specific Collections",value:u.SPECIFIC_COLLECTIONS}],K=(e,d,u)=>{var p,m,v,C,E,b,g,y,I,j,V,R;let _=[],q=[],k={},M={};B.useNewPicker?(k=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,M=null!==(p=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==p?p:[],(null==k?void 0:k.isCustom)&&delete k.isCustom,(null==M?void 0:M.isCustom)&&delete M.isCustom,Object.values(k).forEach((e=>{Object.keys(e.products).forEach((i=>{_.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(M).forEach((e=>{"isCustom"!==e&&q.push({id:e,name:M[e].name,image:M[e].image})}))):(_=d===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,q=null!==(m=d===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==m?m:[]);const G=[null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidProductSelection,null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidProductVariableSelection,null===(E=B.dynamicDiscountValidationError)||void 0===E?void 0:E.inValidCollectionSelection],Q=[null===(b=B.dynamicDiscountValidationError)||void 0===b?void 0:b.inValidBuyXCollectionSelection,null===(g=B.dynamicDiscountValidationError)||void 0===g?void 0:g.inValidBuyXProductSelection,null===(y=B.dynamicDiscountValidationError)||void 0===y?void 0:y.inValidBuyXProductVariableSelection],Y=[null===(I=B.dynamicDiscountValidationError)||void 0===I?void 0:I.inValidGetYCollectionSelection,null===(j=B.dynamicDiscountValidationError)||void 0===j?void 0:j.inValidGetYProductSelection,null===(V=B.dynamicDiscountValidationError)||void 0===V?void 0:V.inValidGetYProductVariableSelection];let X=!1;return"couponAppliesTo"===u&&(X=G.some(Boolean)),"buyX"===u&&(X=Q.some(Boolean)),"getY"===u&&(X=Y.some(Boolean)),i(o,{children:[i("div",Object.assign({style:{display:"flex",gap:18}},{children:[e===c.SPECIFIC_PRODUCTS&&0===_.length&&(d===U.ENTITLED&&!B.entitledProductVariable||d===U.PREREQUISITE&&!B.preRequisiteProductVariable)&&!(null==q?void 0:q.length)&&i(A,{children:[t("div",Object.assign({style:{width:B.isProductVariableSupported?"284px":"300px",display:"flex"}},{children:t(a,{buttonText:"Add Product(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductPickerOpen(d)},error:X})})),B.isProductVariableSupported&&B.productVariableList&&i(o,{children:[t(D,Object.assign({color:h.colorsV2.content.placeholder},{children:"OR"})),t(a,{buttonText:"Add Product(s) Variable",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsProductVariablePickerOpen(d)},error:X})]})]}),e===c.SPECIFIC_COLLECTIONS&&0===q.length&&!(null==_?void 0:_.length)&&t("div",Object.assign({style:{width:"300px",display:"flex"}},{children:t(a,{buttonText:"Add collection(s)",buttonType:"dashRegular",LeadingIcon:O,matchParentWidth:!0,onClick:()=>{B.setIsCollectionPickerOpen(d)},style:{marginTop:"16px"},error:X})}))]})),X&&t("div",Object.assign({style:{margin:"8px 0 0"}},{children:t(l,{type:s.NEGATIVE,text:"Required Field",contentPosition:r.START,icon:()=>t(n,{width:16,height:16,color:h.colorsV2.content.negative})})})),_.length||q.length?i("div",{children:[t(D,Object.assign({style:{margin:"8px 0"}},{children:e===c.SPECIFIC_COLLECTIONS?"Collection(s)":"Product(s)"})),i(N,{children:[t(w,{children:t(S,{width:20,height:20,color:h.colorsV2.content.secondary})}),i(T,{children:[e===c.SPECIFIC_PRODUCTS?_.length:q.length," ",e===c.SPECIFIC_PRODUCTS?"Product(s)":"Collection(s)"," ","added"]}),i("div",Object.assign({style:{display:"flex",gap:4}},{children:[t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?B.setIsProductPickerOpen(d):B.setIsCollectionPickerOpen(d)}},{children:t(x,{width:24,height:24,color:h.colorsV2.content.placeholder})})),t(L,Object.assign({onClick:()=>{e===c.SPECIFIC_PRODUCTS?d===U.ENTITLED?B.setEntitledProducts([]):B.setPrerequisiteProducts([]):d===U.ENTITLED?B.setEntitledCollections([]):B.setPrerequisiteCollections([])}},{children:t(f,{width:24,height:24,color:h.colorsV2.content.placeholder})}))]}))]})]}):d===U.ENTITLED&&B.entitledProductVariable?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.entitledProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setEntitledProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):d===U.PREREQUISITE&&(null===(R=B.preRequisiteProductVariable)||void 0===R?void 0:R.displayName)?i("div",{children:[t(D,Object.assign({style:{margin:"16px 0 8px"}},{children:"Product Variable"})),i(F,{children:[t(T,{children:B.preRequisiteProductVariable.displayName}),t("div",Object.assign({style:{display:"flex",gap:4}},{children:t(L,Object.assign({onClick:()=>{B.setPreRequisiteProductVariable(void 0)}},{children:t(P,{width:24,height:24,color:h.colorsV2.content.primary})}))}))]})]}):t(o,{children:" "})]})},ee=(e,o)=>{var n,l,s,r,a,d,p,m,v,C;let E=[],g=[],h={},P={};B.useNewPicker?(h=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,P=null!==(n=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==n?n:[],(null==h?void 0:h.isCustom)&&delete h.isCustom,(null==P?void 0:P.isCustom)&&delete P.isCustom,Object.values(h).forEach((e=>{Object.keys(e.products).forEach((i=>{E.push({id:i,name:e.products[i].name,image:e.products[i].image})}))})),Object.keys(P).forEach((e=>{"isCustom"!==e&&g.push({id:e,name:P[e].name,image:P[e].image})}))):(E=e===U.ENTITLED?B.entitledProducts:B.prerequisiteProducts,g=null!==(l=e===U.ENTITLED?B.entitledCollections:B.prerequisiteCollections)&&void 0!==l?l:[]);const O=e===U.PREREQUISITE?B.offerAppliesToBuy:B.offerAppliesToGet,I=e===U.PREREQUISITE?U.PREREQUISITE:U.ENTITLED,j=O===u.SPECIFIC_PRODUCTS?c.SPECIFIC_PRODUCTS:c.SPECIFIC_COLLECTIONS;return i("div",{children:[t(T,Object.assign({style:{marginBottom:16}},{children:e===U.PREREQUISITE?"Customer buys":"Customer gets"})),i("div",Object.assign({style:{display:"flex"}},{children:[!o&&t("div",{children:i("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:e===U.ENTITLED?null!==(r=null===(s=B.discountData.entitledQuantity)||void 0===s?void 0:s.toString())&&void 0!==r?r:"":null!==(d=null===(a=B.discountData.prerequisiteQuantity)||void 0===a?void 0:a.toString())&&void 0!==d?d:"",type:"number",onChangeText:i=>{e===U.ENTITLED?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledQuantity:parseInt(i)})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteQuantity:parseInt(i)}))},labelText:"Quantity of products",placeholder:"Eg. 2",width:"300px",errorMessage:e===U.PREREQUISITE&&(null===(p=B.dynamicDiscountValidationError)||void 0===p?void 0:p.inValidBuyXValue)||e===U.ENTITLED&&(null===(m=B.dynamicDiscountValidationError)||void 0===m?void 0:m.inValidGetYValue)?"Required Field":"",state:e===U.PREREQUISITE&&(null===(v=B.dynamicDiscountValidationError)||void 0===v?void 0:v.inValidBuyXValue)||e===U.ENTITLED&&(null===(C=B.dynamicDiscountValidationError)||void 0===C?void 0:C.inValidGetYValue)?"invalid":"none"})})),t("div",{className:"input__wrapper"})]}))}),i("div",{children:[t(D,Object.assign({style:{marginBottom:8}},{children:"Any items from"})),e===U.PREREQUISITE&&t(b,{width:"244px",options:H,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToBuy(e.value),B.setPrerequisiteProducts([]),B.setPrerequisiteCollections([]),B.setPreRequisiteProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidBuyXCollectionSelection:!1,inValidBuyXProductSelection:!1,inValidBuyXProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.entitledCollections,prerequisiteCollections:{}},productsConf:{entitledProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.entitledProducts,prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.entitledProductVariable,prerequisiteProductVariable:{}}}))}}),e===U.ENTITLED&&t(b,{width:"244px",options:J,placement:"bottom-start",onSelect:e=>{var i,t,o;B.setOfferAppliesToGet(e.value),B.setEntitledProducts([]),B.setEntitledCollections([]),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidGetYCollectionSelection:!1,inValidGetYProductSelection:!1,inValidGetYProductVariableSelection:!1}))),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{entitledCollectionIds:[],entitledProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:null===(i=B.discountData.collectionsConf)||void 0===i?void 0:i.prerequisiteCollections},productsConf:{entitledProducts:{},prerequisiteProducts:null===(t=B.discountData.productsConf)||void 0===t?void 0:t.prerequisiteProducts},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:null===(o=B.discountData.productVariableConf)||void 0===o?void 0:o.prerequisiteProductVariable}}))}})]})]})),K(j,I,e===U.PREREQUISITE?"buyX":"getY")]})};return i(I,{children:[i("div",{children:[i("div",Object.assign({style:{display:"flex",gap:16}},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(M=B.discountData.title)&&void 0!==M?M:"",onChangeText:e=>{var i;B.setDiscountData(Object.assign(Object.assign({},B.discountData),{title:null!==(i=null==e?void 0:e.trim())&&void 0!==i?i:""}))},maxCharLimit:30,labelText:"Discount Coupon Title",placeholder:`Eg. “Flat ${null!==(G=B.currency)&&void 0!==G?G:""} 15 Off”`,hintText:"Will be same for everyone. Can’t be changed later",width:"300px",isRequired:!0,errorMessage:(null===(Q=B.dynamicDiscountValidationError)||void 0===Q?void 0:Q.invalidCouponTitle)?"Required Field":"",state:(null===(Y=B.dynamicDiscountValidationError)||void 0===Y?void 0:Y.invalidCouponTitle)?"invalid":"none"})})),!B.hideProbability&&t(y,{value:null!==($=null===(X=B.discountData.probability)||void 0===X?void 0:X.toString())&&void 0!==$?$:"",type:"number",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{probability:e.startsWith(".")?parseFloat(parseFloat(`0${e}`).toFixed(2)):parseFloat(parseFloat(e).toFixed(2))}))},labelText:"Probability of getting coupon ",hintText:"Enter a decimal value between 0-1",placeholder:"Eg. 0.5",maxCharLimit:4,width:"300px",isRequired:!0,errorMessage:(null===(W=B.dynamicDiscountValidationError)||void 0===W?void 0:W.inValidProbability)?"Required Field":"",state:(null===(z=B.dynamicDiscountValidationError)||void 0===z?void 0:z.inValidProbability)?"invalid":"none"})]})),t("div",{style:{height:"1px",width:"100%",background:h.colorsV2.stroke.primary,margin:"24px 0 8px"}})]}),B.allowStaticCoupon&&t((()=>i("div",{children:[t(g,{children:"Discount Details"}),t(R,{children:B.discountDetailsOptions.map((t=>{return i(_,Object.assign({selected:B.selectedDiscountDetails.id===t.id,onClick:()=>(i=>{if(B.selectedDiscountDetails.id!==i.id)if(B.resetValidationErrors(),B.setValidationErrorMessage(""),B.setDiscountCouponAppliesTo(c.ENTIRE_ORDER),B.setSelectedDiscountDetails(i),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0})),B.setPreRequisiteProductVariable(void 0),B.setEntitledProductVariable(void 0),["percentage","amount"].includes(i.value)){B.onChangeCouponType({label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER});const t=Object.assign(Object.assign({},B.discountData),{valueType:"percentage"===i.value?v.PERCENTAGE:v.FIXED_AMOUNT,value:void 0,targetType:C.LINE_ITEM,targetSelection:E.ALL,entitledCollectionIds:[],entitledProductIds:[],prerequisiteCollectionIds:[],prerequisiteProductIds:[],collectionsConf:{entitledCollections:{},prerequisiteCollections:{}},productsConf:{entitledProducts:{},prerequisiteProducts:{}},productVariableConf:{entitledProductVariable:{},prerequisiteProductVariable:{}}}),o=e(t,["entitledQuantity","prerequisiteQuantity"]);B.setDiscountData(o)}else B.onChangeCouponType({label:i.label,selected:!0,value:i.value})})(t)},{children:[t.icon((o=t.id,B.selectedDiscountDetails.id===o?h.colorsV2.stroke.brand:h.colorsV2.text.secondary)),t.label]}),t.id);var o}))})]})),{}),(B.selectedCouponType===p.AMOUNT_OFF_ORDER||B.selectedCouponType===p.AMOUNT_OFF_PRODUCTS)&&(()=>{var e,n,l,s,r,a;return i(o,{children:[t("div",Object.assign({className:"input__rows"},{children:t("div",Object.assign({className:"input__wrapper"},{children:t(y,{value:null!==(l=null===(n=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===n?void 0:n.toString())&&void 0!==l?l:"",labelText:"Discount amount",type:"number",width:"300px",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},placeholder:"15",prefixText:B.discountData.valueType===v.FIXED_AMOUNT?null!==(s=B.currency)&&void 0!==s?s:"":void 0,suffixText:B.discountData.valueType===v.PERCENTAGE?"%":void 0,errorMessage:(null===(r=B.dynamicDiscountValidationError)||void 0===r?void 0:r.inValidDiscountAmount)?"Required Field":"",state:(null===(a=B.dynamicDiscountValidationError)||void 0===a?void 0:a.inValidDiscountAmount)?"invalid":"none"})}))})),t("div",Object.assign({style:{paddingTop:"24px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:i("div",Object.assign({className:"input__wrapper"},{children:[t(g,Object.assign({style:{marginBottom:10}},{children:"Applies to"})),t("div",Object.assign({style:{display:"flex",flexGrow:0,flexShrink:0,flexBasis:"auto"}},{children:t(b,{width:"300px",options:Z,placement:"bottom-start",onSelect:e=>{const i="value"in e&&e.value===c.ENTIRE_ORDER?{label:"Amount off on order",selected:!0,value:p.AMOUNT_OFF_ORDER}:{label:"Amount off on products",selected:!0,value:p.AMOUNT_OFF_PRODUCTS};B.onChangeCouponType(i),B.setDiscountCouponAppliesTo(e.value),B.setEntitledProductVariable(void 0),B.setDynamicDiscountValidationError((e=>Object.assign(Object.assign({},e),{inValidProductVariableSelection:!1,inValidProductSelection:!1,inValidCollectionSelection:!1})))}})})),(B.discountCouponAppliesTo===c.SPECIFIC_PRODUCTS||B.discountCouponAppliesTo===c.SPECIFIC_COLLECTIONS)&&K(B.discountCouponAppliesTo,U.ENTITLED,"couponAppliesTo")]}))}))]})})(),B.selectedCouponType===p.BUY_X_GET_Y&&(()=>{var e,o,n,l,s;return i(I,Object.assign({style:{border:`1px solid ${h.colorsV2.stroke.primary}`,padding:"16px",borderRadius:"4px",margin:0}},{children:[ee(U.PREREQUISITE),t("div",{style:{width:"100%",height:"1px",backgroundColor:h.colorsV2.stroke.primary,margin:"8px 0"}}),ee(U.ENTITLED),t(D,Object.assign({style:{marginTop:"8px"}},{children:"At a discounted value"})),t("div",{children:t(V,{label:"Free",isActive:100===B.discountData.value,onValueChange:e=>{e?B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:100})):B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}})}),i("div",Object.assign({style:{display:"flex",flexDirection:"column"}},{children:[t(V,{label:"Percentage off",isActive:100!==B.discountData.value,onValueChange:()=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:void 0}))}}),100!==B.discountData.value&&t("div",Object.assign({style:{marginTop:8}},{children:t(y,{value:null!==(n=null===(o=null===(e=B.discountData)||void 0===e?void 0:e.value)||void 0===o?void 0:o.toString())&&void 0!==n?n:"",onChangeText:e=>{B.setDiscountData(Object.assign(Object.assign({},B.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Eg. 50",suffixText:"%",width:"300px",errorMessage:(null===(l=B.dynamicDiscountValidationError)||void 0===l?void 0:l.inValidDiscountAmount)?"Required Field":"",state:(null===(s=B.dynamicDiscountValidationError)||void 0===s?void 0:s.inValidDiscountAmount)?"invalid":"none"})}))]}))]}))})(),!B.selectedCouponType&&t(k,{}),B.allowStaticCoupon&&B.selectedCouponType!==p.BUY_X_GET_Y&&t("div",Object.assign({style:{padding:"24px 0 16px",marginTop:16,borderTop:`1px solid ${h.colorsV2.stroke.primary}`}},{children:t(q,{selectedMinimumRequirement:B.selectedMinimumRequirement,setSelectedMinimumRequirement:B.setSelectedMinimumRequirement,discountData:B.discountData,setDiscountData:B.setDiscountData,currency:B.currency,dynamicDiscountValidationError:B.dynamicDiscountValidationError})})),B.selectedCouponType&&!B.hideExpiration&&i("div",Object.assign({style:{padding:B.selectedCouponType!==p.BUY_X_GET_Y?"24px 0 16px":"8px 0",borderTop:B.selectedCouponType!==p.BUY_X_GET_Y?`1px solid ${h.colorsV2.stroke.primary}`:"none"}},{children:[t(d,{label:"Add expiration",isDisabled:!!B.makeExpiryMandatory,isChecked:B.isAddExpirationChecked,onValueChange:e=>{B.setIsAddExpirationChecked(e),B.setDiscountData(Object.assign(Object.assign({},B.discountData),{expireAfter:void 0,expireAt:void 0})),B.setSelectedExpiration(m.DYNAMIC_EXPIRATION)},boldOnChecked:!0,labelSize:"DEFAULT"}),t(D,Object.assign({style:{color:h.colorsV2.text.secondary,marginLeft:28}},{children:"Make coupon only valid till a certain time"})),B.isAddExpirationChecked&&t(j,{discountData:B.discountData,setDiscountData:B.setDiscountData,isAddExpirationChecked:B.isAddExpirationChecked,inValidCouponExpiry:B.dynamicDiscountValidationError.inValidCouponExpiry,selectedExpiration:B.selectedExpiration,setSelectedExpiration:B.setSelectedExpiration})]}))]})};export{U as DISCOUNT_PRODUCTS,B as default};
@@ -1,4 +1,3 @@
1
- import { ApplicationType } from '@bikdotai/bik-models/growth/models/bik-store';
2
1
  import React from 'react';
3
2
  import { Collection, CollectionFetcherReturn, SelectedItems } from '.';
4
3
  import { CollectionsActions, SelectedCollectionsActions } from './reducers';
@@ -10,7 +9,7 @@ interface CollectionsScreenInterface {
10
9
  [key: string]: Collection;
11
10
  };
12
11
  selectedCollections: SelectedItems;
13
- collectionFetcher: (offset: number, storeId: string, appType: ApplicationType) => CollectionFetcherReturn;
12
+ collectionFetcher: (offset: number, storeId: string) => CollectionFetcherReturn;
14
13
  storeId: string;
15
14
  selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>;
16
15
  setCollectionId: React.Dispatch<React.SetStateAction<string>>;
@@ -26,7 +25,6 @@ interface CollectionsScreenInterface {
26
25
  renderWithoutModal?: boolean;
27
26
  pickerType?: 'COLLECTION' | 'PRODUCT';
28
27
  scrollContainerRef: React.RefObject<HTMLDivElement>;
29
- appType: ApplicationType;
30
28
  }
31
29
  export declare const CollectionsScreen: (props: CollectionsScreenInterface) => import("react/jsx-runtime").JSX.Element;
32
30
  export interface CollectionCardInterface {
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import i from"../../assets/icons/chevronRight.svg.js";import{useRef as l,useState as c,useEffect as n}from"react";import{CheckBox as r}from"../checkBox/CheckBox.js";import{IconButton as s}from"../icon-button/IconButton.js";import{Tag as d}from"../tag/Tag.js";import{Tooltip as a}from"../tooltips/Tooltip.js";import{TitleRegular as u,BodyPrimary as h}from"../TypographyStyle.js";import{EmptyState as p}from"./emptyState.js";import{ProductPickerShimmer as m}from"./ProductPickerShimmer.js";import{CollectionCardStyle as C,CollectionCardInfoStyle as v,CollectionCardDetailStyle as g,CollectionNameHolder as y}from"./style.js";import{isCollectionPartiallyChecked as f}from"./utility.js";const b=(e,t,o)=>{if(!e)return"";if(e.length<=t)return e;const i=e.slice(0,t-1);return(o?i.slice(0,i.lastIndexOf(" ")):i)+"..."},k=o=>{var i;const{customCollectionRestriction:r,dataLoading:s,collections:d,selectedCollectionsDispatch:a,setCollectionId:u,setSelectedCollectionId:h,selectedCollections:C,setScreen:v,collectionFetcher:g,collectionsDispatch:y,pagingControls:b,storeId:k,setSaveDisabled:O,hideCollectionCheckbox:I,renderWithoutModal:S,pickerType:P,scrollContainerRef:T,appType:x}=o,D=l(b.curPage),L=!!r&&(null==C?void 0:C.isCustom),[R,E]=c(!1),w=l(!1),B=l(!1),N=()=>{if(!T||!(null==T?void 0:T.current))return;const{scrollTop:e,clientHeight:t,scrollHeight:o}=T.current;e+t>=o-20&&!w.current&&!B.current&&(O(!0),E(!0),B.current=!0,O(!0),E(!0),g(D.current,k,x).then((e=>{y({type:"paged",data:(null==e?void 0:e.collections)||{}}),b.setCurPage(D.current+1),E(!1),O(!1),B.current=!1,Object.keys(null==e?void 0:e.collections).length||(w.current=!0)})).catch())};return n((()=>{var e;return null===(e=null==T?void 0:T.current)||void 0===e||e.addEventListener("scroll",N),()=>{var e;null===(e=null==T?void 0:T.current)||void 0===e||e.removeEventListener("scroll",N)}}),[]),n((()=>{D.current=b.curPage}),[b.curPage]),e("div",{children:[(null===(i=Object.keys(null!=d?d:{}))||void 0===i?void 0:i.length)?Object.keys(d).map((e=>{var o,i;const l=!!(null==C?void 0:C[e])&&("PRODUCT"!==P||!!Object.keys(null!==(i=null===(o=null==C?void 0:C[e])||void 0===o?void 0:o.products)&&void 0!==i?i:{}).length);return t(j,{customCollectionRestriction:r,data:d[e],isDisabled:L&&!(null==C?void 0:C[e]),isChecked:l,isPartiallyChecked:f(e,null==d?void 0:d[e],C),selectedCollectionsDispatch:a,setCollectionId:u,setSelectedCollectionId:h,setScreen:v,id:e,hideCollectionCheckbox:I||"-1"===e,selectedCollections:C,renderWithoutModal:S,pickerType:P},e)})):s?t(m,{}):t(p,{title:"No collections to show",subtitle:"We couldn’t find any collection."}),R&&t(m,{})]})},j=l=>{const{customCollectionRestriction:c,data:n,selectedCollectionsDispatch:p,setCollectionId:m,setSelectedCollectionId:f,isPartiallyChecked:b,setScreen:k,id:j,isChecked:O,isDisabled:I,hideCollectionCheckbox:S,pickerType:P,usedInSearch:T}=l;return n?e(C,Object.assign({isDisabled:I,onClick:e=>{if(!I){if("COLLECTION"===P)return e.stopPropagation(),p({type:"reset",data:{}}),p({type:"selected",data:{id:j,val:n,isRestricted:c}}),m(j),void f(j);m(j),f(j),k("products")}},isActive:O,usedInSearch:null!=T&&T},{children:[e(v,{children:[!S&&t(r,{isDisabled:I,isChecked:O,isPartiallyChecked:b,onValueChange:function(e,t,o){null==o||o.stopPropagation(),p(e?{type:"selected",data:{id:j,val:n,isRestricted:c}}:{type:"unselected",data:{id:j}}),f(e?j:"")}}),t(g,{children:t(a,Object.assign({body:n.name,placement:"bottom",delay:400,variant:"light"},{children:e(y,{children:[t(T?h:u,Object.assign({numberOfLines:1},{children:n.name})),n.isSmartCollection?t("div",Object.assign({style:{display:"flex"}},{children:t(d,{tagText:"Smart Collection",type:"warning"})})):t(o,{})]})}))})]}),"COLLECTION"!==P&&t(s,{height:12,width:12,disabled:I,Icon:i})]})):t(o,{})};export{j as CollectionCard,k as CollectionsScreen,b as truncate};
1
+ import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import i from"../../assets/icons/chevronRight.svg.js";import{useRef as l,useState as c,useEffect as n}from"react";import{CheckBox as r}from"../checkBox/CheckBox.js";import{IconButton as s}from"../icon-button/IconButton.js";import{Tag as d}from"../tag/Tag.js";import{Tooltip as a}from"../tooltips/Tooltip.js";import{TitleRegular as u,BodyPrimary as h}from"../TypographyStyle.js";import{EmptyState as p}from"./emptyState.js";import{ProductPickerShimmer as m}from"./ProductPickerShimmer.js";import{CollectionCardStyle as C,CollectionCardInfoStyle as v,CollectionCardDetailStyle as g,CollectionNameHolder as y}from"./style.js";import{isCollectionPartiallyChecked as f}from"./utility.js";const b=(e,t,o)=>{if(!e)return"";if(e.length<=t)return e;const i=e.slice(0,t-1);return(o?i.slice(0,i.lastIndexOf(" ")):i)+"..."},k=o=>{var i;const{customCollectionRestriction:r,dataLoading:s,collections:d,selectedCollectionsDispatch:a,setCollectionId:u,setSelectedCollectionId:h,selectedCollections:C,setScreen:v,collectionFetcher:g,collectionsDispatch:y,pagingControls:b,storeId:k,setSaveDisabled:O,hideCollectionCheckbox:I,renderWithoutModal:S,pickerType:P,scrollContainerRef:T}=o,x=l(b.curPage),D=!!r&&(null==C?void 0:C.isCustom),[L,R]=c(!1),E=l(!1),w=l(!1),B=()=>{if(!T||!(null==T?void 0:T.current))return;const{scrollTop:e,clientHeight:t,scrollHeight:o}=T.current;e+t>=o-20&&!E.current&&!w.current&&(O(!0),R(!0),w.current=!0,O(!0),R(!0),g(x.current,k).then((e=>{y({type:"paged",data:(null==e?void 0:e.collections)||{}}),b.setCurPage(x.current+1),R(!1),O(!1),w.current=!1,Object.keys(null==e?void 0:e.collections).length||(E.current=!0)})).catch())};return n((()=>{var e;return null===(e=null==T?void 0:T.current)||void 0===e||e.addEventListener("scroll",B),()=>{var e;null===(e=null==T?void 0:T.current)||void 0===e||e.removeEventListener("scroll",B)}}),[]),n((()=>{x.current=b.curPage}),[b.curPage]),e("div",{children:[(null===(i=Object.keys(null!=d?d:{}))||void 0===i?void 0:i.length)?Object.keys(d).map((e=>{var o,i;const l=!!(null==C?void 0:C[e])&&("PRODUCT"!==P||!!Object.keys(null!==(i=null===(o=null==C?void 0:C[e])||void 0===o?void 0:o.products)&&void 0!==i?i:{}).length);return t(j,{customCollectionRestriction:r,data:d[e],isDisabled:D&&!(null==C?void 0:C[e]),isChecked:l,isPartiallyChecked:f(e,null==d?void 0:d[e],C),selectedCollectionsDispatch:a,setCollectionId:u,setSelectedCollectionId:h,setScreen:v,id:e,hideCollectionCheckbox:I||"-1"===e,selectedCollections:C,renderWithoutModal:S,pickerType:P},e)})):s?t(m,{}):t(p,{title:"No collections to show",subtitle:"We couldn’t find any collection."}),L&&t(m,{})]})},j=l=>{const{customCollectionRestriction:c,data:n,selectedCollectionsDispatch:p,setCollectionId:m,setSelectedCollectionId:f,isPartiallyChecked:b,setScreen:k,id:j,isChecked:O,isDisabled:I,hideCollectionCheckbox:S,pickerType:P,usedInSearch:T}=l;return n?e(C,Object.assign({isDisabled:I,onClick:e=>{if(!I){if("COLLECTION"===P)return e.stopPropagation(),p({type:"reset",data:{}}),p({type:"selected",data:{id:j,val:n,isRestricted:c}}),m(j),void f(j);m(j),f(j),k("products")}},isActive:O,usedInSearch:null!=T&&T},{children:[e(v,{children:[!S&&t(r,{isDisabled:I,isChecked:O,isPartiallyChecked:b,onValueChange:function(e,t,o){null==o||o.stopPropagation(),p(e?{type:"selected",data:{id:j,val:n,isRestricted:c}}:{type:"unselected",data:{id:j}}),f(e?j:"")}}),t(g,{children:t(a,Object.assign({body:n.name,placement:"bottom",delay:400,variant:"light"},{children:e(y,{children:[t(T?h:u,Object.assign({numberOfLines:1},{children:n.name})),n.isSmartCollection?t("div",Object.assign({style:{display:"flex"}},{children:t(d,{tagText:"Smart Collection",type:"warning"})})):t(o,{})]})}))})]}),"COLLECTION"!==P&&t(s,{height:12,width:12,disabled:I,Icon:i})]})):t(o,{})};export{j as CollectionCard,k as CollectionsScreen,b as truncate};
@@ -1,5 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { ApplicationType } from '@bikdotai/bik-models/growth/models/bik-store';
3
2
  import { ButtonProps } from '../button/model';
4
3
  import { FooterForNonModalI, OUT_OF_STOCK_ACTION } from './type';
5
4
  export interface ProductVariant {
@@ -69,13 +68,12 @@ export type ProductPickerInterface = {
69
68
  hideGlobalSearch?: boolean;
70
69
  hideInCollectionSearch?: boolean;
71
70
  customCollectionRestriction?: boolean;
72
- searchInCollectionFetcher: (storeId: string, collectionId: string, query: string, appType: ApplicationType) => ProductFetcherReturn;
73
- searchFetcher: (storeId: string, query: string, appType: ApplicationType) => Promise<SearchedItems | SelectedItems>;
74
- collectionFetcher: (offset: number, storeId: string, appType: ApplicationType) => CollectionFetcherReturn;
75
- productFetcher: (collectionId: string, storeId: string, appType: ApplicationType, limit?: number, offset?: number) => ProductFetcherReturn;
76
- fbStatusFetcher?: (storeId: string, variantIds: string[], appType: ApplicationType) => FbStatusFetcherReturn;
71
+ searchInCollectionFetcher: (storeId: string, collectionId: string, query: string) => ProductFetcherReturn;
72
+ searchFetcher: (storeId: string, query: string) => Promise<SearchedItems | SelectedItems>;
73
+ collectionFetcher: (offset: number, storeId: string) => CollectionFetcherReturn;
74
+ productFetcher: (collectionId: string, storeId: string, limit?: number, offset?: number) => ProductFetcherReturn;
75
+ fbStatusFetcher?: (storeId: string, variantIds: string[]) => FbStatusFetcherReturn;
77
76
  storeId: string;
78
- appType?: ApplicationType;
79
77
  selectedItems: SelectedItems;
80
78
  onAdd: (items: SelectedItems, total: number, secondaryClick?: boolean) => void;
81
79
  onClose?: () => void;
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import"../../node_modules/@bikdotai/bik-models/growth/models/bik-store.js";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 a from"../../assets/icons/cross.svg.js";import{Button as d}from"../button/Button.js";import{Input as u}from"../input/Input.js";import{StyledModal as p}from"../modals/styledModal.js";import{Spinner as h}from"../spinner/Spinner.js";import{Tag as m}from"../tag/Tag.js";import{CollectionsScreen as g}from"./collectionScreen.js";import{ProductInfoOverlay as C}from"./productInfoOverlay.js";import{ProductsScreen as y}from"./productScreen.js";import{RearrangeScreen as b}from"./rearrangeScreen.js";import{collectionsReducer as f,searchReducer as S,selectedColectionsReducer as k,CollectionIdContext as v}from"./reducers.js";import{SearchScreen as j}from"./searchScreen.js";import{SelectedScreen as I}from"./selectedScreen.js";import{ContainerStyle as x,ScrollContainerStyle as P,StyledFooterForNonModal as O}from"./style.js";import{OUT_OF_STOCK_ACTION as T}from"./type.js";import{updateAllVariantsForSelectedProducts as D}from"./utility.js";import{__exports as F}from"../../_virtual/bik-store.js";var R;!function(e){e.Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products"}(R||(R={}));const w=w=>{const{storeId:A,selectedItems:B,onClose:E,visible:L,zIndex:z,exactLimit:V,limit:$,hideCollectionCheckbox:M,hideProductCheckbox:H,outOfStockAction:W=T.BLUR,hideVariantCheckbox:_,selectProductsFromCustomCollection:G,hideSelectionCount:K,title:N,width:U,left:Y,renderWithoutModal:q,onClickSave:J,pickerType:Q,hideProductVariants:X=!1,startupScreen:Z=R.Collections,rearrangeEnabled:ee,selectSingleItem:te=!1,showProductDetails:oe,containerStyle:ce,crossButtonInsideHeader:re=!1,footerForNonModal:se={},primaryButton:ie,secondaryButton:ne,subtitle:le}=w,ae=w.appType||F.ApplicationType.BIK,[de,ue]=r(f,{}),[pe,he]=s([R.Collections,R.RearrangeProducts].includes(Z)?Z:R.Collections),[me,ge]=s("grid"),[Ce,ye]=s(""),[be,fe]=s(""),[Se,ke]=s(0),[ve,je]=s(!1),[Ie,xe]=s(0),[Pe,Oe]=s(""),[Te,De]=s(!1),[Fe,Re]=s(!1),[we,Ae]=r(S,{collections:{},products:{}}),[Be,Ee]=r(k,Object.keys(B).length>0?B:{}),Le=i(null),[ze,Ve]=s(!1),[$e,Me]=s();n((()=>{je(!0),Re(!0),w.collectionFetcher(Se,A,ae).then((e=>{ue({type:"fetched",data:(null==e?void 0:e.collections)||{}}),je(!1),ke((e=>e+1)),Re(!1)})).catch()}),[]),n((()=>{let e=0;X?Object.keys(Be||[]).forEach((t=>{var o;Object.keys((null===(o=Be[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c;"-1"!==t&&Be[-1]&&(null===(c=Be[-1].products)||void 0===c?void 0:c[o])||(e+=1)}))})):Object.keys(Be||[]).forEach((t=>{var o;Object.keys((null===(o=Be[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=Be[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),xe(e)}),[de,Be,X]),n((()=>{be&&(je(!0),w.productFetcher(be,A,ae).then((e=>{Object.keys(e).length&&ue({type:"productsFetched",data:{collectionId:be,products:e}}),je(!1)})).catch())}),[be]),n((()=>{const e=setTimeout((()=>{"rearrange"!==pe&&(Pe.length||"collections"!==pe)&&(Pe.length?(De(!0),w.searchFetcher(A,Pe,ae).then((e=>{"collections"in e&&"products"in e?(Ae({type:"set",data:e}),ue({type:"searched",data:e.collections})):(Ae({type:"set",data:{collections:{},products:e}}),ue({type:"searched",data:e})),he("searchProducts"),je(!1),De(!1)}))):he("collections"))}),800);return()=>clearTimeout(e)}),[Pe]),n((()=>{J&&(w.onAdd(Be,Ie),He())}),[J]),n((()=>{te&&Object.keys(Be||{}).length&&Ie&&(w.onAdd(Be,Ie),He())}),[te,Be,Ie]);const He=()=>{Ee({type:"reset",data:{}})},We=()=>V&&Ie>V?t(m,{tagText:`You can only select ${V} products`,type:"negative"}):$&&Ie>$?t(m,{tagText:`You can only select ${$} products`,type:"negative"}):t(d,Ie>0?{onClick:()=>{he(ee?R.RearrangeProducts:R.SelectedProducts)},buttonText:V?`${Ie}/${V} products selected`:`${Ie} products selected`,buttonType:["rearrange","view"].includes(pe)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(pe)}:{disabled:!0,buttonText:V?`${Ie}/${V} products selected`:`${Ie} products selected`,buttonType:"tertiaryGray"}),_e=e=>ve?"Loading...":pe===R.RearrangeProducts?null!=e?e:"Done":null!=e?e:"Add",Ge=e(x,Object.assign({style:null!=ce?ce:{}},{children:[w.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:w.postHeader})),!w.hideGlobalSearch&&t(o,{children:("collections"===pe||"searchProducts"===pe)&&t("div",Object.assign({style:{padding:q?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(u,{placeholder:"Search using ID, Name or SKU ID",noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>Te?t(h,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:Pe,onChangeText:e=>{e.length&&e.trim().length?Oe(e):Oe("")}})}))}),e(P,Object.assign({ref:Le,screenName:pe},{children:["collections"===pe&&t(g,{customCollectionRestriction:w.customCollectionRestriction,dataLoading:Fe,collections:de,selectedCollectionsDispatch:Ee,setCollectionId:ye,setSelectedCollectionId:fe,setScreen:he,selectedCollections:Be,collectionFetcher:w.collectionFetcher,storeId:A,appType:ae,collectionsDispatch:ue,setSaveDisabled:je,pagingControls:{curPage:Se,setCurPage:ke},hideCollectionCheckbox:M,renderWithoutModal:q,pickerType:Q,scrollContainerRef:Le}),"products"===pe&&Ce&&t(v.Provider,Object.assign({value:Ce},{children:t(y,{hideInCollectionSearch:w.hideInCollectionSearch,customCollectionRestriction:w.customCollectionRestriction,productFetcher:w.productFetcher,setScreen:he,storeId:A,appType:ae,data:de[Ce],collectionsDispatch:ue,selectedCollectionsDispatch:Ee,selectedData:Be,setSaveDisabled:je,searchInCollectionFetcher:w.searchInCollectionFetcher,hideProductCheckbox:H,outOfStockAction:W,hideVariantCheckbox:_,selectProductsFromCustomCollection:G,renderWithoutModal:q,pickerType:Q,hideProductVariants:X,fbStatusFetcher:w.fbStatusFetcher,onProductDetailClick:e=>{Ve(!0),Me(e)},showProductDetailInfoIcon:oe,scrollContainerRef:Le})})),"view"===pe&&t(I,{selectedCollections:Be||{},selectedCollectionsDispatch:Ee,setScreen:he,collections:de,hideProductVariants:X,outOfStockAction:W,storeId:A,appType:ae,fbStatusFetcher:w.fbStatusFetcher}),"rearrange"===pe&&t(b,{selectedCollections:Be||{},selectedCollectionsDispatch:Ee,setScreen:he,outOfStockAction:W,rearrangeViewType:"grid"===me?"list":"grid",scrollContainerRef:Le,storeId:A,appType:ae,fbStatusFetcher:w.fbStatusFetcher}),"searchProducts"===pe&&t(j,{customCollectionRestriction:w.customCollectionRestriction,selectedCollections:Be||{},searchedCollections:we||{},searchedCollectionsDispatch:Ae,selectedCollectionsDispatch:Ee,setScreen:he,collections:de,onBackPress:()=>{Oe(""),Ae({type:"set",data:{collections:{},products:{}}})},pickerType:Q,hideProductCheckbox:H,hideProductVariants:X,hideVariantCheckbox:_,storeId:A,appType:ae,fbStatusFetcher:w.fbStatusFetcher,setCollectionId:ye,setSelectedCollectionId:fe,renderWithoutModal:q,hideCollectionCheckbox:M,outOfStockAction:W})]}))]}));return t(o,{children:q?e(o,{children:[Ge,se.renderFooter?e(O,{children:[We(),t(d,{buttonText:_e(se.primaryButtonText),disabled:!se.isLoading&&(ve||Ie<1||V&&Ie<V||!V&&$&&Ie>$)||se.primaryButtonDisabled,isLoading:se.isLoading,onClick:()=>{w.onAdd(Be,Ie),He(),he([R.Collections,R.RearrangeProducts].includes(Z)?Z:R.Collections)}})]}):t(o,{}),ze&&$e?t(C,{productData:$e,outOfStockAction:W,useDynamicInfoImageSize:w.useDynamicInfoImageSize,onClose:()=>{Ve(!1)}}):t(o,{})]}):e(p,Object.assign({zIndex:z,open:L,onClose:()=>{null==E||E(),He()},headingTitle:N||("collections"===pe||"products"===pe?"Select Products":"view"===pe?"Selected Products":"searchProducts"===pe?"Searched Results":"rearrange"===pe?"Rearrange Products":void 0),headingSubtitle:le,footerShadow:!0,centralContainerStyles:{width:U||"600px",left:Y||"auto"},headerRightCustomElement:re?t("div",Object.assign({style:{cursor:"pointer",display:"flex"},onClick:E},{children:t(a,{width:20,height:20,color:l.content.secondary})})):t(o,{}),footerContainerStyle:w.stickyFooter?{position:"absolute",bottom:0,left:0,width:"100%",zIndex:9,background:l.surface.standard}:void 0,primaryButton:ie?(e=>Object.assign(Object.assign({},e),{disabled:!e.isLoading&&(ve||Ie<1||V&&Ie<V||!V&&$&&Ie>$)||e.disabled,onClick:()=>{w.onAdd(Be,Ie),He(),he([R.Collections,R.RearrangeProducts].includes(Z)?Z:R.Collections)}}))(ie):{buttonText:_e(),disabled:ve||Ie<1||V&&Ie<V||!V&&$&&Ie>$||!1,onClick:()=>{w.onAdd(Be,Ie),He()}},secondaryButton:ne?(e=>Object.assign(Object.assign({},e),{disabled:ve||Ie<1||V&&Ie<V||!V&&$&&Ie>$||!1,onClick:()=>{const e=D(Be,de,we);w.onAdd(e,Ie,!0)}}))(ne):void 0,wrapperStyle:w.stickyFooter?{height:"calc(100vh - 168px)"}:void 0,footerLeftCustomElement:K?t(o,{}):We(),hideCrossButton:ze||re},{children:[Ge,ze&&$e?t(C,{productData:$e,useDynamicInfoImageSize:w.useDynamicInfoImageSize,outOfStockAction:W,onClose:()=>{Ve(!1)}}):t(o,{})]}))})};export{w as ProductPickerModal,R as ScreenName};
1
+ import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import c from"../../assets/icons/search.svg.js";import{useReducer as r,useState as s,useEffect as i,useRef as n}from"react";import{COLORS as l}from"../../constants/Theme.js";import d from"../../assets/icons/cross.svg.js";import{Button as a}from"../button/Button.js";import{Input as u}from"../input/Input.js";import{StyledModal as h}from"../modals/styledModal.js";import{Spinner as p}from"../spinner/Spinner.js";import{Tag as m}from"../tag/Tag.js";import{CollectionsScreen as g}from"./collectionScreen.js";import{ProductInfoOverlay as C}from"./productInfoOverlay.js";import{ProductsScreen as f}from"./productScreen.js";import{RearrangeScreen as b}from"./rearrangeScreen.js";import{collectionsReducer as y,searchReducer as S,selectedColectionsReducer as v,CollectionIdContext as k}from"./reducers.js";import{SearchScreen as j}from"./searchScreen.js";import{SelectedScreen as I}from"./selectedScreen.js";import{ContainerStyle as P,ScrollContainerStyle as x,StyledFooterForNonModal as O}from"./style.js";import{OUT_OF_STOCK_ACTION as D}from"./type.js";import{updateAllVariantsForSelectedProducts as F}from"./utility.js";var T;!function(e){e.Collections="collections",e.RearrangeProducts="rearrange",e.SelectedProducts="view",e.SearchProducts="searchProducts",e.Products="products"}(T||(T={}));const R=R=>{const{storeId:A,selectedItems:w,onClose:B,visible:E,zIndex:L,exactLimit:z,limit:V,hideCollectionCheckbox:$,hideProductCheckbox:M,outOfStockAction:H=D.BLUR,hideVariantCheckbox:W,selectProductsFromCustomCollection:G,hideSelectionCount:N,title:K,width:U,left:Y,renderWithoutModal:q,onClickSave:J,pickerType:Q,hideProductVariants:X=!1,startupScreen:Z=T.Collections,rearrangeEnabled:_,selectSingleItem:ee=!1,showProductDetails:te,containerStyle:oe,crossButtonInsideHeader:ce=!1,footerForNonModal:re={},primaryButton:se,secondaryButton:ie,subtitle:ne}=R,[le,de]=r(y,{}),[ae,ue]=s([T.Collections,T.RearrangeProducts].includes(Z)?Z:T.Collections),[he,pe]=s("grid"),[me,ge]=s(""),[Ce,fe]=s(""),[be,ye]=s(0),[Se,ve]=s(!1),[ke,je]=s(0),[Ie,Pe]=s(""),[xe,Oe]=s(!1),[De,Fe]=s(!1),[Te,Re]=r(S,{collections:{},products:{}});i((()=>{console.log("collections changed: ",le)}),[le]);const[Ae,we]=r(v,Object.keys(w).length>0?w:{}),Be=n(null),[Ee,Le]=s(!1),[ze,Ve]=s();i((()=>{ve(!0),Fe(!0),R.collectionFetcher(be,A).then((e=>{de({type:"fetched",data:(null==e?void 0:e.collections)||{}}),ve(!1),ye((e=>e+1)),Fe(!1)})).catch()}),[]),i((()=>{let e=0;X?Object.keys(Ae||[]).forEach((t=>{var o;Object.keys((null===(o=Ae[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c;"-1"!==t&&Ae[-1]&&(null===(c=Ae[-1].products)||void 0===c?void 0:c[o])||(e+=1)}))})):Object.keys(Ae||[]).forEach((t=>{var o;Object.keys((null===(o=Ae[t])||void 0===o?void 0:o.products)||[]).forEach((o=>{var c,r;Object.keys((null===(r=null===(c=Ae[t].products)||void 0===c?void 0:c[o])||void 0===r?void 0:r.variants)||[]).forEach((()=>{e+=1}))}))})),je(e)}),[le,Ae,X]),i((()=>{Ce&&(ve(!0),R.productFetcher(Ce,A).then((e=>{Object.keys(e).length&&de({type:"productsFetched",data:{collectionId:Ce,products:e}}),ve(!1)})).catch())}),[Ce]),i((()=>{const e=setTimeout((()=>{"rearrange"!==ae&&(Ie.length||"collections"!==ae)&&(Ie.length?(Oe(!0),R.searchFetcher(A,Ie).then((e=>{console.log("search data: ",e),"collections"in e&&"products"in e?(Re({type:"set",data:e}),de({type:"searched",data:e.collections})):(Re({type:"set",data:{collections:{},products:e}}),de({type:"searched",data:e})),ue("searchProducts"),ve(!1),Oe(!1)}))):ue("collections"))}),800);return()=>clearTimeout(e)}),[Ie]),i((()=>{J&&(R.onAdd(Ae,ke),$e())}),[J]),i((()=>{ee&&Object.keys(Ae||{}).length&&ke&&(R.onAdd(Ae,ke),$e())}),[ee,Ae,ke]);const $e=()=>{we({type:"reset",data:{}})},Me=()=>z&&ke>z?t(m,{tagText:`You can only select ${z} products`,type:"negative"}):V&&ke>V?t(m,{tagText:`You can only select ${V} products`,type:"negative"}):t(a,ke>0?{onClick:()=>{ue(_?T.RearrangeProducts:T.SelectedProducts)},buttonText:z?`${ke}/${z} products selected`:`${ke} products selected`,buttonType:["rearrange","view"].includes(ae)?"tertiaryGray":"tertiary",disabled:["rearrange","view"].includes(ae)}:{disabled:!0,buttonText:z?`${ke}/${z} products selected`:`${ke} products selected`,buttonType:"tertiaryGray"}),He=e=>Se?"Loading...":ae===T.RearrangeProducts?null!=e?e:"Done":null!=e?e:"Add",We=e(P,Object.assign({style:null!=oe?oe:{}},{children:[R.postHeader&&t("div",Object.assign({style:{padding:"0 24px"}},{children:R.postHeader})),!R.hideGlobalSearch&&t(o,{children:("collections"===ae||"searchProducts"===ae)&&t("div",Object.assign({style:{padding:q?"8px 16px":"12px 24px",borderBottom:"1px solid #E0E0E0"}},{children:t(u,{placeholder:"Search using ID, Name or SKU ID",noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>xe?t(p,{size:"small",color:l.content.primary}):t(c,{})},id:"listInput",height:"24px",type:"text",value:Ie,onChangeText:e=>{e.length&&e.trim().length?Pe(e):Pe("")}})}))}),e(x,Object.assign({ref:Be,screenName:ae},{children:["collections"===ae&&t(g,{customCollectionRestriction:R.customCollectionRestriction,dataLoading:De,collections:le,selectedCollectionsDispatch:we,setCollectionId:ge,setSelectedCollectionId:fe,setScreen:ue,selectedCollections:Ae,collectionFetcher:R.collectionFetcher,storeId:A,collectionsDispatch:de,setSaveDisabled:ve,pagingControls:{curPage:be,setCurPage:ye},hideCollectionCheckbox:$,renderWithoutModal:q,pickerType:Q,scrollContainerRef:Be}),"products"===ae&&me&&t(k.Provider,Object.assign({value:me},{children:t(f,{hideInCollectionSearch:R.hideInCollectionSearch,customCollectionRestriction:R.customCollectionRestriction,productFetcher:R.productFetcher,setScreen:ue,storeId:A,data:le[me],collectionsDispatch:de,selectedCollectionsDispatch:we,selectedData:Ae,setSaveDisabled:ve,searchInCollectionFetcher:R.searchInCollectionFetcher,hideProductCheckbox:M,outOfStockAction:H,hideVariantCheckbox:W,selectProductsFromCustomCollection:G,renderWithoutModal:q,pickerType:Q,hideProductVariants:X,fbStatusFetcher:R.fbStatusFetcher,onProductDetailClick:e=>{Le(!0),Ve(e)},showProductDetailInfoIcon:te,scrollContainerRef:Be})})),"view"===ae&&t(I,{selectedCollections:Ae||{},selectedCollectionsDispatch:we,setScreen:ue,collections:le,hideProductVariants:X,outOfStockAction:H,storeId:A,fbStatusFetcher:R.fbStatusFetcher}),"rearrange"===ae&&t(b,{selectedCollections:Ae||{},selectedCollectionsDispatch:we,setScreen:ue,outOfStockAction:H,rearrangeViewType:"grid"===he?"list":"grid",scrollContainerRef:Be,storeId:A,fbStatusFetcher:R.fbStatusFetcher}),"searchProducts"===ae&&t(j,{customCollectionRestriction:R.customCollectionRestriction,selectedCollections:Ae||{},searchedCollections:Te||{},searchedCollectionsDispatch:Re,selectedCollectionsDispatch:we,setScreen:ue,collections:le,onBackPress:()=>{Pe(""),Re({type:"set",data:{collections:{},products:{}}})},pickerType:Q,hideProductCheckbox:M,hideProductVariants:X,hideVariantCheckbox:W,storeId:A,fbStatusFetcher:R.fbStatusFetcher,setCollectionId:ge,setSelectedCollectionId:fe,renderWithoutModal:q,hideCollectionCheckbox:$,outOfStockAction:H})]}))]}));return t(o,{children:q?e(o,{children:[We,re.renderFooter?e(O,{children:[Me(),t(a,{buttonText:He(re.primaryButtonText),disabled:!re.isLoading&&(Se||ke<1||z&&ke<z||!z&&V&&ke>V)||re.primaryButtonDisabled,isLoading:re.isLoading,onClick:()=>{R.onAdd(Ae,ke),$e(),ue([T.Collections,T.RearrangeProducts].includes(Z)?Z:T.Collections)}})]}):t(o,{}),Ee&&ze?t(C,{productData:ze,outOfStockAction:H,useDynamicInfoImageSize:R.useDynamicInfoImageSize,onClose:()=>{Le(!1)}}):t(o,{})]}):e(h,Object.assign({zIndex:L,open:E,onClose:()=>{null==B||B(),$e()},headingTitle:K||("collections"===ae||"products"===ae?"Select Products":"view"===ae?"Selected Products":"searchProducts"===ae?"Searched Results":"rearrange"===ae?"Rearrange Products":void 0),headingSubtitle:ne,footerShadow:!0,centralContainerStyles:{width:U||"600px",left:Y||"auto"},headerRightCustomElement:ce?t("div",Object.assign({style:{cursor:"pointer",display:"flex"},onClick:B},{children:t(d,{width:20,height:20,color:l.content.secondary})})):t(o,{}),footerContainerStyle:R.stickyFooter?{position:"absolute",bottom:0,left:0,width:"100%",zIndex:9,background:l.surface.standard}:void 0,primaryButton:se?(e=>Object.assign(Object.assign({},e),{disabled:!e.isLoading&&(Se||ke<1||z&&ke<z||!z&&V&&ke>V)||e.disabled,onClick:()=>{R.onAdd(Ae,ke),$e(),ue([T.Collections,T.RearrangeProducts].includes(Z)?Z:T.Collections)}}))(se):{buttonText:He(),disabled:Se||ke<1||z&&ke<z||!z&&V&&ke>V||!1,onClick:()=>{R.onAdd(Ae,ke),$e()}},secondaryButton:ie?(e=>Object.assign(Object.assign({},e),{disabled:Se||ke<1||z&&ke<z||!z&&V&&ke>V||!1,onClick:()=>{console.log("clicked ADD TO CART. Passing: ",{selectedCollections:Ae,collections:le,searchedCollections:Te});const e=F(Ae,le,Te);console.log("response from Filtered collections: ",{filteredCollections:e}),R.onAdd(e,ke,!0)}}))(ie):void 0,wrapperStyle:R.stickyFooter?{height:"calc(100vh - 168px)"}:void 0,footerLeftCustomElement:N?t(o,{}):Me(),hideCrossButton:Ee||ce},{children:[We,Ee&&ze?t(C,{productData:ze,useDynamicInfoImageSize:R.useDynamicInfoImageSize,outOfStockAction:H,onClose:()=>{Le(!1)}}):t(o,{})]}))})};export{R as ProductPickerModal,T as ScreenName};
@@ -1,4 +1,3 @@
1
- import { ApplicationType } from '@bikdotai/bik-models/growth/models/bik-store';
2
1
  import React from 'react';
3
2
  import { Collection, FbStatusFetcherReturn, Product, ProductFetcherReturn, ProductVariant, SelectedItems } from '.';
4
3
  import { CollectionsActions, SelectedCollectionsActions } from './reducers';
@@ -10,10 +9,9 @@ interface ProductsScreenInterface {
10
9
  collectionsDispatch: React.Dispatch<CollectionsActions>;
11
10
  selectedData: SelectedItems;
12
11
  selectedCollectionsDispatch: React.Dispatch<SelectedCollectionsActions>;
13
- searchInCollectionFetcher: (storeId: string, collectionId: string, query: string, appType: ApplicationType) => ProductFetcherReturn;
14
- productFetcher: (collectionId: string, storeId: string, appType: ApplicationType, limit?: number, offset?: number) => ProductFetcherReturn;
12
+ searchInCollectionFetcher: (storeId: string, collectionId: string, query: string) => ProductFetcherReturn;
13
+ productFetcher: (collectionId: string, storeId: string, limit?: number, offset?: number) => ProductFetcherReturn;
15
14
  storeId: string;
16
- appType: ApplicationType;
17
15
  setScreen: React.Dispatch<React.SetStateAction<string>>;
18
16
  setSaveDisabled: React.Dispatch<React.SetStateAction<boolean>>;
19
17
  hideProductCheckbox?: boolean;
@@ -24,7 +22,7 @@ interface ProductsScreenInterface {
24
22
  pickerType?: 'COLLECTION' | 'PRODUCT';
25
23
  hideProductVariants?: boolean;
26
24
  showProductDetailInfoIcon?: boolean;
27
- fbStatusFetcher?: (storeId: string, variantIds: string[], appType: ApplicationType) => FbStatusFetcherReturn;
25
+ fbStatusFetcher?: (storeId: string, variantIds: string[]) => FbStatusFetcherReturn;
28
26
  onProductDetailClick: (productData: Product | ProductVariant) => void;
29
27
  scrollContainerRef: React.RefObject<HTMLDivElement>;
30
28
  }
@@ -1 +1 @@
1
- import{jsxs as t,jsx as e}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import c from"../../assets/icons/box.svg.js";import n from"../../assets/icons/search.svg.js";import{cloneDeep as r}from"lodash";import{useContext as i,useRef as s,useState as l,useEffect as d}from"react";import{COLORS as a}from"../../constants/Theme.js";import{CheckBox as u}from"../checkBox/CheckBox.js";import{IconButton as h}from"../icon-button/IconButton.js";import{InfiniteScroll as p}from"../InfiniteScroll/InfiniteScroll.js";import{Input as m}from"../input/Input.js";import{Spinner as g}from"../spinner/Spinner.js";import{BodyCaption as j,TitleRegular as f}from"../TypographyStyle.js";import{EmptyState as v}from"./emptyState.js";import{ProductGroup as b}from"./product.js";import{ProductPickerShimmer as y}from"./ProductPickerShimmer.js";import{CollectionIdContext as O}from"./reducers.js";import{ProductScreenHeader as k,ProductScreenCollectionCardStyle as C}from"./style.js";import{OUT_OF_STOCK_ACTION as P}from"./type.js";import{getVariantIdsToFetchAtProductLevel as I,markVariantsAsApprovedProductsLevel as D,isCollectionPartiallyChecked as S,isProductPartiallyChecked as x,liftTheStateUp as E}from"./utility.js";const T=T=>{var R,w;const{data:V,collectionsDispatch:A,selectedData:B,selectedCollectionsDispatch:F,productFetcher:J,storeId:K,setScreen:M,setSaveDisabled:N,hideInCollectionSearch:U,customCollectionRestriction:W,hideProductCheckbox:z,outOfStockAction:H=P.BLUR,hideVariantCheckbox:L=!1,selectProductsFromCustomCollection:_=!1,pickerType:q,hideProductVariants:G,fbStatusFetcher:Q,onProductDetailClick:X,showProductDetailInfoIcon:Y,scrollContainerRef:Z,appType:$}=T,tt=i(O),et=s(0),ot=s(!1),[ct,nt]=l(""),[rt,it]=l(!1),[st,lt]=l(V),dt=s(!0),at=s(!1);d((()=>{if(dt.current)return void(dt.current=!1);const t=setTimeout((()=>{ct.length?(it(!0),T.searchInCollectionFetcher(K,tt,ct,$).then((t=>{const e=r(V);e.products=t,lt(e);const o=I(null!=t?t:{});ht(o,null!=t?t:{},!0),N(!1),it(!1)}))):lt(V)}),800);return()=>clearTimeout(t)}),[ct]);d((()=>{var t,e,o,c;at.current=!1,et.current=Math.floor((null===(e=Object.keys(null!==(t=V.products)&&void 0!==t?t:{}))||void 0===e?void 0:e.length)/10);const n=I(null!==(o=V.products)&&void 0!==o?o:{});ht(n,null!==(c=V.products)&&void 0!==c?c:{})}),[tt]);const ut=!!W&&V.isSmartCollection;d((()=>{(null==V?void 0:V.products)||pt(10)}),[]);const ht=(t,e,o)=>{Q||(o?D(e,A,tt,st,lt):D(e,A,tt)),t.length>0&&Q&&Q(K,t,$).then((t=>{const c=Object.assign({},e);Object.keys(e).forEach((o=>{var n,r;Object.keys(null!==(r=null===(n=null==e?void 0:e[o])||void 0===n?void 0:n.variants)&&void 0!==r?r:{}).forEach((n=>{var r,i;const s=null===(r=null==e?void 0:e[o].variants)||void 0===r?void 0:r[n];s&&"REJECTED"===t[n]?s.fbStatus="REJECTED":s&&"APPROVED"===t[n]&&(s.fbStatus="APPROVED");const l=null===(i=null==c?void 0:c[o])||void 0===i?void 0:i.variants;l&&l[n]&&(l[n]=s)}))})),o?(lt((t=>{const e=Object.assign({},t);return e.products=c,e})),A({type:"productsPaged",data:{collectionId:tt,products:c}})):A({type:"productsPaged",data:{collectionId:tt,products:c}})})).catch((t=>{o?D(e,A,tt,st,lt):D(e,A,tt)}))},pt=t=>{N(!0),it(!0),J(tt,K,$,t,0).then((e=>{if(Object.keys(e).length||(at.current=!0),Object.keys(e).length){lt(Object.assign(Object.assign({},st),{products:e}));const t=I(e);ht(t,e),et.current=1}t||F({type:"selected",data:{id:tt,val:Object.assign(Object.assign({},V),{products:e})}}),N(!1),it(!1)})).catch()},mt=(t,e)=>{const o=E(e,V);F({type:t,data:Object.assign(Object.assign({},o),{isRestricted:W})})},gt=!!(null==B?void 0:B[tt])&&!!Object.keys(null!==(w=null===(R=null==B?void 0:B[tt])||void 0===R?void 0:R.products)&&void 0!==w?w:{}).length;return t("div",{children:[t(k,{children:[e(h,{Icon:o,height:16,onClick:()=>{M("collections")}}),e(j,Object.assign({style:{color:a.content.secondary}},{children:V.name}))]}),!U&&e("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e(m,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>rt&&ct.length?e(g,{size:"small",color:a.content.primary}):e(n,{})},id:"listInput",height:"24px",type:"text",value:ct,onChangeText:t=>{t.length&&t.trim().length?nt(t):nt("")},placeholder:"Search using ID, Name or SKU ID"})})),Object.keys((null==st?void 0:st.products)||[]).length>0&&!ut&&!ct.length&&!z&&"-1"!==tt&&t(C,{children:[e(u,{isChecked:gt,isPartiallyChecked:S(tt,st,B,G),onValueChange:function(t){t?pt():F({type:"unselected",data:{id:tt}})}}),e("div",Object.assign({style:{width:40,height:40}},{children:e(c,{})})),e(f,{children:"All Products"})]}),e(p,Object.assign({hasData:!(Object.keys((null==st?void 0:st.products)||[]).length<10)&&!!Object.keys((null==st?void 0:st.products)||[]).length,fetchMore:()=>(ot.current=!0,J(tt,K,$,10,et.current).then((t=>{let e=!1;if(Object.keys(t).length||(e=!0),Object.keys(t).length){const e=st;e.products=Object.assign(Object.assign({},st.products),t),lt(Object.assign({},e));const o=I(t);ht(o,t)}return N(!1),ot.current=!1,et.current+=1,e}))),containerRef:Z},{children:Object.keys((null==st?void 0:st.products)||[]).length?Object.keys(st.products||[]).map((t=>e(b,{outOfStockAction:H,collectionId:tt,isProductPartiallyChecked:x(tt,t,B,st,G),productId:t,data:st.products[t],selectedData:B,selectedCollectionsDispatch:F,viewOnly:!_&&!!ut,upliftAdditions:mt,hideProductCheckbox:z,hideVariantCheckbox:L,hideProductVariants:G,pickerType:q,onProductDetailClick:X,showProductDetailInfoIcon:Y},t))):rt?e(y,{limit:10}):e(v,{title:"No products to show",subtitle:ct.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})}))]})};export{T as ProductsScreen};
1
+ import{jsxs as t,jsx as e}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import c from"../../assets/icons/box.svg.js";import n from"../../assets/icons/search.svg.js";import{cloneDeep as r}from"lodash";import{useContext as i,useRef as s,useState as l,useEffect as d}from"react";import{COLORS as a}from"../../constants/Theme.js";import{CheckBox as u}from"../checkBox/CheckBox.js";import{IconButton as h}from"../icon-button/IconButton.js";import{InfiniteScroll as p}from"../InfiniteScroll/InfiniteScroll.js";import{Input as m}from"../input/Input.js";import{Spinner as g}from"../spinner/Spinner.js";import{BodyCaption as j,TitleRegular as f}from"../TypographyStyle.js";import{EmptyState as v}from"./emptyState.js";import{ProductGroup as b}from"./product.js";import{ProductPickerShimmer as y}from"./ProductPickerShimmer.js";import{CollectionIdContext as O}from"./reducers.js";import{ProductScreenHeader as k,ProductScreenCollectionCardStyle as C}from"./style.js";import{OUT_OF_STOCK_ACTION as P}from"./type.js";import{getVariantIdsToFetchAtProductLevel as I,markVariantsAsApprovedProductsLevel as D,isCollectionPartiallyChecked as S,isProductPartiallyChecked as x,liftTheStateUp as E}from"./utility.js";const R=R=>{var T,w;const{data:V,collectionsDispatch:A,selectedData:B,selectedCollectionsDispatch:F,productFetcher:J,storeId:K,setScreen:M,setSaveDisabled:N,hideInCollectionSearch:U,customCollectionRestriction:W,hideProductCheckbox:z,outOfStockAction:H=P.BLUR,hideVariantCheckbox:L=!1,selectProductsFromCustomCollection:_=!1,pickerType:q,hideProductVariants:G,fbStatusFetcher:Q,onProductDetailClick:X,showProductDetailInfoIcon:Y,scrollContainerRef:Z}=R,$=i(O),tt=s(0),et=s(!1),[ot,ct]=l(""),[nt,rt]=l(!1),[it,st]=l(V),lt=s(!0),dt=s(!1);d((()=>{if(lt.current)return void(lt.current=!1);const t=setTimeout((()=>{ot.length?(rt(!0),R.searchInCollectionFetcher(K,$,ot).then((t=>{const e=r(V);e.products=t,st(e);const o=I(null!=t?t:{});ut(o,null!=t?t:{},!0),N(!1),rt(!1)}))):st(V)}),800);return()=>clearTimeout(t)}),[ot]);d((()=>{var t,e,o,c;dt.current=!1,tt.current=Math.floor((null===(e=Object.keys(null!==(t=V.products)&&void 0!==t?t:{}))||void 0===e?void 0:e.length)/10);const n=I(null!==(o=V.products)&&void 0!==o?o:{});ut(n,null!==(c=V.products)&&void 0!==c?c:{})}),[$]);const at=!!W&&V.isSmartCollection;d((()=>{(null==V?void 0:V.products)||ht(10)}),[]);const ut=(t,e,o)=>{Q||(o?D(e,A,$,it,st):D(e,A,$)),t.length>0&&Q&&Q(K,t).then((t=>{const c=Object.assign({},e);Object.keys(e).forEach((o=>{var n,r;Object.keys(null!==(r=null===(n=null==e?void 0:e[o])||void 0===n?void 0:n.variants)&&void 0!==r?r:{}).forEach((n=>{var r,i;const s=null===(r=null==e?void 0:e[o].variants)||void 0===r?void 0:r[n];s&&"REJECTED"===t[n]?s.fbStatus="REJECTED":s&&"APPROVED"===t[n]&&(s.fbStatus="APPROVED");const l=null===(i=null==c?void 0:c[o])||void 0===i?void 0:i.variants;l&&l[n]&&(l[n]=s)}))})),o?(st((t=>{const e=Object.assign({},t);return e.products=c,e})),A({type:"productsPaged",data:{collectionId:$,products:c}})):A({type:"productsPaged",data:{collectionId:$,products:c}})})).catch((t=>{o?D(e,A,$,it,st):D(e,A,$)}))},ht=t=>{N(!0),rt(!0),J($,K,t,0).then((e=>{if(Object.keys(e).length||(dt.current=!0),Object.keys(e).length){st(Object.assign(Object.assign({},it),{products:e}));const t=I(e);ut(t,e),tt.current=1}t||F({type:"selected",data:{id:$,val:Object.assign(Object.assign({},V),{products:e})}}),N(!1),rt(!1)})).catch()},pt=(t,e)=>{const o=E(e,V);F({type:t,data:Object.assign(Object.assign({},o),{isRestricted:W})})},mt=!!(null==B?void 0:B[$])&&!!Object.keys(null!==(w=null===(T=null==B?void 0:B[$])||void 0===T?void 0:T.products)&&void 0!==w?w:{}).length;return t("div",{children:[t(k,{children:[e(h,{Icon:o,height:16,onClick:()=>{M("collections")}}),e(j,Object.assign({style:{color:a.content.secondary}},{children:V.name}))]}),!U&&e("div",Object.assign({style:{padding:16,height:"76px",borderBottom:"1px solid #E0E0E0"}},{children:e(m,{noKeyDownChange:!0,noErrorHint:!0,rightIcon:{icon:()=>nt&&ot.length?e(g,{size:"small",color:a.content.primary}):e(n,{})},id:"listInput",height:"24px",type:"text",value:ot,onChangeText:t=>{t.length&&t.trim().length?ct(t):ct("")},placeholder:"Search using ID, Name or SKU ID"})})),Object.keys((null==it?void 0:it.products)||[]).length>0&&!at&&!ot.length&&!z&&"-1"!==$&&t(C,{children:[e(u,{isChecked:mt,isPartiallyChecked:S($,it,B,G),onValueChange:function(t){t?ht():F({type:"unselected",data:{id:$}})}}),e("div",Object.assign({style:{width:40,height:40}},{children:e(c,{})})),e(f,{children:"All Products"})]}),e(p,Object.assign({hasData:!(Object.keys((null==it?void 0:it.products)||[]).length<10)&&!!Object.keys((null==it?void 0:it.products)||[]).length,fetchMore:()=>(et.current=!0,J($,K,10,tt.current).then((t=>{let e=!1;if(Object.keys(t).length||(e=!0),Object.keys(t).length){const e=it;e.products=Object.assign(Object.assign({},it.products),t),st(Object.assign({},e));const o=I(t);ut(o,t)}return N(!1),et.current=!1,tt.current+=1,e}))),containerRef:Z},{children:Object.keys((null==it?void 0:it.products)||[]).length?Object.keys(it.products||[]).map((t=>e(b,{outOfStockAction:H,collectionId:$,isProductPartiallyChecked:x($,t,B,it,G),productId:t,data:it.products[t],selectedData:B,selectedCollectionsDispatch:F,viewOnly:!_&&!!at,upliftAdditions:pt,hideProductCheckbox:z,hideVariantCheckbox:L,hideProductVariants:G,pickerType:q,onProductDetailClick:X,showProductDetailInfoIcon:Y},t))):nt?e(y,{limit:10}):e(v,{title:"No products to show",subtitle:ot.length?"We couldn't find the product you were looking for":"We couldn’t find any product in this collection."})}))]})};export{R as ProductsScreen};
@@ -1,4 +1,3 @@
1
- import { ApplicationType } from '@bikdotai/bik-models/growth/models/bik-store';
2
1
  import React from 'react';
3
2
  import { FbStatusFetcherReturn, SelectedItems } from '.';
4
3
  import { SelectedCollectionsActions } from './reducers';
@@ -11,8 +10,7 @@ interface RearrangeScreenInterface {
11
10
  outOfStockAction?: OUT_OF_STOCK_ACTION;
12
11
  scrollContainerRef: React.RefObject<HTMLDivElement>;
13
12
  storeId: string;
14
- appType: ApplicationType;
15
- fbStatusFetcher?: (storeId: string, variantIds: string[], appType: ApplicationType) => FbStatusFetcherReturn;
13
+ fbStatusFetcher?: (storeId: string, variantIds: string[]) => FbStatusFetcherReturn;
16
14
  }
17
15
  /**
18
16
  * Screen will be opened on two conditions -
@@ -1 +1 @@
1
- import{jsxs as t,jsx as e}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import{useState as r,useEffect as s}from"react";import{DragDropContext as c}from"react-beautiful-dnd";import{COLORS as i}from"../../constants/Theme.js";import{IconButton as n}from"../icon-button/IconButton.js";import{BodyCaption as l}from"../TypographyStyle.js";import{EmptyState as a}from"./emptyState.js";import{parseSelectedVariantsToArray as p}from"./helpers/ProductHelper.js";import{SelectedScreenHeader as d}from"./style.js";import{fetchFbStatusCollection as m}from"./utility.js";import{VariantsList as u,VariantsGrid as f}from"./variantComponents.js";const h=h=>{const{selectedCollections:j,selectedCollectionsDispatch:y,setScreen:S,rearrangeViewType:g,outOfStockAction:b,scrollContainerRef:C,storeId:O,fbStatusFetcher:v,appType:T}=h,[V,k]=r(p(j));s((()=>{k(p(j))}),[j]),s((()=>{var t;null===(t=null==C?void 0:C.current)||void 0===t||t.scrollTo({top:0}),m(j,O,T,y,v,"update")}),[]);return t(c,Object.assign({onDragEnd:t=>{if(!t.destination)return;const e=V,[o]=e.splice(t.source.index,1);e.splice(t.destination.index,0,o),e.forEach(((t,e)=>{t.displayOrder=e})),k(e)}},{children:[t(d,{children:[e(n,{Icon:o,width:16,height:16,color:i.content.secondary,onClick:()=>{S("collections")}}),e(l,Object.assign({color:i.content.secondary},{children:"All Products"}))]}),Object.keys(j).length>0?"list"===g?e(u,{selectedVariants:V,setSelectedVariants:k,selectedCollectionsDispatch:y,outOfStockAction:b}):e(f,{selectedVariants:V,setSelectedVariants:k,selectedCollectionsDispatch:y}):e(a,{title:"No Products Selected",subtitle:"Selected products will appear here"})]}))};export{h as RearrangeScreen};
1
+ import{jsxs as t,jsx as e}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import{useState as r,useEffect as s}from"react";import{DragDropContext as c}from"react-beautiful-dnd";import{COLORS as i}from"../../constants/Theme.js";import{IconButton as n}from"../icon-button/IconButton.js";import{BodyCaption as l}from"../TypographyStyle.js";import{EmptyState as a}from"./emptyState.js";import{parseSelectedVariantsToArray as d}from"./helpers/ProductHelper.js";import{SelectedScreenHeader as p}from"./style.js";import{fetchFbStatusCollection as m}from"./utility.js";import{VariantsList as u,VariantsGrid as f}from"./variantComponents.js";const h=h=>{const{selectedCollections:j,selectedCollectionsDispatch:y,setScreen:S,rearrangeViewType:g,outOfStockAction:b,scrollContainerRef:C,storeId:O,fbStatusFetcher:v}=h,[V,k]=r(d(j));s((()=>{k(d(j))}),[j]),s((()=>{var t;null===(t=null==C?void 0:C.current)||void 0===t||t.scrollTo({top:0}),m(j,O,y,v,"update")}),[]);return t(c,Object.assign({onDragEnd:t=>{if(!t.destination)return;const e=V,[o]=e.splice(t.source.index,1);e.splice(t.destination.index,0,o),e.forEach(((t,e)=>{t.displayOrder=e})),k(e)}},{children:[t(p,{children:[e(n,{Icon:o,width:16,height:16,color:i.content.secondary,onClick:()=>{S("collections")}}),e(l,Object.assign({color:i.content.secondary},{children:"All Products"}))]}),Object.keys(j).length>0?"list"===g?e(u,{selectedVariants:V,setSelectedVariants:k,selectedCollectionsDispatch:y,outOfStockAction:b}):e(f,{selectedVariants:V,setSelectedVariants:k,selectedCollectionsDispatch:y}):e(a,{title:"No Products Selected",subtitle:"Selected products will appear here"})]}))};export{h as RearrangeScreen};
@@ -1 +1 @@
1
- import{cloneDeep as t}from"lodash";import{createContext as a}from"react";function e(a,e){var s,d,c,o,r,n,i,u,l,p,v;let O={},g="",b="",j="";switch(e.type){case"selected":return O=t(a),e.data.val.isSmartCollection&&(e.data.isRestricted&&(O={}),O.isCustom=!0),O[e.data.id]=e.data.val,O;case"unselected":return O=t(a),(null==O?void 0:O.isCustom)&&(O.isCustom=!1),delete O[e.data.id],O;case"productUnselected":return O=t(a),g=e.data.productId,b=e.data.collectionId,delete O[b].products[g],Object.keys(O[b].products).length||((null==O?void 0:O.isCustom)&&(O.isCustom=!1),delete O[b]),O;case"productSelected":return O=t(a),g=e.data.productId,b=e.data.collectionId,(null===(s=e.data.catalogOnlyData)||void 0===s?void 0:s.isSmartCollection)&&(e.data.isRestricted&&(O={}),O.isCustom=!0),(null==O?void 0:O[b])||(O[b]=e.data.catalogOnlyData,O[b].products={}),O[b].products[g]=e.data.product,O;case"variantSelected":return O=t(a),g=e.data.productId,b=e.data.collectionId,j=e.data.variantId,(null===(d=e.data.catalogOnlyData)||void 0===d?void 0:d.isSmartCollection)&&(e.data.isRestricted&&(O={}),O.isCustom=!0),(null==O?void 0:O[b])||(O[b]=e.data.catalogOnlyData,O[b].products={},O[b].products[g]=e.data.productOnlyData,O[b].products[g].variants={}),(null===(c=null==O?void 0:O[b])||void 0===c?void 0:c.products)||(O[b].products={}),(null===(r=null===(o=null==O?void 0:O[b])||void 0===o?void 0:o.products)||void 0===r?void 0:r[g])||(O[b].products[g]=e.data.productOnlyData,O[b].products[g].variants={}),O[b].products[g].variants||(O[b].products[g].variants={}),O[b].products[g].variants[j]=e.data.variant,O;case"variantUnselected":return O=t(a),g=e.data.productId,b=e.data.collectionId,j=e.data.variantId,(null===(i=null===(n=O[b].products[g])||void 0===n?void 0:n.variants)||void 0===i?void 0:i[j])&&delete O[b].products[g].variants[j],Object.keys(null!==(p=null===(l=null===(u=O[b].products)||void 0===u?void 0:u[g])||void 0===l?void 0:l.variants)&&void 0!==p?p:{}).length||(delete O[b].products[g],Object.keys(O[b].products).length||((null===(v=O[b])||void 0===v?void 0:v.isSmartCollection)&&(O.isCustom=!1),delete O[b])),O;case"update":return O=Object.assign({},a),O;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 d(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 d=Object.assign({},t[s]),c=a.data[s],o={};for(const t in d.products)if(t in c.products){const a=Object.assign({},d.products[t]),e=c.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,o[t]=a)}Object.keys(o).length>0&&(d.products=o,e[s]=d)}return e;default:return t}}function c(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 o=a("");export{o as CollectionIdContext,s as collectionsReducer,d as paginationReducer,c as searchReducer,e as selectedColectionsReducer};
1
+ import{cloneDeep as t}from"lodash";import{createContext as a}from"react";function e(a,e){var s,d,c,o,r,n,i,l,u,p,v;let O={},g="",b="",j="";switch(e.type){case"selected":return O=t(a),e.data.val.isSmartCollection&&(e.data.isRestricted&&(O={}),O.isCustom=!0),O[e.data.id]=e.data.val,O;case"unselected":return O=t(a),(null==O?void 0:O.isCustom)&&(O.isCustom=!1),delete O[e.data.id],O;case"productUnselected":return O=t(a),g=e.data.productId,b=e.data.collectionId,delete O[b].products[g],Object.keys(O[b].products).length||((null==O?void 0:O.isCustom)&&(O.isCustom=!1),delete O[b]),O;case"productSelected":return O=t(a),g=e.data.productId,b=e.data.collectionId,(null===(s=e.data.catalogOnlyData)||void 0===s?void 0:s.isSmartCollection)&&(e.data.isRestricted&&(O={}),O.isCustom=!0),(null==O?void 0:O[b])||(O[b]=e.data.catalogOnlyData,O[b].products={}),O[b].products[g]=e.data.product,O;case"variantSelected":return O=t(a),g=e.data.productId,b=e.data.collectionId,j=e.data.variantId,(null===(d=e.data.catalogOnlyData)||void 0===d?void 0:d.isSmartCollection)&&(e.data.isRestricted&&(O={}),O.isCustom=!0),(null==O?void 0:O[b])||(O[b]=e.data.catalogOnlyData,O[b].products={},O[b].products[g]=e.data.productOnlyData,O[b].products[g].variants={}),(null===(c=null==O?void 0:O[b])||void 0===c?void 0:c.products)||(O[b].products={}),(null===(r=null===(o=null==O?void 0:O[b])||void 0===o?void 0:o.products)||void 0===r?void 0:r[g])||(O[b].products[g]=e.data.productOnlyData,O[b].products[g].variants={}),O[b].products[g].variants||(O[b].products[g].variants={}),O[b].products[g].variants[j]=e.data.variant,O;case"variantUnselected":return O=t(a),g=e.data.productId,b=e.data.collectionId,j=e.data.variantId,(null===(i=null===(n=O[b].products[g])||void 0===n?void 0:n.variants)||void 0===i?void 0:i[j])&&delete O[b].products[g].variants[j],Object.keys(null!==(p=null===(u=null===(l=O[b].products)||void 0===l?void 0:l[g])||void 0===u?void 0:u.variants)&&void 0!==p?p:{}).length||(delete O[b].products[g],Object.keys(O[b].products).length||((null===(v=O[b])||void 0===v?void 0:v.isSmartCollection)&&(O.isCustom=!1),delete O[b])),O;case"update":return O=Object.assign({},a),O;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":console.log("Searched collections reducer called",{data:a.data,collections:t}),e=Object.assign({},t);for(const t in a.data)t in e||(e[t]=a.data[t]);return e;default:return{}}}function d(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 d=Object.assign({},t[s]),c=a.data[s],o={};for(const t in d.products)if(t in c.products){const a=Object.assign({},d.products[t]),e=c.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,o[t]=a)}Object.keys(o).length>0&&(d.products=o,e[s]=d)}return e;default:return t}}function c(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 o=a("");export{o as CollectionIdContext,s as collectionsReducer,d as paginationReducer,c as searchReducer,e as selectedColectionsReducer};
@@ -1,5 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { ApplicationType } from '@bikdotai/bik-models/growth/models/bik-store';
3
2
  import { Collection, FbStatusFetcherReturn, SearchedItems, SelectedItems } from '.';
4
3
  import { SearchReducerActions, SelectedCollectionsActions } from './reducers';
5
4
  import { OUT_OF_STOCK_ACTION } from './type';
@@ -21,8 +20,7 @@ interface SearchScreenInterface {
21
20
  hideProductVariants?: boolean;
22
21
  hideProductCheckbox?: boolean;
23
22
  storeId: string;
24
- appType: ApplicationType;
25
- fbStatusFetcher?: (storeId: string, variantIds: string[], appType: ApplicationType) => FbStatusFetcherReturn;
23
+ fbStatusFetcher?: (storeId: string, variantIds: string[]) => FbStatusFetcherReturn;
26
24
  hideCollectionCheckbox?: boolean;
27
25
  renderWithoutModal?: boolean;
28
26
  outOfStockAction?: OUT_OF_STOCK_ACTION;
@@ -1 +1 @@
1
- import{jsxs as o,jsx as e,Fragment as t}from"react/jsx-runtime";import l from"../../assets/icons/arrow_left.svg.js";import{useEffect as i}from"react";import{IconButton as c}from"../icon-button/IconButton.js";import{BodyCaption as d}from"../TypographyStyle.js";import{CollectionCard as s}from"./collectionScreen.js";import{EmptyState as r}from"./emptyState.js";import{ProductGroup as n}from"./product.js";import{SelectedScreenHeader as u}from"./style.js";import{fetchFbStatusCollection as a,isCollectionPartiallyChecked as p,isProductPartiallyChecked as h,liftTheStateUp as v}from"./utility.js";const m=m=>{var C;const{customCollectionRestriction:k,selectedCollections:y,searchedCollections:b,searchedCollectionsDispatch:f,selectedCollectionsDispatch:j,setScreen:S,collections:O,onBackPress:P,hideVariantCheckbox:I,pickerType:g,hideProductVariants:x,hideProductCheckbox:D,storeId:T,fbStatusFetcher:V,setCollectionId:w,setSelectedCollectionId:A,hideCollectionCheckbox:R,renderWithoutModal:W,outOfStockAction:B,appType:M}=m;i((()=>{var o;a(null!==(o=b.products)&&void 0!==o?o:{},T,M,f,V,"setProducts")}),[null==b?void 0:b.products]);const F=!!k&&(null==y?void 0:y.isCustom);return o("div",{children:[o(u,{children:[e(c,{Icon:l,onClick:()=>{S("collections"),P()}}),e(d,{children:(null===(C=Object.keys(null==b?void 0:b.collections))||void 0===C?void 0:C.length)?"Searched Collections & Products":"Searched Products"})]}),e("div",{children:Object.keys(null==b?void 0:b.products).length||Object.keys(null==b?void 0:b.collections).length?o(t,{children:[e(t,{children:Object.keys(null==b?void 0:b.collections).map((o=>e(s,{customCollectionRestriction:k,data:null==O?void 0:O[o],isDisabled:F&&!(null==y?void 0:y[o]),isChecked:!!(null==y?void 0:y[o]),isPartiallyChecked:p(o,null==O?void 0:O[o],y,x),selectedCollectionsDispatch:j,setCollectionId:w,setSelectedCollectionId:A,setScreen:S,id:o,hideCollectionCheckbox:R||"-1"===o,selectedCollections:y,renderWithoutModal:W,pickerType:g,usedInSearch:!0},o)))}),e(t,{children:Object.keys(null==b?void 0:b.products).map((o=>{var t,l;return Object.keys((null===(l=null===(t=null==b?void 0:b.products)||void 0===t?void 0:t[o])||void 0===l?void 0:l.products)||[]).map((t=>{var l,i,c;let d=!1;return(null===(l=null==b?void 0:b.products)||void 0===l?void 0:l.isCustom)&&(d=!0),e(n,{collectionId:o,upliftAdditions:(e,t)=>((o,e,t)=>{var l;const i=v(t,null===(l=null==b?void 0:b.products)||void 0===l?void 0:l[o]);j({type:e,data:Object.assign(Object.assign({},i),{isRestricted:k})})})(o,e,t),productId:t,data:(null===(i=null==b?void 0:b.products)||void 0===i?void 0:i[o].products)[t],isProductPartiallyChecked:h(o,t,y,null===(c=b.products)||void 0===c?void 0:c[o],x),selectedData:y,selectedCollectionsDispatch:j,viewOnly:d,hideProductCheckbox:D,hideVariantCheckbox:I,hideProductVariants:x,pickerType:g,outOfStockAction:B},t)}))}))})]}):e(r,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};export{m as SearchScreen};
1
+ import{jsxs as o,jsx as e,Fragment as t}from"react/jsx-runtime";import l from"../../assets/icons/arrow_left.svg.js";import{useEffect as i}from"react";import{IconButton as c}from"../icon-button/IconButton.js";import{BodyCaption as d}from"../TypographyStyle.js";import{CollectionCard as s}from"./collectionScreen.js";import{EmptyState as r}from"./emptyState.js";import{ProductGroup as n}from"./product.js";import{SelectedScreenHeader as u}from"./style.js";import{fetchFbStatusCollection as a,isCollectionPartiallyChecked as p,isProductPartiallyChecked as h,liftTheStateUp as v}from"./utility.js";const m=m=>{var C;const{customCollectionRestriction:k,selectedCollections:y,searchedCollections:b,searchedCollectionsDispatch:f,selectedCollectionsDispatch:j,setScreen:S,collections:O,onBackPress:P,hideVariantCheckbox:I,pickerType:g,hideProductVariants:x,hideProductCheckbox:D,storeId:T,fbStatusFetcher:V,setCollectionId:w,setSelectedCollectionId:A,hideCollectionCheckbox:R,renderWithoutModal:W,outOfStockAction:B}=m;i((()=>{var o;a(null!==(o=b.products)&&void 0!==o?o:{},T,f,V,"setProducts")}),[null==b?void 0:b.products]);const M=!!k&&(null==y?void 0:y.isCustom);return o("div",{children:[o(u,{children:[e(c,{Icon:l,onClick:()=>{S("collections"),P()}}),e(d,{children:(null===(C=Object.keys(null==b?void 0:b.collections))||void 0===C?void 0:C.length)?"Searched Collections & Products":"Searched Products"})]}),e("div",{children:Object.keys(null==b?void 0:b.products).length||Object.keys(null==b?void 0:b.collections).length?o(t,{children:[e(t,{children:Object.keys(null==b?void 0:b.collections).map((o=>e(s,{customCollectionRestriction:k,data:null==O?void 0:O[o],isDisabled:M&&!(null==y?void 0:y[o]),isChecked:!!(null==y?void 0:y[o]),isPartiallyChecked:p(o,null==O?void 0:O[o],y,x),selectedCollectionsDispatch:j,setCollectionId:w,setSelectedCollectionId:A,setScreen:S,id:o,hideCollectionCheckbox:R||"-1"===o,selectedCollections:y,renderWithoutModal:W,pickerType:g,usedInSearch:!0},o)))}),e(t,{children:Object.keys(null==b?void 0:b.products).map((o=>{var t,l;return Object.keys((null===(l=null===(t=null==b?void 0:b.products)||void 0===t?void 0:t[o])||void 0===l?void 0:l.products)||[]).map((t=>{var l,i,c;let d=!1;return(null===(l=null==b?void 0:b.products)||void 0===l?void 0:l.isCustom)&&(d=!0),e(n,{collectionId:o,upliftAdditions:(e,t)=>((o,e,t)=>{var l;const i=v(t,null===(l=null==b?void 0:b.products)||void 0===l?void 0:l[o]);j({type:e,data:Object.assign(Object.assign({},i),{isRestricted:k})})})(o,e,t),productId:t,data:(null===(i=null==b?void 0:b.products)||void 0===i?void 0:i[o].products)[t],isProductPartiallyChecked:h(o,t,y,null===(c=b.products)||void 0===c?void 0:c[o],x),selectedData:y,selectedCollectionsDispatch:j,viewOnly:d,hideProductCheckbox:D,hideVariantCheckbox:I,hideProductVariants:x,pickerType:g,outOfStockAction:B},t)}))}))})]}):e(r,{title:"No search results found",subtitle:"We couldn’t find the product you were looking for."})})]})};export{m as SearchScreen};
@@ -1,5 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { ApplicationType } from '@bikdotai/bik-models/growth/models/bik-store';
3
2
  import { Collection, FbStatusFetcherReturn, SelectedItems } from '.';
4
3
  import { SelectedCollectionsActions } from './reducers';
5
4
  import { OUT_OF_STOCK_ACTION } from './type';
@@ -13,8 +12,7 @@ interface SelectedScreenInterface {
13
12
  hideProductVariants?: boolean;
14
13
  outOfStockAction?: OUT_OF_STOCK_ACTION;
15
14
  storeId: string;
16
- appType: ApplicationType;
17
- fbStatusFetcher?: (storeId: string, variantIds: string[], appType: ApplicationType) => FbStatusFetcherReturn;
15
+ fbStatusFetcher?: (storeId: string, variantIds: string[]) => FbStatusFetcherReturn;
18
16
  }
19
17
  export declare const SelectedScreen: (props: SelectedScreenInterface) => import("react/jsx-runtime").JSX.Element;
20
18
  export {};
@@ -1 +1 @@
1
- import{jsxs as t,jsx as e,Fragment as r}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import{useRef as c,useReducer as i,useEffect as n}from"react";import{IconButton as s}from"../icon-button/IconButton.js";import{BodyCaption as l}from"../TypographyStyle.js";import{EmptyState as d}from"./emptyState.js";import{ProductGroup as u}from"./product.js";import{paginationReducer as a}from"./reducers.js";import{SelectedScreenHeader as p}from"./style.js";import{paginateSelectedItems as m,fetchFbStatusCollection as f,isProductPartiallyChecked as h}from"./utility.js";const y=y=>{const{selectedCollections:v,selectedCollectionsDispatch:j,setScreen:b,collections:S,hideProductVariants:k=!1,outOfStockAction:I,storeId:O,fbStatusFetcher:g,appType:C}=y,P=c(0),w=c(null),[A,D]=i(a,{});n((()=>{P.current=0;const t=m(v,10,0);D({type:"paginate",data:t}),f(t,O,C,D,g,"set"),P.current+=1}),[]),n((()=>{D({type:"filter",data:v})}),[v]),n((()=>{const t=new IntersectionObserver((t=>{if(t[0].isIntersecting&&P.current>0){const t=m(v,10,P.current);D({type:"paginate",data:t}),f(t,O,C,D,g,"update"),P.current+=1}}),{threshold:1});return w.current&&t.observe(w.current),()=>{w.current&&t.unobserve(w.current)}}),[w,v]);const x=v;return t("div",{children:[t(p,{children:[e(s,{Icon:o,onClick:()=>{b("collections")}}),e(l,{children:"Selected Products"})]}),t("div",{children:[Object.keys(A).length>0?e(r,{children:Object.keys(A).map((t=>{var r;return Object.keys((null===(r=null==A?void 0:A[t])||void 0===r?void 0:r.products)||[]).map((r=>{let o=!1;return(null==x?void 0:x.isCustom)&&(o=!0),e(u,{upliftAdditions:null,collectionId:t,productId:r,data:A[t].products[r],isProductPartiallyChecked:h(t,r,x,null==S?void 0:S[t],k),selectedData:x,selectedCollectionsDispatch:j,viewOnly:o,hideProductVariants:k,outOfStockAction:I},r)}))}))}):e(d,{title:"No Products Selected",subtitle:"Select products will appear here"}),e("div",{ref:w})]})]})};export{y as SelectedScreen};
1
+ import{jsxs as t,jsx as e,Fragment as r}from"react/jsx-runtime";import o from"../../assets/icons/arrow_left.svg.js";import{useRef as c,useReducer as i,useEffect as n}from"react";import{IconButton as s}from"../icon-button/IconButton.js";import{BodyCaption as l}from"../TypographyStyle.js";import{EmptyState as d}from"./emptyState.js";import{ProductGroup as u}from"./product.js";import{paginationReducer as a}from"./reducers.js";import{SelectedScreenHeader as p}from"./style.js";import{paginateSelectedItems as m,fetchFbStatusCollection as f,isProductPartiallyChecked as h}from"./utility.js";const v=v=>{const{selectedCollections:y,selectedCollectionsDispatch:j,setScreen:b,collections:S,hideProductVariants:k=!1,outOfStockAction:I,storeId:O,fbStatusFetcher:g}=v,C=c(0),P=c(null),[w,A]=i(a,{});n((()=>{C.current=0;const t=m(y,10,0);A({type:"paginate",data:t}),f(t,O,A,g,"set"),C.current+=1}),[]),n((()=>{A({type:"filter",data:y})}),[y]),n((()=>{const t=new IntersectionObserver((t=>{if(t[0].isIntersecting&&C.current>0){const t=m(y,10,C.current);A({type:"paginate",data:t}),f(t,O,A,g,"update"),C.current+=1}}),{threshold:1});return P.current&&t.observe(P.current),()=>{P.current&&t.unobserve(P.current)}}),[P,y]);const D=y;return t("div",{children:[t(p,{children:[e(s,{Icon:o,onClick:()=>{b("collections")}}),e(l,{children:"Selected Products"})]}),t("div",{children:[Object.keys(w).length>0?e(r,{children:Object.keys(w).map((t=>{var r;return Object.keys((null===(r=null==w?void 0:w[t])||void 0===r?void 0:r.products)||[]).map((r=>{let o=!1;return(null==D?void 0:D.isCustom)&&(o=!0),e(u,{upliftAdditions:null,collectionId:t,productId:r,data:w[t].products[r],isProductPartiallyChecked:h(t,r,D,null==S?void 0:S[t],k),selectedData:D,selectedCollectionsDispatch:j,viewOnly:o,hideProductVariants:k,outOfStockAction:I},r)}))}))}):e(d,{title:"No Products Selected",subtitle:"Select products will appear here"}),e("div",{ref:P})]})]})};export{v as SelectedScreen};
@@ -1,4 +1,3 @@
1
- import { ApplicationType } from '@bikdotai/bik-models/growth/models/bik-store';
2
1
  import { Collection, FbStatusFetcherReturn, Product, ProductVariant, SearchedItems, SelectedItems } from './modal';
3
2
  import { CollectionsActions } from './reducers';
4
3
  export declare const liftTheStateUp: (payload: any, data: any) => any;
@@ -13,7 +12,7 @@ export declare function paginateSelectedItems(selectedItems: SelectedItems, limi
13
12
  *
14
13
  * We first get the variant ids to fetch and only if we have variant ids, we call api.
15
14
  */
16
- export declare const fetchFbStatusCollection: (data: SelectedItems, storeId: string, appType: ApplicationType, dispatcher: any, fbStatusFetcher?: ((storeId: string, variantIds: string[], appType: ApplicationType) => FbStatusFetcherReturn) | undefined, dispatchType?: string) => void;
15
+ export declare const fetchFbStatusCollection: (data: SelectedItems, storeId: string, dispatcher: any, fbStatusFetcher?: ((storeId: string, variantIds: string[]) => FbStatusFetcherReturn) | undefined, dispatchType?: string) => void;
17
16
  /**
18
17
  * Instead of collection level, we do it product level.
19
18
  *
@@ -1 +1 @@
1
- import{cloneDeep as o}from"lodash";const l=(l,i)=>{const n=o(i);if(delete n.products,(l=Object.assign(Object.assign({},l),{catalogOnlyData:n})).productId&&i.products){const t=o(i.products[l.productId]);(null==t?void 0:t.variants)&&delete t.variants,l=Object.assign(Object.assign({},l),{catalogOnlyData:n,productOnlyData:t})}return l};function i(o,l,i){var t;const d={};let v=0;for(const s in o)if(Object.prototype.hasOwnProperty.call(o,s)){const u=o[s],c=n(u.products,l,i-v);c&&Object.keys(c).length>0&&(d[s]=Object.assign(Object.assign({},u),{products:c})),v+=Object.keys(null!==(t=u.products)&&void 0!==t?t:{}).length}return d}function n(o,l,i){if(!o)return{};const n=Object.keys(o).slice(i,i+l),t={};return n.forEach((l=>{t[l]=o[l]})),t}const t=(o,l,i)=>{Object.keys(o).forEach((l=>{var i,n;const t=null!==(n=null===(i=o[l])||void 0===i?void 0:i.products)&&void 0!==n?n:{};Object.keys(t).forEach((i=>{var n,t,d,v;const s=null!==(v=null===(d=null===(t=null===(n=o[l])||void 0===n?void 0:n.products)||void 0===t?void 0:t[i])||void 0===d?void 0:d.variants)&&void 0!==v?v:{};Object.keys(s).forEach((n=>{var t,d,v,s;const u=null===(s=null===(v=null===(d=null===(t=o[l])||void 0===t?void 0:t.products)||void 0===d?void 0:d[i])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[n];u&&!u.fbStatus&&(u.fbStatus="APPROVED")}))}))})),l({type:i,data:o})},d=function(o,l,i,n,d){let v=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"paged";d||t(o,n,v);const s=(o=>{const l=[];return Object.keys(o).forEach((i=>{var n,t;const d=null!==(t=null===(n=o[i])||void 0===n?void 0:n.products)&&void 0!==t?t:{};Object.keys(d).forEach((n=>{var t,d,v,s;const u=null!==(s=null===(v=null===(d=null===(t=o[i])||void 0===t?void 0:t.products)||void 0===d?void 0:d[n])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(u).forEach((t=>{var d,v,s,u;const c=null===(u=null===(s=null===(v=null===(d=o[i])||void 0===d?void 0:d.products)||void 0===v?void 0:v[n])||void 0===s?void 0:s.variants)||void 0===u?void 0:u[t];(null==c?void 0:c.fbStatus)||l.push(t)}))}))})),l})(o);s.length>0&&d&&d(l,s,i).then((l=>{const i=Object.assign({},o);Object.keys(i).forEach((o=>{var n,t;const d=null!==(t=null===(n=i[o])||void 0===n?void 0:n.products)&&void 0!==t?t:{};Object.keys(d).forEach((n=>{var t,d,v,s;const u=null!==(s=null===(v=null===(d=null===(t=i[o])||void 0===t?void 0:t.products)||void 0===d?void 0:d[n])||void 0===v?void 0:v.variants)&&void 0!==s?s:{};Object.keys(u).forEach((t=>{var d,v,s,u;const c=null===(u=null===(s=null===(v=null===(d=i[o])||void 0===d?void 0:d.products)||void 0===v?void 0:v[n])||void 0===s?void 0:s.variants)||void 0===u?void 0:u[t];c&&"REJECTED"===l[t]?c.fbStatus="REJECTED":c&&"APPROVED"===l[t]&&(c.fbStatus="APPROVED")}))}))})),n({type:v,data:i})})).catch((l=>{console.error("Error in fbStatusFetcher",l),t(o,n,v)}))},v=(o,l)=>{const i=[];return Object.keys(null!=o?o:{}).forEach((n=>{var t,d;const v=null!==(d=null===(t=null==o?void 0:o[n])||void 0===t?void 0:t.variants)&&void 0!==d?d:{};Object.keys(v).forEach((t=>{var d,v,s,u,c;let r;r=l?null===(s=null===(v=null===(d=null==l?void 0:l.products)||void 0===d?void 0:d[n])||void 0===v?void 0:v.variants)||void 0===s?void 0:s[t]:null===(c=null===(u=null==o?void 0:o[n])||void 0===u?void 0:u.variants)||void 0===c?void 0:c[t],(null==r?void 0:r.fbStatus)||i.push(t)}))})),i},s=(o,l,i,n,t)=>{const d=Object.assign({},o);if(Object.keys(o).forEach((l=>{var i,n;Object.keys(null!==(n=null===(i=null==o?void 0:o[l])||void 0===i?void 0:i.variants)&&void 0!==n?n:{}).forEach((i=>{var n,t;const v=null===(n=null==o?void 0:o[l].variants)||void 0===n?void 0:n[i];v&&(v.fbStatus="APPROVED");const s=null===(t=null==d?void 0:d[l])||void 0===t?void 0:t.variants;s&&s[i]&&(s[i]=v)}))})),n&&t){const o=Object.assign({},n);o.products=d,t(o),l({type:"productsPaged",data:{collectionId:i,products:d}})}else l({type:"productsPaged",data:{collectionId:i,products:d}})},u=o=>{const l=Object.keys(o.variants||[]);let i=!1;return!(l.length<=1)||(l.forEach((l=>{var n,t;i=null!==(t=null===(n=o.variants)||void 0===n?void 0:n[l].name.includes(o.name))&&void 0!==t&&t})),!i)},c=(o,l,i,n,t)=>{var d,v,s,u,c,r,a,e,p,b,O,f,j,h,y,g,E,k,P;let D=0,V=0;if(null===(v=null===(d=null==i?void 0:i[o])||void 0===d?void 0:d.products)||void 0===v?void 0:v[l]){if(t)return!1;const d=(null===(c=null===(u=null===(s=null==i?void 0:i[o])||void 0===s?void 0:s.products)||void 0===u?void 0:u[l])||void 0===c?void 0:c.variants)||[];if(1===Object.keys(d).length)for(const n in d){const t=null===(a=null===(r=null==i?void 0:i[o])||void 0===r?void 0:r.products)||void 0===a?void 0:a[l],d=null===(O=null===(b=null===(p=null===(e=null==i?void 0:i[o])||void 0===e?void 0:e.products)||void 0===p?void 0:p[l])||void 0===b?void 0:b.variants)||void 0===O?void 0:O[n];if(null===(f=null==d?void 0:d.name)||void 0===f?void 0:f.includes(null!==(j=null==t?void 0:t.name)&&void 0!==j?j:""))return!1}if(null===(g=Object.keys((null===(y=null===(h=null==n?void 0:n.products)||void 0===h?void 0:h[l])||void 0===y?void 0:y.variants)||[]))||void 0===g||g.forEach((()=>V++)),Object.keys((null===(P=null===(k=null===(E=null==i?void 0:i[o])||void 0===E?void 0:E.products)||void 0===k?void 0:k[l])||void 0===P?void 0:P.variants)||[]).forEach((()=>D++)),D>0&&V!==D)return!0}return!1},r=function(o,l,i){var n,t,d,v;let s=0,u=0;if(arguments.length>3&&void 0!==arguments[3]&&arguments[3]){const v=null!==(n=null==l?void 0:l.products)&&void 0!==n?n:{};s=Object.keys(v).length;const c=null!==(d=null===(t=i[o])||void 0===t?void 0:t.products)&&void 0!==d?d:{};u=Object.keys(c).length}else if(i[o]){const n=null==l?void 0:l.products;n&&Object.keys(n).forEach((o=>{var l;const i=null===(l=n[o])||void 0===l?void 0:l.variants;i&&Object.keys(i).forEach((o=>s+=1))}));const t=null===(v=i[o])||void 0===v?void 0:v.products;if(t&&Object.keys(t).forEach((o=>{var l;const i=null===(l=t[o])||void 0===l?void 0:l.variants;i&&Object.keys(i).forEach((o=>u+=1))})),s<=0&&u>0)return!1}return u>0&&s!==u},a=(l,i,n)=>Object.keys(l).reduce(((t,d)=>{var v;return d in i?(t[d]=Object.assign(Object.assign({},l[d]),{products:Object.keys(null!==(v=l[d].products)&&void 0!==v?v:{}).reduce(((t,v)=>{var s,u,c,r,a,e,p,b,O,f;const j=null===(s=i[d].products)||void 0===s?void 0:s[v],h=null===(r=null===(c=null===(u=null==n?void 0:n.products)||void 0===u?void 0:u[d])||void 0===c?void 0:c.products)||void 0===r?void 0:r[v];return j?t[v]=Object.assign(Object.assign({},(null===(a=l[d].products)||void 0===a?void 0:a[v])||{}),{allVariants:o(j.variants)}):h?t[v]=Object.assign(Object.assign({},(null===(e=l[d].products)||void 0===e?void 0:e[v])||{}),{allVariants:o(h.variants)}):(null===(b=null===(p=l[d].products)||void 0===p?void 0:p[v])||void 0===b?void 0:b.allVariants)&&(t[v]=Object.assign(Object.assign({},(null===(O=l[d].products)||void 0===O?void 0:O[v])||{}),{allVariants:o(null===(f=l[d].products)||void 0===f?void 0:f[v].allVariants)})),t}),{})}),t):t}),{}),e=(o,l)=>{var i;if(l)return o.skuId;const n=Object.values(null!==(i=null==o?void 0:o.variants)&&void 0!==i?i:{});return 1===n.length&&n[0].name.includes(o.name)?n[0].skuId:""};export{d as fetchFbStatusCollection,e as getSkuId,v as getVariantIdsToFetchAtProductLevel,r as isCollectionPartiallyChecked,c as isProductPartiallyChecked,l as liftTheStateUp,s as markVariantsAsApprovedProductsLevel,i as paginateSelectedItems,u as shouldShowVariant,a as updateAllVariantsForSelectedProducts};
1
+ import{cloneDeep as o}from"lodash";const l=(l,n)=>{const t=o(n);if(delete t.products,(l=Object.assign(Object.assign({},l),{catalogOnlyData:t})).productId&&n.products){const d=o(n.products[l.productId]);(null==d?void 0:d.variants)&&delete d.variants,l=Object.assign(Object.assign({},l),{catalogOnlyData:t,productOnlyData:d})}return l};function n(o,l,n){var d;const i={};let s=0;for(const v in o)if(Object.prototype.hasOwnProperty.call(o,v)){const c=o[v],u=t(c.products,l,n-s);u&&Object.keys(u).length>0&&(i[v]=Object.assign(Object.assign({},c),{products:u})),s+=Object.keys(null!==(d=c.products)&&void 0!==d?d:{}).length}return i}function t(o,l,n){if(!o)return{};const t=Object.keys(o).slice(n,n+l),d={};return t.forEach((l=>{d[l]=o[l]})),d}const d=(o,l,n)=>{Object.keys(o).forEach((l=>{var n,t;const d=null!==(t=null===(n=o[l])||void 0===n?void 0:n.products)&&void 0!==t?t:{};Object.keys(d).forEach((n=>{var t,d,i,s;const v=null!==(s=null===(i=null===(d=null===(t=o[l])||void 0===t?void 0:t.products)||void 0===d?void 0:d[n])||void 0===i?void 0:i.variants)&&void 0!==s?s:{};Object.keys(v).forEach((t=>{var d,i,s,v;const c=null===(v=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===v?void 0:v[t];c&&!c.fbStatus&&(c.fbStatus="APPROVED")}))}))})),l({type:n,data:o})},i=function(o,l,n,t){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"paged";t||d(o,n,i);const s=(o=>{const l=[];return Object.keys(o).forEach((n=>{var t,d;const i=null!==(d=null===(t=o[n])||void 0===t?void 0:t.products)&&void 0!==d?d:{};Object.keys(i).forEach((t=>{var d,i,s,v;const c=null!==(v=null===(s=null===(i=null===(d=o[n])||void 0===d?void 0:d.products)||void 0===i?void 0:i[t])||void 0===s?void 0:s.variants)&&void 0!==v?v:{};Object.keys(c).forEach((d=>{var i,s,v,c;const u=null===(c=null===(v=null===(s=null===(i=o[n])||void 0===i?void 0:i.products)||void 0===s?void 0:s[t])||void 0===v?void 0:v.variants)||void 0===c?void 0:c[d];(null==u?void 0:u.fbStatus)||l.push(d)}))}))})),l})(o);s.length>0&&t&&t(l,s).then((l=>{const t=Object.assign({},o);Object.keys(t).forEach((o=>{var n,d;const i=null!==(d=null===(n=t[o])||void 0===n?void 0:n.products)&&void 0!==d?d:{};Object.keys(i).forEach((n=>{var d,i,s,v;const c=null!==(v=null===(s=null===(i=null===(d=t[o])||void 0===d?void 0:d.products)||void 0===i?void 0:i[n])||void 0===s?void 0:s.variants)&&void 0!==v?v:{};Object.keys(c).forEach((d=>{var i,s,v,c;const u=null===(c=null===(v=null===(s=null===(i=t[o])||void 0===i?void 0:i.products)||void 0===s?void 0:s[n])||void 0===v?void 0:v.variants)||void 0===c?void 0:c[d];u&&"REJECTED"===l[d]?u.fbStatus="REJECTED":u&&"APPROVED"===l[d]&&(u.fbStatus="APPROVED")}))}))})),n({type:i,data:t})})).catch((l=>{console.error("Error in fbStatusFetcher",l),d(o,n,i)}))},s=(o,l)=>{const n=[];return Object.keys(null!=o?o:{}).forEach((t=>{var d,i;const s=null!==(i=null===(d=null==o?void 0:o[t])||void 0===d?void 0:d.variants)&&void 0!==i?i:{};Object.keys(s).forEach((d=>{var i,s,v,c,u;let e;e=l?null===(v=null===(s=null===(i=null==l?void 0:l.products)||void 0===i?void 0:i[t])||void 0===s?void 0:s.variants)||void 0===v?void 0:v[d]:null===(u=null===(c=null==o?void 0:o[t])||void 0===c?void 0:c.variants)||void 0===u?void 0:u[d],(null==e?void 0:e.fbStatus)||n.push(d)}))})),n},v=(o,l,n,t,d)=>{const i=Object.assign({},o);if(Object.keys(o).forEach((l=>{var n,t;Object.keys(null!==(t=null===(n=null==o?void 0:o[l])||void 0===n?void 0:n.variants)&&void 0!==t?t:{}).forEach((n=>{var t,d;const s=null===(t=null==o?void 0:o[l].variants)||void 0===t?void 0:t[n];s&&(s.fbStatus="APPROVED");const v=null===(d=null==i?void 0:i[l])||void 0===d?void 0:d.variants;v&&v[n]&&(v[n]=s)}))})),t&&d){const o=Object.assign({},t);o.products=i,d(o),l({type:"productsPaged",data:{collectionId:n,products:i}})}else l({type:"productsPaged",data:{collectionId:n,products:i}})},c=o=>{const l=Object.keys(o.variants||[]);let n=!1;return!(l.length<=1)||(l.forEach((l=>{var t,d;n=null!==(d=null===(t=o.variants)||void 0===t?void 0:t[l].name.includes(o.name))&&void 0!==d&&d})),!n)},u=(o,l,n,t,d)=>{var i,s,v,c,u,e,r,a,p,b,O,f,g,j,h,y,E,k,P;let V=0,m=0;if(null===(s=null===(i=null==n?void 0:n[o])||void 0===i?void 0:i.products)||void 0===s?void 0:s[l]){if(d)return!1;const i=(null===(u=null===(c=null===(v=null==n?void 0:n[o])||void 0===v?void 0:v.products)||void 0===c?void 0:c[l])||void 0===u?void 0:u.variants)||[];if(1===Object.keys(i).length)for(const t in i){const d=null===(r=null===(e=null==n?void 0:n[o])||void 0===e?void 0:e.products)||void 0===r?void 0:r[l],i=null===(O=null===(b=null===(p=null===(a=null==n?void 0:n[o])||void 0===a?void 0:a.products)||void 0===p?void 0:p[l])||void 0===b?void 0:b.variants)||void 0===O?void 0:O[t];if(null===(f=null==i?void 0:i.name)||void 0===f?void 0:f.includes(null!==(g=null==d?void 0:d.name)&&void 0!==g?g:""))return!1}if(null===(y=Object.keys((null===(h=null===(j=null==t?void 0:t.products)||void 0===j?void 0:j[l])||void 0===h?void 0:h.variants)||[]))||void 0===y||y.forEach((()=>m++)),Object.keys((null===(P=null===(k=null===(E=null==n?void 0:n[o])||void 0===E?void 0:E.products)||void 0===k?void 0:k[l])||void 0===P?void 0:P.variants)||[]).forEach((()=>V++)),V>0&&m!==V)return!0}return!1},e=function(o,l,n){var t,d,i,s;let v=0,c=0;if(arguments.length>3&&void 0!==arguments[3]&&arguments[3]){const s=null!==(t=null==l?void 0:l.products)&&void 0!==t?t:{};v=Object.keys(s).length;const u=null!==(i=null===(d=n[o])||void 0===d?void 0:d.products)&&void 0!==i?i:{};c=Object.keys(u).length}else if(n[o]){const t=null==l?void 0:l.products;t&&Object.keys(t).forEach((o=>{var l;const n=null===(l=t[o])||void 0===l?void 0:l.variants;n&&Object.keys(n).forEach((o=>v+=1))}));const d=null===(s=n[o])||void 0===s?void 0:s.products;if(d&&Object.keys(d).forEach((o=>{var l;const n=null===(l=d[o])||void 0===l?void 0:l.variants;n&&Object.keys(n).forEach((o=>c+=1))})),v<=0&&c>0)return!1}return c>0&&v!==c},r=(l,n,t)=>{console.log("updateAllVariantsForSelectedProducts called"),console.log("selectedItems:",l),console.log("collections:",n),console.log("searchedProducts:",t);const d=Object.keys(l).reduce(((d,i)=>{var s;return console.log(`Processing collectionId: ${i}`),i in n?(d[i]=Object.assign(Object.assign({},l[i]),{products:Object.keys(null!==(s=l[i].products)&&void 0!==s?s:{}).reduce(((d,s)=>{var v,c,u,e,r,a,p,b,O,f;console.log(` Processing productId: ${s}`);const g=null===(v=n[i].products)||void 0===v?void 0:v[s],j=null===(e=null===(u=null===(c=null==t?void 0:t.products)||void 0===c?void 0:c[i])||void 0===u?void 0:u.products)||void 0===e?void 0:e[s];return g?(console.log(` Product ${s} found in collections[${i}]`),d[s]=Object.assign(Object.assign({},(null===(r=l[i].products)||void 0===r?void 0:r[s])||{}),{allVariants:o(g.variants)})):j?(console.log(` Product ${s} found in searchedProducts.products[${i}]`),d[s]=Object.assign(Object.assign({},(null===(a=l[i].products)||void 0===a?void 0:a[s])||{}),{allVariants:o(j.variants)})):(null===(b=null===(p=l[i].products)||void 0===p?void 0:p[s])||void 0===b?void 0:b.allVariants)?(console.log(` Product ${s} using preselected allVariants`),d[s]=Object.assign(Object.assign({},(null===(O=l[i].products)||void 0===O?void 0:O[s])||{}),{allVariants:o(null===(f=l[i].products)||void 0===f?void 0:f[s].allVariants)})):console.log(` Product ${s} not found in collections or searchedProducts and has no preselected allVariants`),d}),{})}),d):(console.log(`Collection ${i} not found in collections`),d)}),{});return console.log("updatedSelectedItems:",d),d},a=(o,l)=>{var n;if(l)return o.skuId;const t=Object.values(null!==(n=null==o?void 0:o.variants)&&void 0!==n?n:{});return 1===t.length&&t[0].name.includes(o.name)?t[0].skuId:""};export{i as fetchFbStatusCollection,a as getSkuId,s as getVariantIdsToFetchAtProductLevel,e as isCollectionPartiallyChecked,u as isProductPartiallyChecked,l as liftTheStateUp,v as markVariantsAsApprovedProductsLevel,n as paginateSelectedItems,c as shouldShowVariant,r as updateAllVariantsForSelectedProducts};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.665-beta.0.1",
3
+ "version": "0.0.665-beta.2",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -80,7 +80,7 @@
80
80
  "@babel/plugin-transform-runtime": "^7.19.6",
81
81
  "@babel/preset-env": "^7.20.2",
82
82
  "@babel/preset-react": "^7.18.6",
83
- "@bikdotai/bik-models": "^1.25.133",
83
+ "@bikdotai/bik-models": "^1.25.129",
84
84
  "@changesets/cli": "^2.26.0",
85
85
  "@commitlint/cli": "^17.4.1",
86
86
  "@commitlint/config-conventional": "^17.4.0",
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.__exports={};
@@ -1 +0,0 @@
1
- "use strict";var e,i,p=require("../../../../../_virtual/bik-store.js");e=p.__exports,Object.defineProperty(e,"__esModule",{value:!0}),e.ApplicationType=void 0,(i=e.ApplicationType||(e.ApplicationType={})).BIK="BIK",i.MANIFEST="MANIFEST",i.BSP="BSP";
@@ -1 +0,0 @@
1
- var r={};export{r as __exports};
@@ -1 +0,0 @@
1
- import{__exports as e}from"../../../../../_virtual/bik-store.js";var p,i;p=e,Object.defineProperty(p,"__esModule",{value:!0}),p.ApplicationType=void 0,(i=p.ApplicationType||(p.ApplicationType={})).BIK="BIK",i.MANIFEST="MANIFEST",i.BSP="BSP";