@ikas/storefront 6.1.0-beta.390 → 6.1.0-beta.391
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/build/components/checkout/components/cart-summary/loyalty/index.js +1 -1
- package/build/components/checkout/components/secure-card-form/protocol.d.ts +2 -0
- package/build/components/checkout/components/toggle/index.d.ts +2 -0
- package/build/components/checkout/components/toggle/index.js +1 -1
- package/build/components/checkout/components/toggle/style.module.scss.js +1 -1
- package/build/components/checkout/model.d.ts +30 -1
- package/build/components/checkout/model.js +1 -1
- package/build/components/checkout/steps/step-payment/payment-gateways/index.js +1 -1
- package/build/components/checkout/steps/step-payment/payment-gateways/installments/index.js +1 -1
- package/build/components/checkout/steps/step-payment/payment-gateways/saved-cards/index.d.ts +10 -0
- package/build/components/checkout/steps/step-payment/payment-gateways/saved-cards/index.js +1 -0
- package/build/components/checkout/steps/step-payment/payment-gateways/saved-cards/style.module.scss.js +1 -0
- package/build/components/checkout/steps/step-payment/payment-gateways/style.module.scss.js +1 -1
- package/build/pages/checkout.js +1 -1
- package/build/store/checkout/index.d.ts +2 -1
- package/build/store/checkout/index.js +1 -1
- package/build/store/customer/api.d.ts +2 -0
- package/build/store/customer/api.js +1 -1
- package/build/store/customer/index.d.ts +14 -1
- package/build/store/customer/index.js +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__spreadArray as e,__awaiter as t,__generator as n,__assign as o}from'./../../../../../ext/tslib/tslib.es6.js';import*as i from"react";import{observer as a}from"mobx-react-lite";import{IkasStorefrontConfig as r}from"@ikas/storefront-config";import{LoyaltyProgramMethodSpendingTypeEnum as l,searchProducts as s,useLoyaltyPoints as d}from"@ikas/storefront-api";import{IkasCartCreatedBy as c}from"@ikas/storefront-models";import{CheckoutStep as u}from"../../../model.js";import"../../../../../models/data/blog/category/index.js";import"../../../../../models/data/blog/content/index.js";import"../../../../../models/data/blog/meta-data/index.js";import"../../../../../models/data/blog/tag/index.js";import"../../../../../models/data/blog/index.js";import"../../../../../models/data/brand/index.js";import"mobx";import"../../../../../models/data/campaign-offer/index.js";import"../../../../../models/data/cart/campaign-offer/index.js";import"../../../../../models/data/cart/index.js";import"../../../../../models/data/category/path-item/index.js";import"../../../../../models/data/category/index.js";import{IkasCheckout as m}from"../../../../../models/data/checkout/index.js";import"../../../../../models/data/checkout-settings/index.js";import"../../../../../models/data/city/index.js";import"../../../../../models/data/country/index.js";import"../../../../../models/data/customer/address/region/index.js";import"../../../../../models/data/customer/address/index.js";import"../../../../../models/data/customer/address/ikas-localized-customer-address.js";import"../../../../../models/data/customer/attribute/index.js";import"../../../../../models/data/customer/review/summary/index.js";import"../../../../../models/data/customer/review/index.js";import"../../../../../models/data/customer/index.js";import"../../../../../models/data/customer-form-data-input/index.js";import"../../../../../models/data/district/index.js";import"../../../../../models/data/favorite-product/index.js";import"../../../../../models/data/filter-category/index.js";import"../../../../../models/data/html-meta-data/index.js";import{IkasImage as p}from"../../../../../models/data/image/index.js";import"../../../../../models/data/order/address/region/index.js";import"../../../../../models/data/order/address/index.js";import"../../../../../models/data/order/line-item/option/value/index.js";import"../../../../../models/data/order/line-item/variant/value/index.js";import"../../../../../models/data/order/line-item/variant/index.js";import"../../../../../models/data/order/line-item/index.js";import"../../../../../models/data/order/order-transaction-with-prices/index.js";import"../../../../../models/data/order/package/index.js";import"../../../../../models/data/order/transaction/index.js";import"../../../../../models/data/order/index.js";import"../../../../../models/data/payment-gateway/index.js";import"../../../../../models/data/product/attribute-value/index.js";import"../../../../../models/data/product/filter/index.js";import"../../../../../models/data/product/campaign-offer/index.js";import"../../../../../models/data/product/option-set/option/index.js";import"../../../../../models/data/product/option-set/index.js";import"../../../../../models/data/product/stock-location/index.js";import"../../../../../models/data/product/variant/price/index.js";import"../../../../../models/data/product/variant/index.js";import"../../../../../models/data/variant-type/index.js";import"../../../../../models/data/product/index.js";import"../../../../../models/data/raffle/index.js";import"../../../../../models/data/shipping-zone/state/city/district/region/index.js";import"../../../../../models/data/state/index.js";import"../../../../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../../../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../../../../models/data/storefront-popup/index.js";import"../../../../../models/data/theme-json/index.js";import"../../../../../models/data/theme-json/component/index.js";import"../../../../../models/data/theme-json/custom-data/index.js";import"../../../../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../../../../../models/ui/blog-list/index.js";import"../../../../../models/ui/blog-category-list/index.js";import"../../../../../models/ui/brand-list/index.js";import"../../../../../models/ui/category-list/index.js";import"../../../../../models/ui/product-list/index.js";import"../../../../../models/ui/product-attribute-detail/index.js";import"../../../../../models/ui/product-attribute-list/index.js";import"../../../../../models/ui/customer-review-list/index.js";import"../../../../../models/ui/customer-review-summary-list/index.js";import"../../../../../models/ui/validator/index.js";import"../../../../../models/ui/validator/rules/index.js";import"../../../../../models/ui/validator/form/login.js";import"../../../../../models/ui/validator/form/address.js";import"../../../../../models/ui/validator/form/ikas-address.js";import"../../../../../models/ui/validator/form/register.js";import"../../../../../models/ui/validator/form/contact-form.js";import"../../../../../models/ui/validator/form/forgot-password.js";import"../../../../../models/ui/validator/form/recover-password.js";import"../../../../../models/ui/validator/form/account-info.js";import"../../../../../models/ui/validator/form/raffle-form.js";import"../../../../../models/ui/validator/form/customer-review.js";import"../../../../../models/ui/raffle-list/index.js";import{formatCurrency as y}from"../../../../../utils/currency.js";import{useTranslation as v}from"../../../../../utils/i18n.js";import{Button as f}from"../../button/index.js";import g from"../../input-with-button/index.js";import h from"../../svg/cross.js";import{SVGLoyaltyGift as x,SVGLoyaltyBox as k,SVGLoyaltyTag as j}from"./icons.js";import E from"../../svg/star-loyalty.js";import I from"./style.module.scss.js";var S=new Intl.NumberFormat("tr-TR",{maximumFractionDigits:0}),P=function(e){return S.format(Math.floor(e||0))},C=function(e){var t=Math.abs(Math.floor(e)),n=P(t),o="'in";if(0===t)o="'ın";else if(t%1e6==0)o="'un";else if(t%1e3==0)o="'in";else if(t%100==0)o="'ün";else if(t%10==0){o={1:"'un",2:"'nin",3:"'un",4:"'ın",5:"'nin",6:"'ın",7:"'in",8:"'in",9:"'ın"}[t/10%10]}else{o={1:"'in",2:"'nin",3:"'ün",4:"'ün",5:"'in",6:"'nın",7:"'nin",8:"'in",9:"'un"}[t%10]}return n+o},M=function(e){switch(e.type){case l.FREE_PRODUCT:return"GIFT";case l.FREE_SHIPPING:return"SHIPPING";case l.RATIO:return"RATIO";default:return e.isDynamic?"DYNAMIC":"FIXED"}},N=function(e,t){var n,o,i,a,r,l=(null===(n=e.discountSettings)||void 0===n?void 0:n.point)||1,s=null!==(i=null===(o=e.pointUsageLimit)||void 0===o?void 0:o.minPointLimit)&&void 0!==i?i:l,d=Math.min(null!==(r=null===(a=e.pointUsageLimit)||void 0===a?void 0:a.maxPointLimit)&&void 0!==r?r:t,t);return{step:l,min:s,max:Math.max(Math.floor(d/l)*l,0)}},b=function(e){var t=e.kind;return"GIFT"===t?i.createElement(x,null):"SHIPPING"===t?i.createElement(k,null):i.createElement(j,null)},T=function(e){var t,n,o;return!(e.step===u.SUCCESS||!(null===(t=e.customizationProps)||void 0===t?void 0:t.showLoyaltyPoints)||!e.loyaltyCustomerInfo||!(null===(n=e.loyaltySpendingMethods)||void 0===n?void 0:n.length)&&!(null===(o=e.checkout.loyaltyLines)||void 0===o?void 0:o.length)||e.isOpenEditOrderWithTransaction||e.checkout.createdBy===c.UPSELL||e.checkout.createdBy===c.ADMIN)},A=a((function(e){var t,n,o=e.vm,a=v().t,l=o.loyaltyEarningMethod,s=o.loyaltyCustomerInfo;if(!l||!s)return null;var d,c,u,m=l.amountPerPointsEarned||1,p=Math.floor(l.pointsEarned/m*(o.finalPrice||0)),f=s.customerTier,g=r.getCurrentLocale(),h=(f?(null===(n=null===(t=f.translations)||void 0===t?void 0:t.find((function(e){return e.locale===g})))||void 0===n?void 0:n.name)||f.name:null)||a("checkout-page:loyaltyEarnRule",{amount:y(m,o.checkout.currencyCode,o.checkout.currencySymbol),point:P(l.pointsEarned)});return i.createElement("div",{className:I.EarningRow},i.createElement("div",{className:I.EarningRowLeft},i.createElement("span",{className:I.StarIcon},i.createElement(E,null)),i.createElement("span",null,(d=a("checkout-page:loyaltyEarnTitle"),c="".concat(P(p)," ").concat(a("checkout-page:loyaltyPoint")),(u=d.split("{{value}}")).length<2?d:i.createElement(i.Fragment,null,u[0],i.createElement("strong",null,c),u.slice(1).join(c))))),i.createElement("span",{className:I.SecondaryText},h))})),L=a((function(a){var c,g,x,k,j=a.vm,S=v().t,C=i.useState(null),T=C[0],A=C[1],L=i.useState(null),F=L[0],R=L[1],w=i.useState(null),G=w[0],O=w[1],B=i.useState([]),U=B[0],H=B[1],V=j.isLoyaltyPointsVisible,z=Math.floor(null!==(g=null===(c=j.loyaltyCustomerInfo)||void 0===c?void 0:c.totalPoint)&&void 0!==g?g:0),Y=j.checkout.loyaltyLines||[],X=Y.map((function(e){return e.loyaltySpendingMethodId})),_=j.step!==u.SUCCESS&&!j.isOpenEditOrderWithTransaction,W=function(e){return y(e,j.checkout.currencyCode,j.checkout.currencySymbol)},$=function(e){return"".concat(P(e)," ").concat(S("checkout-page:loyaltyPoint"))},q=i.useMemo((function(){var t=(j.loyaltySpendingMethods||[]).filter((function(e){return!X.includes(e.id)})),n=[],o=[];if(t.forEach((function(e){var t,i=M(e);if("GIFT"!==i){var a="DYNAMIC"===i?N(e,z).min:(null===(t=e.discountSettings)||void 0===t?void 0:t.point)||0;n.push({key:e.id,kind:i,methods:[e],minCost:a,maxCost:a,isDisabled:z<a,missingPoint:Math.max(a-z,0)})}else o.push(e)})),o.length){var i=o.map((function(e){var t;return(null===(t=e.discountSettings)||void 0===t?void 0:t.point)||0})),a=Math.min.apply(Math,i);n.push({key:"GIFT",kind:"GIFT",methods:o,minCost:a,maxCost:Math.max.apply(Math,i),isDisabled:z<a,missingPoint:Math.max(a-z,0)})}return e(e([],n.filter((function(e){return!e.isDisabled})),!0),n.filter((function(e){return e.isDisabled})),!0)}),[j.loyaltySpendingMethods,X.join(","),z]),J=q.filter((function(e){return!e.isDisabled})),K=1===q.length&&1===J.length?q[0]:null,Q=_&&q.length>0&&(J.length>0||0===Y.length);i.useEffect((function(){!Q&&V&&j.setIsLoyaltyPointsVisible(!1)}),[Q,V]),i.useEffect((function(){T&&!q.some((function(e){return e.key===T}))&&A(null)}),[q,T]);var Z=i.useMemo((function(){return(j.loyaltySpendingMethodsAll||j.loyaltySpendingMethods||[]).filter((function(e){return e.type===l.FREE_PRODUCT}))}),[j.loyaltySpendingMethodsAll,j.loyaltySpendingMethods]),ee=Z.map((function(e){var t;return(null===(t=e.discountSettings)||void 0===t?void 0:t.freeProductId)||""})).filter(Boolean).join(",");i.useEffect((function(){if(ee){var e=!1;return t(void 0,void 0,void 0,(function(){var t,o,i,a,l;return n(this,(function(n){switch(n.label){case 0:return t=ee.split(","),[4,s({input:{productIdList:t,page:1,perPage:t.length,priceListId:r.getPriceListId(),salesChannelId:r.getSalesChannelId()}},[])];case 1:return o=n.sent(),e||(i=(null===(l=o.data)||void 0===l?void 0:l.data)||[],a=[],Z.forEach((function(e){var t,n,o,r,l,s,d,c,u,m,y,v=i.find((function(t){var n;return t.id===(null===(n=e.discountSettings)||void 0===n?void 0:n.freeProductId)}));if(v){var f=(null===(t=v.variants)||void 0===t?void 0:t.find((function(t){var n;return t.id===(null===(n=e.discountSettings)||void 0===n?void 0:n.freeProductVariantId)})))||(null===(n=v.variants)||void 0===n?void 0:n[0]),g=(null===(l=null===(r=null===(o=null==f?void 0:f.images)||void 0===o?void 0:o.find((function(e){return e.isMain})))||void 0===r?void 0:r.image)||void 0===l?void 0:l.id)||(null===(c=null===(d=null===(s=null==f?void 0:f.images)||void 0===s?void 0:s[0])||void 0===d?void 0:d.image)||void 0===c?void 0:c.id)||null,h=null===(u=null==f?void 0:f.prices)||void 0===u?void 0:u[0];a.push({id:e.id,name:v.name,imageSrc:g?new p({id:g,isVideo:!1}).thumbnailSrc:null,price:h&&null!==(y=null!==(m=h.discountPrice)&&void 0!==m?m:h.sellPrice)&&void 0!==y?y:null,method:e})}})),H(a)),[2]}}))})),function(){e=!0}}}),[ee]);var te=function(e,i,a){return t(void 0,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:if(F)return[2,!1];R(i),n.label=1;case 1:return n.trys.push([1,,7,8]),[4,d({input:o({cartId:j.checkout.id,loyaltyProgramId:e.loyaltyProgramId,loyaltySpendingMethodId:e.id},a?{amount:a}:{})})];case 2:return(t=n.sent()).isSuccess&&t.data?(j.checkout=new m(o(o({},t.data),{shippingAddress:j.checkout.shippingAddress,billingAddress:j.checkout.billingAddress,customer:j.checkout.customer,selectedPaymentGateway:j.checkout.selectedPaymentGateway}),j.countrySettings),[4,j.getLoyaltyCustomerInfo()]):[3,6];case 3:return n.sent(),[4,j.listSpendingMethodsByCartId()];case 4:return n.sent(),[4,j.reInitPaymentMethod()];case 5:return n.sent(),A(null),j.setIsLoyaltyPointsVisible(!1),[2,!0];case 6:return[2,!1];case 7:return R(null),[7];case 8:return[2]}}))}))},ne=function(e){var t;return(j.checkout.totalPrice||0)*((null===(t=e.discountSettings)||void 0===t?void 0:t.discountAmount)||0)/100},oe=function(t){var n,o=t.methods[0];if("DYNAMIC"===t.kind)return i.createElement(D,{vm:j,method:o,balance:z,isLoading:F===t.key,onApply:function(e){return te(o,t.key,e)}});if("GIFT"===t.kind){var a=U.filter((function(e){return t.methods.some((function(t){return t.id===e.method.id}))})),r=e(e([],a.filter((function(e){var t;return((null===(t=e.method.discountSettings)||void 0===t?void 0:t.point)||0)<=z})),!0),a.filter((function(e){var t;return((null===(t=e.method.discountSettings)||void 0===t?void 0:t.point)||0)>z})),!0);return i.createElement("div",{className:I.GiftList},r.map((function(e){var t,n=(null===(t=e.method.discountSettings)||void 0===t?void 0:t.point)||0,o=n>z;return i.createElement("div",{key:e.id,className:[I.GiftRow,o?I.GiftRowDisabled:""].join(" ")},i.createElement("div",{className:I.GiftImage},!!e.imageSrc&&i.createElement("img",{src:e.imageSrc,alt:e.name})),i.createElement("div",{className:I.GiftInfo},i.createElement("span",{className:I.GiftName},e.name),i.createElement("span",{className:I.SecondaryText},$(n),null!==e.price&&i.createElement(i.Fragment,null," · ",i.createElement("s",null,W(e.price))),o&&" · ".concat(S("checkout-page:loyaltyMissingPoints",{point:P(n-z)})))),i.createElement(f,{size:"medium",classes:I.SmallButton,isDisabled:o,isLoading:F===e.id,text:S("checkout-page:loyaltyPointsLineItemButtonAddFree"),onClick:function(){return te(e.method,e.id)}}))})))}var l="SHIPPING"===t.kind?S("checkout-page:loyaltyApplyFreeShipping"):S("checkout-page:loyaltyPointsLineItemButtonApplyAmount",{amount:W("RATIO"===t.kind?ne(o):(null===(n=o.discountSettings)||void 0===n?void 0:n.discountAmount)||0)});return i.createElement(f,{size:"medium",style:{width:"100%"},isLoading:F===t.key,text:l,onClick:function(){return te(o,t.key)}})},ie="DYNAMIC"===(null==K?void 0:K.kind)?K.methods[0]:null;return i.createElement("div",{className:I.LoyaltyBlock},i.createElement("div",{className:I.BalanceRow},i.createElement("div",{className:I.BalanceText},i.createElement("span",{className:I.StarIcon},i.createElement(E,null)),i.createElement("span",null,i.createElement("span",{className:I.SecondaryText},Y.length?S("checkout-page:loyaltyRemainingBalance"):S("checkout-page:loyaltyBalance"))," ",i.createElement("strong",null,$(z)),!!ie&&i.createElement("span",{className:I.SecondaryText}," · ",S("checkout-page:loyaltyRateRule",{point:P((null===(x=ie.discountSettings)||void 0===x?void 0:x.point)||0),amount:W((null===(k=ie.discountSettings)||void 0===k?void 0:k.discountAmount)||0)})))),Q&&i.createElement(f,{isLine:!0,size:"medium",classes:I.UseButton,text:S(V?"checkout-page:actions.cancel":"checkout-page:loyaltyUse"),onClick:function(){V&&A(null),j.setIsLoyaltyPointsVisible(!V)}})),V&&Q&&!!K&&i.createElement("div",{className:I.SingleContent},oe(K)),V&&Q&&!K&&i.createElement("div",{className:I.OptionList},q.map((function(e){var t=T===e.key;return i.createElement("div",{key:e.key,className:[I.OptionCard,t?I.OptionCardSelected:"",e.isDisabled?I.OptionCardDisabled:""].join(" ")},i.createElement("div",{className:I.OptionHeader,onClick:function(){return e.isDisabled||t?void 0:A(e.key)}},i.createElement("span",{className:I.Radio}),i.createElement("span",{className:I.IconBox},i.createElement(b,{kind:e.kind})),i.createElement("div",{className:I.TextColumn},i.createElement("span",{className:I.PrimaryText},function(e){var t,n=(null===(t=e.methods[0].discountSettings)||void 0===t?void 0:t.discountAmount)||0;switch(e.kind){case"DYNAMIC":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleDynamicAmount");case"FIXED":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleFixedAmount",{value:W(n)});case"SHIPPING":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleFreeShipping");case"RATIO":return"".concat(S("checkout-page:loyaltyPointsLinesModalContentItemTitleRatio")," (%").concat(n,")");case"GIFT":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleFreeProduct")}}(e)),i.createElement("span",{className:I.SecondaryText},e.isDisabled?S("checkout-page:loyaltyMissingPoints",{point:P(e.missingPoint)}):function(e){var t,n,o=e.methods[0],i=(null===(t=o.discountSettings)||void 0===t?void 0:t.discountAmount)||0;switch(e.kind){case"DYNAMIC":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleDynamicAmountDescription",{point:P((null===(n=o.discountSettings)||void 0===n?void 0:n.point)||0),amount:W(i)});case"FIXED":return S("checkout-page:loyaltyCardFixedDescription",{amount:W(i)});case"SHIPPING":return S("checkout-page:loyaltyCardFreeShippingDescription");case"RATIO":return S("checkout-page:loyaltyCardRatioDescription",{ratio:String(i),amount:W(ne(o))});case"GIFT":return S("checkout-page:loyaltyCardFreeProductDescription",{count:String(e.methods.length)})}}(e))),i.createElement("span",{className:[I.Cost,I.SecondaryText].join(" ")},function(e){return"DYNAMIC"===e.kind?S("checkout-page:loyaltyCardDynamicCost",{point:P(e.minCost)}):"GIFT"===e.kind&&e.minCost!==e.maxCost?"".concat(P(e.minCost)," ~ ").concat($(e.maxCost)):$(e.minCost)}(e))),t&&i.createElement("div",{className:I.OptionContent},oe(e)))}))),!!Y.length&&i.createElement("div",{className:I.AppliedList},Y.map((function(e){var o,a,r,l,s,d,c=null===(o=j.loyaltySpendingMethodsAll)||void 0===o?void 0:o.find((function(t){return t.id===e.loyaltySpendingMethodId})),u=null===(a=j.checkout.nonCouponAdjustments)||void 0===a?void 0:a.find((function(t){return t.campaignId===e.id})),m=c?M(c):"FIXED",p=(null==u?void 0:u.amount)||0,y="",v=null;if("GIFT"===m){var f=null===(r=null==c?void 0:c.discountSettings)||void 0===r?void 0:r.freeProductId,g=(null===(l=j.checkout.items.find((function(e){return e.variant.productId===f})))||void 0===l?void 0:l.variant.name)||(null===(s=U.find((function(e){return e.method.id===(null==c?void 0:c.id)})))||void 0===s?void 0:s.name);y=g?S("checkout-page:loyaltyAppliedGiftTitle",{name:g}):S("checkout-page:loyaltyPointsLinesModalContentItemTitleFreeProduct"),v=i.createElement("span",null,S("checkout-page:free"))}else"SHIPPING"===m?(y=S("checkout-page:loyaltyPointsLinesModalContentItemTitleFreeShipping"),v=i.createElement("span",null,S("checkout-page:loyaltyAppliedShippingFree"))):(y="RATIO"===m?S("checkout-page:loyaltyAppliedRatioTitle",{ratio:String((null===(d=null==c?void 0:c.discountSettings)||void 0===d?void 0:d.discountAmount)||0)}):S("checkout-page:loyaltyPointsLinesModalContentItemTitleFixedAmount",{value:W(p)}),v=i.createElement("span",{className:I.DiscountValue},"- ",W(p)));return i.createElement("div",{key:e.id,className:I.AppliedRow},i.createElement("span",{className:I.IconBox},i.createElement(b,{kind:m})),i.createElement("div",{className:I.TextColumn},i.createElement("span",{className:I.PrimaryText},y),i.createElement("span",{className:I.SecondaryText},S("checkout-page:loyaltyAppliedPointsUsed",{point:P(e.amount)}))),i.createElement("div",{className:I.AppliedValue},v,_&&i.createElement("span",{className:[I.RemoveIcon,G===e.loyaltySpendingMethodId?I.RemoveIconLoading:""].join(" "),onClick:function(){return o=e.loyaltySpendingMethodId,t(void 0,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:if(G)return[2];O(o),e.label=1;case 1:return e.trys.push([1,,4,5]),[4,j.removeLoyaltyPointsFromCart(o)];case 2:return e.sent(),[4,j.reInitPaymentMethod()];case 3:return e.sent(),[3,5];case 4:return O(null),[7];case 5:return[2]}}))}));var o}},i.createElement(h,null))))}))))})),D=a((function(e){var o,a=e.vm,r=e.method,l=e.balance,s=e.isLoading,d=e.onApply,c=v().t,u=i.useState(""),m=u[0],p=u[1],f=i.useState(null),h=f[0],x=f[1],k=i.useRef(null);i.useEffect((function(){var e;null===(e=k.current)||void 0===e||e.focus()}),[]);var j,E=N(r,l),S=E.step,M=E.min,b=E.max,T=(null===(o=r.discountSettings)||void 0===o?void 0:o.discountAmount)||0,A=function(e){return y(e,a.checkout.currencyCode,a.checkout.currencySymbol)},L=(j=m.replace(/[.\s]/g,""))&&/^\d+$/.test(j)?parseInt(j,10):null,D=null!==L&&L>0?c("checkout-page:loyaltyDynamicPreview",{point:P(L),amount:A(L/S*T)}):"".concat(c("checkout-page:loyaltyDynamicRule",{min:P(M),max:P(b)})," · ").concat(c("checkout-page:loyaltyRateRule",{point:P(S),amount:A(T)}));return i.createElement("div",{className:I.DynamicInput},i.createElement(g,{value:m,inputRef:k,placeholder:c("checkout-page:loyaltyDynamicPlaceholder"),buttonLabel:c("checkout-page:actions.apply"),isLoading:s,onChange:function(e){p(e),h&&x(null)},onClick:function(){return t(void 0,void 0,void 0,(function(){var e;return n(this,(function(t){switch(t.label){case 0:return s?[2]:(e=function(e){if(null===e)return c("checkout-page:loyaltyErrorEmpty");if(e<M)return c("checkout-page:loyaltyErrorMin",{min:P(M)});if(e>b)return c("checkout-page:loyaltyErrorMax",{max:P(b)});if(e%S!=0){var t=Math.min(Math.max(Math.floor(e/S)*S,M),b);return c("checkout-page:loyaltyErrorStep",{point:P(S),pointWithSuffix:C(S),example:P(t)})}return null}(L),x(e),e||null===L?[2]:[4,d(L)]);case 1:return t.sent(),[2]}}))}))}}),i.createElement("div",{className:I.HintRow},i.createElement("span",{className:h?I.ErrorText:I.SecondaryText},h||D),b>=M&&i.createElement("span",{className:I.TextLink,onClick:function(){p(P(b)),x(null)}},c("checkout-page:loyaltyUseAll"))))}));export{A as LoyaltyEarningRow,L as LoyaltyPointsBlock,P as formatPoint,T as isLoyaltyBlockVisible};
|
|
1
|
+
import{__spreadArray as e,__awaiter as t,__generator as n,__assign as o}from'./../../../../../ext/tslib/tslib.es6.js';import*as i from"react";import{observer as a}from"mobx-react-lite";import{IkasStorefrontConfig as l}from"@ikas/storefront-config";import{LoyaltyProgramMethodSpendingTypeEnum as r,searchProducts as s,useLoyaltyPoints as d}from"@ikas/storefront-api";import{IkasCartCreatedBy as c}from"@ikas/storefront-models";import{CheckoutStep as u}from"../../../model.js";import"../../../../../models/data/blog/category/index.js";import"../../../../../models/data/blog/content/index.js";import"../../../../../models/data/blog/meta-data/index.js";import"../../../../../models/data/blog/tag/index.js";import"../../../../../models/data/blog/index.js";import"../../../../../models/data/brand/index.js";import"mobx";import"../../../../../models/data/campaign-offer/index.js";import"../../../../../models/data/cart/campaign-offer/index.js";import"../../../../../models/data/cart/index.js";import"../../../../../models/data/category/path-item/index.js";import"../../../../../models/data/category/index.js";import{IkasCheckout as m}from"../../../../../models/data/checkout/index.js";import"../../../../../models/data/checkout-settings/index.js";import"../../../../../models/data/city/index.js";import"../../../../../models/data/country/index.js";import"../../../../../models/data/customer/address/region/index.js";import"../../../../../models/data/customer/address/index.js";import"../../../../../models/data/customer/address/ikas-localized-customer-address.js";import"../../../../../models/data/customer/attribute/index.js";import"../../../../../models/data/customer/review/summary/index.js";import"../../../../../models/data/customer/review/index.js";import"../../../../../models/data/customer/index.js";import"../../../../../models/data/customer-form-data-input/index.js";import"../../../../../models/data/district/index.js";import"../../../../../models/data/favorite-product/index.js";import"../../../../../models/data/filter-category/index.js";import"../../../../../models/data/html-meta-data/index.js";import{IkasImage as p}from"../../../../../models/data/image/index.js";import"../../../../../models/data/order/address/region/index.js";import"../../../../../models/data/order/address/index.js";import"../../../../../models/data/order/line-item/option/value/index.js";import"../../../../../models/data/order/line-item/variant/value/index.js";import"../../../../../models/data/order/line-item/variant/index.js";import"../../../../../models/data/order/line-item/index.js";import"../../../../../models/data/order/order-transaction-with-prices/index.js";import"../../../../../models/data/order/package/index.js";import"../../../../../models/data/order/transaction/index.js";import"../../../../../models/data/order/index.js";import"../../../../../models/data/payment-gateway/index.js";import"../../../../../models/data/product/attribute-value/index.js";import"../../../../../models/data/product/filter/index.js";import"../../../../../models/data/product/campaign-offer/index.js";import"../../../../../models/data/product/option-set/option/index.js";import"../../../../../models/data/product/option-set/index.js";import"../../../../../models/data/product/stock-location/index.js";import"../../../../../models/data/product/variant/price/index.js";import"../../../../../models/data/product/variant/index.js";import"../../../../../models/data/variant-type/index.js";import"../../../../../models/data/product/index.js";import"../../../../../models/data/raffle/index.js";import"../../../../../models/data/shipping-zone/state/city/district/region/index.js";import"../../../../../models/data/state/index.js";import"../../../../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../../../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../../../../models/data/storefront-popup/index.js";import"../../../../../models/data/theme-json/index.js";import"../../../../../models/data/theme-json/component/index.js";import"../../../../../models/data/theme-json/custom-data/index.js";import"../../../../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../../../../../models/ui/blog-list/index.js";import"../../../../../models/ui/blog-category-list/index.js";import"../../../../../models/ui/brand-list/index.js";import"../../../../../models/ui/category-list/index.js";import"../../../../../models/ui/product-list/index.js";import"../../../../../models/ui/product-attribute-detail/index.js";import"../../../../../models/ui/product-attribute-list/index.js";import"../../../../../models/ui/customer-review-list/index.js";import"../../../../../models/ui/customer-review-summary-list/index.js";import"../../../../../models/ui/validator/index.js";import"../../../../../models/ui/validator/rules/index.js";import"../../../../../models/ui/validator/form/login.js";import"../../../../../models/ui/validator/form/address.js";import"../../../../../models/ui/validator/form/ikas-address.js";import"../../../../../models/ui/validator/form/register.js";import"../../../../../models/ui/validator/form/contact-form.js";import"../../../../../models/ui/validator/form/forgot-password.js";import"../../../../../models/ui/validator/form/recover-password.js";import"../../../../../models/ui/validator/form/account-info.js";import"../../../../../models/ui/validator/form/raffle-form.js";import"../../../../../models/ui/validator/form/customer-review.js";import"../../../../../models/ui/raffle-list/index.js";import{formatCurrency as y}from"../../../../../utils/currency.js";import{useTranslation as v}from"../../../../../utils/i18n.js";import{Button as f}from"../../button/index.js";import g from"../../input-with-button/index.js";import h from"../../svg/cross.js";import{SVGLoyaltyGift as x,SVGLoyaltyBox as k,SVGLoyaltyTag as E}from"./icons.js";import j from"../../svg/star-loyalty.js";import I from"./style.module.scss.js";var S=new Intl.NumberFormat("tr-TR",{maximumFractionDigits:0}),P=function(e){return S.format(Math.floor(e||0))},C=function(e){var t=Math.abs(Math.floor(e)),n=P(t),o="'in";if(0===t)o="'ın";else if(t%1e6==0)o="'un";else if(t%1e3==0)o="'in";else if(t%100==0)o="'ün";else if(t%10==0){o={1:"'un",2:"'nin",3:"'un",4:"'ın",5:"'nin",6:"'ın",7:"'in",8:"'in",9:"'ın"}[t/10%10]}else{o={1:"'in",2:"'nin",3:"'ün",4:"'ün",5:"'in",6:"'nın",7:"'nin",8:"'in",9:"'un"}[t%10]}return n+o},N=function(e){switch(e.type){case r.FREE_PRODUCT:return"GIFT";case r.FREE_SHIPPING:return"SHIPPING";case r.RATIO:return"RATIO";default:return e.isDynamic?"DYNAMIC":"FIXED"}},M=function(e,t){var n,o,i,a,l,r=(null===(n=e.discountSettings)||void 0===n?void 0:n.point)||1,s=null!==(i=null===(o=e.pointUsageLimit)||void 0===o?void 0:o.minPointLimit)&&void 0!==i?i:r,d=Math.min(null!==(l=null===(a=e.pointUsageLimit)||void 0===a?void 0:a.maxPointLimit)&&void 0!==l?l:t,t);return{step:r,min:s,max:Math.max(Math.floor(d/r)*r,0)}},b=function(e){var t=e.kind;return"GIFT"===t?i.createElement(x,null):"SHIPPING"===t?i.createElement(k,null):i.createElement(E,null)},T=function(e){var t,n,o;return!(e.step===u.SUCCESS||!(null===(t=e.customizationProps)||void 0===t?void 0:t.showLoyaltyPoints)||!e.loyaltyCustomerInfo||!(null===(n=e.loyaltySpendingMethods)||void 0===n?void 0:n.length)&&!(null===(o=e.checkout.loyaltyLines)||void 0===o?void 0:o.length)||e.isOpenEditOrderWithTransaction||e.checkout.createdBy===c.UPSELL||e.checkout.createdBy===c.ADMIN)},A=a((function(e){var t,n,o=e.vm,a=v().t,r=o.loyaltyEarningMethod,s=o.loyaltyCustomerInfo;if(!r||!s)return null;var d,c,u,m=r.amountPerPointsEarned||1,p=Math.floor(r.pointsEarned/m*(o.finalPrice||0)),f=s.customerTier,g=l.getCurrentLocale(),h=(f?(null===(n=null===(t=f.translations)||void 0===t?void 0:t.find((function(e){return e.locale===g})))||void 0===n?void 0:n.name)||f.name:null)||a("checkout-page:loyaltyEarnRule",{amount:y(m,o.checkout.currencyCode,o.checkout.currencySymbol),point:P(r.pointsEarned)});return i.createElement("div",{className:I.EarningRow},i.createElement("div",{className:I.EarningRowLeft},i.createElement("span",{className:I.StarIcon},i.createElement(j,null)),i.createElement("span",null,(d=a("checkout-page:loyaltyEarnTitle"),c="".concat(P(p)," ").concat(a("checkout-page:loyaltyPoint")),(u=d.split("{{value}}")).length<2?d:i.createElement(i.Fragment,null,u[0],i.createElement("strong",null,c),u.slice(1).join(c))))),i.createElement("span",{className:I.SecondaryText},h))})),L=a((function(a){var c,g,x,k,E=a.vm,S=v().t,C=i.useState(null),T=C[0],A=C[1],L=i.useState(null),F=L[0],R=L[1],w=i.useState(null),G=w[0],O=w[1],B=i.useState([]),U=B[0],H=B[1],V=i.useState(null),Y=V[0],z=V[1],X=E.isLoyaltyPointsVisible,_=Math.floor(null!==(g=null===(c=E.loyaltyCustomerInfo)||void 0===c?void 0:c.totalPoint)&&void 0!==g?g:0),W=E.checkout.loyaltyLines||[],$=W.map((function(e){return e.loyaltySpendingMethodId})),q=E.step!==u.SUCCESS&&!E.isOpenEditOrderWithTransaction,J=function(e){return y(e,E.checkout.currencyCode,E.checkout.currencySymbol)},K=function(e){return"".concat(P(e)," ").concat(S("checkout-page:loyaltyPoint"))},Q=i.useMemo((function(){var t=(E.loyaltySpendingMethods||[]).filter((function(e){return!$.includes(e.id)})),n=[],o=[];if(t.forEach((function(e){var t,i=N(e);if("GIFT"!==i){var a="DYNAMIC"===i?M(e,_).min:(null===(t=e.discountSettings)||void 0===t?void 0:t.point)||0;n.push({key:e.id,kind:i,methods:[e],minCost:a,maxCost:a,isDisabled:_<a,missingPoint:Math.max(a-_,0)})}else o.push(e)})),o.length){var i=o.map((function(e){var t;return(null===(t=e.discountSettings)||void 0===t?void 0:t.point)||0})),a=Math.min.apply(Math,i);n.push({key:"GIFT",kind:"GIFT",methods:o,minCost:a,maxCost:Math.max.apply(Math,i),isDisabled:_<a,missingPoint:Math.max(a-_,0)})}return e(e([],n.filter((function(e){return!e.isDisabled})),!0),n.filter((function(e){return e.isDisabled})),!0)}),[E.loyaltySpendingMethods,$.join(","),_]),Z=Q.filter((function(e){return!e.isDisabled})),ee=1===Q.length&&1===Z.length?Q[0]:null,te=q&&Q.length>0&&(Z.length>0||0===W.length);i.useEffect((function(){!te&&X&&E.setIsLoyaltyPointsVisible(!1)}),[te,X]),i.useEffect((function(){T&&!Q.some((function(e){return e.key===T}))&&A(null)}),[Q,T]),i.useEffect((function(){z(null)}),[T,X]);var ne=i.useMemo((function(){return(E.loyaltySpendingMethodsAll||E.loyaltySpendingMethods||[]).filter((function(e){return e.type===r.FREE_PRODUCT}))}),[E.loyaltySpendingMethodsAll,E.loyaltySpendingMethods]),oe=ne.map((function(e){var t;return(null===(t=e.discountSettings)||void 0===t?void 0:t.freeProductId)||""})).filter(Boolean).join(",");i.useEffect((function(){if(oe){var e=!1;return t(void 0,void 0,void 0,(function(){var t,o,i,a,r;return n(this,(function(n){switch(n.label){case 0:return t=oe.split(","),[4,s({input:{productIdList:t,page:1,perPage:t.length,priceListId:l.getPriceListId(),salesChannelId:l.getSalesChannelId()}},[])];case 1:return o=n.sent(),e||(i=(null===(r=o.data)||void 0===r?void 0:r.data)||[],a=[],ne.forEach((function(e){var t,n,o,l,r,s,d,c,u,m,y,v=i.find((function(t){var n;return t.id===(null===(n=e.discountSettings)||void 0===n?void 0:n.freeProductId)}));if(v){var f=(null===(t=v.variants)||void 0===t?void 0:t.find((function(t){var n;return t.id===(null===(n=e.discountSettings)||void 0===n?void 0:n.freeProductVariantId)})))||(null===(n=v.variants)||void 0===n?void 0:n[0]),g=(null===(r=null===(l=null===(o=null==f?void 0:f.images)||void 0===o?void 0:o.find((function(e){return e.isMain})))||void 0===l?void 0:l.image)||void 0===r?void 0:r.id)||(null===(c=null===(d=null===(s=null==f?void 0:f.images)||void 0===s?void 0:s[0])||void 0===d?void 0:d.image)||void 0===c?void 0:c.id)||null,h=null===(u=null==f?void 0:f.prices)||void 0===u?void 0:u[0];a.push({id:e.id,name:v.name,imageSrc:g?new p({id:g,isVideo:!1}).thumbnailSrc:null,price:h&&null!==(y=null!==(m=h.discountPrice)&&void 0!==m?m:h.sellPrice)&&void 0!==y?y:null,method:e})}})),H(a)),[2]}}))})),function(){e=!0}}}),[oe]);var ie=function(e,i,a){return t(void 0,void 0,void 0,(function(){var t,l,r;return n(this,(function(n){switch(n.label){case 0:if(F)return[2,!1];R(i),z(null),n.label=1;case 1:return n.trys.push([1,,7,8]),[4,d({input:o({cartId:E.checkout.id,loyaltyProgramId:e.loyaltyProgramId,loyaltySpendingMethodId:e.id},a?{amount:a}:{})})];case 2:return(t=n.sent()).isSuccess&&t.data?(l=!!(null===(r=t.data.loyaltyLines)||void 0===r?void 0:r.some((function(t){return t.loyaltySpendingMethodId===e.id}))),E.checkout=new m(o(o({},t.data),{shippingAddress:E.checkout.shippingAddress,billingAddress:E.checkout.billingAddress,customer:E.checkout.customer,selectedPaymentGateway:E.checkout.selectedPaymentGateway}),E.countrySettings),[4,E.getLoyaltyCustomerInfo()]):[3,6];case 3:return n.sent(),[4,E.listSpendingMethodsByCartId()];case 4:return n.sent(),[4,E.reInitPaymentMethod()];case 5:return n.sent(),l?(A(null),E.setIsLoyaltyPointsVisible(!1),[2,!0]):(z(e.id),[2,!1]);case 6:return[2,!1];case 7:return R(null),[7];case 8:return[2]}}))}))},ae=function(e){var t;return(E.checkout.totalPrice||0)*((null===(t=e.discountSettings)||void 0===t?void 0:t.discountAmount)||0)/100},le=function(e){var t=Y&&e.methods.some((function(e){return e.id===Y}))?S("checkout-page:loyaltyErrorNotApplied"):null;return"DYNAMIC"===e.kind?re(e,t):i.createElement(i.Fragment,null,re(e,null),!!t&&i.createElement("span",{className:I.ErrorText},t))},re=function(t,n){var o,a=t.methods[0];if("DYNAMIC"===t.kind)return i.createElement(D,{vm:E,method:a,balance:_,isLoading:F===t.key,applyError:n,onEdit:function(){return z(null)},onApply:function(e){return ie(a,t.key,e)}});if("GIFT"===t.kind){var l=U.filter((function(e){return t.methods.some((function(t){return t.id===e.method.id}))})),r=e(e([],l.filter((function(e){var t;return((null===(t=e.method.discountSettings)||void 0===t?void 0:t.point)||0)<=_})),!0),l.filter((function(e){var t;return((null===(t=e.method.discountSettings)||void 0===t?void 0:t.point)||0)>_})),!0);return i.createElement("div",{className:I.GiftList},r.map((function(e){var t,n=(null===(t=e.method.discountSettings)||void 0===t?void 0:t.point)||0,o=n>_;return i.createElement("div",{key:e.id,className:[I.GiftRow,o?I.GiftRowDisabled:""].join(" ")},i.createElement("div",{className:I.GiftImage},!!e.imageSrc&&i.createElement("img",{src:e.imageSrc,alt:e.name})),i.createElement("div",{className:I.GiftInfo},i.createElement("span",{className:I.GiftName},e.name),i.createElement("span",{className:I.SecondaryText},K(n),null!==e.price&&i.createElement(i.Fragment,null," · ",i.createElement("s",null,J(e.price))),o&&" · ".concat(S("checkout-page:loyaltyMissingPoints",{point:P(n-_)})))),i.createElement(f,{size:"medium",classes:I.SmallButton,isDisabled:o,isLoading:F===e.id,text:S("checkout-page:loyaltyPointsLineItemButtonAddFree"),onClick:function(){return ie(e.method,e.id)}}))})))}var s="SHIPPING"===t.kind?S("checkout-page:loyaltyApplyFreeShipping"):S("checkout-page:loyaltyPointsLineItemButtonApplyAmount",{amount:J("RATIO"===t.kind?ae(a):(null===(o=a.discountSettings)||void 0===o?void 0:o.discountAmount)||0)});return i.createElement(f,{size:"medium",style:{width:"100%"},isLoading:F===t.key,text:s,onClick:function(){return ie(a,t.key)}})},se="DYNAMIC"===(null==ee?void 0:ee.kind)?ee.methods[0]:null;return i.createElement("div",{className:I.LoyaltyBlock},i.createElement("div",{className:I.BalanceRow},i.createElement("div",{className:I.BalanceText},i.createElement("span",{className:I.StarIcon},i.createElement(j,null)),i.createElement("span",null,i.createElement("span",{className:I.SecondaryText},W.length?S("checkout-page:loyaltyRemainingBalance"):S("checkout-page:loyaltyBalance"))," ",i.createElement("strong",null,K(_)),!!se&&i.createElement("span",{className:I.SecondaryText}," · ",S("checkout-page:loyaltyRateRule",{point:P((null===(x=se.discountSettings)||void 0===x?void 0:x.point)||0),amount:J((null===(k=se.discountSettings)||void 0===k?void 0:k.discountAmount)||0)})))),te&&i.createElement(f,{isLine:!0,size:"medium",classes:I.UseButton,text:S(X?"checkout-page:actions.cancel":"checkout-page:loyaltyUse"),onClick:function(){X&&A(null),E.setIsLoyaltyPointsVisible(!X)}})),X&&te&&!!ee&&i.createElement("div",{className:I.SingleContent},le(ee)),X&&te&&!ee&&i.createElement("div",{className:I.OptionList},Q.map((function(e){var t=T===e.key;return i.createElement("div",{key:e.key,className:[I.OptionCard,t?I.OptionCardSelected:"",e.isDisabled?I.OptionCardDisabled:""].join(" ")},i.createElement("div",{className:I.OptionHeader,onClick:function(){return e.isDisabled||t?void 0:A(e.key)}},i.createElement("span",{className:I.Radio}),i.createElement("span",{className:I.IconBox},i.createElement(b,{kind:e.kind})),i.createElement("div",{className:I.TextColumn},i.createElement("span",{className:I.PrimaryText},function(e){var t,n=(null===(t=e.methods[0].discountSettings)||void 0===t?void 0:t.discountAmount)||0;switch(e.kind){case"DYNAMIC":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleDynamicAmount");case"FIXED":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleFixedAmount",{value:J(n)});case"SHIPPING":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleFreeShipping");case"RATIO":return"".concat(S("checkout-page:loyaltyPointsLinesModalContentItemTitleRatio")," (%").concat(n,")");case"GIFT":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleFreeProduct")}}(e)),i.createElement("span",{className:I.SecondaryText},e.isDisabled?S("checkout-page:loyaltyMissingPoints",{point:P(e.missingPoint)}):function(e){var t,n,o=e.methods[0],i=(null===(t=o.discountSettings)||void 0===t?void 0:t.discountAmount)||0;switch(e.kind){case"DYNAMIC":return S("checkout-page:loyaltyPointsLinesModalContentItemTitleDynamicAmountDescription",{point:P((null===(n=o.discountSettings)||void 0===n?void 0:n.point)||0),amount:J(i)});case"FIXED":return S("checkout-page:loyaltyCardFixedDescription",{amount:J(i)});case"SHIPPING":return S("checkout-page:loyaltyCardFreeShippingDescription");case"RATIO":return S("checkout-page:loyaltyCardRatioDescription",{ratio:String(i),amount:J(ae(o))});case"GIFT":return S("checkout-page:loyaltyCardFreeProductDescription",{count:String(e.methods.length)})}}(e))),i.createElement("span",{className:[I.Cost,I.SecondaryText].join(" ")},function(e){return"DYNAMIC"===e.kind?S("checkout-page:loyaltyCardDynamicCost",{point:P(e.minCost)}):"GIFT"===e.kind&&e.minCost!==e.maxCost?"".concat(P(e.minCost)," ~ ").concat(K(e.maxCost)):K(e.minCost)}(e))),t&&i.createElement("div",{className:I.OptionContent},le(e)))}))),!!W.length&&i.createElement("div",{className:I.AppliedList},W.map((function(e){var o,a,l,r,s,d,c=null===(o=E.loyaltySpendingMethodsAll)||void 0===o?void 0:o.find((function(t){return t.id===e.loyaltySpendingMethodId})),u=null===(a=E.checkout.nonCouponAdjustments)||void 0===a?void 0:a.find((function(t){return t.campaignId===e.id})),m=c?N(c):"FIXED",p=(null==u?void 0:u.amount)||0,y="",v=null;if("GIFT"===m){var f=null===(l=null==c?void 0:c.discountSettings)||void 0===l?void 0:l.freeProductId,g=(null===(r=E.checkout.items.find((function(e){return e.variant.productId===f})))||void 0===r?void 0:r.variant.name)||(null===(s=U.find((function(e){return e.method.id===(null==c?void 0:c.id)})))||void 0===s?void 0:s.name);y=g?S("checkout-page:loyaltyAppliedGiftTitle",{name:g}):S("checkout-page:loyaltyPointsLinesModalContentItemTitleFreeProduct"),v=p?i.createElement("span",{className:I.DiscountValue},"- ",J(p)):i.createElement("span",null,S("checkout-page:free"))}else"SHIPPING"===m?(y=S("checkout-page:loyaltyPointsLinesModalContentItemTitleFreeShipping"),v=i.createElement("span",null,S("checkout-page:loyaltyAppliedShippingFree"))):(y="RATIO"===m?S("checkout-page:loyaltyAppliedRatioTitle",{ratio:String((null===(d=null==c?void 0:c.discountSettings)||void 0===d?void 0:d.discountAmount)||0)}):S("checkout-page:loyaltyPointsLinesModalContentItemTitleFixedAmount",{value:J(p)}),v=i.createElement("span",{className:I.DiscountValue},"- ",J(p)));return i.createElement("div",{key:e.id,className:I.AppliedRow},i.createElement("span",{className:I.IconBox},i.createElement(b,{kind:m})),i.createElement("div",{className:I.TextColumn},i.createElement("span",{className:I.PrimaryText},y),i.createElement("span",{className:I.SecondaryText},S("checkout-page:loyaltyAppliedPointsUsed",{point:P(e.amount)}))),i.createElement("div",{className:I.AppliedValue},v,q&&i.createElement("span",{className:[I.RemoveIcon,G===e.loyaltySpendingMethodId?I.RemoveIconLoading:""].join(" "),onClick:function(){return o=e.loyaltySpendingMethodId,t(void 0,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:if(G)return[2];O(o),e.label=1;case 1:return e.trys.push([1,,4,5]),[4,E.removeLoyaltyPointsFromCart(o)];case 2:return e.sent(),[4,E.reInitPaymentMethod()];case 3:return e.sent(),[3,5];case 4:return O(null),[7];case 5:return[2]}}))}));var o}},i.createElement(h,null))))}))))})),D=a((function(e){var o,a=e.vm,l=e.method,r=e.balance,s=e.isLoading,d=e.applyError,c=e.onEdit,u=e.onApply,m=v().t,p=i.useState(""),f=p[0],h=p[1],x=i.useState(null),k=x[0],E=x[1],j=i.useRef(null);i.useEffect((function(){var e;null===(e=j.current)||void 0===e||e.focus()}),[]);var S,N=M(l,r),b=N.step,T=N.min,A=N.max,L=(null===(o=l.discountSettings)||void 0===o?void 0:o.discountAmount)||0,D=function(e){return y(e,a.checkout.currencyCode,a.checkout.currencySymbol)},F=(S=f.replace(/[.\s]/g,""))&&/^\d+$/.test(S)?parseInt(S,10):null,R=null!==F&&F>0?m("checkout-page:loyaltyDynamicPreview",{point:P(F),amount:D(F/b*L)}):"".concat(m("checkout-page:loyaltyDynamicRule",{min:P(T),max:P(A)})," · ").concat(m("checkout-page:loyaltyRateRule",{point:P(b),amount:D(L)}));return i.createElement("div",{className:I.DynamicInput},i.createElement(g,{value:f,inputRef:j,placeholder:m("checkout-page:loyaltyDynamicPlaceholder"),buttonLabel:m("checkout-page:actions.apply"),isLoading:s,onChange:function(e){h(e),k&&E(null),null==c||c()},onClick:function(){return t(void 0,void 0,void 0,(function(){var e;return n(this,(function(t){switch(t.label){case 0:return s?[2]:(e=function(e){if(null===e)return m("checkout-page:loyaltyErrorEmpty");if(e<T)return m("checkout-page:loyaltyErrorMin",{min:P(T)});if(e>A)return m("checkout-page:loyaltyErrorMax",{max:P(A)});if(e%b!=0){var t=Math.min(Math.max(Math.floor(e/b)*b,T),A);return m("checkout-page:loyaltyErrorStep",{point:P(b),pointWithSuffix:C(b),example:P(t)})}return null}(F),E(e),e||null===F?[2]:[4,u(F)]);case 1:return t.sent(),[2]}}))}))}}),i.createElement("div",{className:I.HintRow},i.createElement("span",{className:k||d?I.ErrorText:I.SecondaryText},k||d||R),A>=T&&i.createElement("span",{className:I.TextLink,onClick:function(){h(P(A)),E(null)}},m("checkout-page:loyaltyUseAll"))))}));export{A as LoyaltyEarningRow,L as LoyaltyPointsBlock,P as formatPoint,T as isLoyaltyBlockVisible};
|
|
@@ -73,6 +73,8 @@ export declare type SecureCardSaleInput = {
|
|
|
73
73
|
masterPassDetail?: object | null;
|
|
74
74
|
metadata?: object | null;
|
|
75
75
|
milesSmiles?: object | null;
|
|
76
|
+
/** PayTR card storage (DEV-3623): save the card with this sale. */
|
|
77
|
+
storeCard?: boolean;
|
|
76
78
|
};
|
|
77
79
|
/**
|
|
78
80
|
* Storefront API request headers the frame forwards (see setAPIClientConfig).
|
|
@@ -6,6 +6,8 @@ declare type Props = {
|
|
|
6
6
|
hasError?: boolean;
|
|
7
7
|
removePadding?: boolean;
|
|
8
8
|
onChange?: (value: boolean) => void;
|
|
9
|
+
/** "radio": ring + dot, for choices inside a payment method box. */
|
|
10
|
+
variant?: "check" | "radio";
|
|
9
11
|
};
|
|
10
12
|
export declare const Toggle: React.FC<Props>;
|
|
11
13
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"react";import{observer as a}from"mobx-react-lite";import o from"../checkbox/check.js";import r from"./style.module.scss.js";var c=a((function(a){var c=a.value,
|
|
1
|
+
import*as e from"react";import{observer as a}from"mobx-react-lite";import o from"../checkbox/check.js";import r from"./style.module.scss.js";var c=a((function(a){var c=a.value,i=a.label,t=a.description,n=a.hasError,l=a.removePadding,s=a.onChange,m=a.variant,h=void 0===m?"check":m,d=[r.CheckboxBorder],b=[r.CheckboxLabel],k=[r.CheckboxDescription],v=[r.CheckboxTick];return c&&(d.push(r.Checked),v.push(r.Visible)),n&&b.push(r.CheckboxLabelError),e.createElement("div",{className:[r.CheckboxWrapper,l?r.WithoutPadding:"",i?"":r.WithoutLabel,"radio"===h?r.Radio:""].join(" "),onClick:function(){s&&s(!c)}},e.createElement("div",{className:r.CheckboxContainer},e.createElement("div",{className:d.join(" ")}),e.createElement("div",{className:v.join(" ")},e.createElement(o,null))),e.createElement("div",{className:r.CheckboxLabelContainer},!!i&&e.createElement("div",{className:b.join(" ")},i),!!t&&e.createElement("div",{className:k.join(" ")},t)))}));export{c as Toggle};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from'./../../../../ext/style-inject/dist/style-inject.es.js';var o={CheckboxWrapper:"style-module_CheckboxWrapper__5RhYr",WithoutPadding:"style-module_WithoutPadding__dZ4VI",WithoutLabel:"style-module_WithoutLabel__YoWH0",CheckboxContainer:"style-module_CheckboxContainer__26lKe",CheckboxBorder:"style-module_CheckboxBorder__7A2SL",Checked:"style-module_Checked__PPUk8",CheckboxTick:"style-module_CheckboxTick__Qp5qA",Visible:"style-module_Visible__M3y9g",CheckboxLabelContainer:"style-module_CheckboxLabelContainer__1g1JQ",CheckboxLabel:"style-module_CheckboxLabel__Oj6l8",CheckboxDescription:"style-module_CheckboxDescription__p7nar",CheckboxLabelError:"style-module_CheckboxLabelError__tYedL"};e(
|
|
1
|
+
import e from'./../../../../ext/style-inject/dist/style-inject.es.js';var o={CheckboxWrapper:"style-module_CheckboxWrapper__5RhYr",WithoutPadding:"style-module_WithoutPadding__dZ4VI",WithoutLabel:"style-module_WithoutLabel__YoWH0",CheckboxContainer:"style-module_CheckboxContainer__26lKe",CheckboxBorder:"style-module_CheckboxBorder__7A2SL",Checked:"style-module_Checked__PPUk8",CheckboxTick:"style-module_CheckboxTick__Qp5qA",Visible:"style-module_Visible__M3y9g",CheckboxLabelContainer:"style-module_CheckboxLabelContainer__1g1JQ",CheckboxLabel:"style-module_CheckboxLabel__Oj6l8",CheckboxDescription:"style-module_CheckboxDescription__p7nar",CheckboxLabelError:"style-module_CheckboxLabelError__tYedL",Radio:"style-module_Radio__2Dyu9"};e('.style-module_CheckboxWrapper__5RhYr {\n width: 100%;\n display: flex;\n padding: 0.5em 0;\n cursor: pointer;\n user-select: none;\n align-items: center;\n}\n.style-module_CheckboxWrapper__5RhYr.style-module_WithoutPadding__dZ4VI {\n padding: 0;\n}\n.style-module_CheckboxWrapper__5RhYr.style-module_WithoutLabel__YoWH0 {\n padding: 0;\n width: auto;\n}\n.style-module_CheckboxWrapper__5RhYr .style-module_CheckboxContainer__26lKe {\n position: relative;\n width: 20px;\n height: 20px;\n margin-right: 16px;\n}\n.style-module_CheckboxWrapper__5RhYr .style-module_CheckboxBorder__7A2SL {\n flex: 0 0 auto;\n width: 20px;\n height: 20px;\n border-radius: 100%;\n border: 1px solid var(--checkout-border-color);\n position: absolute;\n top: 0;\n left: 0;\n transition: border-width 0.2s ease-in-out;\n}\n.style-module_CheckboxWrapper__5RhYr .style-module_CheckboxBorder__7A2SL.style-module_Checked__PPUk8 {\n border: 10px solid var(--checkout-button-bg-color);\n}\n.style-module_CheckboxWrapper__5RhYr .style-module_CheckboxTick__Qp5qA {\n width: 20px;\n height: 20px;\n display: flex;\n justify-content: center;\n align-items: center;\n position: absolute;\n top: 0;\n left: 0;\n color: var(--checkout-button-text-color);\n z-index: 2;\n transition: all 0.2s ease-in-out;\n transition-delay: 0.1s;\n opacity: 0;\n transform: scale(0.2);\n}\n.style-module_CheckboxWrapper__5RhYr .style-module_CheckboxTick__Qp5qA.style-module_Visible__M3y9g {\n opacity: 1;\n transform: scale(1.2);\n}\n.style-module_CheckboxWrapper__5RhYr .style-module_CheckboxLabelContainer__1g1JQ {\n flex: 1 1 auto;\n}\n.style-module_CheckboxWrapper__5RhYr .style-module_CheckboxLabel__Oj6l8 {\n font-weight: normal;\n}\n.style-module_CheckboxWrapper__5RhYr .style-module_CheckboxDescription__p7nar {\n font-weight: normal;\n font-size: 0.9rem;\n color: var(--checkout-secondary-text-color);\n}\n.style-module_CheckboxWrapper__5RhYr .style-module_CheckboxLabelError__tYedL {\n color: var(--checkout-error-color);\n}\n.style-module_CheckboxWrapper__5RhYr.style-module_Radio__2Dyu9 .style-module_CheckboxBorder__7A2SL.style-module_Checked__PPUk8 {\n border: 1.5px solid var(--checkout-button-bg-color);\n}\n.style-module_CheckboxWrapper__5RhYr.style-module_Radio__2Dyu9 .style-module_CheckboxBorder__7A2SL.style-module_Checked__PPUk8::after {\n content: "";\n position: absolute;\n top: 50%;\n left: 50%;\n width: 9px;\n height: 9px;\n border-radius: 100%;\n background: var(--checkout-button-bg-color);\n transform: translate(-50%, -50%);\n}\n.style-module_CheckboxWrapper__5RhYr.style-module_Radio__2Dyu9 .style-module_CheckboxTick__Qp5qA {\n display: none;\n}');export{o as default};
|
|
@@ -13,7 +13,7 @@ import MasterPassModel from "./modelMasterPass";
|
|
|
13
13
|
import { APIResponse } from "@ikas/fe-api-client";
|
|
14
14
|
import { CreateStripePaymentIntentResponse, RetrieveInstallmentInfoResponse, UpdateCartCampaignOfferInput, CreateKlarnaTokenResponse, GetPaypalClientIdResponse, CreatePaypalOrderResponse, CreateAdyenPlatformSessionResponse, HepsipayFrameInitResponse, CreateIyzicoCheckoutFormResponse, CreateTkPayCheckoutFormResponse, LoyaltyCustomerInfo, LoyaltyProgramSpendingMethod, LoyaltyProgramEarningMethod } from "@ikas/storefront-api";
|
|
15
15
|
import { IkasBaseStore } from "../../store";
|
|
16
|
-
import { RetrieveInstallmentInfoQueryParams, SaveCartInput, MilesSmilesDetailsResponse, MilesSmilesPaymentInput } from "@ikas/storefront-api";
|
|
16
|
+
import { RetrieveInstallmentInfoQueryParams, SaveCartInput, MilesSmilesDetailsResponse, MilesSmilesPaymentInput, SavedCard } from "@ikas/storefront-api";
|
|
17
17
|
import { LocalizedAddressModel } from "@ikas/localized-address";
|
|
18
18
|
import { IkasOrderTransactionWithPrices, IkasStoreCreditBalance } from "@ikas/storefront-models";
|
|
19
19
|
import { StripeExpressCheckoutAddressInput, StripeExpressCheckoutSessionContextResponse } from "@ikas/storefront-api/src/__api/types";
|
|
@@ -47,6 +47,13 @@ export default class CheckoutViewModel {
|
|
|
47
47
|
step: CheckoutStep;
|
|
48
48
|
customizationProps?: IkasCheckoutCustomizationProps | null;
|
|
49
49
|
cardData?: CreditCardData | null;
|
|
50
|
+
storeCard: boolean;
|
|
51
|
+
savedCards: SavedCard[];
|
|
52
|
+
/** Gateway the saved cards were listed for. */
|
|
53
|
+
savedCardsGatewayId: string | null;
|
|
54
|
+
/** Selected saved card; null means "pay with a new card". */
|
|
55
|
+
selectedSavedCardId: string | null;
|
|
56
|
+
savedCardCvv: string;
|
|
50
57
|
secureCard: SecureCardViewModel;
|
|
51
58
|
masterPassBridge: MasterPassBridgeViewModel | null;
|
|
52
59
|
paymentGateways: IkasPaymentGateway[];
|
|
@@ -188,6 +195,18 @@ export default class CheckoutViewModel {
|
|
|
188
195
|
get isHepsiPay(): boolean | null | undefined;
|
|
189
196
|
get isIyzico(): boolean | null | undefined;
|
|
190
197
|
get isTkPay(): boolean | null | undefined;
|
|
198
|
+
/** PayTR gateway with card storage turned on, for a logged in customer. */
|
|
199
|
+
isCardStorageGateway: (pg?: IkasPaymentGateway | null) => boolean;
|
|
200
|
+
get isCardStorageEnabled(): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* With the secure card iframe on, the saved card's CVC should be entered in
|
|
203
|
+
* the iframe too (DEV-3623 guide), which the frame does not support yet, so
|
|
204
|
+
* saved cards are not offered there.
|
|
205
|
+
*/
|
|
206
|
+
get canUseSavedCards(): boolean;
|
|
207
|
+
get visibleSavedCards(): SavedCard[];
|
|
208
|
+
get selectedSavedCard(): SavedCard | undefined;
|
|
209
|
+
get isSavedCardCvvValid(): boolean;
|
|
191
210
|
get isFree(): boolean;
|
|
192
211
|
/** Merchant's TK_PAY gateway with Miles&Smiles enabled, if any. */
|
|
193
212
|
get milesSmilesPaymentGateway(): IkasPaymentGateway | undefined;
|
|
@@ -339,6 +358,11 @@ export default class CheckoutViewModel {
|
|
|
339
358
|
onCompletePaymentClick: () => Promise<void>;
|
|
340
359
|
onCompleteDigitalOnlyPaymentClick: () => Promise<void>;
|
|
341
360
|
createSaleTransaction: () => Promise<void>;
|
|
361
|
+
/**
|
|
362
|
+
* Sends savedCardDetail instead of paymentMethodDetail (the backend rejects
|
|
363
|
+
* both together). 3D Secure is decided by the backend.
|
|
364
|
+
*/
|
|
365
|
+
private createSaleTransactionWithSavedCard;
|
|
342
366
|
/** The card iframe adds the card and sends the sale itself. */
|
|
343
367
|
private createSaleTransactionWithSecureCard;
|
|
344
368
|
onCheckoutTransactionSuccess: (checkoutId?: string) => Promise<void>;
|
|
@@ -367,6 +391,11 @@ export default class CheckoutViewModel {
|
|
|
367
391
|
onTkPayPaymentSuccess: (postCallback: () => Promise<void>) => Promise<void>;
|
|
368
392
|
setShowTkPayContainer: (value: boolean) => void;
|
|
369
393
|
setPaymentGateway: (index: number) => Promise<void>;
|
|
394
|
+
listSavedCards: (paymentGateway: IkasPaymentGateway) => Promise<void>;
|
|
395
|
+
/** null selects "pay with a new card". */
|
|
396
|
+
selectSavedCard: (id: string | null) => void;
|
|
397
|
+
onSavedCardCvvChange: (value: string) => void;
|
|
398
|
+
setStoreCard: (value: boolean) => void;
|
|
370
399
|
updatePaymentGateway: (paymentGateway: IkasPaymentGateway) => Promise<boolean>;
|
|
371
400
|
setInstallmentCount: (count: number) => void;
|
|
372
401
|
changeStep: (step: CheckoutStep, checkoutId?: string) => Promise<void>;
|