@ordergroove/offers 2.27.4 → 2.27.7

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.27.4",
3
+ "version": "2.27.7",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -43,7 +43,7 @@
43
43
  "throttle-debounce": "^2.1.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@ordergroove/offers-templates": "^0.4.12"
46
+ "@ordergroove/offers-templates": "^0.4.13"
47
47
  },
48
- "gitHead": "3aa25b94b2ea166d28a20395a43de993c59e65e2"
48
+ "gitHead": "09226ede168eae0ac25625557615c4c6a6dfc247"
49
49
  }
@@ -5,6 +5,7 @@ import { OptinStatus, mapStateToProps as mapStateToPropsOptinStatus } from './Op
5
5
  import { mapStateToProps, frequencyText } from './FrequencyStatus';
6
6
  import { connect } from '../core/connect';
7
7
  import { defaultFrequency } from '../core/props';
8
+ import { configSelector } from '../core/selectors';
8
9
 
9
10
  export class OptinSelect extends withChildOptions(OptinStatus) {
10
11
  static get properties() {
@@ -30,8 +31,14 @@ export class OptinSelect extends withChildOptions(OptinStatus) {
30
31
  `;
31
32
  }
32
33
 
33
- get isSelected() {
34
- return this.subscribed ? this.frequency : 'optedOut';
34
+ get currentFrequency() {
35
+ if (!this.subscribed) {
36
+ return 'optedOut';
37
+ }
38
+ if (this.frequency) {
39
+ return this.frequency;
40
+ }
41
+ return this.defaultFrequency;
35
42
  }
36
43
 
37
44
  onOptinChange(value) {
@@ -43,9 +50,9 @@ export class OptinSelect extends withChildOptions(OptinStatus) {
43
50
  }
44
51
 
45
52
  render() {
46
- const { options: childOptions, isSelected } = this.childOptions;
47
- let options = childOptions;
48
- if (!childOptions.length) {
53
+ const { options: childOptions } = this.childOptions;
54
+ let options;
55
+ if (this.frequencies?.length) {
49
56
  options = [
50
57
  {
51
58
  value: 'optedOut',
@@ -53,17 +60,30 @@ export class OptinSelect extends withChildOptions(OptinStatus) {
53
60
  <og-text key="offerOptOutLabel"></og-text>
54
61
  `
55
62
  },
56
- ...(this.frequencies || []).map(value => ({
63
+ ...this.frequencies.map((value, ix) => ({
57
64
  value,
58
- text: frequencyText(value, this.defaultFrequency)
65
+ text:
66
+ this.frequenciesText && ix in this.frequenciesText
67
+ ? this.frequenciesText[ix]
68
+ : frequencyText(value, this.defaultFrequency)
59
69
  }))
60
70
  ];
71
+ } else {
72
+ options = [
73
+ {
74
+ value: 'optedOut',
75
+ text: html`
76
+ <og-text key="offerOptOutLabel"></og-text>
77
+ `
78
+ },
79
+ ...childOptions
80
+ ];
61
81
  }
62
82
 
63
83
  return html`
64
84
  <og-select
65
85
  .options="${options}"
66
- .selected="${isSelected}"
86
+ .selected="${this.currentFrequency}"
67
87
  .onChange="${({ target: { value } }) => this.onOptinChange(value)}"
68
88
  ></og-select>
69
89
  `;
@@ -73,7 +93,8 @@ export class OptinSelect extends withChildOptions(OptinStatus) {
73
93
  export const ConnectedOptinSelect = connect(
74
94
  (state, ownProps) => ({
75
95
  ...mapStateToPropsOptinStatus(state, ownProps),
76
- ...mapStateToProps(state, ownProps)
96
+ ...mapStateToProps(state, ownProps),
97
+ ...configSelector(state, ownProps, 'frequencies')
77
98
  }),
78
99
  { productChangeFrequency, optoutProduct }
79
100
  )(OptinSelect);