@bikdotai/bik-component-library 0.0.115687-beta.1 → 0.0.115687-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/discount-modal/CouponExpiration/CouponExpiration.js +1 -1
- package/dist/cjs/components/discount-modal/DiscountModal.js +1 -1
- package/dist/cjs/components/shimmer-image/ShimmerImage.d.ts +1 -1
- package/dist/cjs/components/template-context-mapper/modalElements/VariableConnector.js +1 -1
- package/dist/cjs/components/template-preview/WhatsApp/MediaCard.js +1 -1
- package/dist/esm/components/discount-modal/CouponExpiration/CouponExpiration.js +1 -1
- package/dist/esm/components/discount-modal/DiscountModal.js +1 -1
- package/dist/esm/components/shimmer-image/ShimmerImage.d.ts +1 -1
- package/dist/esm/components/template-context-mapper/modalElements/VariableConnector.js +1 -1
- package/dist/esm/components/template-preview/WhatsApp/MediaCard.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),i=require("date-fns"),a=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react/jsx-runtime"),i=require("date-fns"),a=require("react"),s=require("../../custom-date-time/CustomDateTime.js"),r=require("../../input/Input.js"),o=require("../../radioButton/RadioButton.js"),n=require("../../TypographyStyle.js");exports.COUPON_EXPIRATION=void 0,(e=exports.COUPON_EXPIRATION||(exports.COUPON_EXPIRATION={})).FIXED_EXPIRATION="fixedExpiration",e.DYNAMIC_EXPIRATION="dynamicExpiration";exports.CouponExpiration=e=>{var I;const[O,d]=a.useState(e.discountData.expireAt?exports.COUPON_EXPIRATION.FIXED_EXPIRATION:e.discountData.expireAfter?exports.COUPON_EXPIRATION.DYNAMIC_EXPIRATION:void 0),[p,x]=a.useState(),[u,c]=a.useState(),A=(new Date).setDate((new Date).getDate()+1);a.useEffect((()=>{(null==O||p||u)&&e.setDiscountData(Object.assign(Object.assign({},e.discountData),{expireAfter:void 0,expireAt:void 0})),O&&(p||u)&&(O===exports.COUPON_EXPIRATION.FIXED_EXPIRATION?c(void 0):x(void 0))}),[O,p,u]);return t.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:13}},{children:[t.jsx(n.TitleRegular,{children:"Coupon expiration (optional)"}),t.jsxs("div",Object.assign({style:{display:"flex",gap:18}},{children:[t.jsx(o.RadioButton,{isActive:O===exports.COUPON_EXPIRATION.DYNAMIC_EXPIRATION,onValueChange:()=>{c(void 0),d(O===exports.COUPON_EXPIRATION.DYNAMIC_EXPIRATION?void 0:exports.COUPON_EXPIRATION.DYNAMIC_EXPIRATION)}}),t.jsx(n.BodySecondary,{children:"Validity days from coupon claim"})]})),O===exports.COUPON_EXPIRATION.DYNAMIC_EXPIRATION&&t.jsx(r.Input,{errorMessage:u,value:null===(I=e.discountData.expireAfter)||void 0===I?void 0:I.toString(),placeholder:"Enter the number of days",width:"400px",type:"number",onChangeText:t=>{(t=>{c(void 0);const i=Number.parseInt(t);i>0?e.setDiscountData(Object.assign(Object.assign({},e.discountData),{expireAfter:i,expireAt:void 0})):c("Please enter valid input")})(t)}}),t.jsxs("div",Object.assign({style:{display:"flex",gap:18}},{children:[t.jsx(o.RadioButton,{isActive:O===exports.COUPON_EXPIRATION.FIXED_EXPIRATION,onValueChange:()=>{d(O===exports.COUPON_EXPIRATION.FIXED_EXPIRATION?void 0:exports.COUPON_EXPIRATION.FIXED_EXPIRATION)}}),t.jsx(n.BodySecondary,{children:"Fixed expiry date"})]})),O===exports.COUPON_EXPIRATION.FIXED_EXPIRATION&&t.jsxs(t.Fragment,{children:[t.jsx(n.BodySecondary,{children:"Ending on"}),t.jsx(s.CustomDateTime,{placement:"bottom-start",time:e.discountData.expireAt?i.format(new Date(e.discountData.expireAt),"hh:mm a"):i.format(new Date(A),"hh:mm a"),date:e.discountData.expireAt?new Date(e.discountData.expireAt):new Date(A),error:p,setError:x,onChange:t=>{e.setDiscountData(Object.assign(Object.assign({},e.discountData),{expireAt:t,expireAfter:void 0}))},minDate:new Date(A)})]})]}))};
|
|
@@ -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"),d=require("../product-picker/ProductPickerModal.js"),c=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"),T=require("./DiscountUtils.js"),C=require("./DynamicCoupon/DynamicCoupon.js"),S=require("./StaticCoupon/StaticCoupon.js");exports.DiscountModal=E=>{var v,I,O,P,_,D,N,h,b,y;const[U,j]=t.useState(),[f,g]=t.useState(),[m,A]=t.useState(null!==(v=E.data)&&void 0!==v?v:"string"==typeof E.hideOption?{isStaticCoupon:"dynamic"===E.hideOption}:{isStaticCoupon:!1}),[q,x]=t.useState(!0),[R,k]=t.useState(),[w,F]=t.useState((null===(I=E.data)||void 0===I?void 0:I.minAmount)?o.MIN_PURCHASE_REQUIREMENT.AMOUNT:(null===(O=E.data)||void 0===O?void 0:O.minQuantity)?o.MIN_PURCHASE_REQUIREMENT.QUANTITY:o.MIN_PURCHASE_REQUIREMENT.NA),[M,L]=t.useState(void 0),[Y,G]=t.useState(void 0),[B,H]=t.useState(void 0),[V,X]=t.useState(void 0),[Q,z]=t.useState(0);t.useEffect((()=>{let e;const{tempCouponData:t,discountType:o}=K();k(o),A(Object.assign({},t)),E.hideProbability||(e=Z()),x(T.validateDiscountData(t,w,o,E.hideProbability||!1,e,!!t.isStaticCoupon)),E.hideProbability||Z()}),[]),t.useEffect((()=>{let e;E.hideProbability||(e=Z()),x(T.validateDiscountData(m,w,R,E.hideProbability||!1,e,!!m.isStaticCoupon))}),[m,Q,R,w]),t.useEffect((()=>{var e,t,o,i,n,r,s;if(!E.newPickerConf&&((null===(e=E.products)||void 0===e?void 0:e.length)||(null===(t=E.collection)||void 0===t?void 0:t.length))){if(E.products&&(null===(o=E.products)||void 0===o?void 0:o.length)){if(null===(i=E.data)||void 0===i?void 0:i.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))}));G(e)}if(null===(n=E.data)||void 0===n?void 0:n.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))}));L(e)}}if(E.collection&&E.collection.length){if(null===(r=E.data)||void 0===r?void 0:r.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))}));X(e)}if(null===(s=E.data)||void 0===s?void 0:s.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))}));H(e)}}}}),[E.products,E.collection]),t.useEffect((()=>{var e,t,o,i,n,r,s,d;(null===(t=null===(e=E.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&G(E.data.productsConf.entitledProducts),(null===(i=null===(o=E.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&L(E.data.productsConf.prerequisiteProducts),(null===(r=null===(n=E.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&X(E.data.collectionsConf.entitledCollections),(null===(d=null===(s=E.data)||void 0===s?void 0:s.collectionsConf)||void 0===d?void 0:d.prerequisiteCollections)&&H(E.data.collectionsConf.prerequisiteCollections)}),[null===(P=E.data)||void 0===P?void 0:P.productsConf,null===(_=E.data)||void 0===_?void 0:_.collectionsConf]),t.useEffect((()=>{if(!Y)return;if(E.newPickerConf){const e=[];return Object.values(Y).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void A(Object.assign(Object.assign({},m),{entitledProductIds:e}))}const e=Y.map((e=>parseInt(e.id)));A(Object.assign(Object.assign({},m),{entitledProductIds:e}))}),[Y]),t.useEffect((()=>{if(!M)return;if(E.newPickerConf){const e=[];return Object.values(M).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void A(Object.assign(Object.assign({},m),{prerequisiteProductIds:e}))}const e=M.map((e=>parseInt(e.id)));A(Object.assign(Object.assign({},m),{prerequisiteProductIds:e}))}),[M]),t.useEffect((()=>{if(!V)return;if(E.newPickerConf){(null==V?void 0:V.isCustom)&&delete V.isCustom;const e=Object.keys(V).map((e=>parseInt(e)));return void A(Object.assign(Object.assign({},m),{entitledCollectionIds:e}))}const e=V.map((e=>parseInt(e.id)));A(Object.assign(Object.assign({},m),{entitledCollectionIds:e}))}),[V]),t.useEffect((()=>{if(!B)return;if(E.newPickerConf){(null==B?void 0:B.isCustom)&&delete B.isCustom;const e=Object.keys(B).map((e=>parseInt(e)));return void A(Object.assign(Object.assign({},m),{prerequisiteCollectionIds:e}))}const e=B.map((e=>parseInt(e.id)));A(Object.assign(Object.assign({},m),{prerequisiteCollectionIds:e}))}),[B]);const K=()=>{var e,t;let i,n=m;return m.isStaticCoupon||(m.targetType===o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE?i=o.DISCOUNT_TYPES.FREE_SHIPPING:m.targetType===o.DISCOUNT_TARGET_TYPES.LINE_ITEM?i=m.targetSelection===o.DISCOUNT_TARGET_SELECTION.ENTITLED?(null===(e=m.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=m.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?o.DISCOUNT_TYPES.BUY_X_GET_Y:o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS:o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER:(n=Object.assign(Object.assign({},n),{targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,valueType:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT}),i=o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER)),{discountType:i,tempCouponData:n}},$=[{value:o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:R===o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER},{value:o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:R===o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS},{value:o.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:R===o.DISCOUNT_TYPES.BUY_X_GET_Y},{value:o.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:R===o.DISCOUNT_TYPES.FREE_SHIPPING}],Z=()=>{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)+(m.probability||0);return z(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},J=e=>{var t,i,n,r;const s=e.value;k(s),L([]),G([]),H([]),X([]),F(o.MIN_PURCHASE_REQUIREMENT.NA),s===o.DISCOUNT_TYPES.FREE_SHIPPING?A({value:100,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:m.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0}):s===o.DISCOUNT_TYPES.BUY_X_GET_Y?A({targetSelection:o.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:m.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0}):s===o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER?A({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:m.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0}):s===o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS&&A({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:m.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0})};return e.jsxs(s.StyledModal,Object.assign({width:(f||U)&&E.newPickerConf?"25px":"750px",open:E.isOpen,headingTitle:U?"Select Products":E.title,headingSubtitle:U?void 0:E.subTitle,footerLeftCustomElement:E.errorMsg?E.errorMsg&&e.jsx(c.Tag,{theme:"light",tagText:E.errorMsg,type:"negative"}):!E.quadrant||E.hideProbability?e.jsx(e.Fragment,{}):Q<=1?e.jsx(c.Tag,{theme:"light",tagText:`Current probability sum: ${Q}`,type:"white"}):e.jsx(l.Tooltip,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e.jsx("div",{children:e.jsx(c.Tag,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${Q}`,type:"negative",LeadingIcon:a.default})})})),headerRightCustomElement:E.allowStaticCoupon||U?void 0:e.jsx(i.Dropdown,{options:$,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{J(e)}}),onClose:E.onClose,footerShadow:!0,primaryButton:U?{buttonType:"primary",onClick:()=>{j(void 0)},buttonText:"Add"}:f?{buttonType:"primary",onClick:()=>{g(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:q,isLoading:null!==(D=E.loading)&&void 0!==D&&D,onClick:()=>{var e,t;m.isStaticCoupon?E.onSaveClicked({quadrant:m.quadrant,couponCode:m.couponCode,description:m.description,isStaticCoupon:m.isStaticCoupon,probability:m.probability,title:m.title}):E.onSaveClicked(Object.assign(Object.assign({},m),{description:T.descriptionBuilder(m,E.currency,null!==(e=E.products)&&void 0!==e?e:[],null!==(t=E.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:Y,prerequisiteProducts:M},collectionsConf:{entitledCollections:V,prerequisiteCollections:B}}))}},secondaryButton:U?{buttonType:"tertiaryGray",onClick:()=>{j(void 0)},buttonText:"Back"}:f?{buttonType:"tertiaryGray",onClick:()=>{g(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:E.onClose,buttonText:"Close"}},{children:[!U&&!f&&e.jsxs(p.StyledDiscountDialogueContainer,{children:[E.allowStaticCoupon&&!U&&e.jsxs(p.CouponTypeContainerStyled,Object.assign({selectedDiv:m.isStaticCoupon?1:2},{children:["static"===E.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{m.isStaticCoupon||A({isStaticCoupon:!0,quadrant:m.quadrant})}},{children:[e.jsx(n.TitleSmall,Object.assign({style:m.isStaticCoupon?{color:r.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"Static code"})),e.jsx(n.BodyCaption,Object.assign({style:m.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:()=>{m.isStaticCoupon&&(k(o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER),A({isStaticCoupon:!1,quadrant:m.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:m.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"Dynamic code"})),e.jsx(n.BodyCaption,Object.assign({style:m.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),m.isStaticCoupon&&!U&&e.jsx(S.default,{discountData:m,setDiscountData:A,hideProbability:E.hideProbability||!1,discountAdminUrl:E.discountAdminUrl}),!m.isStaticCoupon&&!U&&!f&&e.jsx(C.default,{currency:E.currency,entitledProducts:null!=Y?Y:[],prerequisiteProducts:null!=M?M:[],setEntitledProducts:G,setPrerequisiteProducts:L,discountData:m,productPickerOpen:U,setIsProductPickerOpen:j,setDiscountData:A,selectedCouponType:R,setSelectedCouponType:k,selectedMinimumRequirement:w,setSelectedMinimumRequirement:F,hideProbability:E.hideProbability||!1,hideExpiration:E.hideExpiration||!1,allowStaticCoupon:E.allowStaticCoupon,onChangeCouponType:J,collectionPickerOpen:f,entitledCollections:null!=V?V:[],prerequisiteCollections:null!=B?B:[],setIsCollectionPickerOpen:g,setEntitledCollections:X,setPrerequisiteCollections:H,useNewPicker:!!E.newPickerConf})]}),!!U&&e.jsxs(e.Fragment,{children:[!E.newPickerConf&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsx(d.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(N=E.products)&&void 0!==N?N:[],title:"Select Products",onClose:()=>{j(void 0)},selectedProducts:null!==(h=U===C.DISCOUNT_PRODUCTS.ENTITLED?Y:M)&&void 0!==h?h:[],setSelectedProducts:U===C.DISCOUNT_PRODUCTS.ENTITLED?G:L,onSearchKeyChange:E.onProductSearch})})),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?Y:M,onAdd:e=>{U===C.DISCOUNT_PRODUCTS.ENTITLED?G(e):L(e),j(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})]}),!!f&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsxs(e.Fragment,{children:[E.newPickerConf&&e.jsx(u.ProductPickerModal,{visible:!0,onClose:()=>g(void 0),collectionFetcher:E.newPickerConf.fetchCollections,productFetcher:E.newPickerConf.fetchProducts,selectedItems:f===C.DISCOUNT_PRODUCTS.ENTITLED?V:B,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),f===C.DISCOUNT_PRODUCTS.ENTITLED?X(e):H(e),g(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(d.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(b=E.collection)&&void 0!==b?b:[],title:"Select Products",onClose:()=>{g(void 0)},selectedProducts:null!==(y=f===C.DISCOUNT_PRODUCTS.ENTITLED?V:B)&&void 0!==y?y:[],setSelectedProducts:f===C.DISCOUNT_PRODUCTS.ENTITLED?X:H,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"),d=require("../product-picker/ProductPickerModal.js"),c=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"),T=require("./DiscountUtils.js"),C=require("./DynamicCoupon/DynamicCoupon.js"),S=require("./StaticCoupon/StaticCoupon.js");exports.DiscountModal=E=>{var I,O,P,v,_,D,N,h,b,y;const[U,j]=t.useState(),[g,f]=t.useState(),[m,q]=t.useState(null!==(I=E.data)&&void 0!==I?I:"string"==typeof E.hideOption?{isStaticCoupon:"dynamic"===E.hideOption}:{isStaticCoupon:!1}),[A,R]=t.useState(!0),[x,k]=t.useState(),[w,F]=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),[M,L]=t.useState(void 0),[Y,G]=t.useState(void 0),[B,H]=t.useState(void 0),[V,X]=t.useState(void 0),[Q,z]=t.useState(0);t.useEffect((()=>{let e;const{tempCouponData:t,discountType:o}=K();k(o),q(Object.assign({},t)),E.hideProbability||(e=Z()),R(T.validateDiscountData(t,w,o,E.hideProbability||!1,e,!!t.isStaticCoupon)),E.hideProbability||Z()}),[]),t.useEffect((()=>{let e;E.hideProbability||(e=Z()),R(T.validateDiscountData(m,w,x,E.hideProbability||!1,e,!!m.isStaticCoupon))}),[m,Q,x,w]),t.useEffect((()=>{var e,t,o,i,n,r,s;if(!E.newPickerConf&&((null===(e=E.products)||void 0===e?void 0:e.length)||(null===(t=E.collection)||void 0===t?void 0:t.length))){if(E.products&&(null===(o=E.products)||void 0===o?void 0:o.length)){if(null===(i=E.data)||void 0===i?void 0:i.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))}));G(e)}if(null===(n=E.data)||void 0===n?void 0:n.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))}));L(e)}}if(E.collection&&E.collection.length){if(null===(r=E.data)||void 0===r?void 0:r.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))}));X(e)}if(null===(s=E.data)||void 0===s?void 0:s.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))}));H(e)}}}}),[E.products,E.collection]),t.useEffect((()=>{var e,t,o,i,n,r,s,d;(null===(t=null===(e=E.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&G(E.data.productsConf.entitledProducts),(null===(i=null===(o=E.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&L(E.data.productsConf.prerequisiteProducts),(null===(r=null===(n=E.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&X(E.data.collectionsConf.entitledCollections),(null===(d=null===(s=E.data)||void 0===s?void 0:s.collectionsConf)||void 0===d?void 0:d.prerequisiteCollections)&&H(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(!Y)return;if(E.newPickerConf){const e=[];return Object.values(Y).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void q(Object.assign(Object.assign({},m),{entitledProductIds:e}))}const e=Y.map((e=>parseInt(e.id)));q(Object.assign(Object.assign({},m),{entitledProductIds:e}))}),[Y]),t.useEffect((()=>{if(!M)return;if(E.newPickerConf){const e=[];return Object.values(M).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void q(Object.assign(Object.assign({},m),{prerequisiteProductIds:e}))}const e=M.map((e=>parseInt(e.id)));q(Object.assign(Object.assign({},m),{prerequisiteProductIds:e}))}),[M]),t.useEffect((()=>{if(!V)return;if(E.newPickerConf){(null==V?void 0:V.isCustom)&&delete V.isCustom;const e=Object.keys(V).map((e=>parseInt(e)));return void q(Object.assign(Object.assign({},m),{entitledCollectionIds:e}))}const e=V.map((e=>parseInt(e.id)));q(Object.assign(Object.assign({},m),{entitledCollectionIds:e}))}),[V]),t.useEffect((()=>{if(!B)return;if(E.newPickerConf){(null==B?void 0:B.isCustom)&&delete B.isCustom;const e=Object.keys(B).map((e=>parseInt(e)));return void q(Object.assign(Object.assign({},m),{prerequisiteCollectionIds:e}))}const e=B.map((e=>parseInt(e.id)));q(Object.assign(Object.assign({},m),{prerequisiteCollectionIds:e}))}),[B]);const K=()=>{var e,t;let i,n=m;return m.isStaticCoupon||(m.targetType===o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE?i=o.DISCOUNT_TYPES.FREE_SHIPPING:m.targetType===o.DISCOUNT_TARGET_TYPES.LINE_ITEM?i=m.targetSelection===o.DISCOUNT_TARGET_SELECTION.ENTITLED?(null===(e=m.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=m.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?o.DISCOUNT_TYPES.BUY_X_GET_Y:o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS:o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER:(n=Object.assign(Object.assign({},n),{targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,valueType:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT}),i=o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER)),{discountType:i,tempCouponData:n}},$=[{value:o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:x===o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER},{value:o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:x===o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS},{value:o.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:x===o.DISCOUNT_TYPES.BUY_X_GET_Y},{value:o.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:x===o.DISCOUNT_TYPES.FREE_SHIPPING}],Z=()=>{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)+(m.probability||0);return z(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},J=e=>{var t,i,n,r;const s=e.value;k(s),L([]),G([]),H([]),X([]),F(o.MIN_PURCHASE_REQUIREMENT.NA),s===o.DISCOUNT_TYPES.FREE_SHIPPING?q({value:100,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:m.quadrant,isStaticCoupon:!1,title:""}):s===o.DISCOUNT_TYPES.BUY_X_GET_Y?q({targetSelection:o.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,quadrant:m.quadrant,isStaticCoupon:!1,title:""}):s===o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER?q({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:m.quadrant,isStaticCoupon:!1,title:""}):s===o.DISCOUNT_TYPES.AMOUNT_OFF_PRODUCTS&&q({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:m.quadrant,isStaticCoupon:!1,title:""})};return e.jsxs(s.StyledModal,Object.assign({width:(g||U)&&E.newPickerConf?"25px":"750px",open:E.isOpen,headingTitle:U?"Select Products":E.title,headingSubtitle:U?void 0:E.subTitle,footerLeftCustomElement:E.errorMsg?E.errorMsg&&e.jsx(c.Tag,{theme:"light",tagText:E.errorMsg,type:"negative"}):!E.quadrant||E.hideProbability?e.jsx(e.Fragment,{}):Q<=1?e.jsx(c.Tag,{theme:"light",tagText:`Current probability sum: ${Q}`,type:"white"}):e.jsx(l.Tooltip,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e.jsx("div",{children:e.jsx(c.Tag,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${Q}`,type:"negative",LeadingIcon:a.default})})})),headerRightCustomElement:E.allowStaticCoupon||U?void 0:e.jsx(i.Dropdown,{options:$,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{J(e)}}),onClose:E.onClose,footerShadow:!0,primaryButton:U?{buttonType:"primary",onClick:()=>{j(void 0)},buttonText:"Add"}:g?{buttonType:"primary",onClick:()=>{f(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:A,isLoading:null!==(D=E.loading)&&void 0!==D&&D,onClick:()=>{var e,t;m.isStaticCoupon?E.onSaveClicked({quadrant:m.quadrant,couponCode:m.couponCode,description:m.description,isStaticCoupon:m.isStaticCoupon,probability:m.probability,title:m.title}):E.onSaveClicked(Object.assign(Object.assign({},m),{description:T.descriptionBuilder(m,E.currency,null!==(e=E.products)&&void 0!==e?e:[],null!==(t=E.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:Y,prerequisiteProducts:M},collectionsConf:{entitledCollections:V,prerequisiteCollections:B}}))}},secondaryButton:U?{buttonType:"tertiaryGray",onClick:()=>{j(void 0)},buttonText:"Back"}:g?{buttonType:"tertiaryGray",onClick:()=>{f(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:E.onClose,buttonText:"Close"}},{children:[!U&&!g&&e.jsxs(p.StyledDiscountDialogueContainer,{children:[E.allowStaticCoupon&&!U&&e.jsxs(p.CouponTypeContainerStyled,Object.assign({selectedDiv:m.isStaticCoupon?1:2},{children:["static"===E.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{m.isStaticCoupon||q({isStaticCoupon:!0,quadrant:m.quadrant})}},{children:[e.jsx(n.TitleSmall,Object.assign({style:m.isStaticCoupon?{color:r.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"Static code"})),e.jsx(n.BodyCaption,Object.assign({style:m.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:()=>{m.isStaticCoupon&&(k(o.DISCOUNT_TYPES.AMOUNT_OFF_ORDER),q({isStaticCoupon:!1,quadrant:m.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:m.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"Dynamic code"})),e.jsx(n.BodyCaption,Object.assign({style:m.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),m.isStaticCoupon&&!U&&e.jsx(S.default,{discountData:m,setDiscountData:q,hideProbability:E.hideProbability||!1,discountAdminUrl:E.discountAdminUrl}),!m.isStaticCoupon&&!U&&!g&&e.jsx(C.default,{currency:E.currency,entitledProducts:null!=Y?Y:[],prerequisiteProducts:null!=M?M:[],setEntitledProducts:G,setPrerequisiteProducts:L,discountData:m,productPickerOpen:U,setIsProductPickerOpen:j,setDiscountData:q,selectedCouponType:x,setSelectedCouponType:k,selectedMinimumRequirement:w,setSelectedMinimumRequirement:F,hideProbability:E.hideProbability||!1,hideExpiration:E.hideExpiration||!1,allowStaticCoupon:E.allowStaticCoupon,onChangeCouponType:J,collectionPickerOpen:g,entitledCollections:null!=V?V:[],prerequisiteCollections:null!=B?B:[],setIsCollectionPickerOpen:f,setEntitledCollections:X,setPrerequisiteCollections:H,useNewPicker:!!E.newPickerConf})]}),!!U&&e.jsxs(e.Fragment,{children:[!E.newPickerConf&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsx(d.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(N=E.products)&&void 0!==N?N:[],title:"Select Products",onClose:()=>{j(void 0)},selectedProducts:null!==(h=U===C.DISCOUNT_PRODUCTS.ENTITLED?Y:M)&&void 0!==h?h:[],setSelectedProducts:U===C.DISCOUNT_PRODUCTS.ENTITLED?G:L,onSearchKeyChange:E.onProductSearch})})),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?Y:M,onAdd:e=>{U===C.DISCOUNT_PRODUCTS.ENTITLED?G(e):L(e),j(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})]}),!!g&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsxs(e.Fragment,{children:[E.newPickerConf&&e.jsx(u.ProductPickerModal,{visible:!0,onClose:()=>f(void 0),collectionFetcher:E.newPickerConf.fetchCollections,productFetcher:E.newPickerConf.fetchProducts,selectedItems:g===C.DISCOUNT_PRODUCTS.ENTITLED?V:B,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),g===C.DISCOUNT_PRODUCTS.ENTITLED?X(e):H(e),f(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(d.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(b=E.collection)&&void 0!==b?b:[],title:"Select Products",onClose:()=>{f(void 0)},selectedProducts:null!==(y=g===C.DISCOUNT_PRODUCTS.ENTITLED?V:B)&&void 0!==y?y:[],setSelectedProducts:g===C.DISCOUNT_PRODUCTS.ENTITLED?X:H,onSearchKeyChange:E.onCollectionSearch,searchPlaceholder:"Search collections..."})]})}))]}))};
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
background: ${e=>e.focused&&e.channel===d.CHANNEL_TYPE.EMAIL?v.COLORS.background.warning.light:"transparent"};
|
|
5
5
|
border-radius: 4px;
|
|
6
6
|
padding: 8px 10px;
|
|
7
|
-
`,x={value:"custom_link",label:"Custom URL"},j={value:"custom_text",label:"Custom text"};exports.Container=h,exports.default=a=>{let{onFocus:g,variable:E,index:O,showVariableModal:_,variableList:T,setShowDiscountCheckBox:y,componentType:A,CTAoptions:f}=a;var N,P;const[C,S]=l.useState(!1),[V,k]=l.useState(""),[L,H]=l.useState([]),[w,B]=l.useState(),[Y,q]=l.useState(!1),[M,R]=l.useState(!1),{device:W,channel:D,isError:I,originalVariableList:$,template:U,templateSelectionTriggered:z,setTemplate:Z,setDisplayContent:F,setOriginalVariableList:G,globalNormalizedPlaceholders:J,enabledCustomText:K,pod:Q}=m.useTemplateModalContext();function X(e,t){var l,a,n;const i=e;k(""),B(i),D===d.CHANNEL_TYPE.WHATSAPP?"custom_text"!==i.value&&"custom_link"!==i.value?(ee(null!==(l=i.value)&&void 0!==l?l:"","string"),null==te||te(null!==(a=E.index)&&void 0!==a?a:0,i.value,!0)):(null==te||te(null!==(n=E.index)&&void 0!==n?n:0,E.variableName,!0,"custom_text"),ee("","url"===i.bikPlaceholderType?"link":"string")):"custom_text"!==i.value&&"custom_link"!==i.value?ee(i.value,"url"===i.bikPlaceholderType?"link":"string"):(k(""),ee("",i.value))}function ee(e,t){var l,a,n,i;const o="custom_link"===t?"link":"custom_text"===t?"string":t;if(D!==d.CHANNEL_TYPE.WHATSAPP){const a=b.getVariableNameForEmailByIndex(O+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===W?"template_html_mobile":"template_html_desktop"),i=D===d.CHANNEL_TYPE.EMAIL?null===(l=null==n?void 0:n.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);i&&(i.textContent="custom_text"!==t&&"custom_link"!==t||e?e:E.variableName);const s=$.map(((t,l)=>l===O?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==G||G(s)}if(D===d.CHANNEL_TYPE.WHATSAPP){const l=$;let s=l.body,u=l.header,d=l.buttons;"BODY"===A?s=null===(a=l.body)||void 0===a?void 0:a.map(((t,l)=>l===O?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"HEADER"===A?u=null===(n=l.header)||void 0===n?void 0:n.map(((t,l)=>l===O?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"BUTTONS"===A&&(d=null===(i=l.buttons)||void 0===i?void 0:i.map(((l,a)=>a===O?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:[e]}):l))),null==G||G((e=>Object.assign(Object.assign({},e),{header:u,body:s,buttons:d})))}}function te(e,t,l,a){var n,i,o,s;const u=Object.assign({},U),d=null===(n=null==u?void 0:u.components)||void 0===n?void 0:n.map((l=>{var a,n,i,o,s,u,d,r,c,p;const v=Object.assign({},l);if("BODY"===l.type&&"BODY"===A){if(null===(n=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===n?void 0:n[0]){const l=[...null!==(s=null===(o=null===(i=v.example)||void 0===i?void 0:i.body_text)||void 0===o?void 0:o[0])&&void 0!==s?s:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},v.example),{body_text:[l]});return Object.assign(Object.assign({},v),{example:a})}}else if("HEADER"===l.type&&"HEADER"===A){if(null===(u=l.example)||void 0===u?void 0:u.header_text){const l=[...null!==(r=null===(d=v.example)||void 0===d?void 0:d.header_text)&&void 0!==r?r:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},v.example),{header_text:l});return Object.assign(Object.assign({},v),{example:a})}}else if("BUTTONS"===l.type&&"BUTTONS"===A&&(null===(p=null===(c=l.buttons)||void 0===c?void 0:c[e])||void 0===p?void 0:p.example)){const a=l.buttons.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:[t]}):l));return Object.assign(Object.assign({},v),{buttons:a})}return l}));u.components=d,l&&("BODY"===A&&(null===(i=null==u?void 0:u.mapping)||void 0===i?void 0:i.body)?u.mapping=Object.assign(Object.assign({},u.mapping),{body:u.mapping.body.map(((l,n)=>e===n?"custom_text"===a?`((editableVariable${n+10}))`:t:l))}):"HEADER"===A&&(null===(o=null==u?void 0:u.mapping)||void 0===o?void 0:o.header)?u.mapping=Object.assign(Object.assign({},u.mapping),{header:u.mapping.header.map(((l,n)=>e===n?"custom_text"===a?`((editableVariable${n+20}))`:t:l))}):"BUTTONS"===A&&(null===(s=null==u?void 0:u.mapping)||void 0===s?void 0:s.buttons)&&(u.mapping=Object.assign(Object.assign({},u.mapping),{buttons:u.mapping.buttons.map(((e,l)=>0===l?"custom_link"===a?"((customPlaceholderName))":t:e))}))),null==Z||Z(Object.assign({},u))}return l.useEffect((()=>{C&&(null==g||g())}),[C]),l.useEffect((()=>{!function(){var e,t,l,a,n;const i="mobile"===W?"template_html_mobile":"template_html_desktop",o=document.getElementById(i),s=(null!==(a=null===(l=null===(t=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(n=null==o?void 0:o.contentWindow)||void 0===n?void 0:n.document.head.innerHTML);D===d.CHANNEL_TYPE.EMAIL&&(null==F||F(s))}()}),[z]),l.useEffect((()=>{var e;const t=[];let l=[];if(D!==d.CHANNEL_TYPE.MESSAGE||K){"link"===(null==E?void 0:E.type)?(t.push({label:"",options:[x,j]}),B(x)):(t.push({label:"",options:[x,j]}),B(j));const e=null!=J?J:[];H([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:p.default.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}else{const e=null!=J?J:[];H([{label:"",options:[j,x]},...e]),l=[{label:"",options:[j,x]},...e]}if((D===d.CHANNEL_TYPE.WHATSAPP||D===d.CHANNEL_TYPE.EMAIL||D===d.CHANNEL_TYPE.MESSAGE)&&E.updatedValue)if(u.placeHolderNamePattern.test(E.updatedValue)&&D===d.CHANNEL_TYPE.WHATSAPP||E.updatedValue.startsWith("{{")&&D!==d.CHANNEL_TYPE.WHATSAPP){const e=function(e,t,l){var a;let n={label:"",value:""};const i=l===d.CHANNEL_TYPE.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(_){let t=e.updatedValue;if(Q===r.POD.CHATBOT&&"BUTTONS"===A){const l=null==f?void 0:f.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}n={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===i.trim()&&(n=e)}))}));return n}(E,l,D);e.value&&B(e)}else(null===(e=E.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(B(x),k(E.updatedValue.split("https://")[1])):(B(j),k(E.updatedValue))}),[]),l.useEffect((()=>{W&&w&&V&&setTimeout((()=>{ee("custom_link"===(null==w?void 0:w.value)&&V?V.includes("https")?V:`https://${V}`:V,w.value)}),100)}),[W]),l.useEffect((()=>{!M&&w&&E.updatedValue&&setTimeout((()=>{ee("custom_link"===(null==w?void 0:w.value)&&E.updatedValue?E.updatedValue.includes("https")?E.updatedValue:`https://${E.updatedValue}`:E.updatedValue,w.value),R(!0)}),100)}),[w]),e.jsxs(h,Object.assign({channel:D,focused:C,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(c.BodySecondary,Object.assign({style:{color:I&&!w?v.COLORS.content.negative:v.COLORS.content.primary}},{children:[null===(N=E.variableName)||void 0===N?void 0:N.replace("{{","").replace("}}","")," ","link"===(null==E?void 0:E.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:_?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==w?void 0:w.label)?"space-between":"flex-end"}},{children:[e.jsx(c.BodyPrimary,{children:s.truncate(null!==(P=null==w?void 0:w.label)&&void 0!==P?P:"",20,!0)}),e.jsx(t.default,{onClick:()=>{q(!Y)},width:24,height:24,color:v.COLORS.content.primary})]})):e.jsx(i.Dropdown,{options:L,isSearchable:!1,onSelect:X,defaultOptions:w?[Object.assign(Object.assign({},w),{selected:!0})]:[]})})),("custom_text"===(null==w?void 0:w.value)||"custom_link"===(null==w?void 0:w.value))&&e.jsx(o.Input,{labelText:"custom_text"===(null==w?void 0:w.value)?"Custom text value":"custom_link"===(null==w?void 0:w.value)?"Custom URL value":"",id:`variable-value-${null==w?void 0:w.value}-${O}`,value:V,errorMessage:I?V&&0!==V.trim().length?"custom_link"!==w.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${V.trim()}`)&&0!==V.trim().length?"custom_link"!==w.value&&V.length>30?"Length cannot be more than 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==w?void 0:w.value)?
|
|
7
|
+
`,x={value:"custom_link",label:"Custom URL"},j={value:"custom_text",label:"Custom text"};exports.Container=h,exports.default=a=>{let{onFocus:g,variable:E,index:O,showVariableModal:_,variableList:T,setShowDiscountCheckBox:y,componentType:A,CTAoptions:f}=a;var N,P;const[C,S]=l.useState(!1),[V,k]=l.useState(""),[L,H]=l.useState([]),[w,B]=l.useState(),[Y,q]=l.useState(!1),[M,R]=l.useState(!1),{device:W,channel:D,isError:I,originalVariableList:$,template:U,templateSelectionTriggered:z,setTemplate:Z,setDisplayContent:F,setOriginalVariableList:G,globalNormalizedPlaceholders:J,enabledCustomText:K,pod:Q}=m.useTemplateModalContext();function X(e,t){var l,a,n;const i=e;k(""),B(i),D===d.CHANNEL_TYPE.WHATSAPP?"custom_text"!==i.value&&"custom_link"!==i.value?(ee(null!==(l=i.value)&&void 0!==l?l:"","string"),null==te||te(null!==(a=E.index)&&void 0!==a?a:0,i.value,!0)):(null==te||te(null!==(n=E.index)&&void 0!==n?n:0,E.variableName,!0,"custom_text"),ee("","url"===i.bikPlaceholderType?"link":"string")):"custom_text"!==i.value&&"custom_link"!==i.value?ee(i.value,"url"===i.bikPlaceholderType?"link":"string"):(k(""),ee("",i.value))}function ee(e,t){var l,a,n,i;const o="custom_link"===t?"link":"custom_text"===t?"string":t;if(D!==d.CHANNEL_TYPE.WHATSAPP){const a=b.getVariableNameForEmailByIndex(O+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===W?"template_html_mobile":"template_html_desktop"),i=D===d.CHANNEL_TYPE.EMAIL?null===(l=null==n?void 0:n.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);i&&(i.textContent="custom_text"!==t&&"custom_link"!==t||e?e:E.variableName);const s=$.map(((t,l)=>l===O?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==G||G(s)}if(D===d.CHANNEL_TYPE.WHATSAPP){const l=$;let s=l.body,u=l.header,d=l.buttons;"BODY"===A?s=null===(a=l.body)||void 0===a?void 0:a.map(((t,l)=>l===O?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"HEADER"===A?u=null===(n=l.header)||void 0===n?void 0:n.map(((t,l)=>l===O?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"BUTTONS"===A&&(d=null===(i=l.buttons)||void 0===i?void 0:i.map(((l,a)=>a===O?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:[e]}):l))),null==G||G((e=>Object.assign(Object.assign({},e),{header:u,body:s,buttons:d})))}}function te(e,t,l,a){var n,i,o,s;const u=Object.assign({},U),d=null===(n=null==u?void 0:u.components)||void 0===n?void 0:n.map((l=>{var a,n,i,o,s,u,d,r,c,p;const v=Object.assign({},l);if("BODY"===l.type&&"BODY"===A){if(null===(n=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===n?void 0:n[0]){const l=[...null!==(s=null===(o=null===(i=v.example)||void 0===i?void 0:i.body_text)||void 0===o?void 0:o[0])&&void 0!==s?s:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},v.example),{body_text:[l]});return Object.assign(Object.assign({},v),{example:a})}}else if("HEADER"===l.type&&"HEADER"===A){if(null===(u=l.example)||void 0===u?void 0:u.header_text){const l=[...null!==(r=null===(d=v.example)||void 0===d?void 0:d.header_text)&&void 0!==r?r:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},v.example),{header_text:l});return Object.assign(Object.assign({},v),{example:a})}}else if("BUTTONS"===l.type&&"BUTTONS"===A&&(null===(p=null===(c=l.buttons)||void 0===c?void 0:c[e])||void 0===p?void 0:p.example)){const a=l.buttons.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:[t]}):l));return Object.assign(Object.assign({},v),{buttons:a})}return l}));u.components=d,l&&("BODY"===A&&(null===(i=null==u?void 0:u.mapping)||void 0===i?void 0:i.body)?u.mapping=Object.assign(Object.assign({},u.mapping),{body:u.mapping.body.map(((l,n)=>e===n?"custom_text"===a?`((editableVariable${n+10}))`:t:l))}):"HEADER"===A&&(null===(o=null==u?void 0:u.mapping)||void 0===o?void 0:o.header)?u.mapping=Object.assign(Object.assign({},u.mapping),{header:u.mapping.header.map(((l,n)=>e===n?"custom_text"===a?`((editableVariable${n+20}))`:t:l))}):"BUTTONS"===A&&(null===(s=null==u?void 0:u.mapping)||void 0===s?void 0:s.buttons)&&(u.mapping=Object.assign(Object.assign({},u.mapping),{buttons:u.mapping.buttons.map(((e,l)=>0===l?"custom_link"===a?"((customPlaceholderName))":t:e))}))),null==Z||Z(Object.assign({},u))}return l.useEffect((()=>{C&&(null==g||g())}),[C]),l.useEffect((()=>{!function(){var e,t,l,a,n;const i="mobile"===W?"template_html_mobile":"template_html_desktop",o=document.getElementById(i),s=(null!==(a=null===(l=null===(t=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(n=null==o?void 0:o.contentWindow)||void 0===n?void 0:n.document.head.innerHTML);D===d.CHANNEL_TYPE.EMAIL&&(null==F||F(s))}()}),[z]),l.useEffect((()=>{var e;const t=[];let l=[];if(D!==d.CHANNEL_TYPE.MESSAGE||K){"link"===(null==E?void 0:E.type)?(t.push({label:"",options:[x,j]}),B(x)):(t.push({label:"",options:[x,j]}),B(j));const e=null!=J?J:[];H([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:p.default.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}else{const e=null!=J?J:[];H([{label:"",options:[j,x]},...e]),l=[{label:"",options:[j,x]},...e]}if((D===d.CHANNEL_TYPE.WHATSAPP||D===d.CHANNEL_TYPE.EMAIL||D===d.CHANNEL_TYPE.MESSAGE)&&E.updatedValue)if(u.placeHolderNamePattern.test(E.updatedValue)&&D===d.CHANNEL_TYPE.WHATSAPP||E.updatedValue.startsWith("{{")&&D!==d.CHANNEL_TYPE.WHATSAPP){const e=function(e,t,l){var a;let n={label:"",value:""};const i=l===d.CHANNEL_TYPE.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(_){let t=e.updatedValue;if(Q===r.POD.CHATBOT&&"BUTTONS"===A){const l=null==f?void 0:f.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}n={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===i.trim()&&(n=e)}))}));return n}(E,l,D);e.value&&B(e)}else(null===(e=E.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(B(x),k(E.updatedValue.split("https://")[1])):(B(j),k(E.updatedValue))}),[]),l.useEffect((()=>{W&&w&&V&&setTimeout((()=>{ee("custom_link"===(null==w?void 0:w.value)&&V?V.includes("https")?V:`https://${V}`:V,w.value)}),100)}),[W]),l.useEffect((()=>{!M&&w&&E.updatedValue&&setTimeout((()=>{ee("custom_link"===(null==w?void 0:w.value)&&E.updatedValue?E.updatedValue.includes("https")?E.updatedValue:`https://${E.updatedValue}`:E.updatedValue,w.value),R(!0)}),100)}),[w]),e.jsxs(h,Object.assign({channel:D,focused:C,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(c.BodySecondary,Object.assign({style:{color:I&&!w?v.COLORS.content.negative:v.COLORS.content.primary}},{children:[null===(N=E.variableName)||void 0===N?void 0:N.replace("{{","").replace("}}","")," ","link"===(null==E?void 0:E.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:_?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==w?void 0:w.label)?"space-between":"flex-end"}},{children:[e.jsx(c.BodyPrimary,{children:s.truncate(null!==(P=null==w?void 0:w.label)&&void 0!==P?P:"",20,!0)}),e.jsx(t.default,{onClick:()=>{q(!Y)},width:24,height:24,color:v.COLORS.content.primary})]})):e.jsx(i.Dropdown,{options:L,isSearchable:!1,onSelect:X,defaultOptions:w?[Object.assign(Object.assign({},w),{selected:!0})]:[]})})),("custom_text"===(null==w?void 0:w.value)||"custom_link"===(null==w?void 0:w.value))&&e.jsx(o.Input,{labelText:"custom_text"===(null==w?void 0:w.value)?"Custom text value":"custom_link"===(null==w?void 0:w.value)?"Custom URL value":"",id:`variable-value-${null==w?void 0:w.value}-${O}`,value:V,errorMessage:I?V&&0!==V.trim().length?"custom_link"!==w.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${V.trim()}`)&&0!==V.trim().length?"custom_link"!==w.value&&V.length>30?"Length cannot be more than 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==w?void 0:w.value)?2e3:30,prefixText:"custom_link"===(null==w?void 0:w.value)?"https://":"",placeholder:"link"===E.type||"custom_link"===w.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{!function(e,t){var l;k(t);const a="custom_link"===(null==w?void 0:w.value)&&t?t.includes("https")?t:`https://${t}`:t;ee(a,e),D===d.CHANNEL_TYPE.WHATSAPP&&(null==te||te(null!==(l=E.index)&&void 0!==l?l:0,a,"custom_link"===e,e))}(w.value,e)}}),Y&&e.jsx(n.AddVariableV2SideModal,{zIndex:2e3,data:null!=T?T:[],showVariable:Y,setShowVariable:q,placeholder:"Add a variable",customTrigger:e=>{null==y||y(!1),"{{custom.url}}"===e.actualValue?X({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?X({label:e.displayName,selected:!0,value:"custom_text"}):X({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../assets/icons/filePdf.svg.js"),r=require("../../../assets/icons/image.svg.js"),i=require("../../../assets/icons/videoRecorder.svg.js"),t=require("../../TypographyStyle.js"),a=require("../../../constants/Theme.js"),d=require("../models/TemplateMeta.js"),n=require("./ChatUI.style.js"),o=require("../../shimmer-image/ShimmerImage.js");const c=o=>{let{headerAssetName:c,mediaType:l}=o;const m=l===d.HEADER_TYPES.IMAGE?r.default:l===d.HEADER_TYPES.VIDEO?i.default:s.default;return e.jsxs(n.MediaContainer,{children:[e.jsx(m,{height:40,width:40,color:a.COLORS.icon.placeholder}),!!c&&e.jsx(t.BodySecondary,Object.assign({style:{color:a.COLORS.content.secondary,marginTop:8}},{children:c}))]})};exports.MediaCard=s=>{let{headerAssetLink:r,headerAssetName:i,mediaType:t,imagePreviewStyles:a}=s;if(!r||t===d.HEADER_TYPES.DOCUMENT)return e.jsx(c,Object.assign({},{headerAssetLink:r,headerAssetName:i,mediaType:t}));return e.jsx(n.MediaContainer,{children:t===d.HEADER_TYPES.IMAGE?e.jsx(o.ShimmerImage,{imageUrl:r,alt:r,width:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),s=require("../../../assets/icons/filePdf.svg.js"),r=require("../../../assets/icons/image.svg.js"),i=require("../../../assets/icons/videoRecorder.svg.js"),t=require("../../TypographyStyle.js"),a=require("../../../constants/Theme.js"),d=require("../models/TemplateMeta.js"),n=require("./ChatUI.style.js"),o=require("../../shimmer-image/ShimmerImage.js");const c=o=>{let{headerAssetName:c,mediaType:l}=o;const m=l===d.HEADER_TYPES.IMAGE?r.default:l===d.HEADER_TYPES.VIDEO?i.default:s.default;return e.jsxs(n.MediaContainer,{children:[e.jsx(m,{height:40,width:40,color:a.COLORS.icon.placeholder}),!!c&&e.jsx(t.BodySecondary,Object.assign({style:{color:a.COLORS.content.secondary,marginTop:8}},{children:c}))]})};exports.MediaCard=s=>{let{headerAssetLink:r,headerAssetName:i,mediaType:t,imagePreviewStyles:a}=s;if(!r||t===d.HEADER_TYPES.DOCUMENT)return e.jsx(c,Object.assign({},{headerAssetLink:r,headerAssetName:i,mediaType:t}));return e.jsx(n.MediaContainer,{children:t===d.HEADER_TYPES.IMAGE?e.jsx(o.ShimmerImage,{imageUrl:r,alt:r,width:"100%",height:156,borderRadius:8}):t===d.HEADER_TYPES.VIDEO?e.jsx("video",Object.assign({src:r,style:{width:"100%",minHeight:"156px",borderRadius:8},controls:!0},{children:e.jsx("track",{default:!0,kind:"captions",srcLang:"en",src:r})})):e.jsx(e.Fragment,{})})},exports.NoMediaCard=c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t,Fragment as i}from"react/jsx-runtime";import{format as a}from"date-fns";import{useState as n,useEffect as o}from"react";import{CustomDateTime as r}from"../../custom-date-time/CustomDateTime.js";import{Input as s}from"../../input/Input.js";import{RadioButton as d}from"../../radioButton/RadioButton.js";import{TitleRegular as c,BodySecondary as p}from"../../TypographyStyle.js";var D;!function(e){e.FIXED_EXPIRATION="fixedExpiration",e.DYNAMIC_EXPIRATION="dynamicExpiration"}(D||(D={}));const I=I=>{var
|
|
1
|
+
import{jsxs as e,jsx as t,Fragment as i}from"react/jsx-runtime";import{format as a}from"date-fns";import{useState as n,useEffect as o}from"react";import{CustomDateTime as r}from"../../custom-date-time/CustomDateTime.js";import{Input as s}from"../../input/Input.js";import{RadioButton as d}from"../../radioButton/RadioButton.js";import{TitleRegular as c,BodySecondary as p}from"../../TypographyStyle.js";var D;!function(e){e.FIXED_EXPIRATION="fixedExpiration",e.DYNAMIC_EXPIRATION="dynamicExpiration"}(D||(D={}));const I=I=>{var l;const[m,u]=n(I.discountData.expireAt?D.FIXED_EXPIRATION:I.discountData.expireAfter?D.DYNAMIC_EXPIRATION:void 0),[A,x]=n(),[E,v]=n(),O=(new Date).setDate((new Date).getDate()+1);o((()=>{(null==m||A||E)&&I.setDiscountData(Object.assign(Object.assign({},I.discountData),{expireAfter:void 0,expireAt:void 0})),m&&(A||E)&&(m===D.FIXED_EXPIRATION?v(void 0):x(void 0))}),[m,A,E]);return e("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:13}},{children:[t(c,{children:"Coupon expiration (optional)"}),e("div",Object.assign({style:{display:"flex",gap:18}},{children:[t(d,{isActive:m===D.DYNAMIC_EXPIRATION,onValueChange:()=>{v(void 0),u(m===D.DYNAMIC_EXPIRATION?void 0:D.DYNAMIC_EXPIRATION)}}),t(p,{children:"Validity days from coupon claim"})]})),m===D.DYNAMIC_EXPIRATION&&t(s,{errorMessage:E,value:null===(l=I.discountData.expireAfter)||void 0===l?void 0:l.toString(),placeholder:"Enter the number of days",width:"400px",type:"number",onChangeText:e=>{(e=>{v(void 0);const t=Number.parseInt(e);t>0?I.setDiscountData(Object.assign(Object.assign({},I.discountData),{expireAfter:t,expireAt:void 0})):v("Please enter valid input")})(e)}}),e("div",Object.assign({style:{display:"flex",gap:18}},{children:[t(d,{isActive:m===D.FIXED_EXPIRATION,onValueChange:()=>{u(m===D.FIXED_EXPIRATION?void 0:D.FIXED_EXPIRATION)}}),t(p,{children:"Fixed expiry date"})]})),m===D.FIXED_EXPIRATION&&e(i,{children:[t(p,{children:"Ending on"}),t(r,{placement:"bottom-start",time:I.discountData.expireAt?a(new Date(I.discountData.expireAt),"hh:mm a"):a(new Date(O),"hh:mm a"),date:I.discountData.expireAt?new Date(I.discountData.expireAt):new Date(O),error:A,setError:x,onChange:e=>{I.setDiscountData(Object.assign(Object.assign({},I.discountData),{expireAt:e,expireAfter:void 0}))},minDate:new Date(O)})]})]}))};export{D as COUPON_EXPIRATION,I as CouponExpiration};
|
|
@@ -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 d,DISCOUNT_TYPES as c,DISCOUNT_TARGET_SELECTION as l,DISCOUNT_VALUE_TYPES as s}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 v}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 C}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 T}from"../product-picker-v2/modal.js";import{StyledDiscountDialogueContainer as P,CouponTypeContainerStyled as f}from"./DiscountModal.styled.js";import{validateDiscountData as I,descriptionBuilder as O}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,A,q,x,M;const[L,R]=i(),[U,G]=i(),[B,Y]=i(null!==(w=j.data)&&void 0!==w?w:"string"==typeof j.hideOption?{isStaticCoupon:"dynamic"===j.hideOption}:{isStaticCoupon:!1}),[X,H]=i(!0),[V,z]=i(),[K,Q]=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),[$,Z]=i(void 0),[J,W]=i(void 0),[ee,te]=i(void 0),[oe,ie]=i(void 0),[ne,re]=i(0);n((()=>{let e;const{tempCouponData:t,discountType:o}=de();z(o),Y(Object.assign({},t)),j.hideProbability||(e=le()),H(I(t,K,o,j.hideProbability||!1,e,!!t.isStaticCoupon)),j.hideProbability||le()}),[]),n((()=>{let e;j.hideProbability||(e=le()),H(I(B,K,V,j.hideProbability||!1,e,!!B.isStaticCoupon))}),[B,ne,V,K]),n((()=>{var e,t,o,i,n,r,d;if(!j.newPickerConf&&((null===(e=j.products)||void 0===e?void 0:e.length)||(null===(t=j.collection)||void 0===t?void 0:t.length))){if(j.products&&(null===(o=j.products)||void 0===o?void 0:o.length)){if(null===(i=j.data)||void 0===i?void 0:i.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))}));W(e)}if(null===(n=j.data)||void 0===n?void 0:n.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))}));Z(e)}}if(j.collection&&j.collection.length){if(null===(r=j.data)||void 0===r?void 0:r.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))}));ie(e)}if(null===(d=j.data)||void 0===d?void 0:d.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))}));te(e)}}}}),[j.products,j.collection]),n((()=>{var e,t,o,i,n,r,d,c;(null===(t=null===(e=j.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&W(j.data.productsConf.entitledProducts),(null===(i=null===(o=j.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&Z(j.data.productsConf.prerequisiteProducts),(null===(r=null===(n=j.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&ie(j.data.collectionsConf.entitledCollections),(null===(c=null===(d=j.data)||void 0===d?void 0:d.collectionsConf)||void 0===c?void 0:c.prerequisiteCollections)&&te(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)return;if(j.newPickerConf){const e=[];return Object.values(J).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void Y(Object.assign(Object.assign({},B),{entitledProductIds:e}))}const e=J.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{entitledProductIds:e}))}),[J]),n((()=>{if(!$)return;if(j.newPickerConf){const e=[];return Object.values($).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void Y(Object.assign(Object.assign({},B),{prerequisiteProductIds:e}))}const e=$.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{prerequisiteProductIds:e}))}),[$]),n((()=>{if(!oe)return;if(j.newPickerConf){(null==oe?void 0:oe.isCustom)&&delete oe.isCustom;const e=Object.keys(oe).map((e=>parseInt(e)));return void Y(Object.assign(Object.assign({},B),{entitledCollectionIds:e}))}const e=oe.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{entitledCollectionIds:e}))}),[oe]),n((()=>{if(!ee)return;if(j.newPickerConf){(null==ee?void 0:ee.isCustom)&&delete ee.isCustom;const e=Object.keys(ee).map((e=>parseInt(e)));return void Y(Object.assign(Object.assign({},B),{prerequisiteCollectionIds:e}))}const e=ee.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{prerequisiteCollectionIds:e}))}),[ee]);const de=()=>{var e,t;let o,i=B;return B.isStaticCoupon||(B.targetType===d.SHIPPING_LINE?o=c.FREE_SHIPPING:B.targetType===d.LINE_ITEM?o=B.targetSelection===l.ENTITLED?(null===(e=B.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=B.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?c.BUY_X_GET_Y:c.AMOUNT_OFF_PRODUCTS:c.AMOUNT_OFF_ORDER:(i=Object.assign(Object.assign({},i),{targetType:d.LINE_ITEM,targetSelection:l.ALL,valueType:s.FIXED_AMOUNT}),o=c.AMOUNT_OFF_ORDER)),{discountType:o,tempCouponData:i}},ce=[{value:c.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:V===c.AMOUNT_OFF_ORDER},{value:c.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:V===c.AMOUNT_OFF_PRODUCTS},{value:c.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:V===c.BUY_X_GET_Y},{value:c.FREE_SHIPPING,label:"Free shipping",selected:V===c.FREE_SHIPPING}],le=()=>{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)+(B.probability||0);return re(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},se=e=>{var t,o,i,n;const a=e.value;z(a),Z([]),W([]),te([]),ie([]),Q(r.NA),a===c.FREE_SHIPPING?Y({value:100,targetSelection:l.ALL,targetType:d.SHIPPING_LINE,valueType:s.PERCENTAGE,quadrant:B.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0}):a===c.BUY_X_GET_Y?Y({targetSelection:l.ENTITLED,targetType:d.LINE_ITEM,valueType:s.PERCENTAGE,quadrant:B.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0}):a===c.AMOUNT_OFF_ORDER?Y({targetSelection:l.ALL,targetType:d.LINE_ITEM,valueType:null!==(o=null===(t=j.data)||void 0===t?void 0:t.valueType)&&void 0!==o?o:s.FIXED_AMOUNT,quadrant:B.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0}):a===c.AMOUNT_OFF_PRODUCTS&&Y({targetSelection:l.ENTITLED,targetType:d.LINE_ITEM,valueType:null!==(n=null===(i=j.data)||void 0===i?void 0:i.valueType)&&void 0!==n?n:s.FIXED_AMOUNT,quadrant:B.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0})};return e(C,Object.assign({width:(U||L)&&j.newPickerConf?"25px":"750px",open:j.isOpen,headingTitle:L?"Select Products":j.title,headingSubtitle:L?void 0:j.subTitle,footerLeftCustomElement:j.errorMsg?j.errorMsg&&t(h,{theme:"light",tagText:j.errorMsg,type:"negative"}):!j.quadrant||j.hideProbability?t(o,{}):ne<=1?t(h,{theme:"light",tagText:`Current probability sum: ${ne}`,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: ${ne}`,type:"negative",LeadingIcon:y})})})),headerRightCustomElement:j.allowStaticCoupon||L?void 0:t(a,{options:ce,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{se(e)}}),onClose:j.onClose,footerShadow:!0,primaryButton:L?{buttonType:"primary",onClick:()=>{R(void 0)},buttonText:"Add"}:U?{buttonType:"primary",onClick:()=>{G(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:X,isLoading:null!==(F=j.loading)&&void 0!==F&&F,onClick:()=>{var e,t;B.isStaticCoupon?j.onSaveClicked({quadrant:B.quadrant,couponCode:B.couponCode,description:B.description,isStaticCoupon:B.isStaticCoupon,probability:B.probability,title:B.title}):j.onSaveClicked(Object.assign(Object.assign({},B),{description:O(B,j.currency,null!==(e=j.products)&&void 0!==e?e:[],null!==(t=j.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:J,prerequisiteProducts:$},collectionsConf:{entitledCollections:oe,prerequisiteCollections:ee}}))}},secondaryButton:L?{buttonType:"tertiaryGray",onClick:()=>{R(void 0)},buttonText:"Back"}:U?{buttonType:"tertiaryGray",onClick:()=>{G(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:j.onClose,buttonText:"Close"}},{children:[!L&&!U&&e(P,{children:[j.allowStaticCoupon&&!L&&e(f,Object.assign({selectedDiv:B.isStaticCoupon?1:2},{children:["static"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{B.isStaticCoupon||Y({isStaticCoupon:!0,quadrant:B.quadrant})}},{children:[t(u,Object.assign({style:B.isStaticCoupon?{color:v.colorsV2.content.brand}:{}},{children:"Static code"})),t(p,Object.assign({style:B.isStaticCoupon?{color:v.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{B.isStaticCoupon&&(z(c.AMOUNT_OFF_ORDER),Y({isStaticCoupon:!1,quadrant:B.quadrant,targetType:d.LINE_ITEM,targetSelection:l.ALL,valueType:s.FIXED_AMOUNT}))}},{children:[t(u,Object.assign({style:B.isStaticCoupon?{}:{color:v.colorsV2.content.brand}},{children:"Dynamic code"})),t(p,Object.assign({style:B.isStaticCoupon?{}:{color:v.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),B.isStaticCoupon&&!L&&t(S,{discountData:B,setDiscountData:Y,hideProbability:j.hideProbability||!1,discountAdminUrl:j.discountAdminUrl}),!B.isStaticCoupon&&!L&&!U&&t(g,{currency:j.currency,entitledProducts:null!=J?J:[],prerequisiteProducts:null!=$?$:[],setEntitledProducts:W,setPrerequisiteProducts:Z,discountData:B,productPickerOpen:L,setIsProductPickerOpen:R,setDiscountData:Y,selectedCouponType:V,setSelectedCouponType:z,selectedMinimumRequirement:K,setSelectedMinimumRequirement:Q,hideProbability:j.hideProbability||!1,hideExpiration:j.hideExpiration||!1,allowStaticCoupon:j.allowStaticCoupon,onChangeCouponType:se,collectionPickerOpen:U,entitledCollections:null!=oe?oe:[],prerequisiteCollections:null!=ee?ee:[],setIsCollectionPickerOpen:G,setEntitledCollections:ie,setPrerequisiteCollections:te,useNewPicker:!!j.newPickerConf})]}),!!L&&e(o,{children:[!j.newPickerConf&&t("div",Object.assign({style:{padding:"12px 0"}},{children:t(m,{show:!0,onSave:()=>{},products:null!==(A=j.products)&&void 0!==A?A:[],title:"Select Products",onClose:()=>{R(void 0)},selectedProducts:null!==(q=L===E.ENTITLED?J:$)&&void 0!==q?q:[],setSelectedProducts:L===E.ENTITLED?W:Z,onSearchKeyChange:j.onProductSearch})})),j.newPickerConf&&t(T,{visible:!0,onClose:()=>R(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:L===E.ENTITLED?J:$,onAdd:e=>{L===E.ENTITLED?W(e):Z(e),R(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})]}),!!U&&t("div",Object.assign({style:{padding:"12px 0"}},{children:e(o,{children:[j.newPickerConf&&t(T,{visible:!0,onClose:()=>G(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:U===E.ENTITLED?oe:ee,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),U===E.ENTITLED?ie(e):te(e),G(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!==(x=j.collection)&&void 0!==x?x:[],title:"Select Products",onClose:()=>{G(void 0)},selectedProducts:null!==(M=U===E.ENTITLED?oe:ee)&&void 0!==M?M:[],setSelectedProducts:U===E.ENTITLED?ie:te,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 l,DISCOUNT_VALUE_TYPES as s}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 T}from"../product-picker-v2/modal.js";import{StyledDiscountDialogueContainer as P,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,A,L;const[x,R]=i(),[U,G]=i(),[B,Y]=i(null!==(w=j.data)&&void 0!==w?w:"string"==typeof j.hideOption?{isStaticCoupon:"dynamic"===j.hideOption}:{isStaticCoupon:!1}),[X,H]=i(!0),[V,z]=i(),[K,Q]=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),[$,Z]=i(void 0),[J,W]=i(void 0),[ee,te]=i(void 0),[oe,ie]=i(void 0),[ne,re]=i(0);n((()=>{let e;const{tempCouponData:t,discountType:o}=ce();z(o),Y(Object.assign({},t)),j.hideProbability||(e=le()),H(O(t,K,o,j.hideProbability||!1,e,!!t.isStaticCoupon)),j.hideProbability||le()}),[]),n((()=>{let e;j.hideProbability||(e=le()),H(O(B,K,V,j.hideProbability||!1,e,!!B.isStaticCoupon))}),[B,ne,V,K]),n((()=>{var e,t,o,i,n,r,c;if(!j.newPickerConf&&((null===(e=j.products)||void 0===e?void 0:e.length)||(null===(t=j.collection)||void 0===t?void 0:t.length))){if(j.products&&(null===(o=j.products)||void 0===o?void 0:o.length)){if(null===(i=j.data)||void 0===i?void 0:i.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))}));W(e)}if(null===(n=j.data)||void 0===n?void 0:n.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))}));Z(e)}}if(j.collection&&j.collection.length){if(null===(r=j.data)||void 0===r?void 0:r.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))}));ie(e)}if(null===(c=j.data)||void 0===c?void 0:c.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))}));te(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)&&W(j.data.productsConf.entitledProducts),(null===(i=null===(o=j.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&Z(j.data.productsConf.prerequisiteProducts),(null===(r=null===(n=j.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&ie(j.data.collectionsConf.entitledCollections),(null===(d=null===(c=j.data)||void 0===c?void 0:c.collectionsConf)||void 0===d?void 0:d.prerequisiteCollections)&&te(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)return;if(j.newPickerConf){const e=[];return Object.values(J).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void Y(Object.assign(Object.assign({},B),{entitledProductIds:e}))}const e=J.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{entitledProductIds:e}))}),[J]),n((()=>{if(!$)return;if(j.newPickerConf){const e=[];return Object.values($).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void Y(Object.assign(Object.assign({},B),{prerequisiteProductIds:e}))}const e=$.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{prerequisiteProductIds:e}))}),[$]),n((()=>{if(!oe)return;if(j.newPickerConf){(null==oe?void 0:oe.isCustom)&&delete oe.isCustom;const e=Object.keys(oe).map((e=>parseInt(e)));return void Y(Object.assign(Object.assign({},B),{entitledCollectionIds:e}))}const e=oe.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{entitledCollectionIds:e}))}),[oe]),n((()=>{if(!ee)return;if(j.newPickerConf){(null==ee?void 0:ee.isCustom)&&delete ee.isCustom;const e=Object.keys(ee).map((e=>parseInt(e)));return void Y(Object.assign(Object.assign({},B),{prerequisiteCollectionIds:e}))}const e=ee.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{prerequisiteCollectionIds:e}))}),[ee]);const ce=()=>{var e,t;let o,i=B;return B.isStaticCoupon||(B.targetType===c.SHIPPING_LINE?o=d.FREE_SHIPPING:B.targetType===c.LINE_ITEM?o=B.targetSelection===l.ENTITLED?(null===(e=B.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=B.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?d.BUY_X_GET_Y:d.AMOUNT_OFF_PRODUCTS:d.AMOUNT_OFF_ORDER:(i=Object.assign(Object.assign({},i),{targetType:c.LINE_ITEM,targetSelection:l.ALL,valueType:s.FIXED_AMOUNT}),o=d.AMOUNT_OFF_ORDER)),{discountType:o,tempCouponData:i}},de=[{value:d.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:V===d.AMOUNT_OFF_ORDER},{value:d.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:V===d.AMOUNT_OFF_PRODUCTS},{value:d.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:V===d.BUY_X_GET_Y},{value:d.FREE_SHIPPING,label:"Free shipping",selected:V===d.FREE_SHIPPING}],le=()=>{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)+(B.probability||0);return re(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},se=e=>{var t,o,i,n;const a=e.value;z(a),Z([]),W([]),te([]),ie([]),Q(r.NA),a===d.FREE_SHIPPING?Y({value:100,targetSelection:l.ALL,targetType:c.SHIPPING_LINE,valueType:s.PERCENTAGE,quadrant:B.quadrant,isStaticCoupon:!1,title:""}):a===d.BUY_X_GET_Y?Y({targetSelection:l.ENTITLED,targetType:c.LINE_ITEM,valueType:s.PERCENTAGE,quadrant:B.quadrant,isStaticCoupon:!1,title:""}):a===d.AMOUNT_OFF_ORDER?Y({targetSelection:l.ALL,targetType:c.LINE_ITEM,valueType:null!==(o=null===(t=j.data)||void 0===t?void 0:t.valueType)&&void 0!==o?o:s.FIXED_AMOUNT,quadrant:B.quadrant,isStaticCoupon:!1,title:""}):a===d.AMOUNT_OFF_PRODUCTS&&Y({targetSelection:l.ENTITLED,targetType:c.LINE_ITEM,valueType:null!==(n=null===(i=j.data)||void 0===i?void 0:i.valueType)&&void 0!==n?n:s.FIXED_AMOUNT,quadrant:B.quadrant,isStaticCoupon:!1,title:""})};return e(v,Object.assign({width:(U||x)&&j.newPickerConf?"25px":"750px",open:j.isOpen,headingTitle:x?"Select Products":j.title,headingSubtitle:x?void 0:j.subTitle,footerLeftCustomElement:j.errorMsg?j.errorMsg&&t(h,{theme:"light",tagText:j.errorMsg,type:"negative"}):!j.quadrant||j.hideProbability?t(o,{}):ne<=1?t(h,{theme:"light",tagText:`Current probability sum: ${ne}`,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: ${ne}`,type:"negative",LeadingIcon:y})})})),headerRightCustomElement:j.allowStaticCoupon||x?void 0:t(a,{options:de,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{se(e)}}),onClose:j.onClose,footerShadow:!0,primaryButton:x?{buttonType:"primary",onClick:()=>{R(void 0)},buttonText:"Add"}:U?{buttonType:"primary",onClick:()=>{G(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:X,isLoading:null!==(F=j.loading)&&void 0!==F&&F,onClick:()=>{var e,t;B.isStaticCoupon?j.onSaveClicked({quadrant:B.quadrant,couponCode:B.couponCode,description:B.description,isStaticCoupon:B.isStaticCoupon,probability:B.probability,title:B.title}):j.onSaveClicked(Object.assign(Object.assign({},B),{description:f(B,j.currency,null!==(e=j.products)&&void 0!==e?e:[],null!==(t=j.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:J,prerequisiteProducts:$},collectionsConf:{entitledCollections:oe,prerequisiteCollections:ee}}))}},secondaryButton:x?{buttonType:"tertiaryGray",onClick:()=>{R(void 0)},buttonText:"Back"}:U?{buttonType:"tertiaryGray",onClick:()=>{G(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:j.onClose,buttonText:"Close"}},{children:[!x&&!U&&e(P,{children:[j.allowStaticCoupon&&!x&&e(I,Object.assign({selectedDiv:B.isStaticCoupon?1:2},{children:["static"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{B.isStaticCoupon||Y({isStaticCoupon:!0,quadrant:B.quadrant})}},{children:[t(u,Object.assign({style:B.isStaticCoupon?{color:C.colorsV2.content.brand}:{}},{children:"Static code"})),t(p,Object.assign({style:B.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:()=>{B.isStaticCoupon&&(z(d.AMOUNT_OFF_ORDER),Y({isStaticCoupon:!1,quadrant:B.quadrant,targetType:c.LINE_ITEM,targetSelection:l.ALL,valueType:s.FIXED_AMOUNT}))}},{children:[t(u,Object.assign({style:B.isStaticCoupon?{}:{color:C.colorsV2.content.brand}},{children:"Dynamic code"})),t(p,Object.assign({style:B.isStaticCoupon?{}:{color:C.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),B.isStaticCoupon&&!x&&t(S,{discountData:B,setDiscountData:Y,hideProbability:j.hideProbability||!1,discountAdminUrl:j.discountAdminUrl}),!B.isStaticCoupon&&!x&&!U&&t(g,{currency:j.currency,entitledProducts:null!=J?J:[],prerequisiteProducts:null!=$?$:[],setEntitledProducts:W,setPrerequisiteProducts:Z,discountData:B,productPickerOpen:x,setIsProductPickerOpen:R,setDiscountData:Y,selectedCouponType:V,setSelectedCouponType:z,selectedMinimumRequirement:K,setSelectedMinimumRequirement:Q,hideProbability:j.hideProbability||!1,hideExpiration:j.hideExpiration||!1,allowStaticCoupon:j.allowStaticCoupon,onChangeCouponType:se,collectionPickerOpen:U,entitledCollections:null!=oe?oe:[],prerequisiteCollections:null!=ee?ee:[],setIsCollectionPickerOpen:G,setEntitledCollections:ie,setPrerequisiteCollections:te,useNewPicker:!!j.newPickerConf})]}),!!x&&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:()=>{R(void 0)},selectedProducts:null!==(M=x===E.ENTITLED?J:$)&&void 0!==M?M:[],setSelectedProducts:x===E.ENTITLED?W:Z,onSearchKeyChange:j.onProductSearch})})),j.newPickerConf&&t(T,{visible:!0,onClose:()=>R(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:x===E.ENTITLED?J:$,onAdd:e=>{x===E.ENTITLED?W(e):Z(e),R(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})]}),!!U&&t("div",Object.assign({style:{padding:"12px 0"}},{children:e(o,{children:[j.newPickerConf&&t(T,{visible:!0,onClose:()=>G(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:U===E.ENTITLED?oe:ee,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),U===E.ENTITLED?ie(e):te(e),G(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!==(A=j.collection)&&void 0!==A?A:[],title:"Select Products",onClose:()=>{G(void 0)},selectedProducts:null!==(L=U===E.ENTITLED?oe:ee)&&void 0!==L?L:[],setSelectedProducts:U===E.ENTITLED?ie:te,onSearchKeyChange:j.onCollectionSearch,searchPlaceholder:"Search collections..."})]})}))]}))};export{j as DiscountModal};
|
|
@@ -4,4 +4,4 @@ import{jsxs as e,jsx as t}from"react/jsx-runtime";import l from"../../../assets/
|
|
|
4
4
|
background: ${e=>e.focused&&e.channel===c.EMAIL?g.background.warning.light:"transparent"};
|
|
5
5
|
border-radius: 4px;
|
|
6
6
|
padding: 8px 10px;
|
|
7
|
-
`,O={value:"custom_link",label:"Custom URL"},_={value:"custom_text",label:"Custom text"},f=n=>{let{onFocus:f,variable:y,index:T,showVariableModal:k,variableList:A,setShowDiscountCheckBox:V,componentType:E,CTAoptions:S}=n;var P,w;const[C,B]=a(!1),[L,H]=a(""),[N,M]=a([]),[W,$]=a(),[D,I]=a(!1),[R,U]=a(!1),{device:z,channel:Y,isError:Z,originalVariableList:G,template:q,templateSelectionTriggered:F,setTemplate:J,setDisplayContent:K,setOriginalVariableList:Q,globalNormalizedPlaceholders:X,enabledCustomText:ee,pod:te}=h();function le(e,t){var l,a,i;const n=e;H(""),$(n),Y===c.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(ae(null!==(l=n.value)&&void 0!==l?l:"","string"),null==ie||ie(null!==(a=y.index)&&void 0!==a?a:0,n.value,!0)):(null==ie||ie(null!==(i=y.index)&&void 0!==i?i:0,y.variableName,!0,"custom_text"),ae("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?ae(n.value,"url"===n.bikPlaceholderType?"link":"string"):(H(""),ae("",n.value))}function ae(e,t){var l,a,i,n;const o="custom_link"===t?"link":"custom_text"===t?"string":t;if(Y!==c.WHATSAPP){const a=x(T+1),i=null===document||void 0===document?void 0:document.getElementById("mobile"===z?"template_html_mobile":"template_html_desktop"),n=Y===c.EMAIL?null===(l=null==i?void 0:i.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:y.variableName);const s=G.map(((t,l)=>l===T?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==Q||Q(s)}if(Y===c.WHATSAPP){const l=G;let s=l.body,u=l.header,d=l.buttons;"BODY"===E?s=null===(a=l.body)||void 0===a?void 0:a.map(((t,l)=>l===T?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"HEADER"===E?u=null===(i=l.header)||void 0===i?void 0:i.map(((t,l)=>l===T?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"BUTTONS"===E&&(d=null===(n=l.buttons)||void 0===n?void 0:n.map(((l,a)=>a===T?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:[e]}):l))),null==Q||Q((e=>Object.assign(Object.assign({},e),{header:u,body:s,buttons:d})))}}function ie(e,t,l,a){var i,n,o,s;const u=Object.assign({},q),d=null===(i=null==u?void 0:u.components)||void 0===i?void 0:i.map((l=>{var a,i,n,o,s,u,d,r,c,p;const m=Object.assign({},l);if("BODY"===l.type&&"BODY"===E){if(null===(i=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===i?void 0:i[0]){const l=[...null!==(s=null===(o=null===(n=m.example)||void 0===n?void 0:n.body_text)||void 0===o?void 0:o[0])&&void 0!==s?s:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},m.example),{body_text:[l]});return Object.assign(Object.assign({},m),{example:a})}}else if("HEADER"===l.type&&"HEADER"===E){if(null===(u=l.example)||void 0===u?void 0:u.header_text){const l=[...null!==(r=null===(d=m.example)||void 0===d?void 0:d.header_text)&&void 0!==r?r:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},m.example),{header_text:l});return Object.assign(Object.assign({},m),{example:a})}}else if("BUTTONS"===l.type&&"BUTTONS"===E&&(null===(p=null===(c=l.buttons)||void 0===c?void 0:c[e])||void 0===p?void 0:p.example)){const a=l.buttons.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:[t]}):l));return Object.assign(Object.assign({},m),{buttons:a})}return l}));u.components=d,l&&("BODY"===E&&(null===(n=null==u?void 0:u.mapping)||void 0===n?void 0:n.body)?u.mapping=Object.assign(Object.assign({},u.mapping),{body:u.mapping.body.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))}):"HEADER"===E&&(null===(o=null==u?void 0:u.mapping)||void 0===o?void 0:o.header)?u.mapping=Object.assign(Object.assign({},u.mapping),{header:u.mapping.header.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+20}))`:t:l))}):"BUTTONS"===E&&(null===(s=null==u?void 0:u.mapping)||void 0===s?void 0:s.buttons)&&(u.mapping=Object.assign(Object.assign({},u.mapping),{buttons:u.mapping.buttons.map(((e,l)=>0===l?"custom_link"===a?"((customPlaceholderName))":t:e))}))),null==J||J(Object.assign({},u))}return i((()=>{C&&(null==f||f())}),[C]),i((()=>{!function(){var e,t,l,a,i;const n="mobile"===z?"template_html_mobile":"template_html_desktop",o=document.getElementById(n),s=(null!==(a=null===(l=null===(t=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(i=null==o?void 0:o.contentWindow)||void 0===i?void 0:i.document.head.innerHTML);Y===c.EMAIL&&(null==K||K(s))}()}),[F]),i((()=>{var e;const t=[];let l=[];if(Y!==c.MESSAGE||ee){"link"===(null==y?void 0:y.type)?(t.push({label:"",options:[O,_]}),$(O)):(t.push({label:"",options:[O,_]}),$(_));const e=null!=X?X:[];M([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:b.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}else{const e=null!=X?X:[];M([{label:"",options:[_,O]},...e]),l=[{label:"",options:[_,O]},...e]}if((Y===c.WHATSAPP||Y===c.EMAIL||Y===c.MESSAGE)&&y.updatedValue)if(r.test(y.updatedValue)&&Y===c.WHATSAPP||y.updatedValue.startsWith("{{")&&Y!==c.WHATSAPP){const e=function(e,t,l){var a;let i={label:"",value:""};const n=l===c.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(k){let t=e.updatedValue;if(te===p.CHATBOT&&"BUTTONS"===E){const l=null==S?void 0:S.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}i={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(i=e)}))}));return i}(y,l,Y);e.value&&$(e)}else(null===(e=y.updatedValue)||void 0===e?void 0:e.startsWith("https"))?($(O),H(y.updatedValue.split("https://")[1])):($(_),H(y.updatedValue))}),[]),i((()=>{z&&W&&L&&setTimeout((()=>{ae("custom_link"===(null==W?void 0:W.value)&&L?L.includes("https")?L:`https://${L}`:L,W.value)}),100)}),[z]),i((()=>{!R&&W&&y.updatedValue&&setTimeout((()=>{ae("custom_link"===(null==W?void 0:W.value)&&y.updatedValue?y.updatedValue.includes("https")?y.updatedValue:`https://${y.updatedValue}`:y.updatedValue,W.value),U(!0)}),100)}),[W]),e(j,Object.assign({channel:Y,focused:C,onMouseEnter:()=>B(!0),onMouseLeave:()=>B(!1)},{children:[t("div",Object.assign({style:{marginBottom:8}},{children:e(m,Object.assign({style:{color:Z&&!W?g.content.negative:g.content.primary}},{children:[null===(P=y.variableName)||void 0===P?void 0:P.replace("{{","").replace("}}","")," ","link"===(null==y?void 0:y.type)?"link":"variable"]}))})),t("div",Object.assign({style:{marginBottom:12}},{children:k?e("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==W?void 0:W.label)?"space-between":"flex-end"}},{children:[t(v,{children:d(null!==(w=null==W?void 0:W.label)&&void 0!==w?w:"",20,!0)}),t(l,{onClick:()=>{I(!D)},width:24,height:24,color:g.content.primary})]})):t(s,{options:N,isSearchable:!1,onSelect:le,defaultOptions:W?[Object.assign(Object.assign({},W),{selected:!0})]:[]})})),("custom_text"===(null==W?void 0:W.value)||"custom_link"===(null==W?void 0:W.value))&&t(u,{labelText:"custom_text"===(null==W?void 0:W.value)?"Custom text value":"custom_link"===(null==W?void 0:W.value)?"Custom URL value":"",id:`variable-value-${null==W?void 0:W.value}-${T}`,value:L,errorMessage:Z?L&&0!==L.trim().length?"custom_link"!==W.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${L.trim()}`)&&0!==L.trim().length?"custom_link"!==W.value&&L.length>30?"Length cannot be more than 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==W?void 0:W.value)?
|
|
7
|
+
`,O={value:"custom_link",label:"Custom URL"},_={value:"custom_text",label:"Custom text"},f=n=>{let{onFocus:f,variable:y,index:T,showVariableModal:k,variableList:A,setShowDiscountCheckBox:V,componentType:E,CTAoptions:S}=n;var P,w;const[C,B]=a(!1),[L,H]=a(""),[N,M]=a([]),[W,$]=a(),[D,I]=a(!1),[R,U]=a(!1),{device:z,channel:Y,isError:Z,originalVariableList:G,template:q,templateSelectionTriggered:F,setTemplate:J,setDisplayContent:K,setOriginalVariableList:Q,globalNormalizedPlaceholders:X,enabledCustomText:ee,pod:te}=h();function le(e,t){var l,a,i;const n=e;H(""),$(n),Y===c.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(ae(null!==(l=n.value)&&void 0!==l?l:"","string"),null==ie||ie(null!==(a=y.index)&&void 0!==a?a:0,n.value,!0)):(null==ie||ie(null!==(i=y.index)&&void 0!==i?i:0,y.variableName,!0,"custom_text"),ae("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?ae(n.value,"url"===n.bikPlaceholderType?"link":"string"):(H(""),ae("",n.value))}function ae(e,t){var l,a,i,n;const o="custom_link"===t?"link":"custom_text"===t?"string":t;if(Y!==c.WHATSAPP){const a=x(T+1),i=null===document||void 0===document?void 0:document.getElementById("mobile"===z?"template_html_mobile":"template_html_desktop"),n=Y===c.EMAIL?null===(l=null==i?void 0:i.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:y.variableName);const s=G.map(((t,l)=>l===T?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==Q||Q(s)}if(Y===c.WHATSAPP){const l=G;let s=l.body,u=l.header,d=l.buttons;"BODY"===E?s=null===(a=l.body)||void 0===a?void 0:a.map(((t,l)=>l===T?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"HEADER"===E?u=null===(i=l.header)||void 0===i?void 0:i.map(((t,l)=>l===T?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"BUTTONS"===E&&(d=null===(n=l.buttons)||void 0===n?void 0:n.map(((l,a)=>a===T?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:[e]}):l))),null==Q||Q((e=>Object.assign(Object.assign({},e),{header:u,body:s,buttons:d})))}}function ie(e,t,l,a){var i,n,o,s;const u=Object.assign({},q),d=null===(i=null==u?void 0:u.components)||void 0===i?void 0:i.map((l=>{var a,i,n,o,s,u,d,r,c,p;const m=Object.assign({},l);if("BODY"===l.type&&"BODY"===E){if(null===(i=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===i?void 0:i[0]){const l=[...null!==(s=null===(o=null===(n=m.example)||void 0===n?void 0:n.body_text)||void 0===o?void 0:o[0])&&void 0!==s?s:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},m.example),{body_text:[l]});return Object.assign(Object.assign({},m),{example:a})}}else if("HEADER"===l.type&&"HEADER"===E){if(null===(u=l.example)||void 0===u?void 0:u.header_text){const l=[...null!==(r=null===(d=m.example)||void 0===d?void 0:d.header_text)&&void 0!==r?r:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},m.example),{header_text:l});return Object.assign(Object.assign({},m),{example:a})}}else if("BUTTONS"===l.type&&"BUTTONS"===E&&(null===(p=null===(c=l.buttons)||void 0===c?void 0:c[e])||void 0===p?void 0:p.example)){const a=l.buttons.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:[t]}):l));return Object.assign(Object.assign({},m),{buttons:a})}return l}));u.components=d,l&&("BODY"===E&&(null===(n=null==u?void 0:u.mapping)||void 0===n?void 0:n.body)?u.mapping=Object.assign(Object.assign({},u.mapping),{body:u.mapping.body.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))}):"HEADER"===E&&(null===(o=null==u?void 0:u.mapping)||void 0===o?void 0:o.header)?u.mapping=Object.assign(Object.assign({},u.mapping),{header:u.mapping.header.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+20}))`:t:l))}):"BUTTONS"===E&&(null===(s=null==u?void 0:u.mapping)||void 0===s?void 0:s.buttons)&&(u.mapping=Object.assign(Object.assign({},u.mapping),{buttons:u.mapping.buttons.map(((e,l)=>0===l?"custom_link"===a?"((customPlaceholderName))":t:e))}))),null==J||J(Object.assign({},u))}return i((()=>{C&&(null==f||f())}),[C]),i((()=>{!function(){var e,t,l,a,i;const n="mobile"===z?"template_html_mobile":"template_html_desktop",o=document.getElementById(n),s=(null!==(a=null===(l=null===(t=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(i=null==o?void 0:o.contentWindow)||void 0===i?void 0:i.document.head.innerHTML);Y===c.EMAIL&&(null==K||K(s))}()}),[F]),i((()=>{var e;const t=[];let l=[];if(Y!==c.MESSAGE||ee){"link"===(null==y?void 0:y.type)?(t.push({label:"",options:[O,_]}),$(O)):(t.push({label:"",options:[O,_]}),$(_));const e=null!=X?X:[];M([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:b.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}else{const e=null!=X?X:[];M([{label:"",options:[_,O]},...e]),l=[{label:"",options:[_,O]},...e]}if((Y===c.WHATSAPP||Y===c.EMAIL||Y===c.MESSAGE)&&y.updatedValue)if(r.test(y.updatedValue)&&Y===c.WHATSAPP||y.updatedValue.startsWith("{{")&&Y!==c.WHATSAPP){const e=function(e,t,l){var a;let i={label:"",value:""};const n=l===c.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(k){let t=e.updatedValue;if(te===p.CHATBOT&&"BUTTONS"===E){const l=null==S?void 0:S.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}i={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(i=e)}))}));return i}(y,l,Y);e.value&&$(e)}else(null===(e=y.updatedValue)||void 0===e?void 0:e.startsWith("https"))?($(O),H(y.updatedValue.split("https://")[1])):($(_),H(y.updatedValue))}),[]),i((()=>{z&&W&&L&&setTimeout((()=>{ae("custom_link"===(null==W?void 0:W.value)&&L?L.includes("https")?L:`https://${L}`:L,W.value)}),100)}),[z]),i((()=>{!R&&W&&y.updatedValue&&setTimeout((()=>{ae("custom_link"===(null==W?void 0:W.value)&&y.updatedValue?y.updatedValue.includes("https")?y.updatedValue:`https://${y.updatedValue}`:y.updatedValue,W.value),U(!0)}),100)}),[W]),e(j,Object.assign({channel:Y,focused:C,onMouseEnter:()=>B(!0),onMouseLeave:()=>B(!1)},{children:[t("div",Object.assign({style:{marginBottom:8}},{children:e(m,Object.assign({style:{color:Z&&!W?g.content.negative:g.content.primary}},{children:[null===(P=y.variableName)||void 0===P?void 0:P.replace("{{","").replace("}}","")," ","link"===(null==y?void 0:y.type)?"link":"variable"]}))})),t("div",Object.assign({style:{marginBottom:12}},{children:k?e("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==W?void 0:W.label)?"space-between":"flex-end"}},{children:[t(v,{children:d(null!==(w=null==W?void 0:W.label)&&void 0!==w?w:"",20,!0)}),t(l,{onClick:()=>{I(!D)},width:24,height:24,color:g.content.primary})]})):t(s,{options:N,isSearchable:!1,onSelect:le,defaultOptions:W?[Object.assign(Object.assign({},W),{selected:!0})]:[]})})),("custom_text"===(null==W?void 0:W.value)||"custom_link"===(null==W?void 0:W.value))&&t(u,{labelText:"custom_text"===(null==W?void 0:W.value)?"Custom text value":"custom_link"===(null==W?void 0:W.value)?"Custom URL value":"",id:`variable-value-${null==W?void 0:W.value}-${T}`,value:L,errorMessage:Z?L&&0!==L.trim().length?"custom_link"!==W.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${L.trim()}`)&&0!==L.trim().length?"custom_link"!==W.value&&L.length>30?"Length cannot be more than 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==W?void 0:W.value)?2e3:30,prefixText:"custom_link"===(null==W?void 0:W.value)?"https://":"",placeholder:"link"===y.type||"custom_link"===W.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{!function(e,t){var l;H(t);const a="custom_link"===(null==W?void 0:W.value)&&t?t.includes("https")?t:`https://${t}`:t;ae(a,e),Y===c.WHATSAPP&&(null==ie||ie(null!==(l=y.index)&&void 0!==l?l:0,a,"custom_link"===e,e))}(W.value,e)}}),D&&t(o,{zIndex:2e3,data:null!=A?A:[],showVariable:D,setShowVariable:I,placeholder:"Add a variable",customTrigger:e=>{null==V||V(!1),"{{custom.url}}"===e.actualValue?le({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?le({label:e.displayName,selected:!0,value:"custom_text"}):le({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{j as Container,f as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,Fragment as s,jsxs as r}from"react/jsx-runtime";import t from"../../../assets/icons/filePdf.svg.js";import i from"../../../assets/icons/image.svg.js";import o from"../../../assets/icons/videoRecorder.svg.js";import{BodySecondary as m}from"../../TypographyStyle.js";import{COLORS as a}from"../../../constants/Theme.js";import{HEADER_TYPES as n}from"../models/TemplateMeta.js";import{MediaContainer as d}from"./ChatUI.style.js";import{ShimmerImage as c}from"../../shimmer-image/ShimmerImage.js";const h=s=>{let{headerAssetName:c,mediaType:h}=s;const l=h===n.IMAGE?i:h===n.VIDEO?o:t;return r(d,{children:[e(l,{height:40,width:40,color:a.icon.placeholder}),!!c&&e(m,Object.assign({style:{color:a.content.secondary,marginTop:8}},{children:c}))]})},l=r=>{let{headerAssetLink:t,headerAssetName:i,mediaType:o,imagePreviewStyles:m}=r;if(!t||o===n.DOCUMENT)return e(h,Object.assign({},{headerAssetLink:t,headerAssetName:i,mediaType:o}));return e(d,{children:o===n.IMAGE?e(c,{imageUrl:t,alt:t,width:
|
|
1
|
+
import{jsx as e,Fragment as s,jsxs as r}from"react/jsx-runtime";import t from"../../../assets/icons/filePdf.svg.js";import i from"../../../assets/icons/image.svg.js";import o from"../../../assets/icons/videoRecorder.svg.js";import{BodySecondary as m}from"../../TypographyStyle.js";import{COLORS as a}from"../../../constants/Theme.js";import{HEADER_TYPES as n}from"../models/TemplateMeta.js";import{MediaContainer as d}from"./ChatUI.style.js";import{ShimmerImage as c}from"../../shimmer-image/ShimmerImage.js";const h=s=>{let{headerAssetName:c,mediaType:h}=s;const l=h===n.IMAGE?i:h===n.VIDEO?o:t;return r(d,{children:[e(l,{height:40,width:40,color:a.icon.placeholder}),!!c&&e(m,Object.assign({style:{color:a.content.secondary,marginTop:8}},{children:c}))]})},l=r=>{let{headerAssetLink:t,headerAssetName:i,mediaType:o,imagePreviewStyles:m}=r;if(!t||o===n.DOCUMENT)return e(h,Object.assign({},{headerAssetLink:t,headerAssetName:i,mediaType:o}));return e(d,{children:o===n.IMAGE?e(c,{imageUrl:t,alt:t,width:"100%",height:156,borderRadius:8}):o===n.VIDEO?e("video",Object.assign({src:t,style:{width:"100%",minHeight:"156px",borderRadius:8},controls:!0},{children:e("track",{default:!0,kind:"captions",srcLang:"en",src:t})})):e(s,{})})};export{l as MediaCard,h as NoMediaCard};
|