@nnc-digital/nnc-design-system 0.4.7 → 0.4.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/build/index.js CHANGED
@@ -4052,12 +4052,9 @@ var ErrorTextWrapper = styled__default["default"].div(templateObject_5 || (templ
4052
4052
  var DropDownSelectContainer = styled__default["default"].div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n padding-bottom: 20px;\n"], ["\n padding-bottom: 20px;\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
- var UPRNPageTitleRow = styled__default["default"].div(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n justify-content: center;\n margin-bottom: 1em;\n margin-top: 2em;\n width: 100%;\n"], ["\n justify-content: center;\n margin-bottom: 1em;\n margin-top: 2em;\n width: 100%;\n"])));
4056
- var UPRNPageUPRNRow = styled__default["default"].div(templateObject_10 || (templateObject_10 = __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"])));
4057
- var UPRNPageSectionTitle = styled__default["default"].div(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n font-size: 2em;\n font-weight: 700;\n"], ["\n font-size: 2em;\n font-weight: 700;\n"])));
4058
- var UPRNPageUPRNTitle = styled__default["default"].div(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n font-size: 1.5em;\n"], ["\n font-size: 1.5em;\n"])));
4059
- styled__default["default"].input(templateObject_13 || (templateObject_13 = __makeTemplateObject([""], [""])));
4060
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13;
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"])));
4056
+ styled__default["default"].input(templateObject_10 || (templateObject_10 = __makeTemplateObject([""], [""])));
4057
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
4061
4058
 
4062
4059
  const Container$16 = styled__default["default"].div`
4063
4060
  display: flex;
@@ -4323,14 +4320,15 @@ var Heading = function (_a) {
4323
4320
  * Returns the Bin Collection Checker form component to conduct search by postcode.
4324
4321
  */
4325
4322
  var BinCollection = function (_a) {
4326
- var _b = _a.formError, formError = _b === void 0 ? false : _b, _c = _a.baseUrl, baseUrl = _c === void 0 ? process.env.NEXT_PUBLIC_DRUPAL_APP_API_BASE_URL : _c;
4327
- var BinCollectionApiUrl = "".concat(baseUrl, "bin-collection-search/premiselist/");
4328
- var CalendarEventsApiUrl = "".concat(baseUrl, "bin-collection-search/calendarevents/");
4323
+ var _b = _a.formError, formError = _b === void 0 ? false : _b, _c = _a.graphqlApiEndpoint, graphqlApiEndpoint = _c === void 0 ? process.env.NEXT_PUBLIC_DRUPAL_APP_API_BASE_URL : _c;
4324
+ var BinCollectionApiUrl = "".concat(graphqlApiEndpoint, "bin-collection-search/premiselist/");
4325
+ var CalendarEventsApiUrl = "".concat(graphqlApiEndpoint, "bin-collection-search/calendarevents/");
4329
4326
  var themeContext = React.useContext(styled.ThemeContext);
4330
4327
  var _d = React.useState(false), isLoading = _d[0], setIsLoading = _d[1];
4331
4328
  var _e = React.useState(formError), isError = _e[0], setError = _e[1];
4332
4329
  var _f = React.useState(''), errorText = _f[0], setErrorText = _f[1];
4333
4330
  var _g = React.useState([]), addressOptions = _g[0], setAddressOptions = _g[1];
4331
+ var seenTitles = React.useRef(new Set());
4334
4332
  var handleSubmit = function (e) {
4335
4333
  e.preventDefault();
4336
4334
  var enteredPostcode = e.target.elements.postcode.value;
@@ -4424,13 +4422,14 @@ var BinCollection = function (_a) {
4424
4422
  setCalendarEvents({});
4425
4423
  setError(false);
4426
4424
  setErrorText('');
4425
+ seenTitles.current.clear();
4427
4426
  };
4428
4427
  var formatTitle = function (apiTitle) {
4429
4428
  var mappings = [
4430
- { keyword: 'Bin Refuse bin', replacement: 'Refuse bin' },
4431
- { keyword: 'Bin Recycling', replacement: 'Recycling bin' },
4432
- { keyword: 'Recycling Paper Box', replacement: 'Recycling Paper Box bin' },
4433
- { keyword: 'Garden', replacement: 'Garden bin' }
4429
+ { keyword: 'Refuse', replacement: 'General refuse bin' },
4430
+ { keyword: 'Recycling', replacement: 'Recycling bin' },
4431
+ { keyword: 'Garden', replacement: 'Garden bin' },
4432
+ { keyword: 'Food', replacement: 'Food caddy' },
4434
4433
  ];
4435
4434
  for (var _i = 0, mappings_1 = mappings; _i < mappings_1.length; _i++) {
4436
4435
  var mapping = mappings_1[_i];
@@ -4438,12 +4437,15 @@ var BinCollection = function (_a) {
4438
4437
  return mapping.replacement;
4439
4438
  }
4440
4439
  }
4441
- return apiTitle;
4440
+ return null;
4442
4441
  };
4442
+ React.useEffect(function () {
4443
+ seenTitles.current.clear();
4444
+ }, [calendarEvents]);
4443
4445
  return (React__default["default"].createElement(Container$17, { "data-testid": "BinCollection" },
4444
4446
  React__default["default"].createElement(FormWithLine, { onSubmit: handleSubmit, isError: isError, lineColour: themeContext.theme_vars.colours.grey_dark, hideLine: true },
4445
4447
  React__default["default"].createElement(FormContainer$1, { isLoading: isLoading },
4446
- React__default["default"].createElement(Heading, { level: 2, text: "Bin Collection Checker" }),
4448
+ React__default["default"].createElement(Heading, { level: 2, text: "Bin collection checker" }),
4447
4449
  React__default["default"].createElement(ErrorTextWrapper, null, errorText && React__default["default"].createElement(ErrorText$1, null, errorText)),
4448
4450
  React__default["default"].createElement(FormInnerContainer, null,
4449
4451
  React__default["default"].createElement(Input$6, { type: "text", placeholder: "Enter a postcode", name: "postcode", isErrored: isError, maxLength: 10 }),
@@ -4454,13 +4456,17 @@ var BinCollection = function (_a) {
4454
4456
  React__default["default"].createElement("div", null, Object.entries(calendarEvents).map(function (_a) {
4455
4457
  var apiTitle = _a[0], dates = _a[1];
4456
4458
  var title = formatTitle(apiTitle);
4459
+ // If we've seen this title before, or if title is null, we skip rendering it
4460
+ if (seenTitles.current.has(title) || title === null) {
4461
+ return null;
4462
+ }
4463
+ // Mark the title as seen
4464
+ seenTitles.current.add(title);
4457
4465
  return (React__default["default"].createElement(React__default["default"].Fragment, { key: title },
4458
- React__default["default"].createElement(UPRNPageTitleRow, null,
4459
- React__default["default"].createElement(UPRNPageSectionTitle, null, title)),
4466
+ React__default["default"].createElement(Heading, { level: 3, text: title }),
4460
4467
  dates
4461
4468
  .sort(function (a, b) { return new Date(a).getTime() - new Date(b).getTime(); })
4462
- .map(function (date) { return (React__default["default"].createElement(UPRNPageUPRNRow, { key: "".concat(title, "-").concat(date.toString()) },
4463
- React__default["default"].createElement(UPRNPageUPRNTitle, null, date.toLocaleDateString('en-GB', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })))); })));
4469
+ .map(function (date) { return (React__default["default"].createElement("p", null, date.toLocaleDateString('en-GB', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }))); })));
4464
4470
  })),
4465
4471
  Object.keys(calendarEvents).length > 0 && (React__default["default"].createElement(FormButton, { size: "small", type: "button", "aria-label": "Reset", text: "Find a different address", onClick: resetForm }))));
4466
4472
  };