@woosmap/ui 4.162.2 → 4.162.4

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": "@woosmap/ui",
3
- "version": "4.162.2",
3
+ "version": "4.162.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/WebGeoServices/ui.git"
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import PricingSlider from './PricingSlider';
4
4
  import PricingData from './PricingData';
5
+ import pricingData from './PricingData';
5
6
 
6
7
  class PricingSimulator extends Component {
7
8
  constructor(props) {
@@ -9,23 +10,52 @@ class PricingSimulator extends Component {
9
10
  const sliders = {};
10
11
  Object.keys(PricingData).forEach((category) => {
11
12
  Object.keys(PricingData[category].pricings).forEach((pricingKey) => {
12
- sliders[category + pricingKey] = { queries: PricingData[category].pricings[pricingKey].defaultQueries };
13
+ if (!sliders[category]) {
14
+ sliders[category] = {};
15
+ }
16
+ sliders[category][pricingKey] = { queries: PricingData[category].pricings[pricingKey].defaultQueries };
13
17
  });
14
18
  });
15
- this.state = { total: 0, sliders };
19
+ this.state = { sliders };
16
20
  }
17
21
 
18
- onChange = (pricingKey) => (data) => {
22
+ onChange = (category, pricingKey) => (data) => {
19
23
  console.log(pricingKey, data);
20
24
  const { sliders } = this.state;
21
25
  const newSliders = { ...sliders };
22
- newSliders[pricingKey] = data;
26
+ newSliders[category][pricingKey] = data;
23
27
  this.setState({ sliders: newSliders });
24
28
  };
25
29
 
30
+ computeTotal = () => {
31
+ let freeQueriesTotal = 0;
32
+ let eligibleTotal = 0;
33
+ let notEligibleTotal = 0;
34
+
35
+ const { sliders } = this.state;
36
+ Object.keys(sliders).forEach((category) => {
37
+ Object.keys(sliders[category]).forEach((pricingKey) => {
38
+ const { discountEligible } = PricingData[category].pricings[pricingKey];
39
+ if (discountEligible) {
40
+ if (!Number.isNaN(freeQueriesTotal)) {
41
+ freeQueriesTotal += sliders[category].queries;
42
+ }
43
+ eligibleTotal += sliders[category].amount;
44
+ } else if (sliders[category].queries > 0) {
45
+ freeQueriesTotal = false;
46
+ notEligibleTotal += sliders[category].amount;
47
+ }
48
+ });
49
+ });
50
+ const total = notEligibleTotal + eligibleTotal;
51
+ console.log(total, freeQueriesTotal, notEligibleTotal, eligibleTotal);
52
+ return { total, freeQueriesTotal, notEligibleTotal, eligibleTotal };
53
+ };
54
+
26
55
  render() {
27
- const { total, sliders } = this.state;
56
+ const { sliders } = this.state;
28
57
  const { publicMode, currency } = this.props;
58
+ const { total } = this.computeTotal();
29
59
  return (
30
60
  <>
31
61
  <div className="pricing-nav">
@@ -69,7 +99,7 @@ class PricingSimulator extends Component {
69
99
  publicMode={publicMode}
70
100
  currency={currency}
71
101
  values={sliders[category + pricingKey]}
72
- onChange={this.onChange(category + pricingKey)}
102
+ onChange={this.onChange(category, pricingKey)}
73
103
  />
74
104
  );
75
105
  })}
@@ -11,7 +11,7 @@ class PricingSlider extends Component {
11
11
  let q = queries;
12
12
  let previousPricingTier;
13
13
  if (queries === '∞') {
14
- return this.contactSalesButton();
14
+ return queries;
15
15
  }
16
16
  return parseInt(
17
17
  pricing.reduce((amount, tier, index) => {
@@ -137,12 +137,12 @@ class PricingSlider extends Component {
137
137
  const { name, productPricing, currency, values } = this.props;
138
138
  const { queries } = values;
139
139
  const { displayedPricing, amount, formatedQueries, marks, computedQueries } = this.getDisplayedData(queries);
140
- const displayedAmount =
141
- amount === 0 ? (
142
- <span className="free-label">FREE</span>
143
- ) : (
144
- <span className="amount">{`${amount} ${currency}`}</span>
145
- );
140
+ let displayedAmount = <span className="free-label">FREE</span>;
141
+ if (amount === '∞') {
142
+ displayedAmount = this.contactSalesButton();
143
+ } else if (amount > 0) {
144
+ displayedAmount = <span className="amount">{`${amount} ${currency}`}</span>;
145
+ }
146
146
  return (
147
147
  <div className="pricing-slider__wrapper" id={name}>
148
148
  <div className="pricing-slider__info">