@nnc-digital/nnc-design-system 0.4.7 → 0.4.15
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 +36 -21
- package/build/index.esm.js.map +1 -1
- package/build/index.js +35 -20
- package/build/index.js.map +1 -1
- package/build/library/components/BinCollection/BinCollection.styles.d.ts +0 -3
- package/build/library/components/BinCollection/BinCollection.types.d.ts +2 -2
- package/package.json +1 -2
package/build/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Component, cloneElement, useState, useContext, useEffect,
|
|
1
|
+
import React, { Component, cloneElement, useState, useContext, useEffect, useRef, useId, createContext } from 'react';
|
|
2
2
|
import styled, { css, ThemeContext, ThemeProvider, createGlobalStyle } from 'styled-components';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import require$$0 from 'tty';
|
|
@@ -4037,12 +4037,9 @@ var ErrorTextWrapper = styled.div(templateObject_5 || (templateObject_5 = __make
|
|
|
4037
4037
|
var DropDownSelectContainer = styled.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n padding-bottom: 20px;\n"], ["\n padding-bottom: 20px;\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
|
-
|
|
4041
|
-
|
|
4042
|
-
var
|
|
4043
|
-
var UPRNPageUPRNTitle = styled.div(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n font-size: 1.5em;\n"], ["\n font-size: 1.5em;\n"])));
|
|
4044
|
-
styled.input(templateObject_13 || (templateObject_13 = __makeTemplateObject([""], [""])));
|
|
4045
|
-
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;
|
|
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"])));
|
|
4041
|
+
styled.input(templateObject_10 || (templateObject_10 = __makeTemplateObject([""], [""])));
|
|
4042
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
|
|
4046
4043
|
|
|
4047
4044
|
const Container$16 = styled.div`
|
|
4048
4045
|
display: flex;
|
|
@@ -4308,14 +4305,16 @@ var Heading = function (_a) {
|
|
|
4308
4305
|
* Returns the Bin Collection Checker form component to conduct search by postcode.
|
|
4309
4306
|
*/
|
|
4310
4307
|
var BinCollection = function (_a) {
|
|
4311
|
-
var _b = _a.formError, formError = _b === void 0 ? false : _b, _c = _a.
|
|
4312
|
-
var BinCollectionApiUrl = "".concat(
|
|
4313
|
-
var CalendarEventsApiUrl = "".concat(
|
|
4308
|
+
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;
|
|
4309
|
+
var BinCollectionApiUrl = "".concat(graphqlApiEndpoint, "bin-collection-search/premiselist/");
|
|
4310
|
+
var CalendarEventsApiUrl = "".concat(graphqlApiEndpoint, "bin-collection-search/calendarevents/");
|
|
4314
4311
|
var themeContext = useContext(ThemeContext);
|
|
4315
4312
|
var _d = useState(false), isLoading = _d[0], setIsLoading = _d[1];
|
|
4316
4313
|
var _e = useState(formError), isError = _e[0], setError = _e[1];
|
|
4317
4314
|
var _f = useState(''), errorText = _f[0], setErrorText = _f[1];
|
|
4318
4315
|
var _g = useState([]), addressOptions = _g[0], setAddressOptions = _g[1];
|
|
4316
|
+
var seenTitles = useRef(new Set());
|
|
4317
|
+
var _h = useState(false), noResultsFound = _h[0], setNoResultsFound = _h[1];
|
|
4319
4318
|
var handleSubmit = function (e) {
|
|
4320
4319
|
e.preventDefault();
|
|
4321
4320
|
var enteredPostcode = e.target.elements.postcode.value;
|
|
@@ -4384,7 +4383,7 @@ var BinCollection = function (_a) {
|
|
|
4384
4383
|
return acc;
|
|
4385
4384
|
}, {});
|
|
4386
4385
|
};
|
|
4387
|
-
var
|
|
4386
|
+
var _j = useState({}), calendarEvents = _j[0], setCalendarEvents = _j[1];
|
|
4388
4387
|
/**
|
|
4389
4388
|
* Returns an array of calendar events based on selected address for next 42 days.
|
|
4390
4389
|
*/
|
|
@@ -4397,6 +4396,12 @@ var BinCollection = function (_a) {
|
|
|
4397
4396
|
axios.get("".concat(CalendarEventsApiUrl).concat(selectedUPRN, "/").concat(startDate, "/").concat(endDate))
|
|
4398
4397
|
.then(function (response) {
|
|
4399
4398
|
var groupedData = groupByTitle(response.data);
|
|
4399
|
+
if (Object.keys(groupedData).length === 0) {
|
|
4400
|
+
setNoResultsFound(true);
|
|
4401
|
+
}
|
|
4402
|
+
else {
|
|
4403
|
+
setNoResultsFound(false);
|
|
4404
|
+
}
|
|
4400
4405
|
setCalendarEvents(groupedData);
|
|
4401
4406
|
})
|
|
4402
4407
|
.catch(function (error) {
|
|
@@ -4409,13 +4414,15 @@ var BinCollection = function (_a) {
|
|
|
4409
4414
|
setCalendarEvents({});
|
|
4410
4415
|
setError(false);
|
|
4411
4416
|
setErrorText('');
|
|
4417
|
+
seenTitles.current.clear();
|
|
4418
|
+
setNoResultsFound(false);
|
|
4412
4419
|
};
|
|
4413
4420
|
var formatTitle = function (apiTitle) {
|
|
4414
4421
|
var mappings = [
|
|
4415
|
-
{ keyword: '
|
|
4416
|
-
{ keyword: '
|
|
4417
|
-
{ keyword: '
|
|
4418
|
-
{ keyword: '
|
|
4422
|
+
{ keyword: 'Refuse', replacement: 'General refuse bin' },
|
|
4423
|
+
{ keyword: 'Recycling', replacement: 'Recycling bin' },
|
|
4424
|
+
{ keyword: 'Garden', replacement: 'Garden bin' },
|
|
4425
|
+
{ keyword: 'Food', replacement: 'Food caddy' },
|
|
4419
4426
|
];
|
|
4420
4427
|
for (var _i = 0, mappings_1 = mappings; _i < mappings_1.length; _i++) {
|
|
4421
4428
|
var mapping = mappings_1[_i];
|
|
@@ -4423,12 +4430,15 @@ var BinCollection = function (_a) {
|
|
|
4423
4430
|
return mapping.replacement;
|
|
4424
4431
|
}
|
|
4425
4432
|
}
|
|
4426
|
-
return
|
|
4433
|
+
return null;
|
|
4427
4434
|
};
|
|
4435
|
+
useEffect(function () {
|
|
4436
|
+
seenTitles.current.clear();
|
|
4437
|
+
}, [calendarEvents]);
|
|
4428
4438
|
return (React.createElement(Container$17, { "data-testid": "BinCollection" },
|
|
4429
4439
|
React.createElement(FormWithLine, { onSubmit: handleSubmit, isError: isError, lineColour: themeContext.theme_vars.colours.grey_dark, hideLine: true },
|
|
4430
4440
|
React.createElement(FormContainer$1, { isLoading: isLoading },
|
|
4431
|
-
React.createElement(Heading, { level: 2, text: "Bin
|
|
4441
|
+
React.createElement(Heading, { level: 2, text: "Bin collection checker" }),
|
|
4432
4442
|
React.createElement(ErrorTextWrapper, null, errorText && React.createElement(ErrorText$1, null, errorText)),
|
|
4433
4443
|
React.createElement(FormInnerContainer, null,
|
|
4434
4444
|
React.createElement(Input$6, { type: "text", placeholder: "Enter a postcode", name: "postcode", isErrored: isError, maxLength: 10 }),
|
|
@@ -4436,16 +4446,21 @@ var BinCollection = function (_a) {
|
|
|
4436
4446
|
React.createElement(FormButton, { size: "large", type: "submit", "aria-label": "Submit", text: "Find" }))))),
|
|
4437
4447
|
addressOptions.length > 0 && (React.createElement(DropDownSelectContainer, null,
|
|
4438
4448
|
React.createElement(DropDownSelect, { onChange: handleAddressChange, id: "address", label: "Select your address", options: __spreadArray([{ title: 'Select an address', value: '' }], addressOptions, true) }))),
|
|
4449
|
+
noResultsFound && React.createElement("p", null, "No results found."),
|
|
4439
4450
|
React.createElement("div", null, Object.entries(calendarEvents).map(function (_a) {
|
|
4440
4451
|
var apiTitle = _a[0], dates = _a[1];
|
|
4441
4452
|
var title = formatTitle(apiTitle);
|
|
4453
|
+
// If we've seen this title before, or if title is null, we skip rendering it
|
|
4454
|
+
if (seenTitles.current.has(title) || title === null) {
|
|
4455
|
+
return null;
|
|
4456
|
+
}
|
|
4457
|
+
// Mark the title as seen
|
|
4458
|
+
seenTitles.current.add(title);
|
|
4442
4459
|
return (React.createElement(React.Fragment, { key: title },
|
|
4443
|
-
React.createElement(
|
|
4444
|
-
React.createElement(UPRNPageSectionTitle, null, title)),
|
|
4460
|
+
React.createElement(Heading, { level: 3, text: title }),
|
|
4445
4461
|
dates
|
|
4446
4462
|
.sort(function (a, b) { return new Date(a).getTime() - new Date(b).getTime(); })
|
|
4447
|
-
.map(function (date) { return (React.createElement(
|
|
4448
|
-
React.createElement(UPRNPageUPRNTitle, null, date.toLocaleDateString('en-GB', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })))); })));
|
|
4463
|
+
.map(function (date) { return (React.createElement("p", null, date.toLocaleDateString('en-GB', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }))); })));
|
|
4449
4464
|
})),
|
|
4450
4465
|
Object.keys(calendarEvents).length > 0 && (React.createElement(FormButton, { size: "small", type: "button", "aria-label": "Reset", text: "Find a different address", onClick: resetForm }))));
|
|
4451
4466
|
};
|