@ordergroove/offers 2.40.4 → 2.41.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordergroove/offers",
3
- "version": "2.40.4",
3
+ "version": "2.41.0",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -49,5 +49,5 @@
49
49
  "@ordergroove/offers-templates": "^0.9.6",
50
50
  "@types/lodash.memoize": "^4.1.9"
51
51
  },
52
- "gitHead": "7047889836c2225038223496a0b0c317756fa15d"
52
+ "gitHead": "24e315047abbe0e265409f1f5265e3d9fd462672"
53
53
  }
@@ -1,5 +1,5 @@
1
1
  import { html, css } from 'lit-element';
2
- import { fetchOrders } from '../core/actions';
2
+ import { fetchOrders, createIu, concludeUpsell } from '../core/actions';
3
3
  import { connect } from '../core/connect';
4
4
  import { auth } from '../core/props';
5
5
  import { withProduct } from '../core/resolveProperties';
@@ -26,13 +26,17 @@ export class UpsellButton extends withProduct(TemplateElement) {
26
26
  },
27
27
  auth,
28
28
  isPreview: { type: Boolean, attribute: false },
29
- target: { type: String }
29
+ target: { type: String },
30
+ // If set, creates the IU item immediately instead of opening a modal
31
+ skipModal: { type: Boolean, attribute: 'skip-modal' }
30
32
  };
31
33
  }
32
34
 
33
35
  constructor() {
34
36
  super();
35
37
  this.fetchOrders = () => 0;
38
+ this.createIu = () => 0;
39
+ this.concludeUpsell = () => 0;
36
40
  this.addEventListener('click', this.handleClick.bind(this));
37
41
  }
38
42
 
@@ -44,7 +48,10 @@ export class UpsellButton extends withProduct(TemplateElement) {
44
48
 
45
49
  handleClick() {
46
50
  let modal;
47
- if (!this.target && this.offer) {
51
+ if (this.skipModal) {
52
+ this.createIu(this.product, this.nextUpcomingOrder.public_id, 1, false, null);
53
+ this.concludeUpsell(this.product);
54
+ } else if (!this.target && this.offer) {
48
55
  // TODO remove offer shadowRoot built in code.
49
56
  modal = this.offer.querySelector('og-upsell-modal');
50
57
  if (!modal) {
@@ -70,9 +77,10 @@ export class UpsellButton extends withProduct(TemplateElement) {
70
77
  }
71
78
 
72
79
  export const mapStateToProps = state => ({
73
- isPreview: state.previewUpsellOffer
80
+ isPreview: state.previewUpsellOffer,
81
+ nextUpcomingOrder: state.previewUpsellOffer ? { public_id: 'preview-order-id' } : state.nextUpcomingOrder
74
82
  });
75
83
 
76
- export const ConnectedUpsellButton = connect(mapStateToProps, { fetchOrders })(UpsellButton);
84
+ export const ConnectedUpsellButton = connect(mapStateToProps, { fetchOrders, createIu, concludeUpsell })(UpsellButton);
77
85
 
78
86
  export default UpsellButton;
@@ -52,4 +52,15 @@ describe('UpsellButton', () => {
52
52
  await ogUpsellButton.click();
53
53
  expect(ogUpsellModal.getAttribute('show')).toEqual('true');
54
54
  });
55
+
56
+ it('should create IU directly if skip-modal attribute set', async () => {
57
+ const ogUpsellButton = new UpsellButton();
58
+ ogUpsellButton.setAttribute('product', 'yum product');
59
+ ogUpsellButton.setAttribute('skip-modal', '');
60
+ ogUpsellButton.auth = 'yum auth';
61
+ ogUpsellButton.nextUpcomingOrder = { public_id: 'yum public_id' };
62
+ ogUpsellButton.createIu = jasmine.createSpy('createIu');
63
+ await ogUpsellButton.click();
64
+ expect(ogUpsellButton.createIu).toHaveBeenCalledWith({ id: 'yum product' }, 'yum public_id', 1, false, null);
65
+ });
55
66
  });