@ordergroove/offers 2.23.1 → 2.24.1-alpha-PR-566-18.13

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/build.js +5 -0
  3. package/dist/bundle-report.html +221 -63
  4. package/dist/examples.js +385 -1897
  5. package/dist/examples.js.map +7 -1
  6. package/dist/offers.js +266 -214
  7. package/dist/offers.js.map +7 -1
  8. package/examples/index.html +3 -0
  9. package/examples/index.js +19 -6
  10. package/karma-functional.conf.js +12 -10
  11. package/karma.conf.js +20 -10
  12. package/package.json +10 -15
  13. package/src/__tests__/offers.spec.js +111 -0
  14. package/src/__tests__/test-mode.spec.js +16 -0
  15. package/src/components/FrequencyStatus.js +2 -2
  16. package/src/components/IncentiveText.js +1 -1
  17. package/src/components/Offer.js +21 -15
  18. package/src/components/OptinButton.js +2 -5
  19. package/src/components/OptinSelect.js +2 -2
  20. package/src/components/OptinToggle.js +1 -4
  21. package/src/components/OptoutButton.js +1 -4
  22. package/src/components/Price.js +54 -0
  23. package/src/components/SelectFrequency.js +4 -8
  24. package/src/components/UpsellButton.js +2 -5
  25. package/src/components/UpsellModal.js +6 -10
  26. package/src/components/__tests__/FrequencyStatus.spec.js +33 -38
  27. package/src/components/__tests__/IncentiveText.spec.js +1 -1
  28. package/src/components/__tests__/Modal.spec.js +1 -1
  29. package/src/components/__tests__/NextUpcomingOrder.spec.js +1 -1
  30. package/src/components/__tests__/OG.fspec.js +2 -2
  31. package/src/components/__tests__/Offer.spec.js +5 -7
  32. package/src/components/__tests__/OptinButton.spec.js +1 -1
  33. package/src/components/__tests__/OptinSelect.spec.js +1 -1
  34. package/src/components/__tests__/OptinStatus.spec.js +1 -1
  35. package/src/components/__tests__/Price.fspec.js +43 -0
  36. package/src/components/__tests__/Select.spec.js +1 -1
  37. package/src/components/__tests__/SelectFrequency.spec.js +17 -6
  38. package/src/components/__tests__/Text.spec.js +1 -1
  39. package/src/components/__tests__/Tooltip.spec.js +1 -1
  40. package/src/components/__tests__/UpsellButton.spec.js +4 -6
  41. package/src/components/__tests__/When.spec.js +1 -1
  42. package/src/core/__tests__/api.spec.js +10 -3
  43. package/src/core/__tests__/base.spec.js +8 -2
  44. package/src/core/__tests__/reducer.spec.js +1 -1
  45. package/src/core/actions.js +16 -10
  46. package/src/core/adapters.js +3 -3
  47. package/src/core/api.js +4 -1
  48. package/src/core/constants.js +1 -0
  49. package/src/core/localStorage.js +1 -1
  50. package/src/core/middleware.js +9 -7
  51. package/src/core/reducer.js +10 -0
  52. package/src/core/selectors.js +19 -33
  53. package/src/index.js +187 -153
  54. package/src/init-func-tests.js +1 -2
  55. package/src/init-test.js +3 -0
  56. package/src/test-mode.js +5 -3
  57. package/dist/index.html +0 -125
  58. package/dist/offers-preview-mode.bundle.js +0 -2
  59. package/dist/offers-preview-mode.bundle.js.map +0 -1
  60. package/dist/offers-test-mode.bundle.js +0 -100
  61. package/dist/offers-test-mode.bundle.js.map +0 -1
  62. package/src/_tests_/offers.spec.js +0 -18
  63. package/src/_tests_/test-mode.spec.js +0 -15
  64. package/webpack.config.js +0 -43
@@ -121,5 +121,8 @@
121
121
 
122
122
  <pre id="the-html"></pre>
123
123
  <textarea id="the-js" readonly></textarea>
124
+ <script type="text/javascript" src="examples.js"></script>
125
+ <!-- offers should be latest since it overides og.offers namespace -->
126
+ <script type="text/javascript" src="offers.js"></script>
124
127
  </body>
125
128
  </html>
package/examples/index.js CHANGED
@@ -1,9 +1,19 @@
1
1
  /* global og */
2
2
  import { getMarkup, getStyles } from '@ordergroove/offers-templates';
3
3
 
4
- import runTests from '../src/run-tests';
4
+ // import runTests from '../src/run-tests';
5
5
 
6
- runTests();
6
+ // runTests();
7
+
8
+ window.og_settings = {
9
+ // object were key is product id and value is an array of plan discount
10
+ product_discounts: {
11
+ UD729: {
12
+ '3_1': ['30.00', '10%', '$27.00'],
13
+ '1_2': ['30.00', '20%', '$24.00']
14
+ }
15
+ }
16
+ };
7
17
 
8
18
  const frequencies = [
9
19
  {
@@ -325,7 +335,11 @@ Add item to order on
325
335
  {
326
336
  name: 'Tooltip',
327
337
  selector: 'og-offer[location="tooltip-placement"]',
328
- markup: [['top-left', 'top', 'top-right'], ['left', '', 'right'], ['bottom-left', 'bottom', 'bottom-right']]
338
+ markup: [
339
+ ['top-left', 'top', 'top-right'],
340
+ ['left', '', 'right'],
341
+ ['bottom-left', 'bottom', 'bottom-right']
342
+ ]
329
343
  .map(options =>
330
344
  options
331
345
  .map(
@@ -354,17 +368,16 @@ function updateTemplate(target) {
354
368
 
355
369
  el.setAttribute('location', value);
356
370
  window.location.hash = value;
357
- setImmediate(() => {
371
+ setTimeout(() => {
358
372
  const data = target.dataset.config;
359
373
 
360
374
  const style = document.getElementById('offersGlobalCss');
361
375
  style.innerHTML = '';
362
- console.log('it.config', JSON.parse(data).config, getStyles(JSON.parse(data).config));
363
376
  style.appendChild(document.createTextNode(getStyles(JSON.parse(data).config)));
364
377
 
365
378
  document.getElementById('the-html').innerText = (JSON.parse(data).markup || '').trim();
366
379
  document.getElementById('the-js').innerHTML = data;
367
- });
380
+ }, 0);
368
381
  }
369
382
 
370
383
  const addOption = dropdown => (it, ix) => {
@@ -41,18 +41,20 @@ module.exports = function(config) {
41
41
  // preprocess matching files before serving them to the browser
42
42
  // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
43
43
  preprocessors: {
44
- 'src/**/*.fspec.js': ['webpack', 'sourcemap']
45
- },
46
- webpack: {
47
- mode: 'development'
48
- // devtool: 'inline-source-map'
44
+ 'src/**/*.fspec.js': ['esbuild']
49
45
  },
46
+ esbuild: {
47
+ // Replace some global variables
48
+ define: {
49
+ // COVERAGE: coverage,
50
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || ''),
51
+ ENABLE_PERFORMANCE: true
52
+ },
53
+ // plugins: [createEsbuildPlugin()],
50
54
 
51
- webpackMiddleware: {
52
- // webpack-dev-middleware configuration
53
- // i. e.
54
- stats: 'errors-only'
55
- // logLevel: 'debug'
55
+ // Karma-esbuild specific options
56
+ singleBundle: false // Merge all test files into one bundle(default: true)
57
+ // singleBundle: true // Merge all test files into one bundle(default: true)
56
58
  },
57
59
 
58
60
  // test results reporter to use
package/karma.conf.js CHANGED
@@ -9,6 +9,12 @@ module.exports = function(config) {
9
9
 
10
10
  // list of files / patterns to load in the browser
11
11
  files: [
12
+ {
13
+ pattern: 'src/init-test.js',
14
+ type: 'js',
15
+ included: true,
16
+ served: true
17
+ },
12
18
  {
13
19
  pattern: 'src/**/*.spec.js',
14
20
  type: 'js',
@@ -23,17 +29,21 @@ module.exports = function(config) {
23
29
  // preprocess matching files before serving them to the browser
24
30
  // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
25
31
  preprocessors: {
26
- 'src/**/*.js': ['webpack', 'sourcemap']
32
+ '**/*.js': ['esbuild']
27
33
  },
28
- webpack: {
29
- mode: 'development'
30
- // devtool: 'inline-source-map'
31
- },
32
- webpackMiddleware: {
33
- // webpack-dev-middleware configuration
34
- // i. e.
35
- stats: 'errors-only',
36
- logLevel: 'error'
34
+
35
+ esbuild: {
36
+ // Replace some global variables
37
+ define: {
38
+ // COVERAGE: coverage,
39
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || ''),
40
+ ENABLE_PERFORMANCE: true
41
+ },
42
+ // plugins: [createEsbuildPlugin()],
43
+
44
+ // Karma-esbuild specific options
45
+ singleBundle: false // Merge all test files into one bundle(default: true)
46
+ // singleBundle: true // Merge all test files into one bundle(default: true)
37
47
  },
38
48
 
39
49
  // test results reporter to use
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordergroove/offers",
3
- "version": "2.23.1",
3
+ "version": "2.24.1-alpha-PR-566-18.13+79cf9e73",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -11,21 +11,17 @@
11
11
  "url": "git+https://github.com/ordergroove/plush-toys.git"
12
12
  },
13
13
  "scripts": {
14
- "start": "../../node_modules/.bin/webpack-dev-server",
15
- "build": "rm -rf dist && ../../node_modules/.bin/webpack --mode production",
16
- "build:prod": "rm -rf dist && ../../node_modules/.bin/webpack --mode production --display errors-only",
17
- "build:dev": "rm -rf dist && ../../node_modules/.bin/webpack --mode development",
14
+ "start": "npm run build -- --serve",
15
+ "build": "rm -rf dist && mkdir dist && cp examples/index.html dist/index.html && node build.js",
16
+ "build:prod": "rm -rf dist && node build.js --prod",
18
17
  "bundlesize": "../../node_modules/.bin/bundlesize",
19
18
  "lint": "../../node_modules/.bin/eslint --ignore-path ../../.gitignore ./src",
20
- "dev": "../../node_modules/.bin/webpack-dev-server",
21
- "watch": "rm -rf dist && ../../node_modules/.bin/webpack --mode development --watch",
22
- "prepublishOnly": "npm run -s lint && npm run -s test && npm run -s build:prod && npm run -s bundlesize",
19
+ "prepublishOnly": "npm run -s build:prod && npm run -s bundlesize",
23
20
  "test": "../../node_modules/.bin/karma start --single-run --log-level error --reporters progress && npm run build && ../../node_modules/.bin/karma start --single-run --log-level error --reporters progress karma-functional.conf.js",
24
21
  "test:watch": "../../node_modules/.bin/karma start",
25
22
  "test:watch:functional": "npm run build:dev && ../../node_modules/.bin/karma start karma-functional.conf.js",
26
23
  "test:functional": "npm run test:watch:functional -- --single-run --log-level error --reporters progress",
27
- "test:watch:silent": "../../node_modules/.bin/karma start --log-level error --reporters dots",
28
- "postversion": "../../bin/postversion.sh"
24
+ "test:watch:silent": "../../node_modules/.bin/karma start --log-level error --reporters dots"
29
25
  },
30
26
  "bugs": {
31
27
  "url": "https://github.com/ordergroove/plush-toys/issues"
@@ -37,8 +33,8 @@
37
33
  }
38
34
  ],
39
35
  "dependencies": {
40
- "@ordergroove/auth": "^2.1.9",
41
- "@ordergroove/offers-live-editor": "^0.3.0",
36
+ "@ordergroove/auth": "^2.2.0",
37
+ "@ordergroove/offers-live-editor": "^0.4.0",
42
38
  "lit-element": "^2.1.0",
43
39
  "lodash.memoize": "^4.1.2",
44
40
  "logical-expression-parser": "1.0.0",
@@ -47,8 +43,7 @@
47
43
  "throttle-debounce": "^2.1.0"
48
44
  },
49
45
  "devDependencies": {
50
- "@ordergroove/js-utils": "^1.0.3",
51
- "@ordergroove/offers-templates": "^0.3.19"
46
+ "@ordergroove/offers-templates": "^0.4.0"
52
47
  },
53
- "gitHead": "502b4968dae2de28b0db509f53fa7932172eb688"
48
+ "gitHead": "79cf9e73836b5e364322016e41a01a33a7dc2adb"
54
49
  }
@@ -0,0 +1,111 @@
1
+ import { offers } from '../index';
2
+ import { api } from '../core/api';
3
+
4
+ describe('Offers', () => {
5
+ let register, fetchOfferSpy, mockStore;
6
+ // TODO revisit chunks
7
+ it('should have setPublicPath method as compatibility', () => {
8
+ offers.setPublicPath('yum-path');
9
+ });
10
+
11
+ beforeEach(() => {
12
+ register = spyOn(offers, 'register');
13
+ fetchOfferSpy = spyOn(api, 'fetchOffer');
14
+ const dispatch = jasmine.createSpy();
15
+ mockStore = {
16
+ getState() {
17
+ return { sessionId: 'xyz' };
18
+ },
19
+ dispatch
20
+ };
21
+
22
+ offers.isReady = false;
23
+ });
24
+
25
+ it('should warn if attempting to initialize twice', () => {
26
+ const warn = spyOn(console, 'warn');
27
+
28
+ offers.initialize('0e5de2bedc5e11e3a2e4bc764e106cf4', 'staging');
29
+ expect(warn).not.toHaveBeenCalled();
30
+
31
+ offers.initialize('0e5de2bedc5e11e3a2e4bc764e106cf4', 'staging');
32
+ expect(warn).toHaveBeenCalledWith('og.offers has been initialized already. Skipping.');
33
+ expect(register).toHaveBeenCalledTimes(1);
34
+ });
35
+
36
+ it('should warn if attempting to initialize twice', () => {
37
+ const resolveSettings = spyOn(offers, 'resolveSettings');
38
+ offers.initialize('0e5de2bedc5e11e3a2e4bc764e106cf4', 'staging');
39
+ expect(resolveSettings).toHaveBeenCalledWith(
40
+ '0e5de2bedc5e11e3a2e4bc764e106cf4',
41
+ 'staging',
42
+ undefined,
43
+ offers.store
44
+ );
45
+ });
46
+
47
+ describe('offers.resolveSettings', () => {
48
+ it('should fetch offer for single product in pdp', () => {
49
+ offers.resolveSettings('0e5de2bedc5e11e3a2e4bc764e106cf4', 'staging', { product: '123' }, mockStore);
50
+ expect(fetchOfferSpy).toHaveBeenCalledWith(
51
+ 'https://staging.om.ordergroove.com',
52
+ '0e5de2bedc5e11e3a2e4bc764e106cf4',
53
+ 'xyz',
54
+ '123',
55
+ 'pdp'
56
+ );
57
+ });
58
+
59
+ it('should fetch offer for each product in cart', () => {
60
+ offers.resolveSettings(
61
+ '0e5de2bedc5e11e3a2e4bc764e106cf4',
62
+ 'staging',
63
+ { cart: { products: ['123', '456'] } },
64
+ mockStore
65
+ );
66
+ expect(fetchOfferSpy).toHaveBeenCalledTimes(2);
67
+
68
+ expect(fetchOfferSpy.calls.argsFor(0)).toEqual([
69
+ 'https://staging.om.ordergroove.com',
70
+ '0e5de2bedc5e11e3a2e4bc764e106cf4',
71
+ 'xyz',
72
+ '123',
73
+ 'pdp'
74
+ ]);
75
+ expect(fetchOfferSpy.calls.argsFor(1)).toEqual([
76
+ 'https://staging.om.ordergroove.com',
77
+ '0e5de2bedc5e11e3a2e4bc764e106cf4',
78
+ 'xyz',
79
+ '456',
80
+ 'pdp'
81
+ ]);
82
+ });
83
+
84
+ it('should set product price and discounts', () => {
85
+ offers.resolveSettings(
86
+ '0e5de2bedc5e11e3a2e4bc764e106cf4',
87
+ 'staging',
88
+ {
89
+ // object were key is product id and value is an array of plan discount
90
+ product_discounts: {
91
+ 123: {
92
+ '2_2': ['30.00', '20%', '$24.00'],
93
+ '1_3': ['30.00', '10%', '$27.00']
94
+ }
95
+ }
96
+ },
97
+ mockStore
98
+ );
99
+ expect(mockStore.dispatch).toHaveBeenCalledTimes(1);
100
+ expect(mockStore.dispatch).toHaveBeenCalledWith({
101
+ type: 'RECEIVE_PRODUCT_PLANS',
102
+ payload: {
103
+ 123: {
104
+ '2_2': ['30.00', '20%', '$24.00'],
105
+ '1_3': ['30.00', '10%', '$27.00']
106
+ }
107
+ }
108
+ });
109
+ });
110
+ });
111
+ });
@@ -0,0 +1,16 @@
1
+ import { keys } from '../test-mode';
2
+
3
+ describe('TestMode', () => {
4
+ it('should add the element if correct key stroke is keyed in', async () => {
5
+ document.body.innerHTML = '';
6
+ expect(document.querySelectorAll('og-test-wizard').length).toEqual(0);
7
+ await Promise.all(
8
+ keys.map(async keyCode => {
9
+ document.dispatchEvent(new KeyboardEvent('keyup', { keyCode }));
10
+ await new Promise(res => setTimeout(res, 0));
11
+ })
12
+ );
13
+ await new Promise(res => setTimeout(res, 0));
14
+ expect(document.querySelectorAll('og-test-wizard').length).toEqual(1);
15
+ });
16
+ });
@@ -31,9 +31,9 @@ export class FrequencyStatus extends withProduct(TemplateElement) {
31
31
  return {
32
32
  ...super.properties,
33
33
  disabled: { type: Boolean },
34
- subscribed: subscribed,
34
+ subscribed,
35
35
  frequency: { type: String },
36
- defaultFrequency: defaultFrequency,
36
+ defaultFrequency,
37
37
  productDefaultFrequency: { type: String },
38
38
  frequencies: {
39
39
  converter: {
@@ -97,7 +97,7 @@ export class IncentiveText extends withProduct(LitElement) {
97
97
  const incentiveType = this.initial ? 'initial' : 'ongoing';
98
98
 
99
99
  const incentive = (this.incentives[incentiveType] || []).find(
100
- filterIncentives.bind({ incentiveClass: incentiveClass, incentiveValue: incentiveValue })
100
+ filterIncentives.bind({ incentiveClass, incentiveValue })
101
101
  );
102
102
 
103
103
  return html`
@@ -1,6 +1,7 @@
1
1
  import { html, css } from 'lit-element';
2
2
  import memoize from 'lodash.memoize';
3
3
  import { connect } from '../core/connect';
4
+ import { setPreview } from '../core/actions-preview';
4
5
  import {
5
6
  fetchOffer,
6
7
  productHasChangedComponents,
@@ -133,13 +134,22 @@ export class Offer extends TemplateElement {
133
134
  return `
134
135
  <og-when test="regularEligible">
135
136
  <div>
137
+
136
138
  <og-optout-button>
137
139
  <og-text key="offerOptOutLabel"></og-text>
138
140
  </og-optout-button>
139
141
  </div>
140
142
  <div>
141
143
  <og-optin-button>
142
- <og-text key="offerOptInLabel"></og-text>
144
+
145
+
146
+ <og-price discount>
147
+ <span slot="prepend">Subscribe and get</span>
148
+ <span slot="append">off</span>
149
+ </og-price>
150
+ <og-price regular></og-price>
151
+ <og-price subscription></og-price>
152
+
143
153
  </og-optin-button>
144
154
  <og-tooltip placement="top-right">
145
155
  <div slot="trigger">
@@ -229,9 +239,7 @@ export class Offer extends TemplateElement {
229
239
 
230
240
  updated(changed) {
231
241
  if (changed.has('preview')) {
232
- import(/* webpackChunkName: "offers-preview-mode" */ '../core/actions-preview').then(({ setPreview }) =>
233
- this.store.dispatch(setPreview(this.preview, changed.get('preview'), this))
234
- );
242
+ this.setPreview(this.preview, changed.get('preview'), this);
235
243
  }
236
244
 
237
245
  this.frequency = this.defaultFrequency;
@@ -321,16 +329,14 @@ export const mapStateToProps = (state, ownProps) => ({
321
329
  subscribed: makeOptedinSelector(ownProps.product)(state),
322
330
  ...templatesSelector(state)
323
331
  });
324
- export const ConnectedOffer = connect(
325
- mapStateToProps,
326
- {
327
- fetchOffer,
328
- fetchOrders,
329
- productHasChangedComponents,
330
- optinProduct,
331
- setFirstOrderPlaceDate,
332
- setProductToSubscribe
333
- }
334
- )(Offer);
332
+ export const ConnectedOffer = connect(mapStateToProps, {
333
+ fetchOffer,
334
+ fetchOrders,
335
+ productHasChangedComponents,
336
+ optinProduct,
337
+ setFirstOrderPlaceDate,
338
+ setProductToSubscribe,
339
+ setPreview
340
+ })(Offer);
335
341
 
336
342
  export default ConnectedOffer;
@@ -10,7 +10,7 @@ export class OptinButton extends OptinStatus {
10
10
  return {
11
11
  ...super.properties,
12
12
  frequency: { type: String, reflect: true },
13
- defaultFrequency: defaultFrequency,
13
+ defaultFrequency,
14
14
  optinButtonLabel: { type: String }
15
15
  };
16
16
  }
@@ -34,9 +34,6 @@ export class OptinButton extends OptinStatus {
34
34
  }
35
35
  }
36
36
 
37
- export const ConnectedOptinButton = connect(
38
- mapStateToProps,
39
- { optinProduct }
40
- )(OptinButton);
37
+ export const ConnectedOptinButton = connect(mapStateToProps, { optinProduct })(OptinButton);
41
38
 
42
39
  export default ConnectedOptinButton;
@@ -12,7 +12,7 @@ export class OptinSelect extends withChildOptions(OptinStatus) {
12
12
  ...super.properties,
13
13
  frequencies: { type: Array, attribute: false },
14
14
  frequency: { type: String },
15
- defaultFrequency: defaultFrequency
15
+ defaultFrequency
16
16
  };
17
17
  }
18
18
 
@@ -54,7 +54,7 @@ export class OptinSelect extends withChildOptions(OptinStatus) {
54
54
  `
55
55
  },
56
56
  ...(this.frequencies || []).map(value => ({
57
- value: value,
57
+ value,
58
58
  text: frequencyText(value, this.defaultFrequency)
59
59
  }))
60
60
  ];
@@ -32,9 +32,6 @@ export class OptinToggle extends OptinStatus {
32
32
  }
33
33
  }
34
34
 
35
- export const ConnectedOptinToggle = connect(
36
- mapStateToProps,
37
- { optoutProduct, optinProduct }
38
- )(OptinToggle);
35
+ export const ConnectedOptinToggle = connect(mapStateToProps, { optoutProduct, optinProduct })(OptinToggle);
39
36
 
40
37
  export default ConnectedOptinToggle;
@@ -30,9 +30,6 @@ export class OptoutButton extends OptinStatus {
30
30
  }
31
31
  }
32
32
 
33
- export const ConnectedOptoutButton = connect(
34
- mapStateToProps,
35
- { optoutProduct }
36
- )(OptoutButton);
33
+ export const ConnectedOptoutButton = connect(mapStateToProps, { optoutProduct })(OptoutButton);
37
34
 
38
35
  export default ConnectedOptoutButton;
@@ -0,0 +1,54 @@
1
+ import { html } from 'lit-element';
2
+ import { connect } from '../core/connect';
3
+
4
+ import { withProduct } from '../core/resolveProperties';
5
+ import { TemplateElement } from '../core/base';
6
+ import { makeProductFrequencySelector } from '../core/selectors';
7
+
8
+ export class Price extends withProduct(TemplateElement) {
9
+ static get properties() {
10
+ return {
11
+ ...super.properties,
12
+ regular: { type: Boolean, reflect: true },
13
+ subscription: { type: Boolean, reflect: true },
14
+ discount: { type: Boolean, reflect: true },
15
+ frequency: { type: Object },
16
+ productPlans: { type: Object }
17
+ };
18
+ }
19
+
20
+ get value() {
21
+ const frequency = this.frequency || (this.offer && this.offer.defaultFrequency);
22
+ const plans = this.productPlans[this.product.id] || {};
23
+ const currentPlan = plans[frequency] || [];
24
+ if (!currentPlan) return '';
25
+ const [regularPrice, discountRate, subscriptionPrice] = currentPlan;
26
+ if (subscriptionPrice === regularPrice) return '';
27
+
28
+ if (this.regular) {
29
+ return regularPrice;
30
+ }
31
+ if (this.discount) return discountRate;
32
+ return subscriptionPrice;
33
+ }
34
+
35
+ render() {
36
+ const value = this.value;
37
+ if (value)
38
+ return html`
39
+ <slot name="prepend"></slot>
40
+ ${value}
41
+ <slot name="append"></slot>
42
+ `;
43
+
44
+ return html`
45
+ <slot></slot>
46
+ `;
47
+ }
48
+ }
49
+ const mapStateToProps = (state, ownProps) => ({
50
+ productPlans: state.productPlans,
51
+ frequency: makeProductFrequencySelector(ownProps.product)(state)
52
+ });
53
+
54
+ export default connect(mapStateToProps)(Price);
@@ -73,10 +73,9 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
73
73
 
74
74
  render() {
75
75
  let { options } = this.childOptions;
76
-
77
76
  if (!options.length) {
78
77
  options = (this.frequencies || []).map(value => ({
79
- value: value,
78
+ value,
80
79
  text: frequencyText(value, this.defaultFrequency)
81
80
  }));
82
81
  }
@@ -99,11 +98,8 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
99
98
  }
100
99
  }
101
100
 
102
- export const ConnectedSelectFrequency = connect(
103
- mapStateToProps,
104
- {
105
- productChangeFrequency
106
- }
107
- )(SelectFrequency);
101
+ export const ConnectedSelectFrequency = connect(mapStateToProps, {
102
+ productChangeFrequency
103
+ })(SelectFrequency);
108
104
 
109
105
  export default ConnectedSelectFrequency;
@@ -24,7 +24,7 @@ export class UpsellButton extends withProduct(TemplateElement) {
24
24
  type: String,
25
25
  attribute: false
26
26
  },
27
- auth: auth,
27
+ auth,
28
28
  isPreview: { type: Boolean, attribute: false },
29
29
  target: { type: String }
30
30
  };
@@ -73,9 +73,6 @@ export const mapStateToProps = state => ({
73
73
  isPreview: state.previewUpsellOffer
74
74
  });
75
75
 
76
- export const ConnectedUpsellButton = connect(
77
- mapStateToProps,
78
- { fetchOrders }
79
- )(UpsellButton);
76
+ export const ConnectedUpsellButton = connect(mapStateToProps, { fetchOrders })(UpsellButton);
80
77
 
81
78
  export default UpsellButton;
@@ -10,8 +10,8 @@ export class UpsellModal extends withProduct(TemplateElement) {
10
10
  static get properties() {
11
11
  return {
12
12
  ...super.properties,
13
- defaultFrequency: defaultFrequency,
14
- auth: auth,
13
+ defaultFrequency,
14
+ auth,
15
15
  subscribed: { type: Boolean, attribute: false },
16
16
  frequency: { type: String, attribute: false },
17
17
  nextUpcomingOrder: { type: Object, attribute: false },
@@ -22,7 +22,6 @@ export class UpsellModal extends withProduct(TemplateElement) {
22
22
 
23
23
  constructor() {
24
24
  super();
25
- this.title = '';
26
25
  this.createIu = () => 0;
27
26
  this.concludeUpsell = () => 0;
28
27
  }
@@ -109,12 +108,9 @@ export const mapStateToProps = (state, ownProps) => ({
109
108
  isPreview: state.previewUpsellOffer
110
109
  });
111
110
 
112
- export const ConnectedUpsellModal = connect(
113
- mapStateToProps,
114
- {
115
- concludeUpsell,
116
- createIu
117
- }
118
- )(UpsellModal);
111
+ export const ConnectedUpsellModal = connect(mapStateToProps, {
112
+ concludeUpsell,
113
+ createIu
114
+ })(UpsellModal);
119
115
 
120
116
  export default UpsellModal;