@pelcro/react-pelcro-js 2.7.0-beta.7 → 2.7.0-beta.8

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/index.cjs.js CHANGED
@@ -3620,7 +3620,8 @@ var labels$h = {
3620
3620
  "for": "for",
3621
3621
  interval: "{{count}} {{interval}}",
3622
3622
  interval_plural: "{{count}} {{interval}}s",
3623
- tax: "+ Tax"
3623
+ tax: "+ Tax",
3624
+ removeCoupon: "REMOVE"
3624
3625
  };
3625
3626
  var checkoutForm_en = {
3626
3627
  messages: messages$j,
@@ -3646,7 +3647,8 @@ var labels$g = {
3646
3647
  "for": "pour",
3647
3648
  interval: "{{count}} {{interval}}",
3648
3649
  interval_plural: "{{count}} {{interval}}s",
3649
- tax: "+ Taxe"
3650
+ tax: "+ Taxe",
3651
+ removeCoupon: "RETIRER"
3650
3652
  };
3651
3653
  var checkoutForm_fr = {
3652
3654
  messages: messages$i,
@@ -9144,6 +9146,7 @@ const SUBSCRIBE = "CREATE_SUBSCRIPTION";
9144
9146
  const HANDLE_PAYPAL_SUBSCRIPTION = "HANDLE_PAYPAL_SUBSCRIPTION";
9145
9147
  const DISABLE_COUPON_BUTTON = "DISABLE_COUPON_BUTTON";
9146
9148
  const APPLY_COUPON_CODE = "APPLY_COUPON_CODE";
9149
+ const REMOVE_APPLIED_COUPON = "REMOVE_APPLIED_COUPON";
9147
9150
  const SET_PERCENT_OFF = "SET_PERCENT_OFF";
9148
9151
  const SET_COUPON = "SET_COUPON";
9149
9152
  const SET_COUPON_ERROR = "SET_COUPON_ERROR";
@@ -13017,10 +13020,6 @@ const PaymentMethodContainerWithoutStripe = ({
13017
13020
  });
13018
13021
 
13019
13022
  if (err) {
13020
- dispatch({
13021
- type: SET_PERCENT_OFF,
13022
- payload: ""
13023
- });
13024
13023
  onFailure(err);
13025
13024
  return dispatch({
13026
13025
  type: SET_COUPON_ERROR,
@@ -13115,6 +13114,54 @@ const PaymentMethodContainerWithoutStripe = ({
13115
13114
 
13116
13115
  const debouncedApplyCouponCode = React.useRef(debounce(onApplyCouponCode, 1000)).current;
13117
13116
 
13117
+ const removeAppliedCoupon = state => {
13118
+ state.couponCode = "";
13119
+ dispatch({
13120
+ type: SET_COUPON_ERROR,
13121
+ payload: ""
13122
+ });
13123
+ dispatch({
13124
+ type: SHOW_COUPON_FIELD,
13125
+ payload: false
13126
+ });
13127
+ dispatch({
13128
+ type: SET_COUPON,
13129
+ payload: null
13130
+ });
13131
+ dispatch({
13132
+ type: SET_PERCENT_OFF,
13133
+ payload: ""
13134
+ });
13135
+ dispatch({
13136
+ type: SET_UPDATED_PRICE,
13137
+ payload: null
13138
+ });
13139
+ dispatch({
13140
+ type: SET_TAX_AMOUNT,
13141
+ payload: null
13142
+ });
13143
+ const {
13144
+ currentPlan
13145
+ } = state;
13146
+
13147
+ if (currentPlan) {
13148
+ var _currentPlan$quantity;
13149
+
13150
+ const quantity = (_currentPlan$quantity = currentPlan.quantity) !== null && _currentPlan$quantity !== void 0 ? _currentPlan$quantity : 1;
13151
+ const price = currentPlan.amount;
13152
+ dispatch({
13153
+ type: SET_UPDATED_PRICE,
13154
+ // set original plan price
13155
+ payload: price * quantity
13156
+ });
13157
+ dispatch({
13158
+ type: UPDATE_PAYMENT_REQUEST
13159
+ }); // update the new amount with taxes if site has taxes enabled
13160
+
13161
+ updateTotalAmountWithTax();
13162
+ }
13163
+ };
13164
+
13118
13165
  const subscribe = (stripeSource, state, dispatch) => {
13119
13166
  const {
13120
13167
  couponCode
@@ -13732,6 +13779,9 @@ const PaymentMethodContainerWithoutStripe = ({
13732
13779
  disableCouponButton: true
13733
13780
  }, (state, dispatch) => onApplyCouponCode(state, dispatch));
13734
13781
 
13782
+ case REMOVE_APPLIED_COUPON:
13783
+ return lib_5(state, () => removeAppliedCoupon(state));
13784
+
13735
13785
  case SET_COUPON:
13736
13786
  return lib_7({ ...state,
13737
13787
  couponObject: action.payload
@@ -13900,6 +13950,10 @@ const DiscountedPrice = props => {
13900
13950
  var _order$currency, _order$, _plan$quantity;
13901
13951
 
13902
13952
  const {
13953
+ t
13954
+ } = useTranslation("checkoutForm");
13955
+ const {
13956
+ dispatch,
13903
13957
  state: {
13904
13958
  updatedPrice,
13905
13959
  taxAmount,
@@ -13915,12 +13969,22 @@ const DiscountedPrice = props => {
13915
13969
  const discountedPriceWithoutTax = updatedPrice - taxAmount;
13916
13970
  const priceFormatted = getFormattedPriceByLocal(order ? updatedPrice : discountedPriceWithoutTax * planQuantity, ecommOrderCurrency !== null && ecommOrderCurrency !== void 0 ? ecommOrderCurrency : plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
13917
13971
 
13972
+ const onCouponRemove = () => {
13973
+ dispatch({
13974
+ type: REMOVE_APPLIED_COUPON
13975
+ });
13976
+ };
13977
+
13918
13978
  if (percentOff) {
13919
13979
  return /*#__PURE__*/React__default['default'].createElement("div", Object.assign({
13920
- className: "plc-flex plc-justify-center plc-mt-2 pelcro-discount"
13921
- }, props), "(-", percentOff, ")", " ", /*#__PURE__*/React__default['default'].createElement("span", {
13922
- className: "plc-font-bold pelcro-discounted-price"
13923
- }, priceFormatted));
13980
+ className: "plc-flex plc-items-center plc-justify-center plc-mt-2 pelcro-discount"
13981
+ }, props), "(-", percentOff, ")", /*#__PURE__*/React__default['default'].createElement("span", {
13982
+ className: "plc-ml-1 plc-font-bold pelcro-discounted-price"
13983
+ }, priceFormatted), /*#__PURE__*/React__default['default'].createElement(Button, {
13984
+ variant: "ghost",
13985
+ className: "plc-ml-2 plc-text-red-500 focus:plc-ring-red-500 pelcro-dashboard-sub-cancel-button",
13986
+ onClick: onCouponRemove
13987
+ }, "\u2715 ", t("labels.removeCoupon")));
13924
13988
  }
13925
13989
 
13926
13990
  return "";
package/dist/index.esm.js CHANGED
@@ -3590,7 +3590,8 @@ var labels$h = {
3590
3590
  "for": "for",
3591
3591
  interval: "{{count}} {{interval}}",
3592
3592
  interval_plural: "{{count}} {{interval}}s",
3593
- tax: "+ Tax"
3593
+ tax: "+ Tax",
3594
+ removeCoupon: "REMOVE"
3594
3595
  };
3595
3596
  var checkoutForm_en = {
3596
3597
  messages: messages$j,
@@ -3616,7 +3617,8 @@ var labels$g = {
3616
3617
  "for": "pour",
3617
3618
  interval: "{{count}} {{interval}}",
3618
3619
  interval_plural: "{{count}} {{interval}}s",
3619
- tax: "+ Taxe"
3620
+ tax: "+ Taxe",
3621
+ removeCoupon: "RETIRER"
3620
3622
  };
3621
3623
  var checkoutForm_fr = {
3622
3624
  messages: messages$i,
@@ -9114,6 +9116,7 @@ const SUBSCRIBE = "CREATE_SUBSCRIPTION";
9114
9116
  const HANDLE_PAYPAL_SUBSCRIPTION = "HANDLE_PAYPAL_SUBSCRIPTION";
9115
9117
  const DISABLE_COUPON_BUTTON = "DISABLE_COUPON_BUTTON";
9116
9118
  const APPLY_COUPON_CODE = "APPLY_COUPON_CODE";
9119
+ const REMOVE_APPLIED_COUPON = "REMOVE_APPLIED_COUPON";
9117
9120
  const SET_PERCENT_OFF = "SET_PERCENT_OFF";
9118
9121
  const SET_COUPON = "SET_COUPON";
9119
9122
  const SET_COUPON_ERROR = "SET_COUPON_ERROR";
@@ -12987,10 +12990,6 @@ const PaymentMethodContainerWithoutStripe = ({
12987
12990
  });
12988
12991
 
12989
12992
  if (err) {
12990
- dispatch({
12991
- type: SET_PERCENT_OFF,
12992
- payload: ""
12993
- });
12994
12993
  onFailure(err);
12995
12994
  return dispatch({
12996
12995
  type: SET_COUPON_ERROR,
@@ -13085,6 +13084,54 @@ const PaymentMethodContainerWithoutStripe = ({
13085
13084
 
13086
13085
  const debouncedApplyCouponCode = useRef(debounce(onApplyCouponCode, 1000)).current;
13087
13086
 
13087
+ const removeAppliedCoupon = state => {
13088
+ state.couponCode = "";
13089
+ dispatch({
13090
+ type: SET_COUPON_ERROR,
13091
+ payload: ""
13092
+ });
13093
+ dispatch({
13094
+ type: SHOW_COUPON_FIELD,
13095
+ payload: false
13096
+ });
13097
+ dispatch({
13098
+ type: SET_COUPON,
13099
+ payload: null
13100
+ });
13101
+ dispatch({
13102
+ type: SET_PERCENT_OFF,
13103
+ payload: ""
13104
+ });
13105
+ dispatch({
13106
+ type: SET_UPDATED_PRICE,
13107
+ payload: null
13108
+ });
13109
+ dispatch({
13110
+ type: SET_TAX_AMOUNT,
13111
+ payload: null
13112
+ });
13113
+ const {
13114
+ currentPlan
13115
+ } = state;
13116
+
13117
+ if (currentPlan) {
13118
+ var _currentPlan$quantity;
13119
+
13120
+ const quantity = (_currentPlan$quantity = currentPlan.quantity) !== null && _currentPlan$quantity !== void 0 ? _currentPlan$quantity : 1;
13121
+ const price = currentPlan.amount;
13122
+ dispatch({
13123
+ type: SET_UPDATED_PRICE,
13124
+ // set original plan price
13125
+ payload: price * quantity
13126
+ });
13127
+ dispatch({
13128
+ type: UPDATE_PAYMENT_REQUEST
13129
+ }); // update the new amount with taxes if site has taxes enabled
13130
+
13131
+ updateTotalAmountWithTax();
13132
+ }
13133
+ };
13134
+
13088
13135
  const subscribe = (stripeSource, state, dispatch) => {
13089
13136
  const {
13090
13137
  couponCode
@@ -13702,6 +13749,9 @@ const PaymentMethodContainerWithoutStripe = ({
13702
13749
  disableCouponButton: true
13703
13750
  }, (state, dispatch) => onApplyCouponCode(state, dispatch));
13704
13751
 
13752
+ case REMOVE_APPLIED_COUPON:
13753
+ return lib_5(state, () => removeAppliedCoupon(state));
13754
+
13705
13755
  case SET_COUPON:
13706
13756
  return lib_7({ ...state,
13707
13757
  couponObject: action.payload
@@ -13870,6 +13920,10 @@ const DiscountedPrice = props => {
13870
13920
  var _order$currency, _order$, _plan$quantity;
13871
13921
 
13872
13922
  const {
13923
+ t
13924
+ } = useTranslation("checkoutForm");
13925
+ const {
13926
+ dispatch,
13873
13927
  state: {
13874
13928
  updatedPrice,
13875
13929
  taxAmount,
@@ -13885,12 +13939,22 @@ const DiscountedPrice = props => {
13885
13939
  const discountedPriceWithoutTax = updatedPrice - taxAmount;
13886
13940
  const priceFormatted = getFormattedPriceByLocal(order ? updatedPrice : discountedPriceWithoutTax * planQuantity, ecommOrderCurrency !== null && ecommOrderCurrency !== void 0 ? ecommOrderCurrency : plan === null || plan === void 0 ? void 0 : plan.currency, getPageOrDefaultLanguage());
13887
13941
 
13942
+ const onCouponRemove = () => {
13943
+ dispatch({
13944
+ type: REMOVE_APPLIED_COUPON
13945
+ });
13946
+ };
13947
+
13888
13948
  if (percentOff) {
13889
13949
  return /*#__PURE__*/React__default.createElement("div", Object.assign({
13890
- className: "plc-flex plc-justify-center plc-mt-2 pelcro-discount"
13891
- }, props), "(-", percentOff, ")", " ", /*#__PURE__*/React__default.createElement("span", {
13892
- className: "plc-font-bold pelcro-discounted-price"
13893
- }, priceFormatted));
13950
+ className: "plc-flex plc-items-center plc-justify-center plc-mt-2 pelcro-discount"
13951
+ }, props), "(-", percentOff, ")", /*#__PURE__*/React__default.createElement("span", {
13952
+ className: "plc-ml-1 plc-font-bold pelcro-discounted-price"
13953
+ }, priceFormatted), /*#__PURE__*/React__default.createElement(Button, {
13954
+ variant: "ghost",
13955
+ className: "plc-ml-2 plc-text-red-500 focus:plc-ring-red-500 pelcro-dashboard-sub-cancel-button",
13956
+ onClick: onCouponRemove
13957
+ }, "\u2715 ", t("labels.removeCoupon")));
13894
13958
  }
13895
13959
 
13896
13960
  return "";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pelcro/react-pelcro-js",
3
3
  "description": "Pelcro's React UI Elements",
4
- "version": "2.7.0-beta.7",
4
+ "version": "2.7.0-beta.8",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",