homeflowjs 1.1.3 → 1.1.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": "homeflowjs",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -242,8 +242,11 @@ export default class DraggableMap {
242
242
  minimumFractionDigits: 0,
243
243
  maximumFractionDigits: 0,
244
244
  });
245
- const value = rates && rates[currency] * numericPrice || propertyPrice;
245
+ const value = rates?.[currency] != null ? rates[currency] * numericPrice : propertyPrice;
246
246
  const convertedValue = formatter.format(Math.round(value));
247
+ if (!rates) {
248
+ return value;
249
+ };
247
250
 
248
251
  /*
249
252
  Properties which have different currencies set in admin
@@ -255,7 +258,7 @@ export default class DraggableMap {
255
258
  * Converting the property price to the selected currency
256
259
  * this could either be from GBP to EUR, GBP to USD, EUR to USD, etc
257
260
  */
258
- if ( selectedCurrency === 'GBP' && localCurrencyCode !== null && localCurrencyPrice !== null && localCurrencyCode !== 'GBP' ) {
261
+ if ( rates && selectedCurrency === 'GBP' && localCurrencyCode !== null && localCurrencyPrice !== null && localCurrencyCode !== 'GBP' ) {
259
262
  const value = localCurrencyPrice / rates[localCurrencyCode];
260
263
  return formatter.format(Math.round(value));
261
264
  }
@@ -72,6 +72,7 @@ const RentYieldCalculator = ({
72
72
  currency,
73
73
  grossYieldTitle,
74
74
  netYieldTitle,
75
+ showThousandSeparator,
75
76
  }) => {
76
77
  const customFieldsConfigsList = useMemo(() => initialFieldsConfigsList
77
78
  .map((fieldConfig) => {
@@ -134,6 +135,7 @@ const RentYieldCalculator = ({
134
135
  rangeStylesConfigs={rangeStylesConfigs}
135
136
  inputPrefixString={currency}
136
137
  onRangeInputUpdate={onFormDataUpdate}
138
+ showThousandSeparator={showThousandSeparator}
137
139
  />
138
140
  </div>
139
141
  ))}
@@ -163,6 +165,7 @@ RentYieldCalculator.defaultProps = {
163
165
  currency: '£',
164
166
  grossYieldTitle: 'Gross Yield',
165
167
  netYieldTitle: 'Net Yield',
168
+ showThousandSeparator: true,
166
169
  };
167
170
 
168
171
  const FieldConfigType = PropTypes.shape({
@@ -182,6 +185,7 @@ RentYieldCalculator.propTypes = {
182
185
  currency: PropTypes.string,
183
186
  grossYieldTitle: PropTypes.string,
184
187
  netYieldTitle: PropTypes.string,
188
+ showThousandSeparator: PropTypes.bool,
185
189
  };
186
190
 
187
191
  export default memo(RentYieldCalculator);
@@ -18,9 +18,21 @@ const RangeInput = ({
18
18
  rangeStylesConfigs,
19
19
  inputPrefixString,
20
20
  onRangeInputUpdate,
21
+ showThousandSeparator,
21
22
  }) => {
23
+
24
+ const withThousandSeparator = (number) => {
25
+ if (!showThousandSeparator) {
26
+ return inputPrefixString ? `${inputPrefixString} ${number}` : `${number}`;
27
+ }
28
+
29
+ const separatedNumber = new Intl.NumberFormat().format(number);
30
+
31
+ return inputPrefixString ? `${inputPrefixString} ${separatedNumber}` : `${separatedNumber}`;
32
+ };
33
+
22
34
  const [valueConfig, setValueConfig] = useState({
23
- inputValue: inputPrefixString ? `${inputPrefixString} 0` : '0',
35
+ inputValue: withThousandSeparator(0),
24
36
  rangeValue: 0,
25
37
  });
26
38
 
@@ -35,9 +47,7 @@ const RangeInput = ({
35
47
  useEffect(() => {
36
48
  const validatedValue = onValidateValue(Number(inititalValue));
37
49
  setValueConfig({
38
- inputValue: inputPrefixString
39
- ? `${inputPrefixString} ${validatedValue}`
40
- : `${validatedValue}`,
50
+ inputValue: withThousandSeparator(validatedValue),
41
51
  rangeValue: validatedValue,
42
52
  });
43
53
  }, []);
@@ -47,15 +57,12 @@ const RangeInput = ({
47
57
  const currentValue = isRangeValue ? value[0] : value;
48
58
  const digitValue = isRangeValue
49
59
  ? currentValue
50
- : currentValue.substring(currentValue.indexOf(inputPrefixString) + 1).trim();
60
+ : currentValue.replace(`${inputPrefixString} `, '').replaceAll(',', '');
61
+
62
+ if (isNaN(digitValue)) return;
51
63
 
52
- if (isNaN(digitValue)) {
53
- return;
54
- }
55
64
  const validatedValue = onValidateValue(Number(digitValue));
56
- const inputValue = inputPrefixString
57
- ? `${inputPrefixString} ${validatedValue}`
58
- : `${validatedValue}`;
65
+ const inputValue = withThousandSeparator(validatedValue);
59
66
  const rangeValue = Number(validatedValue);
60
67
 
61
68
  setValueConfig((prevState) => ({
@@ -116,6 +123,7 @@ RangeInput.propTypes = {
116
123
  inititalValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
117
124
  inputPrefixString: PropTypes.string,
118
125
  onRangeInputUpdate: PropTypes.func,
126
+ showThousandSeparator: PropTypes.bool.isRequired,
119
127
  ...RANGE_CONTROLLER_PROP_TYPES,
120
128
  };
121
129