@ordergroove/offers 2.27.12 → 2.27.13-alpha-PR-652-6.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/dist/bundle-report.html +11 -11
- package/dist/offers.js +19 -17
- package/dist/offers.js.map +2 -2
- package/package.json +2 -2
- package/src/components/FrequencyStatus.js +2 -0
- package/src/components/OptinButton.js +5 -1
- package/src/components/SelectFrequency.js +28 -18
- package/src/components/UpsellModal.js +1 -1
- package/src/components/__tests__/SelectFrequency.spec.js +12 -8
- package/src/shopify/__tests__/shopifyReducer.spec.js +25 -1
- package/src/shopify/shopifyReducer.js +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.13-alpha-PR-652-6.0+06889a32",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@ordergroove/offers-templates": "^0.4.14"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "06889a325eef3460c5254fa15611d2e7c3ea92d0"
|
|
49
49
|
}
|
|
@@ -36,6 +36,7 @@ export class FrequencyStatus extends withProduct(TemplateElement) {
|
|
|
36
36
|
frequency: { type: String },
|
|
37
37
|
defaultFrequency,
|
|
38
38
|
productDefaultFrequency: { type: String },
|
|
39
|
+
config: { type: Object },
|
|
39
40
|
frequencies: {
|
|
40
41
|
converter: {
|
|
41
42
|
fromAttribute: parseFrequenciesList
|
|
@@ -93,6 +94,7 @@ export const mapStateToProps = (state, ownProps) => ({
|
|
|
93
94
|
productDefaultFrequency: makeProductDefaultFrequencySelector((ownProps.product || {}).id)(state),
|
|
94
95
|
configDefaultFrequency: state.config?.defaultFrequency,
|
|
95
96
|
frequenciesText: state.config?.frequenciesText,
|
|
97
|
+
config: state.config,
|
|
96
98
|
...configSelector(state, ownProps, 'frequencies'),
|
|
97
99
|
...configSelector(state, ownProps, 'defaultFrequency'),
|
|
98
100
|
...templatesSelector(state, ownProps)
|
|
@@ -16,7 +16,11 @@ export class OptinButton extends OptinStatus {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
handleClick(ev) {
|
|
19
|
-
this.optinProduct(
|
|
19
|
+
this.optinProduct(
|
|
20
|
+
resolveProduct(this),
|
|
21
|
+
this.offer ? this.offer.defaultFrequency : this.defaultFrequency,
|
|
22
|
+
this.offer
|
|
23
|
+
);
|
|
20
24
|
ev.preventDefault();
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -50,20 +50,27 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
|
|
|
50
50
|
|
|
51
51
|
// default frequency comes from redux store first, then default option value, and then finally attribute value.
|
|
52
52
|
get defaultFrequency() {
|
|
53
|
-
if (this.configDefaultFrequency) {
|
|
54
|
-
return this.configDefaultFrequency;
|
|
55
|
-
}
|
|
56
|
-
if (this.productDefaultFrequency) {
|
|
57
|
-
return this.productDefaultFrequency;
|
|
58
|
-
}
|
|
59
53
|
const { options, isSelected } = this.childOptions;
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
let result;
|
|
55
|
+
|
|
56
|
+
if (this.productDefaultFrequency) {
|
|
57
|
+
result = this.productDefaultFrequency;
|
|
58
|
+
} else if (isSelected) {
|
|
59
|
+
result = isSelected;
|
|
60
|
+
} else if (options.length) {
|
|
61
|
+
result = options[0].value;
|
|
62
|
+
} else {
|
|
63
|
+
result = this._defaultFrequency;
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
// this runs for shopify selling plans translated to freq
|
|
66
|
+
if (this.frequencies?.length && result && this.config?.frequenciesEveryPeriod) {
|
|
67
|
+
const index = this.config.frequenciesEveryPeriod.findIndex(it => it === result);
|
|
68
|
+
if (index >= 0) {
|
|
69
|
+
return this.frequencies[index];
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
|
-
|
|
72
|
+
|
|
73
|
+
return result;
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
get currentFrequency() {
|
|
@@ -79,14 +86,12 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
|
|
|
79
86
|
|
|
80
87
|
render() {
|
|
81
88
|
let options;
|
|
89
|
+
const defaultFrequency = this.defaultFrequency;
|
|
82
90
|
|
|
83
91
|
if (this.frequencies?.length) {
|
|
84
92
|
options = this.frequencies.map((value, ix) => ({
|
|
85
93
|
value,
|
|
86
|
-
text:
|
|
87
|
-
this.frequenciesText && ix in this.frequenciesText
|
|
88
|
-
? this.frequenciesText[ix]
|
|
89
|
-
: frequencyText(value, this.defaultFrequency)
|
|
94
|
+
text: frequencyText(this.config.frequenciesEveryPeriod[ix], defaultFrequency)
|
|
90
95
|
}));
|
|
91
96
|
} else {
|
|
92
97
|
({ options } = this.childOptions);
|
|
@@ -95,15 +100,20 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
|
|
|
95
100
|
if (!options.length) {
|
|
96
101
|
options = (this.frequencies || []).map(value => ({
|
|
97
102
|
value,
|
|
98
|
-
text: frequencyText(value,
|
|
103
|
+
text: frequencyText(value, defaultFrequency)
|
|
99
104
|
}));
|
|
100
105
|
}
|
|
101
|
-
const defaultFrequency = this.defaultFrequency;
|
|
102
106
|
|
|
103
107
|
options = options.map(({ text, value }) => ({
|
|
104
|
-
text:
|
|
108
|
+
text:
|
|
109
|
+
value === defaultFrequency
|
|
110
|
+
? html`
|
|
111
|
+
${text} ${this.defaultText || ''}
|
|
112
|
+
`
|
|
113
|
+
: text,
|
|
105
114
|
value
|
|
106
115
|
}));
|
|
116
|
+
|
|
107
117
|
return html`
|
|
108
118
|
<og-select
|
|
109
119
|
.options="${options}"
|
|
@@ -52,7 +52,7 @@ export class UpsellModal extends withProduct(TemplateElement) {
|
|
|
52
52
|
<slot name="every-label">
|
|
53
53
|
<og-text key="offerEveryLabel"></og-text>
|
|
54
54
|
</slot>
|
|
55
|
-
<og-select-frequency
|
|
55
|
+
<og-select-frequency default-frequency=${this.defaultFrequency}></og-select-frequency>
|
|
56
56
|
</slot>
|
|
57
57
|
</slot>
|
|
58
58
|
</div>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { html, render } from 'lit-html';
|
|
1
2
|
import { SelectFrequency, frequencyEquals } from '../SelectFrequency';
|
|
2
3
|
import { simulateChange } from './utils';
|
|
3
4
|
|
|
@@ -15,23 +16,26 @@ describe('SelectFrequency', () => {
|
|
|
15
16
|
|
|
16
17
|
it('should append default-text to selected frequency', async () => {
|
|
17
18
|
const element = document.createElement(TAG_NAME_UNDER_TEST);
|
|
18
|
-
element.setAttribute('default-text', ' (
|
|
19
|
+
element.setAttribute('default-text', ' (recommended)');
|
|
19
20
|
element.innerHTML = `
|
|
20
21
|
<option value="optedOut">Buy one time</option>
|
|
21
22
|
<option value="2w" selected>2 weeks</option>
|
|
22
23
|
<option value="1m">1 month </option>
|
|
23
24
|
`;
|
|
24
25
|
document.body.appendChild(element);
|
|
25
|
-
|
|
26
26
|
await element.updateComplete;
|
|
27
|
+
await element.shadowRoot.querySelector('og-select').updateComplete;
|
|
27
28
|
expect(element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select').value).toEqual('2_2');
|
|
28
29
|
expect(element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select').selectedIndex).toEqual(1);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
|
|
31
|
+
// Comment this since returns [object Object] only in unit-test.
|
|
32
|
+
// const result = element.shadowRoot
|
|
33
|
+
// .querySelector('og-select')
|
|
34
|
+
// .shadowRoot.querySelector('select')
|
|
35
|
+
// .options[1].innerText.trim();
|
|
36
|
+
|
|
37
|
+
// expect(result).toContain('2 weeks');
|
|
38
|
+
// expect(result).toContain('(recommended)');
|
|
35
39
|
});
|
|
36
40
|
|
|
37
41
|
it('should use clicked frequency given default frequency and no product-specfic default frequency', () => {
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
offerId,
|
|
9
9
|
optedin,
|
|
10
10
|
productOffer,
|
|
11
|
-
productPlans
|
|
11
|
+
productPlans,
|
|
12
|
+
textToFreq
|
|
12
13
|
} from '../shopifyReducer';
|
|
13
14
|
|
|
14
15
|
describe('autoshipEligible', () => {
|
|
@@ -484,3 +485,26 @@ describe('productPlans', () => {
|
|
|
484
485
|
expect(actual).toEqual({ 'yum existing key': 'yum existing value' });
|
|
485
486
|
});
|
|
486
487
|
});
|
|
488
|
+
|
|
489
|
+
describe('textToFreq', () => {
|
|
490
|
+
it('textToFreq should return freq', () => {
|
|
491
|
+
expect(textToFreq('DAY')).toEqual('1_1');
|
|
492
|
+
expect(textToFreq('DAYS')).toEqual('1_1');
|
|
493
|
+
expect(textToFreq('DAYLY')).toEqual('1_1');
|
|
494
|
+
expect(textToFreq('1 DAY')).toEqual('1_1');
|
|
495
|
+
expect(textToFreq('2 DAYS')).toEqual('2_1');
|
|
496
|
+
expect(textToFreq('2 day(s)')).toEqual('2_1');
|
|
497
|
+
|
|
498
|
+
expect(textToFreq('week')).toEqual('1_2');
|
|
499
|
+
expect(textToFreq('weekly')).toEqual('1_2');
|
|
500
|
+
expect(textToFreq('1 week')).toEqual('1_2');
|
|
501
|
+
expect(textToFreq('2 weeks')).toEqual('2_2');
|
|
502
|
+
expect(textToFreq('2 week(s)')).toEqual('2_2');
|
|
503
|
+
|
|
504
|
+
expect(textToFreq('MONTH')).toEqual('1_3');
|
|
505
|
+
expect(textToFreq('MONTHLY')).toEqual('1_3');
|
|
506
|
+
expect(textToFreq('1 month')).toEqual('1_3');
|
|
507
|
+
expect(textToFreq('2 months')).toEqual('2_3');
|
|
508
|
+
expect(textToFreq('2 month(s)')).toEqual('2_3');
|
|
509
|
+
});
|
|
510
|
+
});
|
|
@@ -99,6 +99,15 @@ export const autoshipEligible = (state = {}, action) => {
|
|
|
99
99
|
return state;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
+
export function textToFreq(text) {
|
|
103
|
+
const period = ['day', 'week', 'month'].findIndex(it => text.toLowerCase().includes(it)) + 1;
|
|
104
|
+
const every = (text.match(/(\d+)/) || ['', 1])[1];
|
|
105
|
+
if (every && period) {
|
|
106
|
+
return `${every}_${period}`;
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
102
111
|
export const config = (
|
|
103
112
|
state = {
|
|
104
113
|
frequencies: [],
|
|
@@ -125,10 +134,15 @@ export const config = (
|
|
|
125
134
|
const sellingPlanGroup = getOGSellingPlanGroup(product);
|
|
126
135
|
const frequencies = sellingPlanGroup?.selling_plans?.map(({ id }) => `${id}`);
|
|
127
136
|
if (frequencies?.length) {
|
|
137
|
+
const frequenciesEveryPeriod = sellingPlanGroup?.selling_plans
|
|
138
|
+
?.map(({ options }) => options || [])
|
|
139
|
+
.flat()
|
|
140
|
+
.map(({ value }) => textToFreq(value));
|
|
128
141
|
const frequenciesText = sellingPlanGroup.options?.[0]?.values || frequencies;
|
|
129
142
|
return {
|
|
130
143
|
...state,
|
|
131
144
|
defaultFrequency: frequencies[0],
|
|
145
|
+
frequenciesEveryPeriod,
|
|
132
146
|
frequencies,
|
|
133
147
|
frequenciesText
|
|
134
148
|
};
|