homeflowjs 1.0.38 → 1.0.40
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 +1 -1
- package/properties/property-results-pagination/property-results-pagination-item.component.jsx +31 -7
- package/properties/property-results-pagination/property-results-pagination.component.jsx +93 -78
- package/utils/stamp-duty-calculator/english-rates.js +51 -29
- package/utils/stamp-duty-calculator/stamp-duty-calculator.js +2 -2
package/package.json
CHANGED
package/properties/property-results-pagination/property-results-pagination-item.component.jsx
CHANGED
@@ -13,21 +13,45 @@ export default function PropertyResultsPaginationItem({
|
|
13
13
|
LeftChevron,
|
14
14
|
RightChevron,
|
15
15
|
}) {
|
16
|
-
const activeClassName = (className) =>
|
17
|
-
currentPage === pageNumber ? `${className}--active` : ''
|
18
|
-
|
16
|
+
const activeClassName = (className) =>
|
17
|
+
currentPage === pageNumber ? `${className}--active` : '';
|
18
|
+
|
19
|
+
const pageLink = () => {
|
20
|
+
if (window.location.pathname.includes('page-')) {
|
21
|
+
return window.location.pathname.replace(/page-\d+/, `page-${pageNumber}`);
|
22
|
+
}
|
23
|
+
return `${window.location.pathname}/page-${pageNumber}`;
|
24
|
+
};
|
25
|
+
|
19
26
|
return (
|
20
|
-
<li
|
21
|
-
|
27
|
+
<li
|
28
|
+
className={`property-results-pagination__item ${activeClassName(
|
29
|
+
'property-results-pagination__item'
|
30
|
+
)}`}
|
31
|
+
>
|
32
|
+
<a
|
33
|
+
href={pageLink()}
|
34
|
+
className={`property-results-pagination__link ${activeClassName(
|
35
|
+
'property-results-pagination__link'
|
36
|
+
)}`}
|
37
|
+
>
|
22
38
|
{previous && (
|
23
39
|
<>
|
24
40
|
{!noChevrons && <LeftChevron />}
|
25
|
-
{!noPrevOrNextText &&
|
41
|
+
{!noPrevOrNextText && (
|
42
|
+
<span className="property-results-pagination__link-prev-text">
|
43
|
+
Previous
|
44
|
+
</span>
|
45
|
+
)}
|
26
46
|
</>
|
27
47
|
)}
|
28
48
|
{next && (
|
29
49
|
<>
|
30
|
-
{!noPrevOrNextText &&
|
50
|
+
{!noPrevOrNextText && (
|
51
|
+
<span className="property-results-pagination__link-next-text">
|
52
|
+
Next
|
53
|
+
</span>
|
54
|
+
)}
|
31
55
|
{!noChevrons && <RightChevron />}
|
32
56
|
</>
|
33
57
|
)}
|
@@ -22,78 +22,110 @@ export default function PropertyResultsPagination({
|
|
22
22
|
current_page: currentPage,
|
23
23
|
has_next_page: hasNextPage,
|
24
24
|
has_prev_page: hasPrevPage,
|
25
|
-
total_count: totalCount,
|
26
25
|
page_count: pageCount,
|
27
26
|
} = pagination;
|
28
27
|
|
29
28
|
/**
|
30
|
-
* Generates an array of pagination
|
31
|
-
* based on the current page and total page count.
|
32
|
-
* For example the 2,3,4 and 5 in < 1 ... 2 - 3 - 4 - 5 ... 29 >
|
33
|
-
*
|
29
|
+
* Generates an array of pagination with ellipsis '...' where appropriate
|
34
30
|
* @example
|
35
31
|
* currentPage = 1;
|
36
|
-
* pageCount =
|
37
|
-
*
|
32
|
+
* pageCount = 1;
|
33
|
+
* paginationIncrements = 4;
|
34
|
+
* 'Should output: [1]'
|
38
35
|
*
|
39
36
|
* currentPage = 1;
|
40
37
|
* pageCount = 5;
|
41
|
-
*
|
38
|
+
* paginationIncrements = 4;
|
39
|
+
*'Should output: ['1', '2', '3', '4', '5']'
|
40
|
+
*
|
41
|
+
* currentPage = 1;
|
42
|
+
* pageCount = 3;
|
43
|
+
* paginationIncrements = 4;
|
44
|
+
*'Should output: ['1', '2','3']'
|
45
|
+
*
|
46
|
+
* currentPage = 1;
|
47
|
+
* pageCount = 100;
|
48
|
+
* paginationIncrements = 4;
|
49
|
+
*'Should output: ['1', '2', '3', '4', '5', '...', '100']'
|
42
50
|
*
|
43
51
|
* currentPage = 2;
|
44
52
|
* pageCount = 100;
|
45
|
-
*
|
53
|
+
* paginationIncrements = 4;
|
54
|
+
* 'Should output: ['1', '2', '3', '4', '5', '...', '100']'
|
46
55
|
*
|
47
56
|
* currentPage = 3;
|
48
57
|
* pageCount = 100;
|
49
|
-
*
|
58
|
+
* paginationIncrements = 4;
|
59
|
+
* 'Should output: ['1', '...', '3', '4', '5', '6', '...', '100']'
|
50
60
|
*
|
51
|
-
* currentPage =
|
61
|
+
* currentPage = 99;
|
52
62
|
* pageCount = 100;
|
53
|
-
*
|
63
|
+
* paginationIncrements = 4;
|
64
|
+
* 'Should output: ['1', '...', '96', '97', '98', '99', '100']'
|
54
65
|
*
|
55
|
-
* currentPage =
|
56
|
-
* pageCount =
|
57
|
-
*
|
66
|
+
* currentPage = 96;
|
67
|
+
* pageCount = 100;
|
68
|
+
* paginationIncrements = 4;
|
69
|
+
* 'Should output: ['1', '...', '96', '97', '98', '99', '100']'
|
58
70
|
*
|
59
|
-
* currentPage =
|
60
|
-
* pageCount =
|
61
|
-
*
|
62
|
-
*
|
71
|
+
* currentPage = 100;
|
72
|
+
* pageCount = 100;
|
73
|
+
* paginationIncrements = 4;
|
74
|
+
* 'Should output: ['1', '...','96','97', '98', '99', '100']'
|
75
|
+
*
|
76
|
+
* @returns {string[]} An array of strings for pagination.
|
63
77
|
*/
|
64
|
-
const
|
65
|
-
if (pageCount === 1) return [];
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
78
|
+
const generatePagination = () => {
|
79
|
+
if (pageCount === 1) return ['1'];
|
80
|
+
|
81
|
+
let pages = [];
|
82
|
+
|
83
|
+
if (pageCount <= paginationIncrements + 1) {
|
84
|
+
for (let i = 1; i <= pageCount; i++) {
|
85
|
+
pages.push(i.toString());
|
86
|
+
}
|
87
|
+
return pages;
|
73
88
|
}
|
74
89
|
|
75
|
-
if (
|
76
|
-
|
90
|
+
if (currentPage > 1 && currentPage !== 2) {
|
91
|
+
pages.push('1', '...');
|
77
92
|
}
|
78
93
|
|
79
|
-
|
80
|
-
|
81
|
-
startIncrement = pageCount >= paginationIncrements
|
82
|
-
? currentPage - paginationIncrements : currentPage - (paginationIncrements - currentPage);
|
83
|
-
endIncrement = currentPage;
|
94
|
+
if (currentPage === 2) {
|
95
|
+
pages.push('1');
|
84
96
|
}
|
85
97
|
|
86
|
-
|
87
|
-
|
98
|
+
const getStart = () => {
|
99
|
+
if (currentPage + paginationIncrements >= pageCount)
|
100
|
+
return pageCount - paginationIncrements;
|
101
|
+
return Math.max(currentPage, 1);
|
102
|
+
};
|
103
|
+
|
104
|
+
const getEnd = () => {
|
105
|
+
if (currentPage + paginationIncrements >= pageCount) return pageCount;
|
106
|
+
if (currentPage === 1) return paginationIncrements + 1;
|
107
|
+
return Math.min(currentPage + (paginationIncrements - 1), pageCount);
|
108
|
+
};
|
109
|
+
|
110
|
+
const start = getStart();
|
111
|
+
const end = getEnd();
|
112
|
+
|
113
|
+
for (let i = start; i <= end; i++) {
|
114
|
+
pages.push(i.toString());
|
115
|
+
}
|
116
|
+
|
117
|
+
if (end < pageCount) {
|
118
|
+
pages.push('...', pageCount.toString());
|
88
119
|
}
|
89
|
-
|
120
|
+
|
121
|
+
return pages;
|
90
122
|
};
|
91
123
|
|
92
124
|
return (
|
93
125
|
<div className="property-results-pagination" {...otherProps}>
|
94
126
|
<ul className="property-results-pagination__links">
|
95
127
|
{/* Previous page */}
|
96
|
-
{hasPrevPage &&
|
128
|
+
{hasPrevPage && !noChevrons && !noPrevOrNextText && (
|
97
129
|
<PropertyResultsPaginationItem
|
98
130
|
previous
|
99
131
|
pageNumber={currentPage - 1}
|
@@ -102,45 +134,28 @@ export default function PropertyResultsPagination({
|
|
102
134
|
/>
|
103
135
|
)}
|
104
136
|
|
105
|
-
{
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
{
|
127
|
-
{totalCount > paginationIncrements && (
|
128
|
-
<li className="property-results-pagination__item property-results-pagination__item--ellipsis">
|
129
|
-
<span className="property-results-pagination__ellipsis">…</span>
|
130
|
-
</li>
|
131
|
-
)}
|
132
|
-
|
133
|
-
{/* Total page count */}
|
134
|
-
{showIfPageCountIsOne && pageCount !== 0 ? (
|
135
|
-
<PropertyResultsPaginationItem pageNumber={pageCount} currentPage={currentPage} />
|
136
|
-
) : (
|
137
|
-
pageCount > 1 && (
|
138
|
-
<PropertyResultsPaginationItem pageNumber={pageCount} currentPage={currentPage} />
|
139
|
-
)
|
140
|
-
)}
|
141
|
-
|
142
|
-
{/* Previous page */}
|
143
|
-
{hasNextPage && (!noChevrons && !noPrevOrNextText) && (
|
137
|
+
{generatePagination().map((page) => {
|
138
|
+
if (page === '...') {
|
139
|
+
// Ellipsis
|
140
|
+
return (
|
141
|
+
<li className="property-results-pagination__item property-results-pagination__item--ellipsis">
|
142
|
+
<span className="property-results-pagination__ellipsis">
|
143
|
+
…
|
144
|
+
</span>
|
145
|
+
</li>
|
146
|
+
);
|
147
|
+
}
|
148
|
+
return (
|
149
|
+
<PropertyResultsPaginationItem
|
150
|
+
key={page}
|
151
|
+
pageNumber={parseInt(page, 10)}
|
152
|
+
currentPage={currentPage}
|
153
|
+
/>
|
154
|
+
);
|
155
|
+
})}
|
156
|
+
|
157
|
+
{/* Next page */}
|
158
|
+
{hasNextPage && !noChevrons && !noPrevOrNextText && (
|
144
159
|
<PropertyResultsPaginationItem
|
145
160
|
next
|
146
161
|
pageNumber={currentPage + 1}
|
@@ -1,9 +1,28 @@
|
|
1
1
|
const calculateRange = (price, lower, upper, rate) => {
|
2
2
|
if (price <= lower) return 0;
|
3
3
|
return (Math.min(upper, price) - lower) * rate;
|
4
|
-
}
|
4
|
+
};
|
5
|
+
|
6
|
+
const englishRates = (
|
7
|
+
price,
|
8
|
+
firstTimeBuyer,
|
9
|
+
additionalProperty,
|
10
|
+
ukResident = true, // Default to true if not explicitly specified
|
11
|
+
isCompany
|
12
|
+
) => {
|
13
|
+
// Handle cases where price is missing or invalid
|
14
|
+
if (!price || price <= 0) {
|
15
|
+
return {
|
16
|
+
rate1: 0,
|
17
|
+
rate2: 0,
|
18
|
+
rate3: 0,
|
19
|
+
rate4: 0,
|
20
|
+
rate5: 0,
|
21
|
+
totalRate: 0,
|
22
|
+
effectiveRate: 0,
|
23
|
+
};
|
24
|
+
}
|
5
25
|
|
6
|
-
const englishRates = (price, firstTimeBuyer, additionalProperty, ukResident) => {
|
7
26
|
let effectiveRate = 0;
|
8
27
|
let totalRate = 0;
|
9
28
|
let rate1 = 0;
|
@@ -12,36 +31,39 @@ const englishRates = (price, firstTimeBuyer, additionalProperty, ukResident) =>
|
|
12
31
|
let rate4 = 0;
|
13
32
|
let rate5 = 0;
|
14
33
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
34
|
+
if (isCompany) {
|
35
|
+
// Company buy: Flat rate of 17% for properties above £500,000
|
36
|
+
if (price > 500000) {
|
37
|
+
totalRate = price * 0.17;
|
38
|
+
}
|
39
|
+
} else {
|
40
|
+
// Individual buyers
|
41
|
+
if (firstTimeBuyer && price <= 625000) {
|
42
|
+
rate2 = calculateRange(price, 425000, Number.POSITIVE_INFINITY, 0.05);
|
43
|
+
}
|
19
44
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
45
|
+
if (additionalProperty) {
|
46
|
+
// Additional property rates
|
47
|
+
rate1 = calculateRange(price, 0, 250000, 0.05);
|
48
|
+
rate2 = calculateRange(price, 250000, 925000, 0.10);
|
49
|
+
rate3 = calculateRange(price, 925000, 1500000, 0.15);
|
50
|
+
rate4 = calculateRange(price, 1500000, Number.POSITIVE_INFINITY, 0.17);
|
51
|
+
} else if (!(firstTimeBuyer && price <= 625000)) {
|
52
|
+
// Moving or first-time buyer > £625,000
|
53
|
+
rate2 = calculateRange(price, 250000, 925000, 0.05);
|
54
|
+
rate3 = calculateRange(price, 925000, 1500000, 0.10);
|
55
|
+
rate4 = calculateRange(price, 1500000, Number.POSITIVE_INFINITY, 0.12);
|
56
|
+
}
|
27
57
|
|
28
|
-
|
29
|
-
if (
|
30
|
-
!(firstTimeBuyer && price <= 625000)
|
31
|
-
&& !additionalProperty
|
32
|
-
) {
|
33
|
-
rate2 = calculateRange(price, 250000, 925000, 0.05);
|
34
|
-
rate3 = calculateRange(price, 925000, 1500000, 0.10);
|
35
|
-
rate4 = calculateRange(price, 1500000, Number.POSITIVE_INFINITY, 0.12);
|
36
|
-
}
|
58
|
+
totalRate = rate1 + rate2 + rate3 + rate4 + rate5;
|
37
59
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
effectiveRate += 0.02;
|
60
|
+
// Apply additional rate for non-UK residents only if applicable
|
61
|
+
if (!ukResident && additionalProperty) {
|
62
|
+
totalRate += price * 0.02; // Non-UK resident surcharge
|
63
|
+
}
|
43
64
|
}
|
44
|
-
|
65
|
+
|
66
|
+
effectiveRate = (totalRate / price) * 100;
|
45
67
|
|
46
68
|
return {
|
47
69
|
rate1,
|
@@ -50,7 +72,7 @@ const englishRates = (price, firstTimeBuyer, additionalProperty, ukResident) =>
|
|
50
72
|
rate4,
|
51
73
|
rate5,
|
52
74
|
totalRate,
|
53
|
-
effectiveRate
|
75
|
+
effectiveRate,
|
54
76
|
};
|
55
77
|
};
|
56
78
|
|
@@ -10,7 +10,7 @@ import welshRates from './welsh-rates';
|
|
10
10
|
* different layout and/or styles to the DefaultStampDutyCalculator component.
|
11
11
|
*/
|
12
12
|
const stampDutyCalculator = ({
|
13
|
-
price, country, firstTimeBuyer, additionalProperty, ukResident = true
|
13
|
+
price, country, firstTimeBuyer, additionalProperty, ukResident = true, isCompany
|
14
14
|
}) => {
|
15
15
|
if (!price) {
|
16
16
|
return {
|
@@ -29,7 +29,7 @@ const stampDutyCalculator = ({
|
|
29
29
|
}
|
30
30
|
|
31
31
|
// If country not is not specified use English rates by default
|
32
|
-
return englishRates(price, firstTimeBuyer, additionalProperty, ukResident);
|
32
|
+
return englishRates(price, firstTimeBuyer, additionalProperty, ukResident, isCompany);
|
33
33
|
};
|
34
34
|
|
35
35
|
export default stampDutyCalculator;
|