@bikdotai/bik-component-library 0.0.441-beta.1 → 0.0.442-beta.1

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