@woosmap/ui 4.162.3 → 4.162.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": "@woosmap/ui",
3
- "version": "4.162.3",
3
+ "version": "4.162.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/WebGeoServices/ui.git"
@@ -9,23 +9,52 @@ class PricingSimulator extends Component {
9
9
  const sliders = {};
10
10
  Object.keys(PricingData).forEach((category) => {
11
11
  Object.keys(PricingData[category].pricings).forEach((pricingKey) => {
12
- sliders[category + pricingKey] = { queries: PricingData[category].pricings[pricingKey].defaultQueries };
12
+ if (!sliders[category]) {
13
+ sliders[category] = {};
14
+ }
15
+ sliders[category][pricingKey] = { queries: PricingData[category].pricings[pricingKey].defaultQueries };
13
16
  });
14
17
  });
15
- this.state = { total: 0, sliders };
18
+ this.state = { sliders };
16
19
  }
17
20
 
18
- onChange = (pricingKey) => (data) => {
21
+ onChange = (category, pricingKey) => (data) => {
19
22
  console.log(pricingKey, data);
20
23
  const { sliders } = this.state;
21
24
  const newSliders = { ...sliders };
22
- newSliders[pricingKey] = data;
25
+ newSliders[category][pricingKey] = data;
23
26
  this.setState({ sliders: newSliders });
24
27
  };
25
28
 
29
+ computeTotal = () => {
30
+ let freeQueriesTotal = 0;
31
+ let eligibleTotal = 0;
32
+ let notEligibleTotal = 0;
33
+
34
+ const { sliders } = this.state;
35
+ Object.keys(sliders).forEach((category) => {
36
+ Object.keys(sliders[category]).forEach((pricingKey) => {
37
+ const { discountEligible } = PricingData[category].pricings[pricingKey];
38
+ if (discountEligible) {
39
+ if (!Number.isNaN(freeQueriesTotal)) {
40
+ freeQueriesTotal += sliders[category].queries;
41
+ }
42
+ eligibleTotal += sliders[category].amount;
43
+ } else if (sliders[category].queries > 0) {
44
+ freeQueriesTotal = false;
45
+ notEligibleTotal += sliders[category].amount;
46
+ }
47
+ });
48
+ });
49
+ const total = notEligibleTotal + eligibleTotal;
50
+ console.log(total, freeQueriesTotal, notEligibleTotal, eligibleTotal);
51
+ return { total, freeQueriesTotal, notEligibleTotal, eligibleTotal };
52
+ };
53
+
26
54
  render() {
27
- const { total, sliders } = this.state;
55
+ const { sliders } = this.state;
28
56
  const { publicMode, currency } = this.props;
57
+ const { total } = this.computeTotal();
29
58
  return (
30
59
  <>
31
60
  <div className="pricing-nav">
@@ -68,8 +97,8 @@ class PricingSimulator extends Component {
68
97
  key={`pricing_${pricingKey.replace(' ', '')}`}
69
98
  publicMode={publicMode}
70
99
  currency={currency}
71
- values={sliders[category + pricingKey]}
72
- onChange={this.onChange(category + pricingKey)}
100
+ values={sliders[category][pricingKey]}
101
+ onChange={this.onChange(category, pricingKey)}
73
102
  />
74
103
  );
75
104
  })}