homeflowjs 0.10.12 → 0.10.14

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.10.12",
3
+ "version": "0.10.14",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,7 +3,7 @@ import { connect } from 'react-redux';
3
3
 
4
4
  import './stamp-duty-calculator.styles.scss';
5
5
 
6
- const BTLCalculator = ({ purchasePrice, setPurchasePrice }) => {
6
+ const BTLCalculator = ({ purchasePrice, setPurchasePrice, firstTimeBuyer }) => {
7
7
  const [effectiveRate, setEffectiveRate] = useState();
8
8
  const [totalRate, setTotalRate] = useState();
9
9
  const [rate0, setRate0] = useState();
@@ -31,45 +31,66 @@ const BTLCalculator = ({ purchasePrice, setPurchasePrice }) => {
31
31
  let rate1 = 0;
32
32
  let rate2 = 0;
33
33
  let rate3 = 0;
34
- let rate4 = 0;
35
-
36
- if (price - 40000 > 0) {
37
- rate0 = price;
38
- rate0 *= 0.03;
39
- if (rate0 > 125000 * 0.03) {
40
- rate0 = 125000 * 0.03;
34
+
35
+ if (firstTimeBuyer) {
36
+ if (price - 250000 > 0) {
37
+ rate0 = price;
38
+ rate0 *= 0;
39
+ if (rate0 > 250000 * 0) {
40
+ rate0 = 250000 * 0;
41
+ }
41
42
  }
42
- }
43
- if (price - 125000 > 0) {
44
- rate1 = (price - 125000);
45
- rate1 *= 0.05;
46
- if (rate1 > 125000 * 0.05) {
47
- rate1 = 125000 * 0.05;
43
+ if (price - 250000 > 0) {
44
+ rate1 = (price - 250000);
45
+ rate1 *= 0.05;
46
+ if (rate1 > 675000 * 0.05) {
47
+ rate1 = 675000 * 0.05;
48
+ }
48
49
  }
49
- }
50
50
 
51
- if (price - 250000 > 0) {
52
- rate2 = (price - 250000);
53
- rate2 *= 0.08;
54
- if (rate2 > 675000 * 0.08) {
55
- rate2 = 675000 * 0.08;
51
+ if (price - 925000 > 0) {
52
+ rate2 = (price - 925000);
53
+ rate2 *= 0.10;
54
+ if (rate2 > 575000 * 0.10) {
55
+ rate2 = 575000 * 0.10;
56
+ }
56
57
  }
57
- }
58
58
 
59
- if (price - 925000 > 0) {
60
- rate3 = (price - 925000);
61
- rate3 *= 0.13;
62
- if (rate3 > 575000 * 0.13) {
63
- rate3 = 575000 * 0.13;
59
+ if (price - 1500000 > 0) {
60
+ rate3 = (price - 1500000);
61
+ rate3 *= 0.12;
62
+ }
63
+ } else {
64
+ if (price - 250000 > 0) {
65
+ rate0 = price;
66
+ rate0 *= 0.03;
67
+ if (rate0 > 250000 * 0.03) {
68
+ rate0 = 250000 * 0.03;
69
+ }
70
+ }
71
+ if (price - 250000 > 0) {
72
+ rate1 = (price - 250000);
73
+ rate1 *= 0.08;
74
+ if (rate1 > 675000 * 0.08) {
75
+ rate1 = 675000 * 0.08;
76
+ }
77
+ }
78
+
79
+ if (price - 925000 > 0) {
80
+ rate2 = (price - 925000);
81
+ rate2 *= 0.13;
82
+ if (rate2 > 575000 * 0.13) {
83
+ rate2 = 575000 * 0.13;
84
+ }
64
85
  }
65
- }
66
86
 
67
- if (price - 1500000 > 0) {
68
- rate4 = (price - 1500000);
69
- rate4 *= 0.15;
87
+ if (price - 1500000 > 0) {
88
+ rate3 = (price - 1500000);
89
+ rate3 *= 0.15;
90
+ }
70
91
  }
71
92
 
72
- totalRate = rate0 + rate1 + rate2 + rate3 + rate4;
93
+ totalRate = rate0 + rate1 + rate2 + rate3;
73
94
  effectiveRate = totalRate / price;
74
95
  effectiveRate *= 100;
75
96
 
@@ -90,7 +111,7 @@ const BTLCalculator = ({ purchasePrice, setPurchasePrice }) => {
90
111
  setPurchasePrice(property.price_value);
91
112
  calculateStampDuty(property.price_value);
92
113
  }
93
- }, []);
114
+ }, [firstTimeBuyer]);
94
115
 
95
116
  const handlePriceInputChange = ({ target: { value } }) => {
96
117
  const numberString = value.substring(1);
@@ -146,57 +167,100 @@ const BTLCalculator = ({ purchasePrice, setPurchasePrice }) => {
146
167
  </tr>
147
168
  </thead>
148
169
  <tbody>
149
- <tr>
150
- <td>Between £0 and £125,000</td>
151
- <td>3%</td>
152
- <td className="rate0">
153
- £
154
- {Number(rate0).toLocaleString()}
155
- </td>
156
- </tr>
157
- <tr>
158
- <td>Between £125,000 and £250,000</td>
159
- <td>5%</td>
160
- <td className="rate1">
161
- £
162
- {Number(rate1).toLocaleString()}
163
- </td>
164
- </tr>
165
- <tr>
166
- <td>Between £250,000 and £925,000</td>
167
- <td>8%</td>
168
- <td className="rate2">
169
- £
170
- {Number(rate2).toLocaleString()}
171
- </td>
172
- </tr>
173
- <tr>
174
- <td>Between £925,000 and £1,500,000</td>
175
- <td>13%</td>
176
- <td className="rate3">
177
- £
178
- {Number(rate3).toLocaleString()}
179
- </td>
180
- </tr>
181
- <tr>
182
- <td>Over £1,500,000</td>
183
- <td>15%</td>
184
- <td className="rate4">
185
- £
186
- {Number(rate4).toLocaleString()}
187
- </td>
188
- </tr>
189
- <tr className="totals">
190
- <td>Total</td>
191
- <td className="effectiveRate">
192
- {effectiveRate}
193
- %
194
- </td>
195
- <td className="totalRate">
196
- £
197
- {Number(totalRate).toLocaleString()}
198
- </td>
199
- </tr>
170
+ {(firstTimeBuyer ? (
171
+ <>
172
+ <tr>
173
+ <td>Between £0 and 250,000</td>
174
+ <td>0%</td>
175
+ <td className="rate0">
176
+ £
177
+ {Number(rate0).toLocaleString()}
178
+ </td>
179
+ </tr>
180
+ <tr>
181
+ <td>Between £250,000 and £925,000</td>
182
+ <td>5%</td>
183
+ <td className="rate1">
184
+ £
185
+ {Number(rate1).toLocaleString()}
186
+ </td>
187
+ </tr>
188
+ <tr>
189
+ <td>Between £925,000 and £1,500,000</td>
190
+ <td>10%</td>
191
+ <td className="rate2">
192
+ £
193
+ {Number(rate2).toLocaleString()}
194
+ </td>
195
+ </tr>
196
+ <tr>
197
+ <td>Over £1,500,000</td>
198
+ <td>12%</td>
199
+ <td className="rate3">
200
+ £
201
+ {Number(rate3).toLocaleString()}
202
+ </td>
203
+ </tr>
204
+ <tr className="totals">
205
+ <td>Total</td>
206
+ <td className="effectiveRate">
207
+ {effectiveRate}
208
+ %
209
+ </td>
210
+ <td className="totalRate">
211
+ £
212
+ {Number(totalRate).toLocaleString()}
213
+ </td>
214
+ </tr>
215
+ </>
216
+ ) : (
217
+ <>
218
+ <tr>
219
+ <td>Between £0 and 250,000</td>
220
+ <td>3%</td>
221
+ <td className="rate0">
222
+ £
223
+ {Number(rate0).toLocaleString()}
224
+ </td>
225
+ </tr>
226
+ <tr>
227
+ <td>Between £250,000 and £925,000</td>
228
+ <td>8%</td>
229
+ <td className="rate1">
230
+ £
231
+ {Number(rate1).toLocaleString()}
232
+ </td>
233
+ </tr>
234
+ <tr>
235
+ <td>Between £925,000 and £1,500,000</td>
236
+ <td>13%</td>
237
+ <td className="rate3">
238
+ £
239
+ {Number(rate2).toLocaleString()}
240
+ </td>
241
+ </tr>
242
+ <tr>
243
+ <td>Over £1,500,000</td>
244
+ <td>15%</td>
245
+ <td className="rate4">
246
+ £
247
+ {Number(rate3).toLocaleString()}
248
+ </td>
249
+ </tr>
250
+ <tr className="totals">
251
+ <td>Total</td>
252
+ <td className="effectiveRate">
253
+ {effectiveRate}
254
+ %
255
+ </td>
256
+ <td className="totalRate">
257
+ £
258
+ {Number(totalRate).toLocaleString()}
259
+ </td>
260
+ </tr>
261
+ </>
262
+ ))}
263
+
200
264
  </tbody>
201
265
  </table>
202
266
  </div>
@@ -28,6 +28,7 @@ const StampDutyCalculator = ({ scotland, themePreferences }) => {
28
28
  <BTLCalculator
29
29
  purchasePrice={purchasePrice}
30
30
  setPurchasePrice={setPurchasePrice}
31
+ firstTimeBuyer={purchaseType === 'firstTimeBuyer'}
31
32
  />
32
33
  );
33
34
  }
@@ -21,22 +21,45 @@ const MarketingPreferencesForm = ({ buttonClass, buttonSpanClass, strict }) => {
21
21
  const handleSubmit = (e) => {
22
22
  e.preventDefault();
23
23
 
24
- if (!user.marketing_preference_id) {
24
+ if (!user?.user_id) {
25
25
  notify('Please sign in to update your preferences', 'error');
26
26
  return;
27
27
  }
28
28
 
29
- fetch(`/marketing_preferences/${user.marketing_preference_id}`, {
29
+ /**
30
+ * cms created users don't have marketing_preference_id
31
+ * associated to them. To update marketing preferences
32
+ * we can use any of those 2 endpoints depending on the
33
+ * data we pass. Ideally this should get fixed by BE at some point.
34
+ */
35
+ const url = user?.marketing_preference_id
36
+ ? `/marketing_preferences/${user.marketing_preference_id}`
37
+ : `/custom_marketing_preferences/${user.user_id}`;
38
+
39
+ const optInAtAndUrl = {
40
+ opt_in_marketing_at: optInMarketing ? 'optin' : 'optout',
41
+ opt_in_marketing_url: document.URL,
42
+ };
43
+
44
+ const body = {
45
+ user_id: user.user_id,
46
+ ...(!user.marketing_preference_id ? ({
47
+ marketing_preferences: {
48
+ is_opted_in_to_marketing: optInMarketing,
49
+ ...optInAtAndUrl,
50
+ },
51
+ }) : ({
52
+ ...optInAtAndUrl,
53
+ })),
54
+ };
55
+
56
+ fetch(url, {
30
57
  method: 'POST',
31
58
  headers: {
32
59
  'Content-Type': 'application/json',
33
60
  'X-Http-Method-Override': 'put',
34
61
  },
35
- body: JSON.stringify({
36
- opt_in_marketing_at: optInMarketing ? 'optin' : 'optout',
37
- opt_in_marketing_url: document.URL,
38
- user_id: user.user_id,
39
- }),
62
+ body: JSON.stringify(body),
40
63
  }).then((res) => {
41
64
  if (res.ok && (res.status === 200 || res.status === 204)) {
42
65
  dispatch(setCurrentUser({