@ordergroove/offers 2.28.2 → 2.28.3-alpha-PR-686-2.5

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.28.2",
3
+ "version": "2.28.3-alpha-PR-686-2.5+6aa5b16b",
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,7 +45,7 @@
45
45
  "throttle-debounce": "^2.1.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@ordergroove/offers-templates": "^0.4.17"
48
+ "@ordergroove/offers-templates": "^0.4.18-alpha-PR-686-2.5+6aa5b16b"
49
49
  },
50
- "gitHead": "0dae2ce3e9690f602b03af9511f2c242023ac438"
50
+ "gitHead": "6aa5b16b582ba0393ad6477f1a6c3fcaa11dc8e6"
51
51
  }
@@ -0,0 +1,58 @@
1
+ import { LitElement, html } from 'lit-element';
2
+
3
+ import { connect } from '../core/connect';
4
+ import { withProduct } from '../core/resolveProperties';
5
+ import { configSelector, hasShopifySellingPlansSelector, makeProductDefaultFrequencySelector } from '../core/selectors';
6
+ import { isOgFrequency, mapFrequencyToSellingPlan } from '../core/utils';
7
+
8
+ export class DefaultFrequencyText extends withProduct(LitElement) {
9
+ static get properties() {
10
+ return {
11
+ ...super.properties,
12
+ configDefaultFrequency: { type: String, attribute: false },
13
+ defaultFrequency: { type: String, attribute: false },
14
+ frequencies: { type: Array, attribute: false },
15
+ frequenciesEveryPeriod: { type: Array, attribute: false },
16
+ frequency: {
17
+ type: String,
18
+ attribute: true
19
+ },
20
+ hasShopifySellingPlans: { type: Boolean, attribute: false },
21
+ productDefaultFrequency: { type: String, attribute: false }
22
+ };
23
+ }
24
+
25
+ get safeFrequency() {
26
+ if (isOgFrequency(this.frequency) && this.hasShopifySellingPlans) {
27
+ return mapFrequencyToSellingPlan(this.frequencies, this.frequenciesEveryPeriod, this.frequency);
28
+ }
29
+
30
+ return this.frequency;
31
+ }
32
+
33
+ get shouldShowFrequencyText() {
34
+ return !!(
35
+ this.productDefaultFrequency === this.safeFrequency ||
36
+ (!this.productDefaultFrequency &&
37
+ [this.configDefaultFrequency, this.defaultFrequency].some(it => it === this.safeFrequency))
38
+ );
39
+ }
40
+
41
+ render() {
42
+ return this.shouldShowFrequencyText
43
+ ? html`
44
+ <slot></slot>
45
+ `
46
+ : html``;
47
+ }
48
+ }
49
+
50
+ export const mapStateToProps = (state, ownProps) => ({
51
+ productDefaultFrequency: makeProductDefaultFrequencySelector((ownProps.product || {}).id)(state),
52
+ hasShopifySellingPlans: hasShopifySellingPlansSelector(state),
53
+ configDefaultFrequency: state.config?.defaultFrequency,
54
+ ...configSelector(state, ownProps, 'frequencies', []),
55
+ ...configSelector(state, ownProps, 'frequenciesEveryPeriod', [])
56
+ });
57
+
58
+ export const ConnectedDefaultFrequencyText = connect(mapStateToProps)(DefaultFrequencyText);
@@ -131,6 +131,17 @@ export const makeProductDefaultFrequencySelector = memoize(productId =>
131
131
  )
132
132
  );
133
133
 
134
+ /**
135
+ * Returns a boolean representing if a merchant has Shopify selling plans
136
+ * @param {Object} state
137
+ */
138
+ export const hasShopifySellingPlansSelector = state =>
139
+ [
140
+ platform.shopify_selling_plans,
141
+ !!frequenciesEveryPeriodSelector(state).length,
142
+ !!sellingPlansSelector(state).length
143
+ ].every(it => !!it);
144
+
134
145
  /**
135
146
  * Convert a string from camel case to kebab case.
136
147
  * @param {String} string
package/src/make-api.js CHANGED
@@ -20,6 +20,7 @@ import { Modal } from './components/Modal';
20
20
  import { Select } from './components/Select';
21
21
  import { Tooltip } from './components/Tooltip';
22
22
  import { ConnectedFrequencyStatus } from './components/FrequencyStatus';
23
+ import { ConnectedDefaultFrequencyText } from './components/DefaultFrequencyText';
23
24
  import * as testMode from './test-mode';
24
25
  import { api } from './core/api';
25
26
  import { environment, offer } from './core/reducer';
@@ -51,6 +52,7 @@ export default function makeApi(store) {
51
52
  customElements.define('og-upsell-modal', ConnectedUpsellModal);
52
53
  customElements.define('og-next-upcoming-order', ConnectedNextUpcomingOrder);
53
54
  customElements.define('og-price', ConnectedPrice);
55
+ customElements.define('og-default-frequency-text', ConnectedDefaultFrequencyText);
54
56
  } catch (err) {
55
57
  console.info('OG WebComponents already registered, skipping.');
56
58
  }