@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.
@@ -4034,7 +4034,7 @@ var FormContainer$1 = styled.div(templateObject_4 || (templateObject_4 = __makeT
4034
4034
  return props.isLoading && "\n opacity: 0.5; \n pointer-events: none;\n ";
4035
4035
  });
4036
4036
  var ErrorTextWrapper = styled.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: block;\n width: 100%;\n"], ["\n display: block;\n width: 100%;\n"])));
4037
- var DropDownSelectContainer = styled.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n padding-bottom: 20px;\n"], ["\n padding-bottom: 20px;\n"])));
4037
+ var DropDownSelectContainer = styled.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n padding-bottom: 20px;\n width: 90%;\n"], ["\n padding-bottom: 20px;\n width: 90%;\n"])));
4038
4038
  var FormInnerContainer = styled.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"])));
4039
4039
  styled.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; });
4040
4040
  styled.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"])));
@@ -4314,6 +4314,7 @@ var BinCollection = function (_a) {
4314
4314
  var _f = useState(''), errorText = _f[0], setErrorText = _f[1];
4315
4315
  var _g = useState([]), addressOptions = _g[0], setAddressOptions = _g[1];
4316
4316
  var seenTitles = useRef(new Set());
4317
+ var _h = useState(false), noResultsFound = _h[0], setNoResultsFound = _h[1];
4317
4318
  var handleSubmit = function (e) {
4318
4319
  e.preventDefault();
4319
4320
  var enteredPostcode = e.target.elements.postcode.value;
@@ -4326,14 +4327,23 @@ var BinCollection = function (_a) {
4326
4327
  fetchAddresses(enteredPostcode);
4327
4328
  }
4328
4329
  };
4330
+ var formatUKPostcode = function (postcode) {
4331
+ // Remove existing spaces and convert to uppercase
4332
+ var cleaned = postcode.replace(/\s/g, '').toUpperCase();
4333
+ // Add space before the last 3 characters
4334
+ var formatted = cleaned.slice(0, -3) + " " + cleaned.slice(-3);
4335
+ return formatted;
4336
+ };
4329
4337
  /**
4330
4338
  * Returns an array of address options based on the entered postcode.
4331
4339
  */
4332
4340
  var fetchAddresses = function (postcode) { return __awaiter(void 0, void 0, void 0, function () {
4333
4341
  return __generator(this, function (_a) {
4342
+ setCalendarEvents({});
4334
4343
  setError(false);
4335
4344
  setErrorText('');
4336
4345
  setIsLoading(true);
4346
+ postcode = formatUKPostcode(postcode);
4337
4347
  axios.get("".concat(BinCollectionApiUrl).concat(postcode))
4338
4348
  .then(function (response) {
4339
4349
  setIsLoading(false);
@@ -4382,7 +4392,7 @@ var BinCollection = function (_a) {
4382
4392
  return acc;
4383
4393
  }, {});
4384
4394
  };
4385
- var _h = useState({}), calendarEvents = _h[0], setCalendarEvents = _h[1];
4395
+ var _j = useState({}), calendarEvents = _j[0], setCalendarEvents = _j[1];
4386
4396
  /**
4387
4397
  * Returns an array of calendar events based on selected address for next 42 days.
4388
4398
  */
@@ -4395,6 +4405,12 @@ var BinCollection = function (_a) {
4395
4405
  axios.get("".concat(CalendarEventsApiUrl).concat(selectedUPRN, "/").concat(startDate, "/").concat(endDate))
4396
4406
  .then(function (response) {
4397
4407
  var groupedData = groupByTitle(response.data);
4408
+ if (Object.keys(groupedData).length === 0) {
4409
+ setNoResultsFound(true);
4410
+ }
4411
+ else {
4412
+ setNoResultsFound(false);
4413
+ }
4398
4414
  setCalendarEvents(groupedData);
4399
4415
  })
4400
4416
  .catch(function (error) {
@@ -4408,18 +4424,53 @@ var BinCollection = function (_a) {
4408
4424
  setError(false);
4409
4425
  setErrorText('');
4410
4426
  seenTitles.current.clear();
4427
+ setNoResultsFound(false);
4411
4428
  };
4412
4429
  var formatTitle = function (apiTitle) {
4413
4430
  var mappings = [
4414
- { keyword: 'Refuse', replacement: 'General refuse bin' },
4415
- { keyword: 'Recycling', replacement: 'Recycling bin' },
4416
- { keyword: 'Garden', replacement: 'Garden bin' },
4417
- { keyword: 'Food', replacement: 'Food caddy' },
4431
+ {
4432
+ keyword: 'Refuse',
4433
+ replacement: 'General refuse bin',
4434
+ allowedValues: [
4435
+ 'Refuse bin 1100l', 'Refuse bin 140l', 'Refuse bin 180l',
4436
+ 'Refuse bin 240l', 'Refuse bin 360l', 'Refuse bin 660l',
4437
+ 'Refuse Chamberlain', 'Refuse Palladin', 'Authorised bin (larger h/hold) 120l',
4438
+ 'Authorised bin (larger h/hold) 140l', 'Authorised bin (larger h/hold) 180l',
4439
+ 'Authorised bin (offensive) 140l', 'Authorised bin (offensive) 180l', 'Authorised bin (offensive) 240l',
4440
+ ]
4441
+ },
4442
+ {
4443
+ keyword: 'Recycling',
4444
+ replacement: 'Recycling bin',
4445
+ allowedValues: [
4446
+ 'Recycling 1100l', 'Recycling 140l', 'Recycling 180l',
4447
+ 'Recycling 240l', 'Recycling bin 1100l'
4448
+ ]
4449
+ },
4450
+ {
4451
+ keyword: 'Garden',
4452
+ replacement: 'Garden bin',
4453
+ allowedValues: [
4454
+ 'Garden 140l', 'Garden 180l', 'Garden 240l'
4455
+ ]
4456
+ },
4457
+ {
4458
+ keyword: 'Food',
4459
+ replacement: 'Food caddy',
4460
+ allowedValues: [
4461
+ 'Communal food bin (exterior) 180L',
4462
+ 'Food Caddy (exterior) 23l',
4463
+ 'Food Caddy (indoor) 5l'
4464
+ ]
4465
+ },
4418
4466
  ];
4419
4467
  for (var _i = 0, mappings_1 = mappings; _i < mappings_1.length; _i++) {
4420
4468
  var mapping = mappings_1[_i];
4421
- if (apiTitle.includes(mapping.keyword)) {
4422
- return mapping.replacement;
4469
+ for (var _a = 0, _b = mapping.allowedValues; _a < _b.length; _a++) {
4470
+ var value = _b[_a];
4471
+ if (apiTitle.includes(value)) {
4472
+ return mapping.replacement;
4473
+ }
4423
4474
  }
4424
4475
  }
4425
4476
  return null;
@@ -4438,21 +4489,20 @@ var BinCollection = function (_a) {
4438
4489
  React.createElement(FormButton, { size: "large", type: "submit", "aria-label": "Submit", text: "Find" }))))),
4439
4490
  addressOptions.length > 0 && (React.createElement(DropDownSelectContainer, null,
4440
4491
  React.createElement(DropDownSelect, { onChange: handleAddressChange, id: "address", label: "Select your address", options: __spreadArray([{ title: 'Select an address', value: '' }], addressOptions, true) }))),
4441
- React.createElement("div", null, Object.entries(calendarEvents).map(function (_a) {
4442
- var apiTitle = _a[0], dates = _a[1];
4443
- var title = formatTitle(apiTitle);
4444
- // If we've seen this title before, or if title is null, we skip rendering it
4445
- if (seenTitles.current.has(title) || title === null) {
4446
- return null;
4447
- }
4448
- // Mark the title as seen
4449
- seenTitles.current.add(title);
4450
- return (React.createElement(React.Fragment, { key: title },
4451
- React.createElement(Heading, { level: 3, text: title }),
4452
- dates
4453
- .sort(function (a, b) { return new Date(a).getTime() - new Date(b).getTime(); })
4454
- .map(function (date) { return (React.createElement("p", null, date.toLocaleDateString('en-GB', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }))); })));
4455
- })),
4492
+ noResultsFound && React.createElement("p", null, "No results found."),
4493
+ React.createElement("div", null, (function () {
4494
+ var order = ['General refuse bin', 'Recycling bin', 'Garden bin', 'Food caddy'];
4495
+ var uniqueTitles = Array.from(new Set(Object.keys(calendarEvents).map(function (apiTitle) { return formatTitle(apiTitle); }).filter(function (title) { return title !== null; })));
4496
+ var sortedTitles = uniqueTitles.sort(function (a, b) { return order.indexOf(a) - order.indexOf(b); });
4497
+ return sortedTitles.map(function (title, index) {
4498
+ var apiTitlesForThisType = Object.keys(calendarEvents).filter(function (apiTitle) { return formatTitle(apiTitle) === title; });
4499
+ return (React.createElement(React.Fragment, { key: "".concat(title, "-").concat(index) },
4500
+ React.createElement(Heading, { level: 3, text: title }),
4501
+ apiTitlesForThisType.flatMap(function (apiTitle) { return calendarEvents[apiTitle]; })
4502
+ .sort(function (a, b) { return new Date(a).getTime() - new Date(b).getTime(); })
4503
+ .map(function (date) { return (React.createElement("p", null, date.toLocaleDateString('en-GB', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }))); })));
4504
+ });
4505
+ })()),
4456
4506
  Object.keys(calendarEvents).length > 0 && (React.createElement(FormButton, { size: "small", type: "button", "aria-label": "Reset", text: "Find a different address", onClick: resetForm }))));
4457
4507
  };
4458
4508