@bikdotai/bik-component-library 0.0.292-beta-discount-collection-0.2 → 0.0.292
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/DiscountModal.d.ts +1 -3
- package/dist/cjs/components/discount-modal/DiscountModal.js +1 -1
- package/dist/cjs/components/discount-modal/DiscountUtils.js +1 -1
- package/dist/cjs/components/discount-modal/DynamicCoupon/DynamicCoupon.d.ts +1 -7
- package/dist/cjs/components/discount-modal/DynamicCoupon/DynamicCoupon.js +1 -1
- package/dist/cjs/components/product-picker/type.d.ts +5 -15
- package/dist/esm/components/discount-modal/DiscountModal.d.ts +1 -3
- package/dist/esm/components/discount-modal/DiscountModal.js +1 -1
- package/dist/esm/components/discount-modal/DiscountUtils.js +1 -1
- package/dist/esm/components/discount-modal/DynamicCoupon/DynamicCoupon.d.ts +1 -7
- package/dist/esm/components/discount-modal/DynamicCoupon/DynamicCoupon.js +1 -1
- package/dist/esm/components/product-picker/type.d.ts +5 -15
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ICouponData } from "./type";
|
|
3
|
-
import {
|
|
3
|
+
import { Product } from "../product-picker/type";
|
|
4
4
|
export interface DiscountDialogueI {
|
|
5
5
|
hideOption?: 'static' | 'dynamic';
|
|
6
6
|
isOpen: boolean;
|
|
@@ -11,13 +11,11 @@ export interface DiscountDialogueI {
|
|
|
11
11
|
data?: ICouponData;
|
|
12
12
|
onSaveClicked: (discountData: ICouponData) => void;
|
|
13
13
|
onProductSearch: (key: string) => Promise<Product[]>;
|
|
14
|
-
onCollectionSearch: (key: string) => Promise<Collection[]>;
|
|
15
14
|
hideExpiration?: boolean;
|
|
16
15
|
hideProbability?: boolean;
|
|
17
16
|
probability?: number[];
|
|
18
17
|
quadrant?: number;
|
|
19
18
|
products?: Product[];
|
|
20
|
-
collection?: Collection[];
|
|
21
19
|
discountAdminUrl?: string;
|
|
22
20
|
currency?: string;
|
|
23
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),o=require("./type.js");require("../dropdown/DropdownPopover/index.js");var i=require("../dropdown/Dropdown.js");require("../dropdown/ChipDropdown.js"),require("../zeroState/ZeroState.js");var n=require("../TypographyStyle.js"),s=require("../../constants/Theme.js");require("../dropdown/OpenedDropdown/components/description/Description.styled.js"),require("../checkBox/CheckBox.styled.js"),require("../list-item/ListItem.js"),require("../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js"),require("../dropdown/OpenedDropdown/components/menu/MenuItem.js"),require("../dropdown/OpenedDropdown/components/menu/MenuList.styled.js"),require("../button/Button.js"),require("../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js"),require("../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js"),require("../input/Input.js"),require("../dropdown/MenuItem/MenuItem.js");var r=require("../modals/styledModal.js"),l=require("../product-picker/ProductPickerModal.js"),d=require("../tag/Tag.js"),c=require("../tooltips/Tooltip.js"),a=require("../../assets/icons/triangle_error.svg.js"),u=require("./DiscountModal.styled.js"),p=require("./DiscountUtils.js"),T=require("./DynamicCoupon/DynamicCoupon.js"),E=require("./StaticCoupon/StaticCoupon.js");exports.DiscountModal=S=>{var C,I,P,b,y;const[O,_]=t.useState(),[v,D]=t.useState(),[N,g]=t.useState(null!==(C=S.data)&&void 0!==C?C:"string"==typeof S.hideOption?{isStaticCoupon:"dynamic"===S.hideOption}:{isStaticCoupon:!1}),[j,U]=t.useState(!0),[m,h]=t.useState(),[q,A]=t.useState((null===(I=S.data)||void 0===I?void 0:I.minAmount)?o.MIN_PURCHASE_REQUIREMENT.AMOUNT:(null===(P=S.data)||void 0===P?void 0:P.minQuantity)?o.MIN_PURCHASE_REQUIREMENT.QUANTITY:o.MIN_PURCHASE_REQUIREMENT.NA),[x,R]=t.useState([]),[f,Y]=t.useState([]),[w,L]=t.useState([]),[M,G]=t.useState([]),[F,k]=t.useState(0);t.useEffect((()=>{let e;S.hideProbability||(e=H()),U(p.validateDiscountData(N,q,m,S.hideProbability||!1,e,!!N.isStaticCoupon)),S.hideProbability||H()}),[]),t.useEffect((()=>{let e;S.hideProbability||(e=H()),U(p.validateDiscountData(N,q,m,S.hideProbability||!1,e,!!N.isStaticCoupon))}),[N,F,m,q]),t.useEffect((()=>{var e,t,o,i,n;if(console.log("lib:: entering initial effect"),S.products&&(null===(e=S.products)||void 0===e?void 0:e.length)){if(console.log("lib:: entered products"),null===(t=S.data)||void 0===t?void 0:t.entitledProductIds){const e=S.products.filter((e=>{var t,o;return null===(o=null===(t=S.data)||void 0===t?void 0:t.entitledProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));console.log("lib:: newEntitledProducts",e),Y(e)}if(null===(o=S.data)||void 0===o?void 0:o.prerequisiteProductIds){const e=S.products.filter((e=>{var t,o;return null===(o=null===(t=S.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));console.log("lib:: newPrerequisiteProducts",e),R(e)}}if(S.collection&&S.collection.length){if(console.log("lib:: entered collections"),null===(i=S.data)||void 0===i?void 0:i.entitledCollectionIds){const e=S.collection.filter((e=>{var t,o;return null===(o=null===(t=S.data)||void 0===t?void 0:t.entitledCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));console.log("lib:: newEntitledCollection",e),G(e)}if(null===(n=S.data)||void 0===n?void 0:n.prerequisiteCollectionIds){const e=S.collection.filter((e=>{var t,o;return null===(o=null===(t=S.data)||void 0===t?void 0:t.prerequisiteCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));console.log("lib:: newPrerequisiteCollection",e),L(e)}}}),[S.products,S.collection]),t.useEffect((()=>{const e=f.map((e=>parseInt(e.id)));console.log("lib:: entitledProducts",f,e),g(Object.assign(Object.assign({},N),{entitledProductIds:e}))}),[f]),t.useEffect((()=>{const e=x.map((e=>parseInt(e.id)));console.log("lib:: preRequisiteProducts",x,x),g(Object.assign(Object.assign({},N),{prerequisiteProductIds:e}))}),[x]),t.useEffect((()=>{const e=M.map((e=>parseInt(e.id)));console.log("lib:: entitledCollections",M,e),g(Object.assign(Object.assign({},N),{entitledCollectionIds:e}))}),[M]),t.useEffect((()=>{const e=w.map((e=>parseInt(e.id)));console.log("lib:: preRequisiteCollections",w,e),g(Object.assign(Object.assign({},N),{prerequisiteCollectionIds:e}))}),[w]),t.useEffect((()=>{N.targetType===o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE?h(o.DISCOUNT_TYPES.FREE_SHIPPING):N.targetSelection===o.DISCOUNT_TARGET_SELECTION.ENTITLED?h(o.DISCOUNT_TYPES.BUY_X_GET_Y):N.valueType===o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT?h(o.DISCOUNT_TYPES.FIXED_AMOUNT):N.valueType===o.DISCOUNT_VALUE_TYPES.PERCENTAGE&&h(o.DISCOUNT_TYPES.PERCENTAGE)}),[]);const B=[{value:o.DISCOUNT_TYPES.FIXED_AMOUNT,label:"Fixed Amount",selected:m===o.DISCOUNT_TYPES.FIXED_AMOUNT},{value:o.DISCOUNT_TYPES.PERCENTAGE,label:"Percentage",selected:m===o.DISCOUNT_TYPES.PERCENTAGE},{value:o.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:m===o.DISCOUNT_TYPES.BUY_X_GET_Y},{value:o.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:m===o.DISCOUNT_TYPES.FREE_SHIPPING}],H=()=>{if(!S.quadrant||!S.probability)return;const e=[...S.probability];let t=[];e.length>=S.quadrant&&e.splice(S.quadrant-1,1),t=e;const o=t.reduce(((e,t)=>e+t),0)+(N.probability||0);return k(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},Q=e=>{const t=e.value;h(t),t===o.DISCOUNT_TYPES.FREE_SHIPPING?(R([]),Y([]),g(Object.assign(Object.assign({},N),{value:100,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,entitledQuantity:void 0,prerequisiteQuantity:void 0,entitledProductIds:void 0,prerequisiteProductIds:void 0}))):t===o.DISCOUNT_TYPES.BUY_X_GET_Y?g(Object.assign(Object.assign({},N),{targetSelection:o.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE})):t===o.DISCOUNT_TYPES.PERCENTAGE?(R([]),Y([]),g(Object.assign(Object.assign({},N),{targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,entitledQuantity:void 0,prerequisiteQuantity:void 0,entitledProductIds:void 0,prerequisiteProductIds:void 0}))):t===o.DISCOUNT_TYPES.FIXED_AMOUNT&&(R([]),Y([]),g(Object.assign(Object.assign({},N),{targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,entitledQuantity:void 0,prerequisiteQuantity:void 0,entitledProductIds:void 0,prerequisiteProductIds:void 0})))};return e.jsxs(r.StyledModal,Object.assign({open:S.isOpen,headingTitle:O?"Select Products":S.title,headingSubtitle:O?void 0:S.subTitle,footerLeftCustomElement:!S.quadrant||S.hideProbability?e.jsx(e.Fragment,{}):F<=1?e.jsx(d.Tag,{theme:"light",tagText:`Current probability sum: ${F}`,type:"white"}):e.jsx(c.Tooltip,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e.jsx("div",{children:e.jsx(d.Tag,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${F}`,type:"negative",LeadingIcon:a.default})})})),headerRightCustomElement:S.allowStaticCoupon||O?void 0:e.jsx(i.Dropdown,{options:B,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{Q(e)}}),onClose:S.onClose,footerShadow:!0,primaryButton:O?{buttonType:"primary",onClick:()=>{_(void 0)},buttonText:"Add"}:v?{buttonType:"primary",onClick:()=>{D(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:j,onClick:()=>{N.isStaticCoupon?S.onSaveClicked({quadrant:N.quadrant,couponCode:N.couponCode,description:N.description,isStaticCoupon:N.isStaticCoupon,probability:N.probability,title:N.title}):S.onSaveClicked(N),g({})}},secondaryButton:O?{buttonType:"tertiaryGray",onClick:()=>{_(void 0)},buttonText:"Back"}:v?{buttonType:"tertiaryGray",onClick:()=>{D(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:S.onClose,buttonText:"Close"}},{children:[!O&&!v&&e.jsxs(u.StyledDiscountDialogueContainer,{children:[S.allowStaticCoupon&&!O&&e.jsxs(u.CouponTypeContainerStyled,Object.assign({selectedDiv:N.isStaticCoupon?1:2},{children:["static"===S.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{g({isStaticCoupon:!0,couponCode:N.couponCode,description:N.description,quadrant:N.quadrant})}},{children:[e.jsx(n.TitleSmall,Object.assign({style:N.isStaticCoupon?{color:s.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"Static code"})),e.jsx(n.BodyCaption,Object.assign({style:N.isStaticCoupon?{color:s.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===S.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{g(Object.assign(Object.assign({},N),{isStaticCoupon:!1}))}},{children:[e.jsx(n.TitleSmall,Object.assign({style:N.isStaticCoupon?{}:{color:s.DEFAULT_THEME.colorsV2.content.brand}},{children:"Dynamic code"})),e.jsx(n.BodyCaption,Object.assign({style:N.isStaticCoupon?{}:{color:s.DEFAULT_THEME.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),N.isStaticCoupon&&!O&&e.jsx(E.default,{discountData:N,setDiscountData:g,hideProbability:S.hideProbability||!1,discountAdminUrl:S.discountAdminUrl}),!N.isStaticCoupon&&!O&&!v&&e.jsx(T.default,{currency:S.currency,entitledProducts:f,prerequisiteProducts:x,setEntitledProducts:Y,setPrerequisiteProducts:R,discountData:N,productPickerOpen:O,setIsProductPickerOpen:_,setDiscountData:g,selectedCouponType:m,setSelectedCouponType:h,selectedMinimumRequirement:q,setSelectedMinimumRequirement:A,hideProbability:S.hideProbability||!1,hideExpiration:S.hideExpiration||!1,allowStaticCoupon:S.allowStaticCoupon,onChangeCouponType:Q,collectionPickerOpen:v,entitledCollections:M,prerequisiteCollections:w,setIsCollectionPickerOpen:D,setEntitledCollections:G,setPrerequisiteCollections:L})]}),!!O&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsx(l.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(b=S.products)&&void 0!==b?b:[],title:"Select Products",onClose:()=>{_(void 0)},selectedProducts:O===T.DISCOUNT_PRODUCTS.ENTITLED?f:x,setSelectedProducts:O===T.DISCOUNT_PRODUCTS.ENTITLED?Y:R,onSearchKeyChange:S.onProductSearch})})),!!v&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsx(l.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(y=S.collection)&&void 0!==y?y:[],title:"Select Products",onClose:()=>{D(void 0)},selectedProducts:v===T.DISCOUNT_PRODUCTS.ENTITLED?M:w,setSelectedProducts:v===T.DISCOUNT_PRODUCTS.ENTITLED?G:L,onSearchKeyChange:S.onCollectionSearch,searchPlaceholder:"Search collections..."})}))]}))};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),o=require("./type.js");require("../dropdown/DropdownPopover/index.js");var i=require("../dropdown/Dropdown.js");require("../dropdown/ChipDropdown.js"),require("../zeroState/ZeroState.js");var n=require("../TypographyStyle.js"),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"),a=require("../tag/Tag.js"),u=require("../tooltips/Tooltip.js"),c=require("../../assets/icons/triangle_error.svg.js"),l=require("./DiscountModal.styled.js"),p=require("./DiscountUtils.js"),T=require("./DynamicCoupon/DynamicCoupon.js"),E=require("./StaticCoupon/StaticCoupon.js");exports.DiscountModal=S=>{var C,I,P,_;const[y,O]=t.useState(),[b,D]=t.useState(null!==(C=S.data)&&void 0!==C?C:"string"==typeof S.hideOption?{isStaticCoupon:"dynamic"===S.hideOption}:{isStaticCoupon:!1}),[N,j]=t.useState(!0),[v,U]=t.useState(),[m,g]=t.useState((null===(I=S.data)||void 0===I?void 0:I.minAmount)?o.MIN_PURCHASE_REQUIREMENT.AMOUNT:(null===(P=S.data)||void 0===P?void 0:P.minQuantity)?o.MIN_PURCHASE_REQUIREMENT.QUANTITY:o.MIN_PURCHASE_REQUIREMENT.NA),[h,q]=t.useState([]),[A,x]=t.useState([]),[R,Y]=t.useState(0);t.useEffect((()=>{let e;S.hideProbability||(e=M()),j(p.validateDiscountData(b,m,v,S.hideProbability||!1,e,!!b.isStaticCoupon)),S.hideProbability||M()}),[]),t.useEffect((()=>{let e;S.hideProbability||(e=M()),j(p.validateDiscountData(b,m,v,S.hideProbability||!1,e,!!b.isStaticCoupon))}),[b,R,v,m]),t.useEffect((()=>{var e,t;if(S.products){if(null===(e=S.data)||void 0===e?void 0:e.entitledProductIds){const e=S.products.filter((e=>{var t,o;return null===(o=null===(t=S.data)||void 0===t?void 0:t.entitledProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));x(e)}if(null===(t=S.data)||void 0===t?void 0:t.prerequisiteProductIds){const e=S.products.filter((e=>{var t,o;return null===(o=null===(t=S.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));q(e)}}}),[]),t.useEffect((()=>{const e=A.map((e=>parseInt(e.id)));D(Object.assign(Object.assign({},b),{entitledProductIds:e}))}),[A]),t.useEffect((()=>{const e=h.map((e=>parseInt(e.id)));D(Object.assign(Object.assign({},b),{prerequisiteProductIds:e}))}),[h]),t.useEffect((()=>{b.targetType===o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE?U(o.DISCOUNT_TYPES.FREE_SHIPPING):b.targetSelection===o.DISCOUNT_TARGET_SELECTION.ENTITLED?U(o.DISCOUNT_TYPES.BUY_X_GET_Y):b.valueType===o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT?U(o.DISCOUNT_TYPES.FIXED_AMOUNT):b.valueType===o.DISCOUNT_VALUE_TYPES.PERCENTAGE&&U(o.DISCOUNT_TYPES.PERCENTAGE)}),[]);const L=[{value:o.DISCOUNT_TYPES.FIXED_AMOUNT,label:"Fixed Amount",selected:v===o.DISCOUNT_TYPES.FIXED_AMOUNT},{value:o.DISCOUNT_TYPES.PERCENTAGE,label:"Percentage",selected:v===o.DISCOUNT_TYPES.PERCENTAGE},{value:o.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:v===o.DISCOUNT_TYPES.BUY_X_GET_Y},{value:o.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:v===o.DISCOUNT_TYPES.FREE_SHIPPING}],M=()=>{if(!S.quadrant||!S.probability)return;const e=[...S.probability];let t=[];e.length>=S.quadrant&&e.splice(S.quadrant-1,1),t=e;const o=t.reduce(((e,t)=>e+t),0)+(b.probability||0);return Y(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},w=e=>{const t=e.value;U(t),t===o.DISCOUNT_TYPES.FREE_SHIPPING?(q([]),x([]),D(Object.assign(Object.assign({},b),{value:100,targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.SHIPPING_LINE,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,entitledQuantity:void 0,prerequisiteQuantity:void 0,entitledProductIds:void 0,prerequisiteProductIds:void 0}))):t===o.DISCOUNT_TYPES.BUY_X_GET_Y?D(Object.assign(Object.assign({},b),{targetSelection:o.DISCOUNT_TARGET_SELECTION.ENTITLED,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE})):t===o.DISCOUNT_TYPES.PERCENTAGE?(q([]),x([]),D(Object.assign(Object.assign({},b),{targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.PERCENTAGE,entitledQuantity:void 0,prerequisiteQuantity:void 0,entitledProductIds:void 0,prerequisiteProductIds:void 0}))):t===o.DISCOUNT_TYPES.FIXED_AMOUNT&&(q([]),x([]),D(Object.assign(Object.assign({},b),{targetSelection:o.DISCOUNT_TARGET_SELECTION.ALL,targetType:o.DISCOUNT_TARGET_TYPES.LINE_ITEM,valueType:o.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT,entitledQuantity:void 0,prerequisiteQuantity:void 0,entitledProductIds:void 0,prerequisiteProductIds:void 0})))};return e.jsxs(s.StyledModal,Object.assign({open:S.isOpen,headingTitle:y?"Select Products":S.title,headingSubtitle:y?void 0:S.subTitle,footerLeftCustomElement:!S.quadrant||S.hideProbability?e.jsx(e.Fragment,{}):R<=1?e.jsx(a.Tag,{theme:"light",tagText:`Current probability sum: ${R}`,type:"white"}):e.jsx(u.Tooltip,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e.jsx("div",{children:e.jsx(a.Tag,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${R}`,type:"negative",LeadingIcon:c.default})})})),headerRightCustomElement:S.allowStaticCoupon||y?void 0:e.jsx(i.Dropdown,{options:L,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{w(e)}}),onClose:S.onClose,footerShadow:!0,primaryButton:y?{buttonType:"primary",onClick:()=>{O(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:N,onClick:()=>{b.isStaticCoupon?S.onSaveClicked({quadrant:b.quadrant,couponCode:b.couponCode,description:b.description,isStaticCoupon:b.isStaticCoupon,probability:b.probability,title:b.title}):S.onSaveClicked(b),D({})}},secondaryButton:y?{buttonType:"tertiaryGray",onClick:()=>{O(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:S.onClose,buttonText:"Close"}},{children:[!y&&e.jsxs(l.StyledDiscountDialogueContainer,{children:[S.allowStaticCoupon&&!y&&e.jsxs(l.CouponTypeContainerStyled,Object.assign({selectedDiv:b.isStaticCoupon?1:2},{children:["static"===S.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{D({isStaticCoupon:!0,couponCode:b.couponCode,description:b.description,quadrant:b.quadrant})}},{children:[e.jsx(n.TitleSmall,Object.assign({style:b.isStaticCoupon?{color:r.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"Static code"})),e.jsx(n.BodyCaption,Object.assign({style:b.isStaticCoupon?{color:r.DEFAULT_THEME.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===S.hideOption?e.jsx(e.Fragment,{}):e.jsxs("div",Object.assign({className:"coupon-type__container",onClick:()=>{D(Object.assign(Object.assign({},b),{isStaticCoupon:!1}))}},{children:[e.jsx(n.TitleSmall,Object.assign({style:b.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"Dynamic code"})),e.jsx(n.BodyCaption,Object.assign({style:b.isStaticCoupon?{}:{color:r.DEFAULT_THEME.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),b.isStaticCoupon&&!y&&e.jsx(E.default,{discountData:b,setDiscountData:D,hideProbability:S.hideProbability||!1,discountAdminUrl:S.discountAdminUrl}),!b.isStaticCoupon&&!y&&e.jsx(T.default,{currency:S.currency,entitledProducts:A,prerequisiteProducts:h,setEntitledProducts:x,setPrerequisiteProducts:q,discountData:b,productPickerOpen:y,setIsProductPickerOpen:O,setDiscountData:D,selectedCouponType:v,setSelectedCouponType:U,selectedMinimumRequirement:m,setSelectedMinimumRequirement:g,hideProbability:S.hideProbability||!1,hideExpiration:S.hideExpiration||!1,allowStaticCoupon:S.allowStaticCoupon,onChangeCouponType:w})]}),!!y&&e.jsx("div",Object.assign({style:{padding:"12px 0"}},{children:e.jsx(d.ProductPickerContent,{show:!0,onSave:()=>{},products:null!==(_=S.products)&&void 0!==_?_:[],title:"Select Products",onClose:()=>{O(void 0)},selectedProducts:y===T.DISCOUNT_PRODUCTS.ENTITLED?A:h,setSelectedProducts:y===T.DISCOUNT_PRODUCTS.ENTITLED?x:q,onSearchKeyChange:S.onProductSearch})}))]}))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./type.js");exports.validateDiscountData=(i,t,r,n,u,T)=>{var E,l
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./type.js");exports.validateDiscountData=(i,t,r,n,u,T)=>{var E,l;if(!i.title)return!0;if(!n){if(isNaN(i.probability))return!0;if((i.probability||0)>1)return!0;if((i.probability||0)<0)return!0;if(u>1)return!0}if(T){if(!(null==i?void 0:i.couponCode))return!0;if(!i.description)return!0}else{if(r&&r===e.DISCOUNT_TYPES.FIXED_AMOUNT){if(i.valueType!==e.DISCOUNT_VALUE_TYPES.FIXED_AMOUNT)return!0;if(!(null==i?void 0:i.value)||(null==i?void 0:i.value)<=0)return!0;if(t===e.MIN_PURCHASE_REQUIREMENT.AMOUNT&&(!i.minAmount||(null==i?void 0:i.minAmount)<=0))return!0;if(t===e.MIN_PURCHASE_REQUIREMENT.QUANTITY&&(!(null==i?void 0:i.minQuantity)||(null==i?void 0:i.minQuantity)<=0))return!0;if(i.targetType!==e.DISCOUNT_TARGET_TYPES.LINE_ITEM)return!0;if(i.targetSelection!==e.DISCOUNT_TARGET_SELECTION.ALL)return!0}else if(r&&r===e.DISCOUNT_TYPES.PERCENTAGE){if(i.valueType!==e.DISCOUNT_VALUE_TYPES.PERCENTAGE)return!0;if(!(null==i?void 0:i.value)||(null==i?void 0:i.value)<=0||(null==i?void 0:i.value)>100)return!0;if(t===e.MIN_PURCHASE_REQUIREMENT.AMOUNT&&(!i.minAmount||(null==i?void 0:i.minAmount)<=0))return!0;if(t===e.MIN_PURCHASE_REQUIREMENT.QUANTITY&&(!(null==i?void 0:i.minQuantity)||(null==i?void 0:i.minQuantity)<=0))return!0;if(i.targetType!==e.DISCOUNT_TARGET_TYPES.LINE_ITEM)return!0;if(i.targetSelection!==e.DISCOUNT_TARGET_SELECTION.ALL)return!0}else if(r&&r===e.DISCOUNT_TYPES.BUY_X_GET_Y){if(!(i.entitledQuantity&&(null===(E=i.entitledProductIds)||void 0===E?void 0:E.length)&&i.prerequisiteQuantity&&(null===(l=i.prerequisiteProductIds)||void 0===l?void 0:l.length)))return!0;if(i.valueType!==e.DISCOUNT_VALUE_TYPES.PERCENTAGE)return!0;if(!i.value)return!0;if(i.value<=0||i.value>100)return!0;if(i.targetSelection!==e.DISCOUNT_TARGET_SELECTION.ENTITLED)return!0;if(i.targetType!==e.DISCOUNT_TARGET_TYPES.LINE_ITEM)return!0}else if(r&&e.DISCOUNT_TYPES.FREE_SHIPPING){if(i.valueType!==e.DISCOUNT_VALUE_TYPES.PERCENTAGE)return!0;if(i.targetType!==e.DISCOUNT_TARGET_TYPES.SHIPPING_LINE)return!0;if(100!==i.value)return!0;if(i.targetSelection!==e.DISCOUNT_TARGET_SELECTION.ALL)return!0;if(t===e.MIN_PURCHASE_REQUIREMENT.AMOUNT&&(!i.minAmount||(null==i?void 0:i.minAmount)<=0))return!0;if(t===e.MIN_PURCHASE_REQUIREMENT.QUANTITY&&(!(null==i?void 0:i.minQuantity)||(null==i?void 0:i.minQuantity)<=0))return!0}if(null!==i.expireAfter&&void 0!==i.expireAfter&&i.expireAfter<=0)return!0;if(i.expireAt&&i.expireAt<new Date)return!0}return!1};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DISCOUNT_TYPES, ICouponData, MIN_PURCHASE_REQUIREMENT } from "../type";
|
|
3
3
|
import { SingleOption } from "../../dropdown/type";
|
|
4
|
-
import {
|
|
4
|
+
import { Product } from "../../product-picker/type";
|
|
5
5
|
export declare enum DISCOUNT_PRODUCTS {
|
|
6
6
|
ENTITLED = "entitled",
|
|
7
7
|
PREREQUISITE = "prerequisite"
|
|
@@ -9,9 +9,7 @@ export declare enum DISCOUNT_PRODUCTS {
|
|
|
9
9
|
interface DynamicCouponI {
|
|
10
10
|
discountData: ICouponData;
|
|
11
11
|
setIsProductPickerOpen: React.Dispatch<React.SetStateAction<DISCOUNT_PRODUCTS | undefined>>;
|
|
12
|
-
setIsCollectionPickerOpen: React.Dispatch<React.SetStateAction<DISCOUNT_PRODUCTS | undefined>>;
|
|
13
12
|
productPickerOpen: DISCOUNT_PRODUCTS | undefined;
|
|
14
|
-
collectionPickerOpen: DISCOUNT_PRODUCTS | undefined;
|
|
15
13
|
setDiscountData: React.Dispatch<React.SetStateAction<ICouponData>>;
|
|
16
14
|
selectedCouponType: DISCOUNT_TYPES | undefined;
|
|
17
15
|
setSelectedCouponType: React.Dispatch<React.SetStateAction<DISCOUNT_TYPES | undefined>>;
|
|
@@ -19,12 +17,8 @@ interface DynamicCouponI {
|
|
|
19
17
|
setSelectedMinimumRequirement: React.Dispatch<React.SetStateAction<MIN_PURCHASE_REQUIREMENT>>;
|
|
20
18
|
entitledProducts: Product[];
|
|
21
19
|
prerequisiteProducts: Product[];
|
|
22
|
-
entitledCollections: Collection[];
|
|
23
|
-
prerequisiteCollections: Collection[];
|
|
24
20
|
setEntitledProducts: React.Dispatch<React.SetStateAction<Product[]>>;
|
|
25
21
|
setPrerequisiteProducts: React.Dispatch<React.SetStateAction<Product[]>>;
|
|
26
|
-
setEntitledCollections: React.Dispatch<React.SetStateAction<Collection[]>>;
|
|
27
|
-
setPrerequisiteCollections: React.Dispatch<React.SetStateAction<Collection[]>>;
|
|
28
22
|
onChangeCouponType: (option: SingleOption) => void;
|
|
29
23
|
hideExpiration?: boolean;
|
|
30
24
|
hideProbability?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../button/Button.js");require("react");var s=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"),a=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("../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js"),require("../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js");var r=require("../../input/Input.js"),o=require("../../../assets/icons/cross.svg.js");require("../../dropdown/MenuItem/MenuItem.js"),require("../../modals/styledModal.js"),require("../../../node_modules/lodash.debounce/index.js"),require("../../bik-layout/CommonStyles.js"),require("../../product-picker/ProductPicker.styled.js"),require("../../../utils/DateUtils.js"),require("../../tag/Tag.js"),require("@tippyjs/react"),require("../../tooltips/TooltipInternal.js");var l=require("../DiscountModal.styled.js"),d=require("../CouponExpiration/CouponExpiration.js"),c=require("../../radioButton/RadioButton.js"),u=require("../../../assets/icons/cursor.svg.js"),p=require("../../../assets/icons/plus.svg.js");const j="https://jkfenner.com/wp-content/uploads/2019/11/default.jpg";var T;function x(){return null}exports.DISCOUNT_PRODUCTS=void 0,(T=exports.DISCOUNT_PRODUCTS||(exports.DISCOUNT_PRODUCTS={})).ENTITLED="entitled",T.PREREQUISITE="prerequisite";exports.default=T=>{var m;const E=[{value:s.DISCOUNT_TYPES.FIXED_AMOUNT,label:"Fixed Amount",selected:T.selectedCouponType===s.DISCOUNT_TYPES.FIXED_AMOUNT},{value:s.DISCOUNT_TYPES.PERCENTAGE,label:"Percentage",selected:T.selectedCouponType===s.DISCOUNT_TYPES.PERCENTAGE},{value:s.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:T.selectedCouponType===s.DISCOUNT_TYPES.BUY_X_GET_Y},{value:s.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:T.selectedCouponType===s.DISCOUNT_TYPES.FREE_SHIPPING}],g=[{selected:T.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.NA,label:"No minimum requirements",value:s.MIN_PURCHASE_REQUIREMENT.NA},{selected:T.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT,label:`Minimum purchase amount (${null!==(m=T.currency)&&void 0!==m?m:"₹"})`,value:s.MIN_PURCHASE_REQUIREMENT.AMOUNT},{selected:T.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.QUANTITY,label:"Minimum quantity of items",value:s.MIN_PURCHASE_REQUIREMENT.QUANTITY}],D=()=>{var t,a,o,l,d;return e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsxs("div",Object.assign({className:"input__wrapper"},{children:[e.jsx(n.BodySecondary,Object.assign({style:{marginBottom:10}},{children:"Min purchase requirements"})),e.jsx(i.Dropdown,{options:g,placement:"bottom-start",onSelect:e=>{const t=e.value;T.setSelectedMinimumRequirement(t),T.setDiscountData(Object.assign(Object.assign({},T.discountData),{minQuantity:void 0,minAmount:void 0}))}})]})),e.jsx("div",Object.assign({className:"input__wrapper"},{children:T.selectedMinimumRequirement!==s.MIN_PURCHASE_REQUIREMENT.NA&&e.jsx(r.Input,{value:T.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?null!==(a=null===(t=T.discountData.minAmount)||void 0===t?void 0:t.toString())&&void 0!==a?a:"":null!==(l=null===(o=T.discountData.minQuantity)||void 0===o?void 0:o.toString())&&void 0!==l?l:"",onChangeText:e=>{T.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?T.setDiscountData(Object.assign(Object.assign({},T.discountData),{minAmount:parseInt(e)})):T.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.QUANTITY&&T.setDiscountData(Object.assign(Object.assign({},T.discountData),{minQuantity:parseInt(e)}))},labelText:T.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?"Minimum purchase amount":"Minimum purchase quantity",prefixText:T.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?null!==(d=T.currency)&&void 0!==d?d:"₹":void 0,type:"number",placeholder:T.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?"1000.00":"2"})}))]}))},b=s=>{var i,l,d;const c=s===exports.DISCOUNT_PRODUCTS.ENTITLED?T.entitledProducts:T.prerequisiteProducts,u=null!==(i=s===exports.DISCOUNT_PRODUCTS.ENTITLED?T.entitledCollections:T.prerequisiteCollections)&&void 0!==i?i:[];return e.jsxs(e.Fragment,{children:[e.jsx(n.TitleRegular,{children:s===exports.DISCOUNT_PRODUCTS.PREREQUISITE?"Customer spends":"Customer gets"}),e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{value:s===exports.DISCOUNT_PRODUCTS.ENTITLED?null===(l=T.discountData.entitledQuantity)||void 0===l?void 0:l.toString():null===(d=T.discountData.prerequisiteQuantity)||void 0===d?void 0:d.toString(),type:"number",onChangeText:e=>{s===exports.DISCOUNT_PRODUCTS.ENTITLED?T.setDiscountData(Object.assign(Object.assign({},T.discountData),{entitledQuantity:parseInt(e)})):T.setDiscountData(Object.assign(Object.assign({},T.discountData),{prerequisiteQuantity:parseInt(e)}))},labelText:"Add quantity",placeholder:"Add quantity"})})),e.jsx("div",{className:"input__wrapper"})]})),e.jsxs("div",Object.assign({style:{display:"flex",gap:18}},{children:[e.jsx(t.Button,{buttonText:"Add product",buttonType:"tertiary",LeadingIcon:p.default,onClick:()=>{T.setIsProductPickerOpen(s)}}),e.jsx(t.Button,{buttonText:"Add collection",buttonType:"tertiary",LeadingIcon:p.default,onClick:()=>{T.setIsCollectionPickerOpen(s)}})]})),!!c.length&&e.jsxs("div",Object.assign({style:{margin:"8px 0"}},{children:[e.jsx(n.TitleSmall,{children:"Products"}),c.map((t=>e.jsxs("div",Object.assign({style:{padding:"20px 0 12px 0",borderBottom:`1px solid ${a.DEFAULT_THEME.colorsV2.stroke.primary}`,display:"flex"}},{children:[e.jsxs("div",Object.assign({style:{display:"flex",gap:16,alignItems:"center",flex:.8}},{children:[e.jsx("img",{src:t.image,onError:e=>{e.target.onerror=null,e.target.src=j},style:{height:40,width:40,objectFit:"cover",borderRadius:4}}),e.jsx(n.TitleSmall,{children:t.name})]})),e.jsx("div",Object.assign({style:{flex:.2,display:"flex",justifyContent:"flex-end",alignItems:"center"}},{children:e.jsx("div",Object.assign({style:{cursor:"pointer"},onClick:()=>{const e=c.filter((e=>e.id!==t.id));s===exports.DISCOUNT_PRODUCTS.ENTITLED?T.setEntitledProducts(e):T.setPrerequisiteProducts(e)}},{children:e.jsx(o.default,{width:14,color:a.DEFAULT_THEME.colorsV2.content.primary})}))}))]}),t.id)))]})),!!u.length&&e.jsxs("div",Object.assign({style:{margin:"8px 0"}},{children:[e.jsx(n.TitleSmall,{children:"Collections"}),u.map((t=>e.jsxs("div",Object.assign({style:{padding:"20px 0 12px 0",borderBottom:`1px solid ${a.DEFAULT_THEME.colorsV2.stroke.primary}`,display:"flex"}},{children:[e.jsxs("div",Object.assign({style:{display:"flex",gap:16,alignItems:"center",flex:.8}},{children:[e.jsx("img",{src:t.image,onError:e=>{e.target.onerror=null,e.target.src=j},style:{height:40,width:40,objectFit:"cover",borderRadius:4}}),e.jsx(n.TitleSmall,{children:t.name})]})),e.jsx("div",Object.assign({style:{flex:.2,display:"flex",justifyContent:"flex-end",alignItems:"center"}},{children:e.jsx("div",Object.assign({style:{cursor:"pointer"},onClick:()=>{const e=u.filter((e=>e.id!==t.id));s===exports.DISCOUNT_PRODUCTS.ENTITLED?T.setEntitledCollections(e):T.setPrerequisiteCollections(e)}},{children:e.jsx(o.default,{width:14,color:a.DEFAULT_THEME.colorsV2.content.primary})}))}))]}),t.id)))]}))]})};return e.jsxs(l.DynamicCouponContainer,{children:[T.allowStaticCoupon&&e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(i.Dropdown,{options:E,width:"290px",placement:"bottom-start",onSelect:e=>{T.onChangeCouponType(e)}})})),e.jsx("div",{className:"input__wrapper"})]})),(T.selectedCouponType===s.DISCOUNT_TYPES.PERCENTAGE||T.selectedCouponType===s.DISCOUNT_TYPES.FIXED_AMOUNT)&&(()=>{var t,i,n,a;return e.jsxs(e.Fragment,{children:[e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{value:T.discountData.title,onChangeText:e=>{T.setDiscountData(Object.assign(Object.assign({},T.discountData),{title:e}))},maxCharLimit:18,labelText:"Code title",placeholder:"eg: Flat 50% Off"})})),e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{value:null===(i=null===(t=T.discountData)||void 0===t?void 0:t.value)||void 0===i?void 0:i.toString(),labelText:"Discount code value",type:"number",onChangeText:e=>{T.setDiscountData(Object.assign(Object.assign({},T.discountData),{value:parseInt(e)}))},placeholder:T.selectedCouponType===s.DISCOUNT_TYPES.FIXED_AMOUNT?"0.00":"Enter a value",prefixText:T.selectedCouponType===s.DISCOUNT_TYPES.FIXED_AMOUNT?null!==(n=T.currency)&&void 0!==n?n:"₹":void 0,suffixText:T.selectedCouponType===s.DISCOUNT_TYPES.PERCENTAGE?"%":void 0})}))]})),D(),!T.hideProbability&&e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{type:"number",value:null===(a=T.discountData.probability)||void 0===a?void 0:a.toString(),onChangeText:e=>{T.setDiscountData(Object.assign(Object.assign({},T.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})})),e.jsx("div",{className:"input__wrapper"})]}))]})})(),T.selectedCouponType===s.DISCOUNT_TYPES.FREE_SHIPPING&&(()=>{var t;return e.jsxs(e.Fragment,{children:[e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{value:T.discountData.title,onChangeText:e=>{T.setDiscountData(Object.assign(Object.assign({},T.discountData),{title:e}))},labelText:"Code title",placeholder:"eg: Flat 50% Off",maxCharLimit:18})})),e.jsx("div",Object.assign({className:"input__wrapper"},{children:!T.hideProbability&&e.jsx(r.Input,{value:null===(t=T.discountData.probability)||void 0===t?void 0:t.toString(),type:"number",onChangeText:e=>{T.setDiscountData(Object.assign(Object.assign({},T.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})}))]})),D()]})})(),T.selectedCouponType===s.DISCOUNT_TYPES.BUY_X_GET_Y&&(()=>{var t;return e.jsxs(l.DynamicCouponContainer,{children:[e.jsx("div",Object.assign({className:"input__rows"},{children:e.jsxs("div",Object.assign({style:{display:"flex",gap:20,flex:1}},{children:[e.jsx("div",Object.assign({style:{flex:1}},{children:e.jsx(r.Input,{value:T.discountData.title,onChangeText:e=>{T.setDiscountData(Object.assign(Object.assign({},T.discountData),{title:e}))},maxCharLimit:18,labelText:"Code title",placeholder:"eg: Flat 50% Off"})})),!T.hideProbability&&e.jsx("div",Object.assign({style:{flex:1}},{children:e.jsx(r.Input,{value:null===(t=T.discountData.probability)||void 0===t?void 0:t.toString(),type:"number",onChangeText:e=>{T.setDiscountData(Object.assign(Object.assign({},T.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})}))]}))})),e.jsx(x,{}),b(exports.DISCOUNT_PRODUCTS.PREREQUISITE),e.jsx(x,{}),b(exports.DISCOUNT_PRODUCTS.ENTITLED),e.jsx(x,{}),e.jsx(n.TitleRegular,{children:"At a discount value"}),e.jsxs("div",Object.assign({style:{display:"flex",gap:18,alignItems:"center"}},{children:[e.jsx(c.RadioButton,{isActive:100!==T.discountData.value,onValueChange:()=>{T.setDiscountData(Object.assign(Object.assign({},T.discountData),{value:void 0}))}}),e.jsx(n.BodySecondary,{children:"Percentage"}),100!==T.discountData.value&&e.jsx(r.Input,{variant:"small",onChangeText:e=>{T.setDiscountData(Object.assign(Object.assign({},T.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Enter percentage eg: 10%",suffixText:"%",width:"238px"})]})),e.jsxs("div",Object.assign({style:{display:"flex",gap:18}},{children:[e.jsx(c.RadioButton,{isActive:100===T.discountData.value,onValueChange:e=>{e?T.setDiscountData(Object.assign(Object.assign({},T.discountData),{value:100})):T.setDiscountData(Object.assign(Object.assign({},T.discountData),{value:void 0}))}}),e.jsx(n.BodySecondary,{children:"Free"})]}))]})})(),T.selectedCouponType&&!T.hideExpiration&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{height:6,borderTop:`1px solid ${a.DEFAULT_THEME.colorsV2.stroke.primary}`,marginTop:12}}),e.jsx(d.CouponExpiration,{discountData:T.discountData,setDiscountData:T.setDiscountData})]}),!T.selectedCouponType&&e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:10,padding:"40px 0",justifyContent:"center",alignItems:"center"}},{children:[e.jsx("div",Object.assign({style:{height:52,width:52,backgroundColor:a.DEFAULT_THEME.colorsV2.background.inverse,borderRadius:"50%",display:"flex",justifyContent:"center",alignItems:"center"}},{children:e.jsx(u.default,{width:32,color:a.DEFAULT_THEME.colorsV2.content.primaryInverse})})),e.jsx(n.TitleMedium,{children:"No discount has been selected"}),e.jsx(n.BodyPrimary,{children:"Please select a discount type"})]}))]})};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../button/Button.js");require("react");var s=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"),a=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("../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js"),require("../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js");var r=require("../../input/Input.js"),o=require("../../../assets/icons/cross.svg.js");require("../../dropdown/MenuItem/MenuItem.js"),require("../../modals/styledModal.js"),require("../../../node_modules/lodash.debounce/index.js"),require("../../bik-layout/CommonStyles.js"),require("../../product-picker/ProductPicker.styled.js"),require("../../../utils/DateUtils.js"),require("../../tag/Tag.js"),require("@tippyjs/react"),require("../../tooltips/TooltipInternal.js");var l=require("../DiscountModal.styled.js"),d=require("../CouponExpiration/CouponExpiration.js"),u=require("../../radioButton/RadioButton.js"),c=require("../../../assets/icons/cursor.svg.js"),p=require("../../../assets/icons/plus.svg.js");var j;function T(){return null}exports.DISCOUNT_PRODUCTS=void 0,(j=exports.DISCOUNT_PRODUCTS||(exports.DISCOUNT_PRODUCTS={})).ENTITLED="entitled",j.PREREQUISITE="prerequisite";exports.default=j=>{var m;const x=[{value:s.DISCOUNT_TYPES.FIXED_AMOUNT,label:"Fixed Amount",selected:j.selectedCouponType===s.DISCOUNT_TYPES.FIXED_AMOUNT},{value:s.DISCOUNT_TYPES.PERCENTAGE,label:"Percentage",selected:j.selectedCouponType===s.DISCOUNT_TYPES.PERCENTAGE},{value:s.DISCOUNT_TYPES.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:j.selectedCouponType===s.DISCOUNT_TYPES.BUY_X_GET_Y},{value:s.DISCOUNT_TYPES.FREE_SHIPPING,label:"Free shipping",selected:j.selectedCouponType===s.DISCOUNT_TYPES.FREE_SHIPPING}],E=[{selected:j.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.NA,label:"No minimum requirements",value:s.MIN_PURCHASE_REQUIREMENT.NA},{selected:j.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT,label:`Minimum purchase amount (${null!==(m=j.currency)&&void 0!==m?m:"₹"})`,value:s.MIN_PURCHASE_REQUIREMENT.AMOUNT},{selected:j.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.QUANTITY,label:"Minimum quantity of items",value:s.MIN_PURCHASE_REQUIREMENT.QUANTITY}],D=()=>{var t,a,o,l,d;return e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsxs("div",Object.assign({className:"input__wrapper"},{children:[e.jsx(n.BodySecondary,Object.assign({style:{marginBottom:10}},{children:"Min purchase requirements"})),e.jsx(i.Dropdown,{options:E,placement:"bottom-start",onSelect:e=>{const t=e.value;j.setSelectedMinimumRequirement(t),j.setDiscountData(Object.assign(Object.assign({},j.discountData),{minQuantity:void 0,minAmount:void 0}))}})]})),e.jsx("div",Object.assign({className:"input__wrapper"},{children:j.selectedMinimumRequirement!==s.MIN_PURCHASE_REQUIREMENT.NA&&e.jsx(r.Input,{value:j.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?null!==(a=null===(t=j.discountData.minAmount)||void 0===t?void 0:t.toString())&&void 0!==a?a:"":null!==(l=null===(o=j.discountData.minQuantity)||void 0===o?void 0:o.toString())&&void 0!==l?l:"",onChangeText:e=>{j.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?j.setDiscountData(Object.assign(Object.assign({},j.discountData),{minAmount:parseInt(e)})):j.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.QUANTITY&&j.setDiscountData(Object.assign(Object.assign({},j.discountData),{minQuantity:parseInt(e)}))},labelText:j.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?"Minimum purchase amount":"Minimum purchase quantity",prefixText:j.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?null!==(d=j.currency)&&void 0!==d?d:"₹":void 0,type:"number",placeholder:j.selectedMinimumRequirement===s.MIN_PURCHASE_REQUIREMENT.AMOUNT?"1000.00":"2"})}))]}))},b=s=>{var i,l;const d=s===exports.DISCOUNT_PRODUCTS.ENTITLED?j.entitledProducts:j.prerequisiteProducts;return e.jsxs(e.Fragment,{children:[e.jsx(n.TitleRegular,{children:s===exports.DISCOUNT_PRODUCTS.PREREQUISITE?"Customer spends":"Customer gets"}),e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{value:s===exports.DISCOUNT_PRODUCTS.ENTITLED?null===(i=j.discountData.entitledQuantity)||void 0===i?void 0:i.toString():null===(l=j.discountData.prerequisiteQuantity)||void 0===l?void 0:l.toString(),type:"number",onChangeText:e=>{s===exports.DISCOUNT_PRODUCTS.ENTITLED?j.setDiscountData(Object.assign(Object.assign({},j.discountData),{entitledQuantity:parseInt(e)})):j.setDiscountData(Object.assign(Object.assign({},j.discountData),{prerequisiteQuantity:parseInt(e)}))},labelText:"Add quantity",placeholder:"Add quantity"})})),e.jsx("div",{className:"input__wrapper"})]})),e.jsx("div",{children:e.jsx(t.Button,{buttonText:"Add product",buttonType:"tertiary",LeadingIcon:p.default,onClick:()=>{j.setIsProductPickerOpen(s)}})}),d.map((t=>e.jsxs("div",Object.assign({style:{padding:"20px 0 12px 0",borderBottom:`1px solid ${a.DEFAULT_THEME.colorsV2.stroke.primary}`,display:"flex"}},{children:[e.jsxs("div",Object.assign({style:{display:"flex",gap:16,alignItems:"center",flex:.8}},{children:[e.jsx("img",{src:t.image,onError:e=>{e.target.onerror=null,e.target.src="https://jkfenner.com/wp-content/uploads/2019/11/default.jpg"},style:{height:40,width:40,objectFit:"cover",borderRadius:4}}),e.jsx(n.TitleSmall,{children:t.name})]})),e.jsx("div",Object.assign({style:{flex:.2,display:"flex",justifyContent:"flex-end",alignItems:"center"}},{children:e.jsx("div",Object.assign({style:{cursor:"pointer"},onClick:()=>{const e=d.filter((e=>e.id!==t.id));s===exports.DISCOUNT_PRODUCTS.ENTITLED?j.setEntitledProducts(e):j.setPrerequisiteProducts(e)}},{children:e.jsx(o.default,{width:14,color:a.DEFAULT_THEME.colorsV2.content.primary})}))}))]}),t.id)))]})};return e.jsxs(l.DynamicCouponContainer,{children:[j.allowStaticCoupon&&e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(i.Dropdown,{options:x,width:"290px",placement:"bottom-start",onSelect:e=>{j.onChangeCouponType(e)}})})),e.jsx("div",{className:"input__wrapper"})]})),(j.selectedCouponType===s.DISCOUNT_TYPES.PERCENTAGE||j.selectedCouponType===s.DISCOUNT_TYPES.FIXED_AMOUNT)&&(()=>{var t,i,n,a;return e.jsxs(e.Fragment,{children:[e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{value:j.discountData.title,onChangeText:e=>{j.setDiscountData(Object.assign(Object.assign({},j.discountData),{title:e}))},maxCharLimit:18,labelText:"Code title",placeholder:"eg: Flat 50% Off"})})),e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{value:null===(i=null===(t=j.discountData)||void 0===t?void 0:t.value)||void 0===i?void 0:i.toString(),labelText:"Discount code value",type:"number",onChangeText:e=>{j.setDiscountData(Object.assign(Object.assign({},j.discountData),{value:parseInt(e)}))},placeholder:j.selectedCouponType===s.DISCOUNT_TYPES.FIXED_AMOUNT?"0.00":"Enter a value",prefixText:j.selectedCouponType===s.DISCOUNT_TYPES.FIXED_AMOUNT?null!==(n=j.currency)&&void 0!==n?n:"₹":void 0,suffixText:j.selectedCouponType===s.DISCOUNT_TYPES.PERCENTAGE?"%":void 0})}))]})),D(),!j.hideProbability&&e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{type:"number",value:null===(a=j.discountData.probability)||void 0===a?void 0:a.toString(),onChangeText:e=>{j.setDiscountData(Object.assign(Object.assign({},j.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})})),e.jsx("div",{className:"input__wrapper"})]}))]})})(),j.selectedCouponType===s.DISCOUNT_TYPES.FREE_SHIPPING&&(()=>{var t;return e.jsxs(e.Fragment,{children:[e.jsxs("div",Object.assign({className:"input__rows"},{children:[e.jsx("div",Object.assign({className:"input__wrapper"},{children:e.jsx(r.Input,{value:j.discountData.title,onChangeText:e=>{j.setDiscountData(Object.assign(Object.assign({},j.discountData),{title:e}))},labelText:"Code title",placeholder:"eg: Flat 50% Off",maxCharLimit:18})})),e.jsx("div",Object.assign({className:"input__wrapper"},{children:!j.hideProbability&&e.jsx(r.Input,{value:null===(t=j.discountData.probability)||void 0===t?void 0:t.toString(),type:"number",onChangeText:e=>{j.setDiscountData(Object.assign(Object.assign({},j.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})}))]})),D()]})})(),j.selectedCouponType===s.DISCOUNT_TYPES.BUY_X_GET_Y&&(()=>{var t;return e.jsxs(l.DynamicCouponContainer,{children:[e.jsx("div",Object.assign({className:"input__rows"},{children:e.jsxs("div",Object.assign({style:{display:"flex",gap:20,flex:1}},{children:[e.jsx("div",Object.assign({style:{flex:1}},{children:e.jsx(r.Input,{value:j.discountData.title,onChangeText:e=>{j.setDiscountData(Object.assign(Object.assign({},j.discountData),{title:e}))},maxCharLimit:18,labelText:"Code title",placeholder:"eg: Flat 50% Off"})})),!j.hideProbability&&e.jsx("div",Object.assign({style:{flex:1}},{children:e.jsx(r.Input,{value:null===(t=j.discountData.probability)||void 0===t?void 0:t.toString(),type:"number",onChangeText:e=>{j.setDiscountData(Object.assign(Object.assign({},j.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})}))]}))})),e.jsx(T,{}),b(exports.DISCOUNT_PRODUCTS.PREREQUISITE),e.jsx(T,{}),b(exports.DISCOUNT_PRODUCTS.ENTITLED),e.jsx(T,{}),e.jsx(n.TitleRegular,{children:"At a discount value"}),e.jsxs("div",Object.assign({style:{display:"flex",gap:18,alignItems:"center"}},{children:[e.jsx(u.RadioButton,{isActive:100!==j.discountData.value,onValueChange:e=>{j.setDiscountData(Object.assign(Object.assign({},j.discountData),{value:void 0}))}}),e.jsx(n.BodySecondary,{children:"Percentage"}),100!==j.discountData.value&&e.jsx(r.Input,{variant:"small",onChangeText:e=>{j.setDiscountData(Object.assign(Object.assign({},j.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Enter percentage eg: 10%",suffixText:"%",width:"238px"})]})),e.jsxs("div",Object.assign({style:{display:"flex",gap:18}},{children:[e.jsx(u.RadioButton,{isActive:100===j.discountData.value,onValueChange:e=>{e?j.setDiscountData(Object.assign(Object.assign({},j.discountData),{value:100})):j.setDiscountData(Object.assign(Object.assign({},j.discountData),{value:void 0}))}}),e.jsx(n.BodySecondary,{children:"Free"})]}))]})})(),j.selectedCouponType&&!j.hideExpiration&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{height:6,borderTop:`1px solid ${a.DEFAULT_THEME.colorsV2.stroke.primary}`,marginTop:12}}),e.jsx(d.CouponExpiration,{discountData:j.discountData,setDiscountData:j.setDiscountData})]}),!j.selectedCouponType&&e.jsxs("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:10,padding:"40px 0",justifyContent:"center",alignItems:"center"}},{children:[e.jsx("div",Object.assign({style:{height:52,width:52,backgroundColor:a.DEFAULT_THEME.colorsV2.background.inverse,borderRadius:"50%",display:"flex",justifyContent:"center",alignItems:"center"}},{children:e.jsx(c.default,{width:32,color:a.DEFAULT_THEME.colorsV2.content.primaryInverse})})),e.jsx(n.TitleMedium,{children:"No discount has been selected"}),e.jsx(n.BodyPrimary,{children:"Please select a discount type"})]}))]})};
|
|
@@ -13,15 +13,15 @@ export interface IInstaPost {
|
|
|
13
13
|
}
|
|
14
14
|
export interface ProductPickerProps {
|
|
15
15
|
show: boolean;
|
|
16
|
-
products: Product[]
|
|
16
|
+
products: Product[];
|
|
17
17
|
onClose: () => void;
|
|
18
18
|
title: string;
|
|
19
|
-
onSave: (productIds: Product[]
|
|
20
|
-
onSearchKeyChange: (key: string) => Promise<Product[]
|
|
19
|
+
onSave: (productIds: Product[]) => void;
|
|
20
|
+
onSearchKeyChange: (key: string) => Promise<Product[]>;
|
|
21
21
|
instaPost?: IInstaPost;
|
|
22
22
|
searchPlaceholder?: string;
|
|
23
|
-
selectedProducts: Product[]
|
|
24
|
-
setSelectedProducts: React.Dispatch<React.SetStateAction<Product[]
|
|
23
|
+
selectedProducts: Product[];
|
|
24
|
+
setSelectedProducts: React.Dispatch<React.SetStateAction<Product[]>>;
|
|
25
25
|
secondaryButtonProps?: ButtonProps;
|
|
26
26
|
}
|
|
27
27
|
export interface Product {
|
|
@@ -42,16 +42,6 @@ export interface Product {
|
|
|
42
42
|
name: string;
|
|
43
43
|
handle: string;
|
|
44
44
|
}
|
|
45
|
-
export interface Collection {
|
|
46
|
-
id: string;
|
|
47
|
-
name: string;
|
|
48
|
-
description: string;
|
|
49
|
-
image: string;
|
|
50
|
-
isHidden: boolean;
|
|
51
|
-
isPrivate: boolean;
|
|
52
|
-
handle: string;
|
|
53
|
-
isSmartCollection: boolean;
|
|
54
|
-
}
|
|
55
45
|
export interface Variant {
|
|
56
46
|
values: string[];
|
|
57
47
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ICouponData } from "./type";
|
|
3
|
-
import {
|
|
3
|
+
import { Product } from "../product-picker/type";
|
|
4
4
|
export interface DiscountDialogueI {
|
|
5
5
|
hideOption?: 'static' | 'dynamic';
|
|
6
6
|
isOpen: boolean;
|
|
@@ -11,13 +11,11 @@ export interface DiscountDialogueI {
|
|
|
11
11
|
data?: ICouponData;
|
|
12
12
|
onSaveClicked: (discountData: ICouponData) => void;
|
|
13
13
|
onProductSearch: (key: string) => Promise<Product[]>;
|
|
14
|
-
onCollectionSearch: (key: string) => Promise<Collection[]>;
|
|
15
14
|
hideExpiration?: boolean;
|
|
16
15
|
hideProbability?: boolean;
|
|
17
16
|
probability?: number[];
|
|
18
17
|
quadrant?: number;
|
|
19
18
|
products?: Product[];
|
|
20
|
-
collection?: Collection[];
|
|
21
19
|
discountAdminUrl?: string;
|
|
22
20
|
currency?: string;
|
|
23
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as t,jsx as e,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
|
|
1
|
+
import{jsxs as t,jsx as e,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 s,DISCOUNT_TARGET_SELECTION as a,DISCOUNT_VALUE_TYPES as c}from"./type.js";import"../dropdown/DropdownPopover/index.js";import{Dropdown as p}from"../dropdown/Dropdown.js";import"../dropdown/ChipDropdown.js";import"../zeroState/ZeroState.js";import{TitleSmall as l,BodyCaption as u}from"../TypographyStyle.js";import{DEFAULT_THEME as m}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 y}from"../modals/styledModal.js";import{ProductPickerContent as b}from"../product-picker/ProductPickerModal.js";import{Tag as E}from"../tag/Tag.js";import{Tooltip as v}from"../tooltips/Tooltip.js";import T from"../../assets/icons/triangle_error.svg.js";import{StyledDiscountDialogueContainer as C,CouponTypeContainerStyled as P}from"./DiscountModal.styled.js";import{validateDiscountData as g}from"./DiscountUtils.js";import I,{DISCOUNT_PRODUCTS as h}from"./DynamicCoupon/DynamicCoupon.js";import j from"./StaticCoupon/StaticCoupon.js";const S=S=>{var O,N,D,_;const[w,f]=i(),[A,q]=i(null!==(O=S.data)&&void 0!==O?O:"string"==typeof S.hideOption?{isStaticCoupon:"dynamic"===S.hideOption}:{isStaticCoupon:!1}),[G,M]=i(!0),[x,F]=i(),[L,R]=i((null===(N=S.data)||void 0===N?void 0:N.minAmount)?r.AMOUNT:(null===(D=S.data)||void 0===D?void 0:D.minQuantity)?r.QUANTITY:r.NA),[k,U]=i([]),[B,X]=i([]),[Y,Q]=i(0);n((()=>{let t;S.hideProbability||(t=V()),M(g(A,L,x,S.hideProbability||!1,t,!!A.isStaticCoupon)),S.hideProbability||V()}),[]),n((()=>{let t;S.hideProbability||(t=V()),M(g(A,L,x,S.hideProbability||!1,t,!!A.isStaticCoupon))}),[A,Y,x,L]),n((()=>{var t,e;if(S.products){if(null===(t=S.data)||void 0===t?void 0:t.entitledProductIds){const t=S.products.filter((t=>{var e,o;return null===(o=null===(e=S.data)||void 0===e?void 0:e.entitledProductIds)||void 0===o?void 0:o.includes(parseInt(t.id))}));X(t)}if(null===(e=S.data)||void 0===e?void 0:e.prerequisiteProductIds){const t=S.products.filter((t=>{var e,o;return null===(o=null===(e=S.data)||void 0===e?void 0:e.prerequisiteProductIds)||void 0===o?void 0:o.includes(parseInt(t.id))}));U(t)}}}),[]),n((()=>{const t=B.map((t=>parseInt(t.id)));q(Object.assign(Object.assign({},A),{entitledProductIds:t}))}),[B]),n((()=>{const t=k.map((t=>parseInt(t.id)));q(Object.assign(Object.assign({},A),{prerequisiteProductIds:t}))}),[k]),n((()=>{A.targetType===d.SHIPPING_LINE?F(s.FREE_SHIPPING):A.targetSelection===a.ENTITLED?F(s.BUY_X_GET_Y):A.valueType===c.FIXED_AMOUNT?F(s.FIXED_AMOUNT):A.valueType===c.PERCENTAGE&&F(s.PERCENTAGE)}),[]);const H=[{value:s.FIXED_AMOUNT,label:"Fixed Amount",selected:x===s.FIXED_AMOUNT},{value:s.PERCENTAGE,label:"Percentage",selected:x===s.PERCENTAGE},{value:s.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:x===s.BUY_X_GET_Y},{value:s.FREE_SHIPPING,label:"Free shipping",selected:x===s.FREE_SHIPPING}],V=()=>{if(!S.quadrant||!S.probability)return;const t=[...S.probability];let e=[];t.length>=S.quadrant&&t.splice(S.quadrant-1,1),e=t;const o=e.reduce(((t,e)=>t+e),0)+(A.probability||0);return Q(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},z=t=>{const e=t.value;F(e),e===s.FREE_SHIPPING?(U([]),X([]),q(Object.assign(Object.assign({},A),{value:100,targetSelection:a.ALL,targetType:d.SHIPPING_LINE,valueType:c.PERCENTAGE,entitledQuantity:void 0,prerequisiteQuantity:void 0,entitledProductIds:void 0,prerequisiteProductIds:void 0}))):e===s.BUY_X_GET_Y?q(Object.assign(Object.assign({},A),{targetSelection:a.ENTITLED,targetType:d.LINE_ITEM,valueType:c.PERCENTAGE})):e===s.PERCENTAGE?(U([]),X([]),q(Object.assign(Object.assign({},A),{targetSelection:a.ALL,targetType:d.LINE_ITEM,valueType:c.PERCENTAGE,entitledQuantity:void 0,prerequisiteQuantity:void 0,entitledProductIds:void 0,prerequisiteProductIds:void 0}))):e===s.FIXED_AMOUNT&&(U([]),X([]),q(Object.assign(Object.assign({},A),{targetSelection:a.ALL,targetType:d.LINE_ITEM,valueType:c.FIXED_AMOUNT,entitledQuantity:void 0,prerequisiteQuantity:void 0,entitledProductIds:void 0,prerequisiteProductIds:void 0})))};return t(y,Object.assign({open:S.isOpen,headingTitle:w?"Select Products":S.title,headingSubtitle:w?void 0:S.subTitle,footerLeftCustomElement:!S.quadrant||S.hideProbability?e(o,{}):Y<=1?e(E,{theme:"light",tagText:`Current probability sum: ${Y}`,type:"white"}):e(v,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:e("div",{children:e(E,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${Y}`,type:"negative",LeadingIcon:T})})})),headerRightCustomElement:S.allowStaticCoupon||w?void 0:e(p,{options:H,width:"200px",placement:"bottom-start",size:"small",onSelect:t=>{z(t)}}),onClose:S.onClose,footerShadow:!0,primaryButton:w?{buttonType:"primary",onClick:()=>{f(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:G,onClick:()=>{A.isStaticCoupon?S.onSaveClicked({quadrant:A.quadrant,couponCode:A.couponCode,description:A.description,isStaticCoupon:A.isStaticCoupon,probability:A.probability,title:A.title}):S.onSaveClicked(A),q({})}},secondaryButton:w?{buttonType:"tertiaryGray",onClick:()=>{f(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:S.onClose,buttonText:"Close"}},{children:[!w&&t(C,{children:[S.allowStaticCoupon&&!w&&t(P,Object.assign({selectedDiv:A.isStaticCoupon?1:2},{children:["static"===S.hideOption?e(o,{}):t("div",Object.assign({className:"coupon-type__container",onClick:()=>{q({isStaticCoupon:!0,couponCode:A.couponCode,description:A.description,quadrant:A.quadrant})}},{children:[e(l,Object.assign({style:A.isStaticCoupon?{color:m.colorsV2.content.brand}:{}},{children:"Static code"})),e(u,Object.assign({style:A.isStaticCoupon?{color:m.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===S.hideOption?e(o,{}):t("div",Object.assign({className:"coupon-type__container",onClick:()=>{q(Object.assign(Object.assign({},A),{isStaticCoupon:!1}))}},{children:[e(l,Object.assign({style:A.isStaticCoupon?{}:{color:m.colorsV2.content.brand}},{children:"Dynamic code"})),e(u,Object.assign({style:A.isStaticCoupon?{}:{color:m.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),A.isStaticCoupon&&!w&&e(j,{discountData:A,setDiscountData:q,hideProbability:S.hideProbability||!1,discountAdminUrl:S.discountAdminUrl}),!A.isStaticCoupon&&!w&&e(I,{currency:S.currency,entitledProducts:B,prerequisiteProducts:k,setEntitledProducts:X,setPrerequisiteProducts:U,discountData:A,productPickerOpen:w,setIsProductPickerOpen:f,setDiscountData:q,selectedCouponType:x,setSelectedCouponType:F,selectedMinimumRequirement:L,setSelectedMinimumRequirement:R,hideProbability:S.hideProbability||!1,hideExpiration:S.hideExpiration||!1,allowStaticCoupon:S.allowStaticCoupon,onChangeCouponType:z})]}),!!w&&e("div",Object.assign({style:{padding:"12px 0"}},{children:e(b,{show:!0,onSave:()=>{},products:null!==(_=S.products)&&void 0!==_?_:[],title:"Select Products",onClose:()=>{f(void 0)},selectedProducts:w===h.ENTITLED?B:k,setSelectedProducts:w===h.ENTITLED?X:U,onSearchKeyChange:S.onProductSearch})}))]}))};export{S as DiscountModal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DISCOUNT_TYPES as e,DISCOUNT_VALUE_TYPES as i,MIN_PURCHASE_REQUIREMENT as t,DISCOUNT_TARGET_TYPES as r,DISCOUNT_TARGET_SELECTION as n}from"./type.js";const u=(u,l,o,
|
|
1
|
+
import{DISCOUNT_TYPES as e,DISCOUNT_VALUE_TYPES as i,MIN_PURCHASE_REQUIREMENT as t,DISCOUNT_TARGET_TYPES as r,DISCOUNT_TARGET_SELECTION as n}from"./type.js";const u=(u,l,f,o,a,v)=>{var T,d;if(!u.title)return!0;if(!o){if(isNaN(u.probability))return!0;if((u.probability||0)>1)return!0;if((u.probability||0)<0)return!0;if(a>1)return!0}if(v){if(!(null==u?void 0:u.couponCode))return!0;if(!u.description)return!0}else{if(f&&f===e.FIXED_AMOUNT){if(u.valueType!==i.FIXED_AMOUNT)return!0;if(!(null==u?void 0:u.value)||(null==u?void 0:u.value)<=0)return!0;if(l===t.AMOUNT&&(!u.minAmount||(null==u?void 0:u.minAmount)<=0))return!0;if(l===t.QUANTITY&&(!(null==u?void 0:u.minQuantity)||(null==u?void 0:u.minQuantity)<=0))return!0;if(u.targetType!==r.LINE_ITEM)return!0;if(u.targetSelection!==n.ALL)return!0}else if(f&&f===e.PERCENTAGE){if(u.valueType!==i.PERCENTAGE)return!0;if(!(null==u?void 0:u.value)||(null==u?void 0:u.value)<=0||(null==u?void 0:u.value)>100)return!0;if(l===t.AMOUNT&&(!u.minAmount||(null==u?void 0:u.minAmount)<=0))return!0;if(l===t.QUANTITY&&(!(null==u?void 0:u.minQuantity)||(null==u?void 0:u.minQuantity)<=0))return!0;if(u.targetType!==r.LINE_ITEM)return!0;if(u.targetSelection!==n.ALL)return!0}else if(f&&f===e.BUY_X_GET_Y){if(!(u.entitledQuantity&&(null===(T=u.entitledProductIds)||void 0===T?void 0:T.length)&&u.prerequisiteQuantity&&(null===(d=u.prerequisiteProductIds)||void 0===d?void 0:d.length)))return!0;if(u.valueType!==i.PERCENTAGE)return!0;if(!u.value)return!0;if(u.value<=0||u.value>100)return!0;if(u.targetSelection!==n.ENTITLED)return!0;if(u.targetType!==r.LINE_ITEM)return!0}else if(f&&e.FREE_SHIPPING){if(u.valueType!==i.PERCENTAGE)return!0;if(u.targetType!==r.SHIPPING_LINE)return!0;if(100!==u.value)return!0;if(u.targetSelection!==n.ALL)return!0;if(l===t.AMOUNT&&(!u.minAmount||(null==u?void 0:u.minAmount)<=0))return!0;if(l===t.QUANTITY&&(!(null==u?void 0:u.minQuantity)||(null==u?void 0:u.minQuantity)<=0))return!0}if(null!==u.expireAfter&&void 0!==u.expireAfter&&u.expireAfter<=0)return!0;if(u.expireAt&&u.expireAt<new Date)return!0}return!1};export{u as validateDiscountData};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DISCOUNT_TYPES, ICouponData, MIN_PURCHASE_REQUIREMENT } from "../type";
|
|
3
3
|
import { SingleOption } from "../../dropdown/type";
|
|
4
|
-
import {
|
|
4
|
+
import { Product } from "../../product-picker/type";
|
|
5
5
|
export declare enum DISCOUNT_PRODUCTS {
|
|
6
6
|
ENTITLED = "entitled",
|
|
7
7
|
PREREQUISITE = "prerequisite"
|
|
@@ -9,9 +9,7 @@ export declare enum DISCOUNT_PRODUCTS {
|
|
|
9
9
|
interface DynamicCouponI {
|
|
10
10
|
discountData: ICouponData;
|
|
11
11
|
setIsProductPickerOpen: React.Dispatch<React.SetStateAction<DISCOUNT_PRODUCTS | undefined>>;
|
|
12
|
-
setIsCollectionPickerOpen: React.Dispatch<React.SetStateAction<DISCOUNT_PRODUCTS | undefined>>;
|
|
13
12
|
productPickerOpen: DISCOUNT_PRODUCTS | undefined;
|
|
14
|
-
collectionPickerOpen: DISCOUNT_PRODUCTS | undefined;
|
|
15
13
|
setDiscountData: React.Dispatch<React.SetStateAction<ICouponData>>;
|
|
16
14
|
selectedCouponType: DISCOUNT_TYPES | undefined;
|
|
17
15
|
setSelectedCouponType: React.Dispatch<React.SetStateAction<DISCOUNT_TYPES | undefined>>;
|
|
@@ -19,12 +17,8 @@ interface DynamicCouponI {
|
|
|
19
17
|
setSelectedMinimumRequirement: React.Dispatch<React.SetStateAction<MIN_PURCHASE_REQUIREMENT>>;
|
|
20
18
|
entitledProducts: Product[];
|
|
21
19
|
prerequisiteProducts: Product[];
|
|
22
|
-
entitledCollections: Collection[];
|
|
23
|
-
prerequisiteCollections: Collection[];
|
|
24
20
|
setEntitledProducts: React.Dispatch<React.SetStateAction<Product[]>>;
|
|
25
21
|
setPrerequisiteProducts: React.Dispatch<React.SetStateAction<Product[]>>;
|
|
26
|
-
setEntitledCollections: React.Dispatch<React.SetStateAction<Collection[]>>;
|
|
27
|
-
setPrerequisiteCollections: React.Dispatch<React.SetStateAction<Collection[]>>;
|
|
28
22
|
onChangeCouponType: (option: SingleOption) => void;
|
|
29
23
|
hideExpiration?: boolean;
|
|
30
24
|
hideProbability?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t,Fragment as i}from"react/jsx-runtime";import{Button as n}from"../../button/Button.js";import"react";import{DISCOUNT_TYPES as s,MIN_PURCHASE_REQUIREMENT as a}from"../type.js";import"../../dropdown/DropdownPopover/index.js";import{Dropdown as o}from"../../dropdown/Dropdown.js";import"../../dropdown/ChipDropdown.js";import"../../zeroState/ZeroState.js";import{TitleRegular as r,BodySecondary as l,TitleMedium as c,BodyPrimary as d,TitleSmall as p}from"../../TypographyStyle.js";import{DEFAULT_THEME as u}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"../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import{Input as m}from"../../input/Input.js";import g from"../../../assets/icons/cross.svg.js";import"../../dropdown/MenuItem/MenuItem.js";import"../../modals/styledModal.js";import"../../../node_modules/lodash.debounce/index.js";import"../../bik-layout/CommonStyles.js";import"../../product-picker/ProductPicker.styled.js";import"../../../utils/DateUtils.js";import"../../tag/Tag.js";import"@tippyjs/react";import"../../tooltips/TooltipInternal.js";import{DynamicCouponContainer as b}from"../DiscountModal.styled.js";import{CouponExpiration as v}from"../CouponExpiration/CouponExpiration.js";import{RadioButton as y}from"../../radioButton/RadioButton.js";import h from"../../../assets/icons/cursor.svg.js";import j from"../../../assets/icons/plus.svg.js";const D="https://jkfenner.com/wp-content/uploads/2019/11/default.jpg";var O;function T(){return null}!function(e){e.ENTITLED="entitled",e.PREREQUISITE="prerequisite"}(O||(O={}));const x=x=>{var E;const C=[{value:s.FIXED_AMOUNT,label:"Fixed Amount",selected:x.selectedCouponType===s.FIXED_AMOUNT},{value:s.PERCENTAGE,label:"Percentage",selected:x.selectedCouponType===s.PERCENTAGE},{value:s.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:x.selectedCouponType===s.BUY_X_GET_Y},{value:s.FREE_SHIPPING,label:"Free shipping",selected:x.selectedCouponType===s.FREE_SHIPPING}],f=[{selected:x.selectedMinimumRequirement===a.NA,label:"No minimum requirements",value:a.NA},{selected:x.selectedMinimumRequirement===a.AMOUNT,label:`Minimum purchase amount (${null!==(E=x.currency)&&void 0!==E?E:"₹"})`,value:a.AMOUNT},{selected:x.selectedMinimumRequirement===a.QUANTITY,label:"Minimum quantity of items",value:a.QUANTITY}],_=()=>{var i,n,s,r,c;return e("div",Object.assign({className:"input__rows"},{children:[e("div",Object.assign({className:"input__wrapper"},{children:[t(l,Object.assign({style:{marginBottom:10}},{children:"Min purchase requirements"})),t(o,{options:f,placement:"bottom-start",onSelect:e=>{const t=e.value;x.setSelectedMinimumRequirement(t),x.setDiscountData(Object.assign(Object.assign({},x.discountData),{minQuantity:void 0,minAmount:void 0}))}})]})),t("div",Object.assign({className:"input__wrapper"},{children:x.selectedMinimumRequirement!==a.NA&&t(m,{value:x.selectedMinimumRequirement===a.AMOUNT?null!==(n=null===(i=x.discountData.minAmount)||void 0===i?void 0:i.toString())&&void 0!==n?n:"":null!==(r=null===(s=x.discountData.minQuantity)||void 0===s?void 0:s.toString())&&void 0!==r?r:"",onChangeText:e=>{x.selectedMinimumRequirement===a.AMOUNT?x.setDiscountData(Object.assign(Object.assign({},x.discountData),{minAmount:parseInt(e)})):x.selectedMinimumRequirement===a.QUANTITY&&x.setDiscountData(Object.assign(Object.assign({},x.discountData),{minQuantity:parseInt(e)}))},labelText:x.selectedMinimumRequirement===a.AMOUNT?"Minimum purchase amount":"Minimum purchase quantity",prefixText:x.selectedMinimumRequirement===a.AMOUNT?null!==(c=x.currency)&&void 0!==c?c:"₹":void 0,type:"number",placeholder:x.selectedMinimumRequirement===a.AMOUNT?"1000.00":"2"})}))]}))},N=s=>{var a,o,l;const c=s===O.ENTITLED?x.entitledProducts:x.prerequisiteProducts,d=null!==(a=s===O.ENTITLED?x.entitledCollections:x.prerequisiteCollections)&&void 0!==a?a:[];return e(i,{children:[t(r,{children:s===O.PREREQUISITE?"Customer spends":"Customer gets"}),e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(m,{value:s===O.ENTITLED?null===(o=x.discountData.entitledQuantity)||void 0===o?void 0:o.toString():null===(l=x.discountData.prerequisiteQuantity)||void 0===l?void 0:l.toString(),type:"number",onChangeText:e=>{s===O.ENTITLED?x.setDiscountData(Object.assign(Object.assign({},x.discountData),{entitledQuantity:parseInt(e)})):x.setDiscountData(Object.assign(Object.assign({},x.discountData),{prerequisiteQuantity:parseInt(e)}))},labelText:"Add quantity",placeholder:"Add quantity"})})),t("div",{className:"input__wrapper"})]})),e("div",Object.assign({style:{display:"flex",gap:18}},{children:[t(n,{buttonText:"Add product",buttonType:"tertiary",LeadingIcon:j,onClick:()=>{x.setIsProductPickerOpen(s)}}),t(n,{buttonText:"Add collection",buttonType:"tertiary",LeadingIcon:j,onClick:()=>{x.setIsCollectionPickerOpen(s)}})]})),!!c.length&&e("div",Object.assign({style:{margin:"8px 0"}},{children:[t(p,{children:"Products"}),c.map((i=>e("div",Object.assign({style:{padding:"20px 0 12px 0",borderBottom:`1px solid ${u.colorsV2.stroke.primary}`,display:"flex"}},{children:[e("div",Object.assign({style:{display:"flex",gap:16,alignItems:"center",flex:.8}},{children:[t("img",{src:i.image,onError:e=>{e.target.onerror=null,e.target.src=D},style:{height:40,width:40,objectFit:"cover",borderRadius:4}}),t(p,{children:i.name})]})),t("div",Object.assign({style:{flex:.2,display:"flex",justifyContent:"flex-end",alignItems:"center"}},{children:t("div",Object.assign({style:{cursor:"pointer"},onClick:()=>{const e=c.filter((e=>e.id!==i.id));s===O.ENTITLED?x.setEntitledProducts(e):x.setPrerequisiteProducts(e)}},{children:t(g,{width:14,color:u.colorsV2.content.primary})}))}))]}),i.id)))]})),!!d.length&&e("div",Object.assign({style:{margin:"8px 0"}},{children:[t(p,{children:"Collections"}),d.map((i=>e("div",Object.assign({style:{padding:"20px 0 12px 0",borderBottom:`1px solid ${u.colorsV2.stroke.primary}`,display:"flex"}},{children:[e("div",Object.assign({style:{display:"flex",gap:16,alignItems:"center",flex:.8}},{children:[t("img",{src:i.image,onError:e=>{e.target.onerror=null,e.target.src=D},style:{height:40,width:40,objectFit:"cover",borderRadius:4}}),t(p,{children:i.name})]})),t("div",Object.assign({style:{flex:.2,display:"flex",justifyContent:"flex-end",alignItems:"center"}},{children:t("div",Object.assign({style:{cursor:"pointer"},onClick:()=>{const e=d.filter((e=>e.id!==i.id));s===O.ENTITLED?x.setEntitledCollections(e):x.setPrerequisiteCollections(e)}},{children:t(g,{width:14,color:u.colorsV2.content.primary})}))}))]}),i.id)))]}))]})};return e(b,{children:[x.allowStaticCoupon&&e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(o,{options:C,width:"290px",placement:"bottom-start",onSelect:e=>{x.onChangeCouponType(e)}})})),t("div",{className:"input__wrapper"})]})),(x.selectedCouponType===s.PERCENTAGE||x.selectedCouponType===s.FIXED_AMOUNT)&&(()=>{var n,a,o,r;return e(i,{children:[e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(m,{value:x.discountData.title,onChangeText:e=>{x.setDiscountData(Object.assign(Object.assign({},x.discountData),{title:e}))},maxCharLimit:18,labelText:"Code title",placeholder:"eg: Flat 50% Off"})})),t("div",Object.assign({className:"input__wrapper"},{children:t(m,{value:null===(a=null===(n=x.discountData)||void 0===n?void 0:n.value)||void 0===a?void 0:a.toString(),labelText:"Discount code value",type:"number",onChangeText:e=>{x.setDiscountData(Object.assign(Object.assign({},x.discountData),{value:parseInt(e)}))},placeholder:x.selectedCouponType===s.FIXED_AMOUNT?"0.00":"Enter a value",prefixText:x.selectedCouponType===s.FIXED_AMOUNT?null!==(o=x.currency)&&void 0!==o?o:"₹":void 0,suffixText:x.selectedCouponType===s.PERCENTAGE?"%":void 0})}))]})),_(),!x.hideProbability&&e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(m,{type:"number",value:null===(r=x.discountData.probability)||void 0===r?void 0:r.toString(),onChangeText:e=>{x.setDiscountData(Object.assign(Object.assign({},x.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})})),t("div",{className:"input__wrapper"})]}))]})})(),x.selectedCouponType===s.FREE_SHIPPING&&(()=>{var n;return e(i,{children:[e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(m,{value:x.discountData.title,onChangeText:e=>{x.setDiscountData(Object.assign(Object.assign({},x.discountData),{title:e}))},labelText:"Code title",placeholder:"eg: Flat 50% Off",maxCharLimit:18})})),t("div",Object.assign({className:"input__wrapper"},{children:!x.hideProbability&&t(m,{value:null===(n=x.discountData.probability)||void 0===n?void 0:n.toString(),type:"number",onChangeText:e=>{x.setDiscountData(Object.assign(Object.assign({},x.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})}))]})),_()]})})(),x.selectedCouponType===s.BUY_X_GET_Y&&(()=>{var i;return e(b,{children:[t("div",Object.assign({className:"input__rows"},{children:e("div",Object.assign({style:{display:"flex",gap:20,flex:1}},{children:[t("div",Object.assign({style:{flex:1}},{children:t(m,{value:x.discountData.title,onChangeText:e=>{x.setDiscountData(Object.assign(Object.assign({},x.discountData),{title:e}))},maxCharLimit:18,labelText:"Code title",placeholder:"eg: Flat 50% Off"})})),!x.hideProbability&&t("div",Object.assign({style:{flex:1}},{children:t(m,{value:null===(i=x.discountData.probability)||void 0===i?void 0:i.toString(),type:"number",onChangeText:e=>{x.setDiscountData(Object.assign(Object.assign({},x.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})}))]}))})),t(T,{}),N(O.PREREQUISITE),t(T,{}),N(O.ENTITLED),t(T,{}),t(r,{children:"At a discount value"}),e("div",Object.assign({style:{display:"flex",gap:18,alignItems:"center"}},{children:[t(y,{isActive:100!==x.discountData.value,onValueChange:()=>{x.setDiscountData(Object.assign(Object.assign({},x.discountData),{value:void 0}))}}),t(l,{children:"Percentage"}),100!==x.discountData.value&&t(m,{variant:"small",onChangeText:e=>{x.setDiscountData(Object.assign(Object.assign({},x.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Enter percentage eg: 10%",suffixText:"%",width:"238px"})]})),e("div",Object.assign({style:{display:"flex",gap:18}},{children:[t(y,{isActive:100===x.discountData.value,onValueChange:e=>{e?x.setDiscountData(Object.assign(Object.assign({},x.discountData),{value:100})):x.setDiscountData(Object.assign(Object.assign({},x.discountData),{value:void 0}))}}),t(l,{children:"Free"})]}))]})})(),x.selectedCouponType&&!x.hideExpiration&&e(i,{children:[t("div",{style:{height:6,borderTop:`1px solid ${u.colorsV2.stroke.primary}`,marginTop:12}}),t(v,{discountData:x.discountData,setDiscountData:x.setDiscountData})]}),!x.selectedCouponType&&e("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:10,padding:"40px 0",justifyContent:"center",alignItems:"center"}},{children:[t("div",Object.assign({style:{height:52,width:52,backgroundColor:u.colorsV2.background.inverse,borderRadius:"50%",display:"flex",justifyContent:"center",alignItems:"center"}},{children:t(h,{width:32,color:u.colorsV2.content.primaryInverse})})),t(c,{children:"No discount has been selected"}),t(d,{children:"Please select a discount type"})]}))]})};export{O as DISCOUNT_PRODUCTS,x as default};
|
|
1
|
+
import{jsxs as e,jsx as t,Fragment as i}from"react/jsx-runtime";import{Button as n}from"../../button/Button.js";import"react";import{DISCOUNT_TYPES as s,MIN_PURCHASE_REQUIREMENT as a}from"../type.js";import"../../dropdown/DropdownPopover/index.js";import{Dropdown as o}from"../../dropdown/Dropdown.js";import"../../dropdown/ChipDropdown.js";import"../../zeroState/ZeroState.js";import{TitleRegular as r,BodySecondary as l,TitleMedium as c,BodyPrimary as d,TitleSmall as u}from"../../TypographyStyle.js";import{DEFAULT_THEME as p}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"../../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import{Input as m}from"../../input/Input.js";import b from"../../../assets/icons/cross.svg.js";import"../../dropdown/MenuItem/MenuItem.js";import"../../modals/styledModal.js";import"../../../node_modules/lodash.debounce/index.js";import"../../bik-layout/CommonStyles.js";import"../../product-picker/ProductPicker.styled.js";import"../../../utils/DateUtils.js";import"../../tag/Tag.js";import"@tippyjs/react";import"../../tooltips/TooltipInternal.js";import{DynamicCouponContainer as g}from"../DiscountModal.styled.js";import{CouponExpiration as v}from"../CouponExpiration/CouponExpiration.js";import{RadioButton as h}from"../../radioButton/RadioButton.js";import j from"../../../assets/icons/cursor.svg.js";import y from"../../../assets/icons/plus.svg.js";var D;function T(){return null}!function(e){e.ENTITLED="entitled",e.PREREQUISITE="prerequisite"}(D||(D={}));const O=O=>{var x;const E=[{value:s.FIXED_AMOUNT,label:"Fixed Amount",selected:O.selectedCouponType===s.FIXED_AMOUNT},{value:s.PERCENTAGE,label:"Percentage",selected:O.selectedCouponType===s.PERCENTAGE},{value:s.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:O.selectedCouponType===s.BUY_X_GET_Y},{value:s.FREE_SHIPPING,label:"Free shipping",selected:O.selectedCouponType===s.FREE_SHIPPING}],_=[{selected:O.selectedMinimumRequirement===a.NA,label:"No minimum requirements",value:a.NA},{selected:O.selectedMinimumRequirement===a.AMOUNT,label:`Minimum purchase amount (${null!==(x=O.currency)&&void 0!==x?x:"₹"})`,value:a.AMOUNT},{selected:O.selectedMinimumRequirement===a.QUANTITY,label:"Minimum quantity of items",value:a.QUANTITY}],N=()=>{var i,n,s,r,c;return e("div",Object.assign({className:"input__rows"},{children:[e("div",Object.assign({className:"input__wrapper"},{children:[t(l,Object.assign({style:{marginBottom:10}},{children:"Min purchase requirements"})),t(o,{options:_,placement:"bottom-start",onSelect:e=>{const t=e.value;O.setSelectedMinimumRequirement(t),O.setDiscountData(Object.assign(Object.assign({},O.discountData),{minQuantity:void 0,minAmount:void 0}))}})]})),t("div",Object.assign({className:"input__wrapper"},{children:O.selectedMinimumRequirement!==a.NA&&t(m,{value:O.selectedMinimumRequirement===a.AMOUNT?null!==(n=null===(i=O.discountData.minAmount)||void 0===i?void 0:i.toString())&&void 0!==n?n:"":null!==(r=null===(s=O.discountData.minQuantity)||void 0===s?void 0:s.toString())&&void 0!==r?r:"",onChangeText:e=>{O.selectedMinimumRequirement===a.AMOUNT?O.setDiscountData(Object.assign(Object.assign({},O.discountData),{minAmount:parseInt(e)})):O.selectedMinimumRequirement===a.QUANTITY&&O.setDiscountData(Object.assign(Object.assign({},O.discountData),{minQuantity:parseInt(e)}))},labelText:O.selectedMinimumRequirement===a.AMOUNT?"Minimum purchase amount":"Minimum purchase quantity",prefixText:O.selectedMinimumRequirement===a.AMOUNT?null!==(c=O.currency)&&void 0!==c?c:"₹":void 0,type:"number",placeholder:O.selectedMinimumRequirement===a.AMOUNT?"1000.00":"2"})}))]}))},C=s=>{var a,o;const l=s===D.ENTITLED?O.entitledProducts:O.prerequisiteProducts;return e(i,{children:[t(r,{children:s===D.PREREQUISITE?"Customer spends":"Customer gets"}),e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(m,{value:s===D.ENTITLED?null===(a=O.discountData.entitledQuantity)||void 0===a?void 0:a.toString():null===(o=O.discountData.prerequisiteQuantity)||void 0===o?void 0:o.toString(),type:"number",onChangeText:e=>{s===D.ENTITLED?O.setDiscountData(Object.assign(Object.assign({},O.discountData),{entitledQuantity:parseInt(e)})):O.setDiscountData(Object.assign(Object.assign({},O.discountData),{prerequisiteQuantity:parseInt(e)}))},labelText:"Add quantity",placeholder:"Add quantity"})})),t("div",{className:"input__wrapper"})]})),t("div",{children:t(n,{buttonText:"Add product",buttonType:"tertiary",LeadingIcon:y,onClick:()=>{O.setIsProductPickerOpen(s)}})}),l.map((i=>e("div",Object.assign({style:{padding:"20px 0 12px 0",borderBottom:`1px solid ${p.colorsV2.stroke.primary}`,display:"flex"}},{children:[e("div",Object.assign({style:{display:"flex",gap:16,alignItems:"center",flex:.8}},{children:[t("img",{src:i.image,onError:e=>{e.target.onerror=null,e.target.src="https://jkfenner.com/wp-content/uploads/2019/11/default.jpg"},style:{height:40,width:40,objectFit:"cover",borderRadius:4}}),t(u,{children:i.name})]})),t("div",Object.assign({style:{flex:.2,display:"flex",justifyContent:"flex-end",alignItems:"center"}},{children:t("div",Object.assign({style:{cursor:"pointer"},onClick:()=>{const e=l.filter((e=>e.id!==i.id));s===D.ENTITLED?O.setEntitledProducts(e):O.setPrerequisiteProducts(e)}},{children:t(b,{width:14,color:p.colorsV2.content.primary})}))}))]}),i.id)))]})};return e(g,{children:[O.allowStaticCoupon&&e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(o,{options:E,width:"290px",placement:"bottom-start",onSelect:e=>{O.onChangeCouponType(e)}})})),t("div",{className:"input__wrapper"})]})),(O.selectedCouponType===s.PERCENTAGE||O.selectedCouponType===s.FIXED_AMOUNT)&&(()=>{var n,a,o,r;return e(i,{children:[e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(m,{value:O.discountData.title,onChangeText:e=>{O.setDiscountData(Object.assign(Object.assign({},O.discountData),{title:e}))},maxCharLimit:18,labelText:"Code title",placeholder:"eg: Flat 50% Off"})})),t("div",Object.assign({className:"input__wrapper"},{children:t(m,{value:null===(a=null===(n=O.discountData)||void 0===n?void 0:n.value)||void 0===a?void 0:a.toString(),labelText:"Discount code value",type:"number",onChangeText:e=>{O.setDiscountData(Object.assign(Object.assign({},O.discountData),{value:parseInt(e)}))},placeholder:O.selectedCouponType===s.FIXED_AMOUNT?"0.00":"Enter a value",prefixText:O.selectedCouponType===s.FIXED_AMOUNT?null!==(o=O.currency)&&void 0!==o?o:"₹":void 0,suffixText:O.selectedCouponType===s.PERCENTAGE?"%":void 0})}))]})),N(),!O.hideProbability&&e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(m,{type:"number",value:null===(r=O.discountData.probability)||void 0===r?void 0:r.toString(),onChangeText:e=>{O.setDiscountData(Object.assign(Object.assign({},O.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})})),t("div",{className:"input__wrapper"})]}))]})})(),O.selectedCouponType===s.FREE_SHIPPING&&(()=>{var n;return e(i,{children:[e("div",Object.assign({className:"input__rows"},{children:[t("div",Object.assign({className:"input__wrapper"},{children:t(m,{value:O.discountData.title,onChangeText:e=>{O.setDiscountData(Object.assign(Object.assign({},O.discountData),{title:e}))},labelText:"Code title",placeholder:"eg: Flat 50% Off",maxCharLimit:18})})),t("div",Object.assign({className:"input__wrapper"},{children:!O.hideProbability&&t(m,{value:null===(n=O.discountData.probability)||void 0===n?void 0:n.toString(),type:"number",onChangeText:e=>{O.setDiscountData(Object.assign(Object.assign({},O.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})}))]})),N()]})})(),O.selectedCouponType===s.BUY_X_GET_Y&&(()=>{var i;return e(g,{children:[t("div",Object.assign({className:"input__rows"},{children:e("div",Object.assign({style:{display:"flex",gap:20,flex:1}},{children:[t("div",Object.assign({style:{flex:1}},{children:t(m,{value:O.discountData.title,onChangeText:e=>{O.setDiscountData(Object.assign(Object.assign({},O.discountData),{title:e}))},maxCharLimit:18,labelText:"Code title",placeholder:"eg: Flat 50% Off"})})),!O.hideProbability&&t("div",Object.assign({style:{flex:1}},{children:t(m,{value:null===(i=O.discountData.probability)||void 0===i?void 0:i.toString(),type:"number",onChangeText:e=>{O.setDiscountData(Object.assign(Object.assign({},O.discountData),{probability:e.startsWith(".")?parseFloat(`0${e}`):parseFloat(e)}))},labelText:"Probability",placeholder:"Enter probability in decimals (0 - 1)"})}))]}))})),t(T,{}),C(D.PREREQUISITE),t(T,{}),C(D.ENTITLED),t(T,{}),t(r,{children:"At a discount value"}),e("div",Object.assign({style:{display:"flex",gap:18,alignItems:"center"}},{children:[t(h,{isActive:100!==O.discountData.value,onValueChange:e=>{O.setDiscountData(Object.assign(Object.assign({},O.discountData),{value:void 0}))}}),t(l,{children:"Percentage"}),100!==O.discountData.value&&t(m,{variant:"small",onChangeText:e=>{O.setDiscountData(Object.assign(Object.assign({},O.discountData),{value:parseInt(e)}))},type:"number",placeholder:"Enter percentage eg: 10%",suffixText:"%",width:"238px"})]})),e("div",Object.assign({style:{display:"flex",gap:18}},{children:[t(h,{isActive:100===O.discountData.value,onValueChange:e=>{e?O.setDiscountData(Object.assign(Object.assign({},O.discountData),{value:100})):O.setDiscountData(Object.assign(Object.assign({},O.discountData),{value:void 0}))}}),t(l,{children:"Free"})]}))]})})(),O.selectedCouponType&&!O.hideExpiration&&e(i,{children:[t("div",{style:{height:6,borderTop:`1px solid ${p.colorsV2.stroke.primary}`,marginTop:12}}),t(v,{discountData:O.discountData,setDiscountData:O.setDiscountData})]}),!O.selectedCouponType&&e("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:10,padding:"40px 0",justifyContent:"center",alignItems:"center"}},{children:[t("div",Object.assign({style:{height:52,width:52,backgroundColor:p.colorsV2.background.inverse,borderRadius:"50%",display:"flex",justifyContent:"center",alignItems:"center"}},{children:t(j,{width:32,color:p.colorsV2.content.primaryInverse})})),t(c,{children:"No discount has been selected"}),t(d,{children:"Please select a discount type"})]}))]})};export{D as DISCOUNT_PRODUCTS,O as default};
|
|
@@ -13,15 +13,15 @@ export interface IInstaPost {
|
|
|
13
13
|
}
|
|
14
14
|
export interface ProductPickerProps {
|
|
15
15
|
show: boolean;
|
|
16
|
-
products: Product[]
|
|
16
|
+
products: Product[];
|
|
17
17
|
onClose: () => void;
|
|
18
18
|
title: string;
|
|
19
|
-
onSave: (productIds: Product[]
|
|
20
|
-
onSearchKeyChange: (key: string) => Promise<Product[]
|
|
19
|
+
onSave: (productIds: Product[]) => void;
|
|
20
|
+
onSearchKeyChange: (key: string) => Promise<Product[]>;
|
|
21
21
|
instaPost?: IInstaPost;
|
|
22
22
|
searchPlaceholder?: string;
|
|
23
|
-
selectedProducts: Product[]
|
|
24
|
-
setSelectedProducts: React.Dispatch<React.SetStateAction<Product[]
|
|
23
|
+
selectedProducts: Product[];
|
|
24
|
+
setSelectedProducts: React.Dispatch<React.SetStateAction<Product[]>>;
|
|
25
25
|
secondaryButtonProps?: ButtonProps;
|
|
26
26
|
}
|
|
27
27
|
export interface Product {
|
|
@@ -42,16 +42,6 @@ export interface Product {
|
|
|
42
42
|
name: string;
|
|
43
43
|
handle: string;
|
|
44
44
|
}
|
|
45
|
-
export interface Collection {
|
|
46
|
-
id: string;
|
|
47
|
-
name: string;
|
|
48
|
-
description: string;
|
|
49
|
-
image: string;
|
|
50
|
-
isHidden: boolean;
|
|
51
|
-
isPrivate: boolean;
|
|
52
|
-
handle: string;
|
|
53
|
-
isSmartCollection: boolean;
|
|
54
|
-
}
|
|
55
45
|
export interface Variant {
|
|
56
46
|
values: string[];
|
|
57
47
|
name: string;
|