@nnc-digital/nnc-design-system 0.4.14 → 0.4.16
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/build/index.esm.js +73 -23
- package/build/index.esm.js.map +1 -1
- package/build/index.js +73 -23
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -4049,7 +4049,7 @@ var FormContainer$1 = styled__default["default"].div(templateObject_4 || (templa
|
|
|
4049
4049
|
return props.isLoading && "\n opacity: 0.5; \n pointer-events: none;\n ";
|
|
4050
4050
|
});
|
|
4051
4051
|
var ErrorTextWrapper = styled__default["default"].div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: block;\n width: 100%;\n"], ["\n display: block;\n width: 100%;\n"])));
|
|
4052
|
-
var DropDownSelectContainer = styled__default["default"].div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n padding-bottom: 20px;\n"], ["\n padding-bottom: 20px;\n"])));
|
|
4052
|
+
var DropDownSelectContainer = styled__default["default"].div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n padding-bottom: 20px;\n width: 90%;\n"], ["\n padding-bottom: 20px;\n width: 90%;\n"])));
|
|
4053
4053
|
var FormInnerContainer = styled__default["default"].div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n justify-content: flex-start;\n"], ["\n display: flex;\n align-items: center;\n justify-content: flex-start;\n"])));
|
|
4054
4054
|
styled__default["default"].label(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n margin-right: ", ";\n"], ["\n display: flex;\n align-items: center;\n margin-right: ", ";\n"])), function (props) { return props.theme.theme_vars.spacingSizes.small; });
|
|
4055
4055
|
styled__default["default"].div(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n display: flex;\n justify-content: left;\n margin-bottom: .5em;\n width: 100%;\n"], ["\n display: flex;\n justify-content: left;\n margin-bottom: .5em;\n width: 100%;\n"])));
|
|
@@ -4329,6 +4329,7 @@ var BinCollection = function (_a) {
|
|
|
4329
4329
|
var _f = React.useState(''), errorText = _f[0], setErrorText = _f[1];
|
|
4330
4330
|
var _g = React.useState([]), addressOptions = _g[0], setAddressOptions = _g[1];
|
|
4331
4331
|
var seenTitles = React.useRef(new Set());
|
|
4332
|
+
var _h = React.useState(false), noResultsFound = _h[0], setNoResultsFound = _h[1];
|
|
4332
4333
|
var handleSubmit = function (e) {
|
|
4333
4334
|
e.preventDefault();
|
|
4334
4335
|
var enteredPostcode = e.target.elements.postcode.value;
|
|
@@ -4341,14 +4342,23 @@ var BinCollection = function (_a) {
|
|
|
4341
4342
|
fetchAddresses(enteredPostcode);
|
|
4342
4343
|
}
|
|
4343
4344
|
};
|
|
4345
|
+
var formatUKPostcode = function (postcode) {
|
|
4346
|
+
// Remove existing spaces and convert to uppercase
|
|
4347
|
+
var cleaned = postcode.replace(/\s/g, '').toUpperCase();
|
|
4348
|
+
// Add space before the last 3 characters
|
|
4349
|
+
var formatted = cleaned.slice(0, -3) + " " + cleaned.slice(-3);
|
|
4350
|
+
return formatted;
|
|
4351
|
+
};
|
|
4344
4352
|
/**
|
|
4345
4353
|
* Returns an array of address options based on the entered postcode.
|
|
4346
4354
|
*/
|
|
4347
4355
|
var fetchAddresses = function (postcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4348
4356
|
return __generator(this, function (_a) {
|
|
4357
|
+
setCalendarEvents({});
|
|
4349
4358
|
setError(false);
|
|
4350
4359
|
setErrorText('');
|
|
4351
4360
|
setIsLoading(true);
|
|
4361
|
+
postcode = formatUKPostcode(postcode);
|
|
4352
4362
|
axios__default["default"].get("".concat(BinCollectionApiUrl).concat(postcode))
|
|
4353
4363
|
.then(function (response) {
|
|
4354
4364
|
setIsLoading(false);
|
|
@@ -4397,7 +4407,7 @@ var BinCollection = function (_a) {
|
|
|
4397
4407
|
return acc;
|
|
4398
4408
|
}, {});
|
|
4399
4409
|
};
|
|
4400
|
-
var
|
|
4410
|
+
var _j = React.useState({}), calendarEvents = _j[0], setCalendarEvents = _j[1];
|
|
4401
4411
|
/**
|
|
4402
4412
|
* Returns an array of calendar events based on selected address for next 42 days.
|
|
4403
4413
|
*/
|
|
@@ -4410,6 +4420,12 @@ var BinCollection = function (_a) {
|
|
|
4410
4420
|
axios__default["default"].get("".concat(CalendarEventsApiUrl).concat(selectedUPRN, "/").concat(startDate, "/").concat(endDate))
|
|
4411
4421
|
.then(function (response) {
|
|
4412
4422
|
var groupedData = groupByTitle(response.data);
|
|
4423
|
+
if (Object.keys(groupedData).length === 0) {
|
|
4424
|
+
setNoResultsFound(true);
|
|
4425
|
+
}
|
|
4426
|
+
else {
|
|
4427
|
+
setNoResultsFound(false);
|
|
4428
|
+
}
|
|
4413
4429
|
setCalendarEvents(groupedData);
|
|
4414
4430
|
})
|
|
4415
4431
|
.catch(function (error) {
|
|
@@ -4423,18 +4439,53 @@ var BinCollection = function (_a) {
|
|
|
4423
4439
|
setError(false);
|
|
4424
4440
|
setErrorText('');
|
|
4425
4441
|
seenTitles.current.clear();
|
|
4442
|
+
setNoResultsFound(false);
|
|
4426
4443
|
};
|
|
4427
4444
|
var formatTitle = function (apiTitle) {
|
|
4428
4445
|
var mappings = [
|
|
4429
|
-
{
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4446
|
+
{
|
|
4447
|
+
keyword: 'Refuse',
|
|
4448
|
+
replacement: 'General refuse bin',
|
|
4449
|
+
allowedValues: [
|
|
4450
|
+
'Refuse bin 1100l', 'Refuse bin 140l', 'Refuse bin 180l',
|
|
4451
|
+
'Refuse bin 240l', 'Refuse bin 360l', 'Refuse bin 660l',
|
|
4452
|
+
'Refuse Chamberlain', 'Refuse Palladin', 'Authorised bin (larger h/hold) 120l',
|
|
4453
|
+
'Authorised bin (larger h/hold) 140l', 'Authorised bin (larger h/hold) 180l',
|
|
4454
|
+
'Authorised bin (offensive) 140l', 'Authorised bin (offensive) 180l', 'Authorised bin (offensive) 240l',
|
|
4455
|
+
]
|
|
4456
|
+
},
|
|
4457
|
+
{
|
|
4458
|
+
keyword: 'Recycling',
|
|
4459
|
+
replacement: 'Recycling bin',
|
|
4460
|
+
allowedValues: [
|
|
4461
|
+
'Recycling 1100l', 'Recycling 140l', 'Recycling 180l',
|
|
4462
|
+
'Recycling 240l', 'Recycling bin 1100l'
|
|
4463
|
+
]
|
|
4464
|
+
},
|
|
4465
|
+
{
|
|
4466
|
+
keyword: 'Garden',
|
|
4467
|
+
replacement: 'Garden bin',
|
|
4468
|
+
allowedValues: [
|
|
4469
|
+
'Garden 140l', 'Garden 180l', 'Garden 240l'
|
|
4470
|
+
]
|
|
4471
|
+
},
|
|
4472
|
+
{
|
|
4473
|
+
keyword: 'Food',
|
|
4474
|
+
replacement: 'Food caddy',
|
|
4475
|
+
allowedValues: [
|
|
4476
|
+
'Communal food bin (exterior) 180L',
|
|
4477
|
+
'Food Caddy (exterior) 23l',
|
|
4478
|
+
'Food Caddy (indoor) 5l'
|
|
4479
|
+
]
|
|
4480
|
+
},
|
|
4433
4481
|
];
|
|
4434
4482
|
for (var _i = 0, mappings_1 = mappings; _i < mappings_1.length; _i++) {
|
|
4435
4483
|
var mapping = mappings_1[_i];
|
|
4436
|
-
|
|
4437
|
-
|
|
4484
|
+
for (var _a = 0, _b = mapping.allowedValues; _a < _b.length; _a++) {
|
|
4485
|
+
var value = _b[_a];
|
|
4486
|
+
if (apiTitle.includes(value)) {
|
|
4487
|
+
return mapping.replacement;
|
|
4488
|
+
}
|
|
4438
4489
|
}
|
|
4439
4490
|
}
|
|
4440
4491
|
return null;
|
|
@@ -4453,21 +4504,20 @@ var BinCollection = function (_a) {
|
|
|
4453
4504
|
React__default["default"].createElement(FormButton, { size: "large", type: "submit", "aria-label": "Submit", text: "Find" }))))),
|
|
4454
4505
|
addressOptions.length > 0 && (React__default["default"].createElement(DropDownSelectContainer, null,
|
|
4455
4506
|
React__default["default"].createElement(DropDownSelect, { onChange: handleAddressChange, id: "address", label: "Select your address", options: __spreadArray([{ title: 'Select an address', value: '' }], addressOptions, true) }))),
|
|
4456
|
-
React__default["default"].createElement("
|
|
4457
|
-
|
|
4458
|
-
var
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
})),
|
|
4507
|
+
noResultsFound && React__default["default"].createElement("p", null, "No results found."),
|
|
4508
|
+
React__default["default"].createElement("div", null, (function () {
|
|
4509
|
+
var order = ['General refuse bin', 'Recycling bin', 'Garden bin', 'Food caddy'];
|
|
4510
|
+
var uniqueTitles = Array.from(new Set(Object.keys(calendarEvents).map(function (apiTitle) { return formatTitle(apiTitle); }).filter(function (title) { return title !== null; })));
|
|
4511
|
+
var sortedTitles = uniqueTitles.sort(function (a, b) { return order.indexOf(a) - order.indexOf(b); });
|
|
4512
|
+
return sortedTitles.map(function (title, index) {
|
|
4513
|
+
var apiTitlesForThisType = Object.keys(calendarEvents).filter(function (apiTitle) { return formatTitle(apiTitle) === title; });
|
|
4514
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, { key: "".concat(title, "-").concat(index) },
|
|
4515
|
+
React__default["default"].createElement(Heading, { level: 3, text: title }),
|
|
4516
|
+
apiTitlesForThisType.flatMap(function (apiTitle) { return calendarEvents[apiTitle]; })
|
|
4517
|
+
.sort(function (a, b) { return new Date(a).getTime() - new Date(b).getTime(); })
|
|
4518
|
+
.map(function (date) { return (React__default["default"].createElement("p", null, date.toLocaleDateString('en-GB', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }))); })));
|
|
4519
|
+
});
|
|
4520
|
+
})()),
|
|
4471
4521
|
Object.keys(calendarEvents).length > 0 && (React__default["default"].createElement(FormButton, { size: "small", type: "button", "aria-label": "Reset", text: "Find a different address", onClick: resetForm }))));
|
|
4472
4522
|
};
|
|
4473
4523
|
|