homeflowjs 0.9.32 → 0.9.34

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": "homeflowjs",
3
- "version": "0.9.32",
3
+ "version": "0.9.34",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,9 +1,10 @@
1
1
  import React, { useState, useEffect } from 'react';
2
2
  import { connect } from 'react-redux';
3
+ import englishRates from '../../utils/stamp-duty-calculator/english-rates';
3
4
 
4
5
  import './stamp-duty-calculator.styles.scss';
5
6
 
6
- const DefaultCalculator = ({ purchasePrice, setPurchasePrice }) => {
7
+ const DefaultCalculator = ({ purchasePrice, setPurchasePrice, firstTimeBuyer, additionalProperty, ukResident, }) => {
7
8
  const [effectiveRate, setEffectiveRate] = useState();
8
9
  const [totalRate, setTotalRate] = useState();
9
10
  const [rate1, setRate1] = useState();
@@ -12,6 +13,10 @@ const DefaultCalculator = ({ purchasePrice, setPurchasePrice }) => {
12
13
  const [rate4, setRate4] = useState();
13
14
  const [rate5, setRate5] = useState();
14
15
 
16
+ const property = Homeflow.get('property');
17
+
18
+ const results = englishRates(property.price_value, firstTimeBuyer, additionalProperty, ukResident);
19
+
15
20
  const calculateStampDuty = (price) => {
16
21
  if (!price) {
17
22
  setRate1(0);
@@ -25,46 +30,15 @@ const DefaultCalculator = ({ purchasePrice, setPurchasePrice }) => {
25
30
  return null;
26
31
  }
27
32
 
28
- let effectiveRate = 0;
29
- let totalRate = 0;
30
- let rate1 = 0;
31
- let rate2 = 0;
32
- let rate3 = 0;
33
- let rate4 = 0;
34
- let rate5 = 0;
35
-
36
- if (price - 125000 > 0) {
37
- rate2 = (price - 125000);
38
- rate2 *= 0.02;
39
- if (rate2 > 125000 * 0.02) {
40
- rate2 = 125000 * 0.02;
41
- }
42
- }
43
-
44
- if (price - 250000 > 0) {
45
- rate3 = (price - 250000);
46
- rate3 *= 0.05;
47
- if (rate3 > 675000 * 0.05) {
48
- rate3 = 675000 * 0.05;
49
- }
50
- }
51
-
52
- if (price - 925000 > 0) {
53
- rate4 = (price - 925000);
54
- rate4 *= 0.10;
55
- if (rate4 > 575000 * 0.10) {
56
- rate4 = 575000 * 0.10;
57
- }
58
- }
59
-
60
- if (price - 1500000 > 0) {
61
- rate5 = (price - 1500000);
62
- rate5 *= 0.12;
63
- }
64
-
65
- totalRate = rate1 + rate2 + rate3 + rate4 + rate5;
66
- effectiveRate = totalRate / price;
67
- effectiveRate *= 100;
33
+ const {
34
+ rate1,
35
+ rate2,
36
+ rate3,
37
+ rate4,
38
+ rate5,
39
+ effectiveRate,
40
+ totalRate
41
+ } = results;
68
42
 
69
43
  setRate1(rate1);
70
44
  setRate2(rate2);
@@ -78,7 +52,6 @@ const DefaultCalculator = ({ purchasePrice, setPurchasePrice }) => {
78
52
  };
79
53
 
80
54
  useEffect(() => {
81
- const property = Homeflow.get('property');
82
55
  if (property && property.price_value) {
83
56
  setPurchasePrice(property.price_value);
84
57
  calculateStampDuty(property.price_value);
@@ -15,6 +15,9 @@ const StampDutyCalculator = ({ scotland, themePreferences }) => {
15
15
  <DefaultCalculator
16
16
  purchasePrice={purchasePrice}
17
17
  setPurchasePrice={setPurchasePrice}
18
+ firstTimeBuyer
19
+ additionalProperty={false}
20
+ ukResident
18
21
  />
19
22
  );
20
23
  }
@@ -31,6 +31,8 @@ export const INITIAL_USER_DATA = {
31
31
  password: '',
32
32
  password_confirmation: '',
33
33
  marketing_preferences: {},
34
+ // honeypot
35
+ body: '',
34
36
  };
35
37
 
36
38
  // set both currentUser and localUser to same initial data
package/user/index.js CHANGED
@@ -8,6 +8,7 @@ import MarketingPreferencesForm from './marketing-preferences-form/marketing-pre
8
8
  import ForgottenPasswordForm from './forgotten-password-form/forgotten-password-form.component';
9
9
  import ResetPasswordForm from './reset-password-form/reset-password-form.component';
10
10
  import UserEditForm from './user-edit-form/user-edit-form.component';
11
+ import UserHoneypot from './user-honeypot/user-honeypot.component';
11
12
 
12
13
  export {
13
14
  withUser,
@@ -20,4 +21,5 @@ export {
20
21
  MarketingPreferencesForm,
21
22
  ForgottenPasswordForm,
22
23
  ResetPasswordForm,
24
+ UserHoneypot,
23
25
  };
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import { useSelector, useDispatch } from "react-redux";
3
+ import { setLocalUser } from "../../actions/user.actions";
4
+
5
+ const UserHoneypot = () => {
6
+ const userBody = useSelector(state => state.user.localUser?.body);
7
+ const dispatch = useDispatch();
8
+
9
+ const handleChange = (e) => {
10
+ dispatch(setLocalUser({ body: e.target.value }));
11
+ };
12
+
13
+ return (
14
+ <input
15
+ type="text"
16
+ name="hfhp"
17
+ value={userBody}
18
+ onChange={handleChange}
19
+ style={{
20
+ height: 0,
21
+ width: 0,
22
+ opacity: 0,
23
+ padding: 0,
24
+ }}
25
+ />
26
+ );
27
+ }
28
+
29
+ export default UserHoneypot;