@bikdotai/bik-component-library 0.0.370 → 0.0.371

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),o=require("./type.js");require("../dropdown/DropdownPopover/index.js");var i=require("../dropdown/Dropdown.js");require("../dropdown/ChipDropdown.js"),require("../zeroState/ZeroState.js");var n=require("../TypographyStyle.js"),r=require("../../constants/Theme.js");require("../dropdown/OpenedDropdown/components/description/Description.styled.js"),require("../checkBox/CheckBox.styled.js"),require("../list-item/ListItem.js"),require("../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js"),require("../dropdown/OpenedDropdown/components/menu/MenuItem.js"),require("../dropdown/OpenedDropdown/components/menu/MenuList.styled.js"),require("../button/Button.js"),require("../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js"),require("../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js"),require("../input/Input.js"),require("../dropdown/MenuItem/MenuItem.js");var s=require("../modals/styledModal.js"),c=require("../product-picker/ProductPickerModal.js"),d=require("../tag/Tag.js"),l=require("../tooltips/Tooltip.js"),a=require("../../assets/icons/triangle_error.svg.js"),u=require("../product-picker-v2/modal.js"),T=require("./DiscountModal.styled.js"),p=require("./DiscountUtils.js"),C=require("./DynamicCoupon/DynamicCoupon.js"),S=require("./StaticCoupon/StaticCoupon.js");exports.DiscountModal=E=>{var O,I,P,v,_,D,N,b;const[h,y]=t.useState(),[U,j]=t.useState(),[g,f]=t.useState(null!==(O=E.data)&&void 0!==O?O:"string"==typeof E.hideOption?{isStaticCoupon:"dynamic"===E.hideOption}:{isStaticCoupon:!1}),[m,q]=t.useState(!0),[A,R]=t.useState(),[x,k]=t.useState((null===(I=E.data)||void 0===I?void 0:I.minAmount)?o.MIN_PURCHASE_REQUIREMENT.AMOUNT:(null===(P=E.data)||void 0===P?void 0:P.minQuantity)?o.MIN_PURCHASE_REQUIREMENT.QUANTITY:o.MIN_PURCHASE_REQUIREMENT.NA),[w,F]=t.useState([]),[M,L]=t.useState([]),[Y,G]=t.useState([]),[B,H]=t.useState([]),[V,X]=t.useState(0);t.useEffect((()=>{let e;Q(),E.hideProbability||(e=K()),q(p.validateDiscountData(g,x,A,E.hideProbability||!1,e,!!g.isStaticCoupon)),E.hideProbability||K()}),[]),t.useEffect((()=>{let e;E.hideProbability||(e=K()),q(p.validateDiscountData(g,x,A,E.hideProbability||!1,e,!!g.isStaticCoupon))}),[g,V,A,x]),t.useEffect((()=>{var e,t,o,i,n;if(!E.newPickerConf){if(E.products&&(null===(e=E.products)||void 0===e?void 0:e.length)){if(null===(t=E.data)||void 0===t?void 0:t.entitledProductIds){const e=E.products.filter((e=>{var t,o;return null===(o=null===(t=E.data)||void 0===t?void 0:t.entitledProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));L(e)}if(null===(o=E.data)||void 0===o?void 0:o.prerequisiteProductIds){const e=E.products.filter((e=>{var t,o;return null===(o=null===(t=E.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));F(e)}}if(E.collection&&E.collection.length){if(null===(i=E.data)||void 0===i?void 0:i.entitledCollectionIds){const e=E.collection.filter((e=>{var t,o;return null===(o=null===(t=E.data)||void 0===t?void 0:t.entitledCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));H(e)}if(null===(n=E.data)||void 0===n?void 0:n.prerequisiteCollectionIds){const e=E.collection.filter((e=>{var t,o;return null===(o=null===(t=E.data)||void 0===t?void 0:t.prerequisiteCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));G(e)}}}}),[E.products,E.collection]),t.useEffect((()=>{var e,t,o,i,n,r,s,c;(null===(t=null===(e=E.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&L(E.data.productsConf.entitledProducts),(null===(i=null===(o=E.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&F(E.data.productsConf.prerequisiteProducts),(null===(r=null===(n=E.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&H(E.data.collectionsConf.entitledCollections),(null===(c=null===(s=E.data)||void 0===s?void 0:s.collectionsConf)||void 0===c?void 0:c.prerequisiteCollections)&&G(E.data.collectionsConf.prerequisiteCollections)}),[null===(v=E.data)||void 0===v?void 0:v.productsConf,null===(_=E.data)||void 0===_?void 0:_.collectionsConf]),t.useEffect((()=>{if(E.newPickerConf){const e=[];return Object.values(M).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void f(Object.assign(Object.assign({},g),{entitledProductIds:e}))}const e=M.map((e=>parseInt(e.id)));f(Object.assign(Object.assign({},g),{entitledProductIds:e}))}),[M]),t.useEffect((()=>{if(E.newPickerConf){const e=[];return Object.values(w).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void f(Object.assign(Object.assign({},g),{prerequisiteProductIds:e}))}const e=w.map((e=>parseInt(e.id)));f(Object.assign(Object.assign({},g),{prerequisiteProductIds:e}))}),[w]),t.useEffect((()=>{if(E.newPickerConf){(null==B?void 0:B.isCustom)&&delete B.isCustom;const e=Object.keys(B).map((e=>parseInt(e)));return void f(Object.assign(Object.assign({},g),{entitledCollectionIds:e}))}const e=B.map((e=>parseInt(e.id)));f(Object.assign(Object.assign({},g),{entitledCollectionIds:e}))}),[B]),t.useEffect((()=>{if(E.newPickerConf){(null==Y?void 0:Y.isCustom)&&delete Y.isCustom;const e=Object.keys(Y).map((e=>parseInt(e)));return void f(Object.assign(Object.assign({},g),{prerequisiteCollectionIds:e}))}const e=Y.map((e=>parseInt(e.id)));f(Object.assign(Object.assign({},g),{prerequisiteCollectionIds:e}))}),[Y]);const Q=()=>{var e,t;g.isStaticCoupon||(g.targetType===o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE?R(o.DISCOUNT_TYPES.FREE_SHIPPING):g.targetType===o.DISCOUNT_TARGET_TYPES.LINE_ITEM?g.targetSelection===o.DISCOUNT_TARGET_SELECTION.ENTITLED?(null===(e=g.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=g.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?R(o.DISCOUNT_TYPES.BUY_X_GET_Y):R(o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS):R(o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER):(f(Object.assign(Object.assign({},g),{targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,valueType:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT})),R(o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER)))};t.useEffect((()=>{f(Object.assign(Object.assign({},g),{targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,valueType:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT})),R(o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER)}),[g.isStaticCoupon]);const z=[{value:o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:A===o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER},{value:o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:A===o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS},{value:o.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:A===o.DISCOUNT_TYPES.BUY_X_GET_Y},{value:o.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:A===o.DISCOUNT_TYPES.FREE_SHIPPING}],K=()=>{if(!E.quadrant||!E.probability)return;const e=[...E.probability];let t=[];e.length>=E.quadrant&&e.splice(E.quadrant-1,1),t=e;const o=t.reduce(((e,t)=>e+t),0)+(g.probability||0);return X(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},$=e=>{var t,i,n,r;const s=e.value;R(s),F([]),L([]),G([]),H([]),k(o.MIN_PURCHASE_REQUIREMENT.NA),s===o.DISCOUNT_TYPES.FREE_SHIPPING?f({value:100,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:g.quadrant,isStaticCoupon:!1}):s===o.DISCOUNT_TYPES.BUY_X_GET_Y?f({targetSelection:o.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:g.quadrant,isStaticCoupon:!1}):s===o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER?f({targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:null!==(i=null===(t=E.data)||void 0===t?void 0:t.valueType)&&void 0!==i?i:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,quadrant:g.quadrant,isStaticCoupon:!1}):s===o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS&&f({targetSelection:o.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:null!==(r=null===(n=E.data)||void 0===n?void 0:n.valueType)&&void 0!==r?r:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,quadrant:g.quadrant,isStaticCoupon:!1})};return e.jsxs(s.StyledModal,Object.assign({width:(U||h)&&E.newPickerConf?"25px":"750px",open:E.isOpen,headingTitle:h?"Select Products":E.title,headingSubtitle:h?void 0:E.subTitle,footerLeftCustomElement:E.errorMsg?E.errorMsg&&e.jsx(d.Tag,{theme:"light",tagText:E.errorMsg,type:"negative"}):!E.quadrant||E.hideProbability?e.jsx(e.Fragment,{}):V<=1?e.jsx(d.Tag,{theme:"light",tagText:`Current probability sum: ${V}`,type:"white"}):e.jsx(l.Tooltip,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e.jsx("div",{children:e.jsx(d.Tag,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${V}`,type:"negative",LeadingIcon:a.default})})})),headerRightCustomElement:E.allowStaticCoupon||h?void 0:e.jsx(i.Dropdown,{options:z,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{$(e)}}),onClose:E.onClose,footerShadow:!0,primaryButton:h?{buttonType:"primary",onClick:()=>{y(void 0)},buttonText:"Add"}:U?{buttonType:"primary",onClick:()=>{j(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:m,isLoading:null!==(D=E.loading)&&void 0!==D&&D,onClick:()=>{var e,t;g.isStaticCoupon?E.onSaveClicked({quadrant:g.quadrant,couponCode:g.couponCode,description:g.description,isStaticCoupon:g.isStaticCoupon,probability:g.probability,title:g.title}):E.onSaveClicked(Object.assign(Object.assign({},g),{description:p.descriptionBuilder(g,E.currency,null!==(e=E.products)&&void 0!==e?e:[],null!==(t=E.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:M,prerequisiteProducts:w},collectionsConf:{entitledCollections:B,prerequisiteCollections:Y}}))}},secondaryButton:h?{buttonType:"tertiaryGray",onClick:()=>{y(void 0)},buttonText:"Back"}:U?{buttonType:"tertiaryGray",onClick:()=>{j(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:E.onClose,buttonText:"Close"}},{children:[!h&&!U&&e.jsxs(T.StyledDiscountDialogueContainer,{children:[E.allowStaticCoupon&&!h&&e.jsxs(T.CouponTypeContainerStyled,Object.assign({selectedDiv:g.isStaticCoupon?1:2},{children:["static"===E.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{g.isStaticCoupon||f({isStaticCoupon:!0,quadrant:g.quadrant})}},{children:[e.jsx(n.TitleSmall,Object.assign({style:g.isStaticCoupon?{color:r.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"Static code"})),e.jsx(n.BodyCaption,Object.assign({style:g.isStaticCoupon?{color:r.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===E.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{g.isStaticCoupon&&f({isStaticCoupon:!1,quadrant:g.quadrant})}},{children:[e.jsx(n.TitleSmall,Object.assign({style:g.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"Dynamic code"})),e.jsx(n.BodyCaption,Object.assign({style:g.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),g.isStaticCoupon&&!h&&e.jsx(S.default,{discountData:g,setDiscountData:f,hideProbability:E.hideProbability||!1,discountAdminUrl:E.discountAdminUrl}),!g.isStaticCoupon&&!h&&!U&&e.jsx(C.default,{currency:E.currency,entitledProducts:M,prerequisiteProducts:w,setEntitledProducts:L,setPrerequisiteProducts:F,discountData:g,productPickerOpen:h,setIsProductPickerOpen:y,setDiscountData:f,selectedCouponType:A,setSelectedCouponType:R,selectedMinimumRequirement:x,setSelectedMinimumRequirement:k,hideProbability:E.hideProbability||!1,hideExpiration:E.hideExpiration||!1,allowStaticCoupon:E.allowStaticCoupon,onChangeCouponType:$,collectionPickerOpen:U,entitledCollections:B,prerequisiteCollections:Y,setIsCollectionPickerOpen:j,setEntitledCollections:H,setPrerequisiteCollections:G,useNewPicker:!!E.newPickerConf})]}),!!h&&e.jsxs(e.Fragment,{children:[!E.newPickerConf&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsx(c.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(N=E.products)&&void 0!==N?N:[],title:"Select Products",onClose:()=>{y(void 0)},selectedProducts:h===C.DISCOUNT_PRODUCTS.ENTITLED?M:w,setSelectedProducts:h===C.DISCOUNT_PRODUCTS.ENTITLED?L:F,onSearchKeyChange:E.onProductSearch})})),E.newPickerConf&&e.jsx(u.ProductPickerModal,{visible:!0,onClose:()=>y(void 0),collectionFetcher:E.newPickerConf.fetchCollections,productFetcher:E.newPickerConf.fetchProducts,selectedItems:h===C.DISCOUNT_PRODUCTS.ENTITLED?M:w,onAdd:e=>{h===C.DISCOUNT_PRODUCTS.ENTITLED?L(e):F(e),y(void 0)},zIndex:200,storeId:E.newPickerConf.storeId,searchInCollectionFetcher:E.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:E.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!U&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsxs(e.Fragment,{children:[E.newPickerConf&&e.jsx(u.ProductPickerModal,{visible:!0,onClose:()=>j(void 0),collectionFetcher:E.newPickerConf.fetchCollections,productFetcher:E.newPickerConf.fetchProducts,selectedItems:U===C.DISCOUNT_PRODUCTS.ENTITLED?B:Y,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),U===C.DISCOUNT_PRODUCTS.ENTITLED?H(e):G(e),j(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:E.newPickerConf.storeId,searchInCollectionFetcher:E.newPickerConf.searchInCollection,searchFetcher:E.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!E.newPickerConf&&e.jsx(c.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(b=E.collection)&&void 0!==b?b:[],title:"Select Products",onClose:()=>{j(void 0)},selectedProducts:U===C.DISCOUNT_PRODUCTS.ENTITLED?B:Y,setSelectedProducts:U===C.DISCOUNT_PRODUCTS.ENTITLED?H:G,onSearchKeyChange:E.onCollectionSearch,searchPlaceholder:"Search collections..."})]})}))]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),o=require("./type.js");require("../dropdown/DropdownPopover/index.js");var i=require("../dropdown/Dropdown.js");require("../dropdown/ChipDropdown.js"),require("../zeroState/ZeroState.js");var n=require("../TypographyStyle.js"),r=require("../../constants/Theme.js");require("../dropdown/OpenedDropdown/components/description/Description.styled.js"),require("../checkBox/CheckBox.styled.js"),require("../list-item/ListItem.js"),require("../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js"),require("../dropdown/OpenedDropdown/components/menu/MenuItem.js"),require("../dropdown/OpenedDropdown/components/menu/MenuList.styled.js"),require("../button/Button.js"),require("../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js"),require("../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js"),require("../input/Input.js"),require("../dropdown/MenuItem/MenuItem.js");var s=require("../modals/styledModal.js"),c=require("../product-picker/ProductPickerModal.js"),d=require("../tag/Tag.js"),l=require("../tooltips/Tooltip.js"),a=require("../../assets/icons/triangle_error.svg.js"),u=require("../product-picker-v2/modal.js"),T=require("./DiscountModal.styled.js"),p=require("./DiscountUtils.js"),C=require("./DynamicCoupon/DynamicCoupon.js"),S=require("./StaticCoupon/StaticCoupon.js");exports.DiscountModal=E=>{var I,O,P,v,_,D,N,b;const[h,y]=t.useState(),[U,j]=t.useState(),[g,f]=t.useState(null!==(I=E.data)&&void 0!==I?I:"string"==typeof E.hideOption?{isStaticCoupon:"dynamic"===E.hideOption}:{isStaticCoupon:!1}),[m,q]=t.useState(!0),[A,R]=t.useState(),[x,k]=t.useState((null===(O=E.data)||void 0===O?void 0:O.minAmount)?o.MIN_PURCHASE_REQUIREMENT.AMOUNT:(null===(P=E.data)||void 0===P?void 0:P.minQuantity)?o.MIN_PURCHASE_REQUIREMENT.QUANTITY:o.MIN_PURCHASE_REQUIREMENT.NA),[w,F]=t.useState([]),[M,L]=t.useState([]),[Y,G]=t.useState([]),[B,H]=t.useState([]),[V,X]=t.useState(0);t.useEffect((()=>{let e;Q(),E.hideProbability||(e=K()),q(p.validateDiscountData(g,x,A,E.hideProbability||!1,e,!!g.isStaticCoupon)),E.hideProbability||K()}),[]),t.useEffect((()=>{let e;E.hideProbability||(e=K()),q(p.validateDiscountData(g,x,A,E.hideProbability||!1,e,!!g.isStaticCoupon))}),[g,V,A,x]),t.useEffect((()=>{var e,t,o,i,n;if(!E.newPickerConf){if(E.products&&(null===(e=E.products)||void 0===e?void 0:e.length)){if(null===(t=E.data)||void 0===t?void 0:t.entitledProductIds){const e=E.products.filter((e=>{var t,o;return null===(o=null===(t=E.data)||void 0===t?void 0:t.entitledProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));L(e)}if(null===(o=E.data)||void 0===o?void 0:o.prerequisiteProductIds){const e=E.products.filter((e=>{var t,o;return null===(o=null===(t=E.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));F(e)}}if(E.collection&&E.collection.length){if(null===(i=E.data)||void 0===i?void 0:i.entitledCollectionIds){const e=E.collection.filter((e=>{var t,o;return null===(o=null===(t=E.data)||void 0===t?void 0:t.entitledCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));H(e)}if(null===(n=E.data)||void 0===n?void 0:n.prerequisiteCollectionIds){const e=E.collection.filter((e=>{var t,o;return null===(o=null===(t=E.data)||void 0===t?void 0:t.prerequisiteCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));G(e)}}}}),[E.products,E.collection]),t.useEffect((()=>{var e,t,o,i,n,r,s,c;(null===(t=null===(e=E.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&L(E.data.productsConf.entitledProducts),(null===(i=null===(o=E.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&F(E.data.productsConf.prerequisiteProducts),(null===(r=null===(n=E.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&H(E.data.collectionsConf.entitledCollections),(null===(c=null===(s=E.data)||void 0===s?void 0:s.collectionsConf)||void 0===c?void 0:c.prerequisiteCollections)&&G(E.data.collectionsConf.prerequisiteCollections)}),[null===(v=E.data)||void 0===v?void 0:v.productsConf,null===(_=E.data)||void 0===_?void 0:_.collectionsConf]),t.useEffect((()=>{if(E.newPickerConf){const e=[];return Object.values(M).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void f(Object.assign(Object.assign({},g),{entitledProductIds:e}))}const e=M.map((e=>parseInt(e.id)));f(Object.assign(Object.assign({},g),{entitledProductIds:e}))}),[M]),t.useEffect((()=>{if(E.newPickerConf){const e=[];return Object.values(w).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void f(Object.assign(Object.assign({},g),{prerequisiteProductIds:e}))}const e=w.map((e=>parseInt(e.id)));f(Object.assign(Object.assign({},g),{prerequisiteProductIds:e}))}),[w]),t.useEffect((()=>{if(E.newPickerConf){(null==B?void 0:B.isCustom)&&delete B.isCustom;const e=Object.keys(B).map((e=>parseInt(e)));return void f(Object.assign(Object.assign({},g),{entitledCollectionIds:e}))}const e=B.map((e=>parseInt(e.id)));f(Object.assign(Object.assign({},g),{entitledCollectionIds:e}))}),[B]),t.useEffect((()=>{if(E.newPickerConf){(null==Y?void 0:Y.isCustom)&&delete Y.isCustom;const e=Object.keys(Y).map((e=>parseInt(e)));return void f(Object.assign(Object.assign({},g),{prerequisiteCollectionIds:e}))}const e=Y.map((e=>parseInt(e.id)));f(Object.assign(Object.assign({},g),{prerequisiteCollectionIds:e}))}),[Y]);const Q=()=>{var e,t;g.isStaticCoupon||(g.targetType===o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE?R(o.DISCOUNT_TYPES.FREE_SHIPPING):g.targetType===o.DISCOUNT_TARGET_TYPES.LINE_ITEM?g.targetSelection===o.DISCOUNT_TARGET_SELECTION.ENTITLED?(null===(e=g.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=g.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?R(o.DISCOUNT_TYPES.BUY_X_GET_Y):R(o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS):R(o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER):(f(Object.assign(Object.assign({},g),{targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,valueType:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT})),R(o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER)))},z=[{value:o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:A===o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER},{value:o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:A===o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS},{value:o.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:A===o.DISCOUNT_TYPES.BUY_X_GET_Y},{value:o.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:A===o.DISCOUNT_TYPES.FREE_SHIPPING}],K=()=>{if(!E.quadrant||!E.probability)return;const e=[...E.probability];let t=[];e.length>=E.quadrant&&e.splice(E.quadrant-1,1),t=e;const o=t.reduce(((e,t)=>e+t),0)+(g.probability||0);return X(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},$=e=>{var t,i,n,r;const s=e.value;R(s),F([]),L([]),G([]),H([]),k(o.MIN_PURCHASE_REQUIREMENT.NA),s===o.DISCOUNT_TYPES.FREE_SHIPPING?f({value:100,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:g.quadrant,isStaticCoupon:!1}):s===o.DISCOUNT_TYPES.BUY_X_GET_Y?f({targetSelection:o.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:g.quadrant,isStaticCoupon:!1}):s===o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER?f({targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:null!==(i=null===(t=E.data)||void 0===t?void 0:t.valueType)&&void 0!==i?i:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,quadrant:g.quadrant,isStaticCoupon:!1}):s===o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS&&f({targetSelection:o.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:null!==(r=null===(n=E.data)||void 0===n?void 0:n.valueType)&&void 0!==r?r:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,quadrant:g.quadrant,isStaticCoupon:!1})};return e.jsxs(s.StyledModal,Object.assign({width:(U||h)&&E.newPickerConf?"25px":"750px",open:E.isOpen,headingTitle:h?"Select Products":E.title,headingSubtitle:h?void 0:E.subTitle,footerLeftCustomElement:E.errorMsg?E.errorMsg&&e.jsx(d.Tag,{theme:"light",tagText:E.errorMsg,type:"negative"}):!E.quadrant||E.hideProbability?e.jsx(e.Fragment,{}):V<=1?e.jsx(d.Tag,{theme:"light",tagText:`Current probability sum: ${V}`,type:"white"}):e.jsx(l.Tooltip,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e.jsx("div",{children:e.jsx(d.Tag,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${V}`,type:"negative",LeadingIcon:a.default})})})),headerRightCustomElement:E.allowStaticCoupon||h?void 0:e.jsx(i.Dropdown,{options:z,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{$(e)}}),onClose:E.onClose,footerShadow:!0,primaryButton:h?{buttonType:"primary",onClick:()=>{y(void 0)},buttonText:"Add"}:U?{buttonType:"primary",onClick:()=>{j(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:m,isLoading:null!==(D=E.loading)&&void 0!==D&&D,onClick:()=>{var e,t;g.isStaticCoupon?E.onSaveClicked({quadrant:g.quadrant,couponCode:g.couponCode,description:g.description,isStaticCoupon:g.isStaticCoupon,probability:g.probability,title:g.title}):E.onSaveClicked(Object.assign(Object.assign({},g),{description:p.descriptionBuilder(g,E.currency,null!==(e=E.products)&&void 0!==e?e:[],null!==(t=E.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:M,prerequisiteProducts:w},collectionsConf:{entitledCollections:B,prerequisiteCollections:Y}}))}},secondaryButton:h?{buttonType:"tertiaryGray",onClick:()=>{y(void 0)},buttonText:"Back"}:U?{buttonType:"tertiaryGray",onClick:()=>{j(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:E.onClose,buttonText:"Close"}},{children:[!h&&!U&&e.jsxs(T.StyledDiscountDialogueContainer,{children:[E.allowStaticCoupon&&!h&&e.jsxs(T.CouponTypeContainerStyled,Object.assign({selectedDiv:g.isStaticCoupon?1:2},{children:["static"===E.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{g.isStaticCoupon||f({isStaticCoupon:!0,quadrant:g.quadrant})}},{children:[e.jsx(n.TitleSmall,Object.assign({style:g.isStaticCoupon?{color:r.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"Static code"})),e.jsx(n.BodyCaption,Object.assign({style:g.isStaticCoupon?{color:r.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===E.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{g.isStaticCoupon&&(R(o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER),f({isStaticCoupon:!1,quadrant:g.quadrant,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,valueType:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT}))}},{children:[e.jsx(n.TitleSmall,Object.assign({style:g.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"Dynamic code"})),e.jsx(n.BodyCaption,Object.assign({style:g.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),g.isStaticCoupon&&!h&&e.jsx(S.default,{discountData:g,setDiscountData:f,hideProbability:E.hideProbability||!1,discountAdminUrl:E.discountAdminUrl}),!g.isStaticCoupon&&!h&&!U&&e.jsx(C.default,{currency:E.currency,entitledProducts:M,prerequisiteProducts:w,setEntitledProducts:L,setPrerequisiteProducts:F,discountData:g,productPickerOpen:h,setIsProductPickerOpen:y,setDiscountData:f,selectedCouponType:A,setSelectedCouponType:R,selectedMinimumRequirement:x,setSelectedMinimumRequirement:k,hideProbability:E.hideProbability||!1,hideExpiration:E.hideExpiration||!1,allowStaticCoupon:E.allowStaticCoupon,onChangeCouponType:$,collectionPickerOpen:U,entitledCollections:B,prerequisiteCollections:Y,setIsCollectionPickerOpen:j,setEntitledCollections:H,setPrerequisiteCollections:G,useNewPicker:!!E.newPickerConf})]}),!!h&&e.jsxs(e.Fragment,{children:[!E.newPickerConf&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsx(c.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(N=E.products)&&void 0!==N?N:[],title:"Select Products",onClose:()=>{y(void 0)},selectedProducts:h===C.DISCOUNT_PRODUCTS.ENTITLED?M:w,setSelectedProducts:h===C.DISCOUNT_PRODUCTS.ENTITLED?L:F,onSearchKeyChange:E.onProductSearch})})),E.newPickerConf&&e.jsx(u.ProductPickerModal,{visible:!0,onClose:()=>y(void 0),collectionFetcher:E.newPickerConf.fetchCollections,productFetcher:E.newPickerConf.fetchProducts,selectedItems:h===C.DISCOUNT_PRODUCTS.ENTITLED?M:w,onAdd:e=>{h===C.DISCOUNT_PRODUCTS.ENTITLED?L(e):F(e),y(void 0)},zIndex:200,storeId:E.newPickerConf.storeId,searchInCollectionFetcher:E.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:E.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!U&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsxs(e.Fragment,{children:[E.newPickerConf&&e.jsx(u.ProductPickerModal,{visible:!0,onClose:()=>j(void 0),collectionFetcher:E.newPickerConf.fetchCollections,productFetcher:E.newPickerConf.fetchProducts,selectedItems:U===C.DISCOUNT_PRODUCTS.ENTITLED?B:Y,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),U===C.DISCOUNT_PRODUCTS.ENTITLED?H(e):G(e),j(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:E.newPickerConf.storeId,searchInCollectionFetcher:E.newPickerConf.searchInCollection,searchFetcher:E.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!E.newPickerConf&&e.jsx(c.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(b=E.collection)&&void 0!==b?b:[],title:"Select Products",onClose:()=>{j(void 0)},selectedProducts:U===C.DISCOUNT_PRODUCTS.ENTITLED?B:Y,setSelectedProducts:U===C.DISCOUNT_PRODUCTS.ENTITLED?H:G,onSearchKeyChange:E.onCollectionSearch,searchPlaceholder:"Search collections..."})]})}))]}))};
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import{useState as i,useEffect as n}from"react";import{MIN_PURCHASE_REQUIREMENT as r,DISCOUNT_TARGET_TYPES as c,DISCOUNT_TYPES as s,DISCOUNT_TARGET_SELECTION as d,DISCOUNT_VALUE_TYPES as l}from"./type.js";import"../dropdown/DropdownPopover/index.js";import{Dropdown as a}from"../dropdown/Dropdown.js";import"../dropdown/ChipDropdown.js";import"../zeroState/ZeroState.js";import{TitleSmall as u,BodyCaption as p}from"../TypographyStyle.js";import{DEFAULT_THEME as C}from"../../constants/Theme.js";import"../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../checkBox/CheckBox.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"../button/Button.js";import"../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../input/Input.js";import"../dropdown/MenuItem/MenuItem.js";import{StyledModal as v}from"../modals/styledModal.js";import{ProductPickerContent as m}from"../product-picker/ProductPickerModal.js";import{Tag as b}from"../tag/Tag.js";import{Tooltip as h}from"../tooltips/Tooltip.js";import y from"../../assets/icons/triangle_error.svg.js";import{ProductPickerModal as P}from"../product-picker-v2/modal.js";import{StyledDiscountDialogueContainer as T,CouponTypeContainerStyled as I}from"./DiscountModal.styled.js";import{validateDiscountData as O,descriptionBuilder as f}from"./DiscountUtils.js";import g,{DISCOUNT_PRODUCTS as E}from"./DynamicCoupon/DynamicCoupon.js";import S from"./StaticCoupon/StaticCoupon.js";const j=j=>{var w,_,k,D,N,F,q,M;const[A,L]=i(),[x,R]=i(),[U,G]=i(null!==(w=j.data)&&void 0!==w?w:"string"==typeof j.hideOption?{isStaticCoupon:"dynamic"===j.hideOption}:{isStaticCoupon:!1}),[B,Y]=i(!0),[X,H]=i(),[V,z]=i((null===(_=j.data)||void 0===_?void 0:_.minAmount)?r.AMOUNT:(null===(k=j.data)||void 0===k?void 0:k.minQuantity)?r.QUANTITY:r.NA),[K,Q]=i([]),[$,Z]=i([]),[J,W]=i([]),[ee,te]=i([]),[oe,ie]=i(0);n((()=>{let e;ne(),j.hideProbability||(e=ce()),Y(O(U,V,X,j.hideProbability||!1,e,!!U.isStaticCoupon)),j.hideProbability||ce()}),[]),n((()=>{let e;j.hideProbability||(e=ce()),Y(O(U,V,X,j.hideProbability||!1,e,!!U.isStaticCoupon))}),[U,oe,X,V]),n((()=>{var e,t,o,i,n;if(!j.newPickerConf){if(j.products&&(null===(e=j.products)||void 0===e?void 0:e.length)){if(null===(t=j.data)||void 0===t?void 0:t.entitledProductIds){const e=j.products.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.entitledProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));Z(e)}if(null===(o=j.data)||void 0===o?void 0:o.prerequisiteProductIds){const e=j.products.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));Q(e)}}if(j.collection&&j.collection.length){if(null===(i=j.data)||void 0===i?void 0:i.entitledCollectionIds){const e=j.collection.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.entitledCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));te(e)}if(null===(n=j.data)||void 0===n?void 0:n.prerequisiteCollectionIds){const e=j.collection.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.prerequisiteCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));W(e)}}}}),[j.products,j.collection]),n((()=>{var e,t,o,i,n,r,c,s;(null===(t=null===(e=j.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&Z(j.data.productsConf.entitledProducts),(null===(i=null===(o=j.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&Q(j.data.productsConf.prerequisiteProducts),(null===(r=null===(n=j.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&te(j.data.collectionsConf.entitledCollections),(null===(s=null===(c=j.data)||void 0===c?void 0:c.collectionsConf)||void 0===s?void 0:s.prerequisiteCollections)&&W(j.data.collectionsConf.prerequisiteCollections)}),[null===(D=j.data)||void 0===D?void 0:D.productsConf,null===(N=j.data)||void 0===N?void 0:N.collectionsConf]),n((()=>{if(j.newPickerConf){const e=[];return Object.values($).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void G(Object.assign(Object.assign({},U),{entitledProductIds:e}))}const e=$.map((e=>parseInt(e.id)));G(Object.assign(Object.assign({},U),{entitledProductIds:e}))}),[$]),n((()=>{if(j.newPickerConf){const e=[];return Object.values(K).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void G(Object.assign(Object.assign({},U),{prerequisiteProductIds:e}))}const e=K.map((e=>parseInt(e.id)));G(Object.assign(Object.assign({},U),{prerequisiteProductIds:e}))}),[K]),n((()=>{if(j.newPickerConf){(null==ee?void 0:ee.isCustom)&&delete ee.isCustom;const e=Object.keys(ee).map((e=>parseInt(e)));return void G(Object.assign(Object.assign({},U),{entitledCollectionIds:e}))}const e=ee.map((e=>parseInt(e.id)));G(Object.assign(Object.assign({},U),{entitledCollectionIds:e}))}),[ee]),n((()=>{if(j.newPickerConf){(null==J?void 0:J.isCustom)&&delete J.isCustom;const e=Object.keys(J).map((e=>parseInt(e)));return void G(Object.assign(Object.assign({},U),{prerequisiteCollectionIds:e}))}const e=J.map((e=>parseInt(e.id)));G(Object.assign(Object.assign({},U),{prerequisiteCollectionIds:e}))}),[J]);const ne=()=>{var e,t;U.isStaticCoupon||(U.targetType===c.SHIPPING_LINE?H(s.FREE_SHIPPING):U.targetType===c.LINE_ITEM?U.targetSelection===d.ENTITLED?(null===(e=U.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=U.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?H(s.BUY_X_GET_Y):H(s.AMOUNT_OFF_PRODUCTS):H(s.AMOUNT_OFF_ORDER):(G(Object.assign(Object.assign({},U),{targetType:c.LINE_ITEM,targetSelection:d.ALL,valueType:l.FIXED_AMOUNT})),H(s.AMOUNT_OFF_ORDER)))};n((()=>{G(Object.assign(Object.assign({},U),{targetType:c.LINE_ITEM,targetSelection:d.ALL,valueType:l.FIXED_AMOUNT})),H(s.AMOUNT_OFF_ORDER)}),[U.isStaticCoupon]);const re=[{value:s.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:X===s.AMOUNT_OFF_ORDER},{value:s.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:X===s.AMOUNT_OFF_PRODUCTS},{value:s.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:X===s.BUY_X_GET_Y},{value:s.FREE_SHIPPING,label:"Free shipping",selected:X===s.FREE_SHIPPING}],ce=()=>{if(!j.quadrant||!j.probability)return;const e=[...j.probability];let t=[];e.length>=j.quadrant&&e.splice(j.quadrant-1,1),t=e;const o=t.reduce(((e,t)=>e+t),0)+(U.probability||0);return ie(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},se=e=>{var t,o,i,n;const a=e.value;H(a),Q([]),Z([]),W([]),te([]),z(r.NA),a===s.FREE_SHIPPING?G({value:100,targetSelection:d.ALL,targetType:c.SHIPPING_LINE,valueType:l.PERCENTAGE,quadrant:U.quadrant,isStaticCoupon:!1}):a===s.BUY_X_GET_Y?G({targetSelection:d.ENTITLED,targetType:c.LINE_ITEM,valueType:l.PERCENTAGE,quadrant:U.quadrant,isStaticCoupon:!1}):a===s.AMOUNT_OFF_ORDER?G({targetSelection:d.ALL,targetType:c.LINE_ITEM,valueType:null!==(o=null===(t=j.data)||void 0===t?void 0:t.valueType)&&void 0!==o?o:l.FIXED_AMOUNT,quadrant:U.quadrant,isStaticCoupon:!1}):a===s.AMOUNT_OFF_PRODUCTS&&G({targetSelection:d.ENTITLED,targetType:c.LINE_ITEM,valueType:null!==(n=null===(i=j.data)||void 0===i?void 0:i.valueType)&&void 0!==n?n:l.FIXED_AMOUNT,quadrant:U.quadrant,isStaticCoupon:!1})};return e(v,Object.assign({width:(x||A)&&j.newPickerConf?"25px":"750px",open:j.isOpen,headingTitle:A?"Select Products":j.title,headingSubtitle:A?void 0:j.subTitle,footerLeftCustomElement:j.errorMsg?j.errorMsg&&t(b,{theme:"light",tagText:j.errorMsg,type:"negative"}):!j.quadrant||j.hideProbability?t(o,{}):oe<=1?t(b,{theme:"light",tagText:`Current probability sum: ${oe}`,type:"white"}):t(h,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:t("div",{children:t(b,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${oe}`,type:"negative",LeadingIcon:y})})})),headerRightCustomElement:j.allowStaticCoupon||A?void 0:t(a,{options:re,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{se(e)}}),onClose:j.onClose,footerShadow:!0,primaryButton:A?{buttonType:"primary",onClick:()=>{L(void 0)},buttonText:"Add"}:x?{buttonType:"primary",onClick:()=>{R(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:B,isLoading:null!==(F=j.loading)&&void 0!==F&&F,onClick:()=>{var e,t;U.isStaticCoupon?j.onSaveClicked({quadrant:U.quadrant,couponCode:U.couponCode,description:U.description,isStaticCoupon:U.isStaticCoupon,probability:U.probability,title:U.title}):j.onSaveClicked(Object.assign(Object.assign({},U),{description:f(U,j.currency,null!==(e=j.products)&&void 0!==e?e:[],null!==(t=j.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:$,prerequisiteProducts:K},collectionsConf:{entitledCollections:ee,prerequisiteCollections:J}}))}},secondaryButton:A?{buttonType:"tertiaryGray",onClick:()=>{L(void 0)},buttonText:"Back"}:x?{buttonType:"tertiaryGray",onClick:()=>{R(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:j.onClose,buttonText:"Close"}},{children:[!A&&!x&&e(T,{children:[j.allowStaticCoupon&&!A&&e(I,Object.assign({selectedDiv:U.isStaticCoupon?1:2},{children:["static"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{U.isStaticCoupon||G({isStaticCoupon:!0,quadrant:U.quadrant})}},{children:[t(u,Object.assign({style:U.isStaticCoupon?{color:C.colorsV2.content.brand}:{}},{children:"Static code"})),t(p,Object.assign({style:U.isStaticCoupon?{color:C.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{U.isStaticCoupon&&G({isStaticCoupon:!1,quadrant:U.quadrant})}},{children:[t(u,Object.assign({style:U.isStaticCoupon?{}:{color:C.colorsV2.content.brand}},{children:"Dynamic code"})),t(p,Object.assign({style:U.isStaticCoupon?{}:{color:C.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),U.isStaticCoupon&&!A&&t(S,{discountData:U,setDiscountData:G,hideProbability:j.hideProbability||!1,discountAdminUrl:j.discountAdminUrl}),!U.isStaticCoupon&&!A&&!x&&t(g,{currency:j.currency,entitledProducts:$,prerequisiteProducts:K,setEntitledProducts:Z,setPrerequisiteProducts:Q,discountData:U,productPickerOpen:A,setIsProductPickerOpen:L,setDiscountData:G,selectedCouponType:X,setSelectedCouponType:H,selectedMinimumRequirement:V,setSelectedMinimumRequirement:z,hideProbability:j.hideProbability||!1,hideExpiration:j.hideExpiration||!1,allowStaticCoupon:j.allowStaticCoupon,onChangeCouponType:se,collectionPickerOpen:x,entitledCollections:ee,prerequisiteCollections:J,setIsCollectionPickerOpen:R,setEntitledCollections:te,setPrerequisiteCollections:W,useNewPicker:!!j.newPickerConf})]}),!!A&&e(o,{children:[!j.newPickerConf&&t("div",Object.assign({style:{padding:"12px 0"}},{children:t(m,{show:!0,onSave:()=>{},products:null!==(q=j.products)&&void 0!==q?q:[],title:"Select Products",onClose:()=>{L(void 0)},selectedProducts:A===E.ENTITLED?$:K,setSelectedProducts:A===E.ENTITLED?Z:Q,onSearchKeyChange:j.onProductSearch})})),j.newPickerConf&&t(P,{visible:!0,onClose:()=>L(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:A===E.ENTITLED?$:K,onAdd:e=>{A===E.ENTITLED?Z(e):Q(e),L(void 0)},zIndex:200,storeId:j.newPickerConf.storeId,searchInCollectionFetcher:j.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:j.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!x&&t("div",Object.assign({style:{padding:"12px 0"}},{children:e(o,{children:[j.newPickerConf&&t(P,{visible:!0,onClose:()=>R(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:x===E.ENTITLED?ee:J,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),x===E.ENTITLED?te(e):W(e),R(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:j.newPickerConf.storeId,searchInCollectionFetcher:j.newPickerConf.searchInCollection,searchFetcher:j.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!j.newPickerConf&&t(m,{show:!0,onSave:()=>{},products:null!==(M=j.collection)&&void 0!==M?M:[],title:"Select Products",onClose:()=>{R(void 0)},selectedProducts:x===E.ENTITLED?ee:J,setSelectedProducts:x===E.ENTITLED?te:W,onSearchKeyChange:j.onCollectionSearch,searchPlaceholder:"Search collections..."})]})}))]}))};export{j as DiscountModal};
1
+ import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import{useState as i,useEffect as n}from"react";import{MIN_PURCHASE_REQUIREMENT as r,DISCOUNT_TARGET_TYPES as c,DISCOUNT_TYPES as d,DISCOUNT_TARGET_SELECTION as s,DISCOUNT_VALUE_TYPES as l}from"./type.js";import"../dropdown/DropdownPopover/index.js";import{Dropdown as a}from"../dropdown/Dropdown.js";import"../dropdown/ChipDropdown.js";import"../zeroState/ZeroState.js";import{TitleSmall as u,BodyCaption as p}from"../TypographyStyle.js";import{DEFAULT_THEME as C}from"../../constants/Theme.js";import"../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../checkBox/CheckBox.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"../button/Button.js";import"../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../input/Input.js";import"../dropdown/MenuItem/MenuItem.js";import{StyledModal as v}from"../modals/styledModal.js";import{ProductPickerContent as m}from"../product-picker/ProductPickerModal.js";import{Tag as h}from"../tag/Tag.js";import{Tooltip as b}from"../tooltips/Tooltip.js";import y from"../../assets/icons/triangle_error.svg.js";import{ProductPickerModal as P}from"../product-picker-v2/modal.js";import{StyledDiscountDialogueContainer as T,CouponTypeContainerStyled as I}from"./DiscountModal.styled.js";import{validateDiscountData as O,descriptionBuilder as f}from"./DiscountUtils.js";import g,{DISCOUNT_PRODUCTS as E}from"./DynamicCoupon/DynamicCoupon.js";import S from"./StaticCoupon/StaticCoupon.js";const j=j=>{var w,_,k,D,N,F,q,M;const[A,L]=i(),[x,R]=i(),[U,G]=i(null!==(w=j.data)&&void 0!==w?w:"string"==typeof j.hideOption?{isStaticCoupon:"dynamic"===j.hideOption}:{isStaticCoupon:!1}),[B,Y]=i(!0),[X,H]=i(),[V,z]=i((null===(_=j.data)||void 0===_?void 0:_.minAmount)?r.AMOUNT:(null===(k=j.data)||void 0===k?void 0:k.minQuantity)?r.QUANTITY:r.NA),[K,Q]=i([]),[$,Z]=i([]),[J,W]=i([]),[ee,te]=i([]),[oe,ie]=i(0);n((()=>{let e;ne(),j.hideProbability||(e=ce()),Y(O(U,V,X,j.hideProbability||!1,e,!!U.isStaticCoupon)),j.hideProbability||ce()}),[]),n((()=>{let e;j.hideProbability||(e=ce()),Y(O(U,V,X,j.hideProbability||!1,e,!!U.isStaticCoupon))}),[U,oe,X,V]),n((()=>{var e,t,o,i,n;if(!j.newPickerConf){if(j.products&&(null===(e=j.products)||void 0===e?void 0:e.length)){if(null===(t=j.data)||void 0===t?void 0:t.entitledProductIds){const e=j.products.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.entitledProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));Z(e)}if(null===(o=j.data)||void 0===o?void 0:o.prerequisiteProductIds){const e=j.products.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));Q(e)}}if(j.collection&&j.collection.length){if(null===(i=j.data)||void 0===i?void 0:i.entitledCollectionIds){const e=j.collection.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.entitledCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));te(e)}if(null===(n=j.data)||void 0===n?void 0:n.prerequisiteCollectionIds){const e=j.collection.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.prerequisiteCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));W(e)}}}}),[j.products,j.collection]),n((()=>{var e,t,o,i,n,r,c,d;(null===(t=null===(e=j.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&Z(j.data.productsConf.entitledProducts),(null===(i=null===(o=j.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&Q(j.data.productsConf.prerequisiteProducts),(null===(r=null===(n=j.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&te(j.data.collectionsConf.entitledCollections),(null===(d=null===(c=j.data)||void 0===c?void 0:c.collectionsConf)||void 0===d?void 0:d.prerequisiteCollections)&&W(j.data.collectionsConf.prerequisiteCollections)}),[null===(D=j.data)||void 0===D?void 0:D.productsConf,null===(N=j.data)||void 0===N?void 0:N.collectionsConf]),n((()=>{if(j.newPickerConf){const e=[];return Object.values($).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void G(Object.assign(Object.assign({},U),{entitledProductIds:e}))}const e=$.map((e=>parseInt(e.id)));G(Object.assign(Object.assign({},U),{entitledProductIds:e}))}),[$]),n((()=>{if(j.newPickerConf){const e=[];return Object.values(K).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void G(Object.assign(Object.assign({},U),{prerequisiteProductIds:e}))}const e=K.map((e=>parseInt(e.id)));G(Object.assign(Object.assign({},U),{prerequisiteProductIds:e}))}),[K]),n((()=>{if(j.newPickerConf){(null==ee?void 0:ee.isCustom)&&delete ee.isCustom;const e=Object.keys(ee).map((e=>parseInt(e)));return void G(Object.assign(Object.assign({},U),{entitledCollectionIds:e}))}const e=ee.map((e=>parseInt(e.id)));G(Object.assign(Object.assign({},U),{entitledCollectionIds:e}))}),[ee]),n((()=>{if(j.newPickerConf){(null==J?void 0:J.isCustom)&&delete J.isCustom;const e=Object.keys(J).map((e=>parseInt(e)));return void G(Object.assign(Object.assign({},U),{prerequisiteCollectionIds:e}))}const e=J.map((e=>parseInt(e.id)));G(Object.assign(Object.assign({},U),{prerequisiteCollectionIds:e}))}),[J]);const ne=()=>{var e,t;U.isStaticCoupon||(U.targetType===c.SHIPPING_LINE?H(d.FREE_SHIPPING):U.targetType===c.LINE_ITEM?U.targetSelection===s.ENTITLED?(null===(e=U.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=U.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?H(d.BUY_X_GET_Y):H(d.AMOUNT_OFF_PRODUCTS):H(d.AMOUNT_OFF_ORDER):(G(Object.assign(Object.assign({},U),{targetType:c.LINE_ITEM,targetSelection:s.ALL,valueType:l.FIXED_AMOUNT})),H(d.AMOUNT_OFF_ORDER)))},re=[{value:d.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:X===d.AMOUNT_OFF_ORDER},{value:d.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:X===d.AMOUNT_OFF_PRODUCTS},{value:d.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:X===d.BUY_X_GET_Y},{value:d.FREE_SHIPPING,label:"Free shipping",selected:X===d.FREE_SHIPPING}],ce=()=>{if(!j.quadrant||!j.probability)return;const e=[...j.probability];let t=[];e.length>=j.quadrant&&e.splice(j.quadrant-1,1),t=e;const o=t.reduce(((e,t)=>e+t),0)+(U.probability||0);return ie(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},de=e=>{var t,o,i,n;const a=e.value;H(a),Q([]),Z([]),W([]),te([]),z(r.NA),a===d.FREE_SHIPPING?G({value:100,targetSelection:s.ALL,targetType:c.SHIPPING_LINE,valueType:l.PERCENTAGE,quadrant:U.quadrant,isStaticCoupon:!1}):a===d.BUY_X_GET_Y?G({targetSelection:s.ENTITLED,targetType:c.LINE_ITEM,valueType:l.PERCENTAGE,quadrant:U.quadrant,isStaticCoupon:!1}):a===d.AMOUNT_OFF_ORDER?G({targetSelection:s.ALL,targetType:c.LINE_ITEM,valueType:null!==(o=null===(t=j.data)||void 0===t?void 0:t.valueType)&&void 0!==o?o:l.FIXED_AMOUNT,quadrant:U.quadrant,isStaticCoupon:!1}):a===d.AMOUNT_OFF_PRODUCTS&&G({targetSelection:s.ENTITLED,targetType:c.LINE_ITEM,valueType:null!==(n=null===(i=j.data)||void 0===i?void 0:i.valueType)&&void 0!==n?n:l.FIXED_AMOUNT,quadrant:U.quadrant,isStaticCoupon:!1})};return e(v,Object.assign({width:(x||A)&&j.newPickerConf?"25px":"750px",open:j.isOpen,headingTitle:A?"Select Products":j.title,headingSubtitle:A?void 0:j.subTitle,footerLeftCustomElement:j.errorMsg?j.errorMsg&&t(h,{theme:"light",tagText:j.errorMsg,type:"negative"}):!j.quadrant||j.hideProbability?t(o,{}):oe<=1?t(h,{theme:"light",tagText:`Current probability sum: ${oe}`,type:"white"}):t(b,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:t("div",{children:t(h,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${oe}`,type:"negative",LeadingIcon:y})})})),headerRightCustomElement:j.allowStaticCoupon||A?void 0:t(a,{options:re,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{de(e)}}),onClose:j.onClose,footerShadow:!0,primaryButton:A?{buttonType:"primary",onClick:()=>{L(void 0)},buttonText:"Add"}:x?{buttonType:"primary",onClick:()=>{R(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:B,isLoading:null!==(F=j.loading)&&void 0!==F&&F,onClick:()=>{var e,t;U.isStaticCoupon?j.onSaveClicked({quadrant:U.quadrant,couponCode:U.couponCode,description:U.description,isStaticCoupon:U.isStaticCoupon,probability:U.probability,title:U.title}):j.onSaveClicked(Object.assign(Object.assign({},U),{description:f(U,j.currency,null!==(e=j.products)&&void 0!==e?e:[],null!==(t=j.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:$,prerequisiteProducts:K},collectionsConf:{entitledCollections:ee,prerequisiteCollections:J}}))}},secondaryButton:A?{buttonType:"tertiaryGray",onClick:()=>{L(void 0)},buttonText:"Back"}:x?{buttonType:"tertiaryGray",onClick:()=>{R(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:j.onClose,buttonText:"Close"}},{children:[!A&&!x&&e(T,{children:[j.allowStaticCoupon&&!A&&e(I,Object.assign({selectedDiv:U.isStaticCoupon?1:2},{children:["static"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{U.isStaticCoupon||G({isStaticCoupon:!0,quadrant:U.quadrant})}},{children:[t(u,Object.assign({style:U.isStaticCoupon?{color:C.colorsV2.content.brand}:{}},{children:"Static code"})),t(p,Object.assign({style:U.isStaticCoupon?{color:C.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{U.isStaticCoupon&&(H(d.AMOUNT_OFF_ORDER),G({isStaticCoupon:!1,quadrant:U.quadrant,targetType:c.LINE_ITEM,targetSelection:s.ALL,valueType:l.FIXED_AMOUNT}))}},{children:[t(u,Object.assign({style:U.isStaticCoupon?{}:{color:C.colorsV2.content.brand}},{children:"Dynamic code"})),t(p,Object.assign({style:U.isStaticCoupon?{}:{color:C.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),U.isStaticCoupon&&!A&&t(S,{discountData:U,setDiscountData:G,hideProbability:j.hideProbability||!1,discountAdminUrl:j.discountAdminUrl}),!U.isStaticCoupon&&!A&&!x&&t(g,{currency:j.currency,entitledProducts:$,prerequisiteProducts:K,setEntitledProducts:Z,setPrerequisiteProducts:Q,discountData:U,productPickerOpen:A,setIsProductPickerOpen:L,setDiscountData:G,selectedCouponType:X,setSelectedCouponType:H,selectedMinimumRequirement:V,setSelectedMinimumRequirement:z,hideProbability:j.hideProbability||!1,hideExpiration:j.hideExpiration||!1,allowStaticCoupon:j.allowStaticCoupon,onChangeCouponType:de,collectionPickerOpen:x,entitledCollections:ee,prerequisiteCollections:J,setIsCollectionPickerOpen:R,setEntitledCollections:te,setPrerequisiteCollections:W,useNewPicker:!!j.newPickerConf})]}),!!A&&e(o,{children:[!j.newPickerConf&&t("div",Object.assign({style:{padding:"12px 0"}},{children:t(m,{show:!0,onSave:()=>{},products:null!==(q=j.products)&&void 0!==q?q:[],title:"Select Products",onClose:()=>{L(void 0)},selectedProducts:A===E.ENTITLED?$:K,setSelectedProducts:A===E.ENTITLED?Z:Q,onSearchKeyChange:j.onProductSearch})})),j.newPickerConf&&t(P,{visible:!0,onClose:()=>L(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:A===E.ENTITLED?$:K,onAdd:e=>{A===E.ENTITLED?Z(e):Q(e),L(void 0)},zIndex:200,storeId:j.newPickerConf.storeId,searchInCollectionFetcher:j.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:j.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!x&&t("div",Object.assign({style:{padding:"12px 0"}},{children:e(o,{children:[j.newPickerConf&&t(P,{visible:!0,onClose:()=>R(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:x===E.ENTITLED?ee:J,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),x===E.ENTITLED?te(e):W(e),R(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:j.newPickerConf.storeId,searchInCollectionFetcher:j.newPickerConf.searchInCollection,searchFetcher:j.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!j.newPickerConf&&t(m,{show:!0,onSave:()=>{},products:null!==(M=j.collection)&&void 0!==M?M:[],title:"Select Products",onClose:()=>{R(void 0)},selectedProducts:x===E.ENTITLED?ee:J,setSelectedProducts:x===E.ENTITLED?te:W,onSearchKeyChange:j.onCollectionSearch,searchPlaceholder:"Search collections..."})]})}))]}))};export{j as DiscountModal};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.370",
3
+ "version": "0.0.371",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",