@nnc-digital/nnc-design-system 0.4.6 → 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.esm.js +42 -25
- package/build/index.esm.js.map +1 -1
- package/build/index.js +41 -24
- package/build/index.js.map +1 -1
- package/build/library/components/BinCollection/BinCollection.styles.d.ts +1 -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';
|
|
@@ -4033,15 +4033,13 @@ var BinCollectionButtonStyles = styled.div(templateObject_3 || (templateObject_3
|
|
|
4033
4033
|
var FormContainer$1 = styled.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n width: 100%;\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n ", "\n"], ["\n width: 100%;\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n ", "\n"])), function (props) {
|
|
4034
4034
|
return props.isLoading && "\n opacity: 0.5; \n pointer-events: none;\n ";
|
|
4035
4035
|
});
|
|
4036
|
-
var
|
|
4037
|
-
var
|
|
4038
|
-
styled.
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
var
|
|
4043
|
-
styled.input(templateObject_12 || (templateObject_12 = __makeTemplateObject([""], [""])));
|
|
4044
|
-
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;
|
|
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"])));
|
|
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
|
+
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
|
+
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;
|
|
4045
4043
|
|
|
4046
4044
|
const Container$16 = styled.div`
|
|
4047
4045
|
display: flex;
|
|
@@ -4307,14 +4305,15 @@ var Heading = function (_a) {
|
|
|
4307
4305
|
* Returns the Bin Collection Checker form component to conduct search by postcode.
|
|
4308
4306
|
*/
|
|
4309
4307
|
var BinCollection = function (_a) {
|
|
4310
|
-
var _b = _a.formError, formError = _b === void 0 ? false : _b, _c = _a.
|
|
4311
|
-
var BinCollectionApiUrl = "".concat(
|
|
4312
|
-
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/");
|
|
4313
4311
|
var themeContext = useContext(ThemeContext);
|
|
4314
4312
|
var _d = useState(false), isLoading = _d[0], setIsLoading = _d[1];
|
|
4315
4313
|
var _e = useState(formError), isError = _e[0], setError = _e[1];
|
|
4316
4314
|
var _f = useState(''), errorText = _f[0], setErrorText = _f[1];
|
|
4317
4315
|
var _g = useState([]), addressOptions = _g[0], setAddressOptions = _g[1];
|
|
4316
|
+
var seenTitles = useRef(new Set());
|
|
4318
4317
|
var handleSubmit = function (e) {
|
|
4319
4318
|
e.preventDefault();
|
|
4320
4319
|
var enteredPostcode = e.target.elements.postcode.value;
|
|
@@ -4332,13 +4331,22 @@ var BinCollection = function (_a) {
|
|
|
4332
4331
|
*/
|
|
4333
4332
|
var fetchAddresses = function (postcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4334
4333
|
return __generator(this, function (_a) {
|
|
4334
|
+
setError(false);
|
|
4335
|
+
setErrorText('');
|
|
4336
|
+
setIsLoading(true);
|
|
4335
4337
|
axios.get("".concat(BinCollectionApiUrl).concat(postcode))
|
|
4336
4338
|
.then(function (response) {
|
|
4337
4339
|
setIsLoading(false);
|
|
4340
|
+
// Check if there are any addresses returned
|
|
4341
|
+
if (response.data.data.length === 0) {
|
|
4342
|
+
setError(true);
|
|
4343
|
+
setErrorText('No addresses found for the provided postcode.');
|
|
4344
|
+
return;
|
|
4345
|
+
}
|
|
4338
4346
|
// Transform the response data into the expected format
|
|
4339
4347
|
var transformedAddresses = response.data.data.map(function (item) { return ({
|
|
4340
4348
|
value: item.UPRN,
|
|
4341
|
-
title: "".concat(item.Address
|
|
4349
|
+
title: "".concat(item.Address)
|
|
4342
4350
|
}); });
|
|
4343
4351
|
setAddressOptions(transformedAddresses);
|
|
4344
4352
|
})
|
|
@@ -4399,13 +4407,14 @@ var BinCollection = function (_a) {
|
|
|
4399
4407
|
setCalendarEvents({});
|
|
4400
4408
|
setError(false);
|
|
4401
4409
|
setErrorText('');
|
|
4410
|
+
seenTitles.current.clear();
|
|
4402
4411
|
};
|
|
4403
4412
|
var formatTitle = function (apiTitle) {
|
|
4404
4413
|
var mappings = [
|
|
4405
|
-
{ keyword: '
|
|
4406
|
-
{ keyword: '
|
|
4407
|
-
{ keyword: '
|
|
4408
|
-
{ keyword: '
|
|
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' },
|
|
4409
4418
|
];
|
|
4410
4419
|
for (var _i = 0, mappings_1 = mappings; _i < mappings_1.length; _i++) {
|
|
4411
4420
|
var mapping = mappings_1[_i];
|
|
@@ -4413,14 +4422,18 @@ var BinCollection = function (_a) {
|
|
|
4413
4422
|
return mapping.replacement;
|
|
4414
4423
|
}
|
|
4415
4424
|
}
|
|
4416
|
-
return
|
|
4425
|
+
return null;
|
|
4417
4426
|
};
|
|
4427
|
+
useEffect(function () {
|
|
4428
|
+
seenTitles.current.clear();
|
|
4429
|
+
}, [calendarEvents]);
|
|
4418
4430
|
return (React.createElement(Container$17, { "data-testid": "BinCollection" },
|
|
4419
4431
|
React.createElement(FormWithLine, { onSubmit: handleSubmit, isError: isError, lineColour: themeContext.theme_vars.colours.grey_dark, hideLine: true },
|
|
4420
4432
|
React.createElement(FormContainer$1, { isLoading: isLoading },
|
|
4421
|
-
React.createElement(Heading, { level: 2, text: "Bin
|
|
4433
|
+
React.createElement(Heading, { level: 2, text: "Bin collection checker" }),
|
|
4434
|
+
React.createElement(ErrorTextWrapper, null, errorText && React.createElement(ErrorText$1, null, errorText)),
|
|
4422
4435
|
React.createElement(FormInnerContainer, null,
|
|
4423
|
-
React.createElement(Input$6, { type: "text", placeholder: "Enter a postcode", name: "postcode",
|
|
4436
|
+
React.createElement(Input$6, { type: "text", placeholder: "Enter a postcode", name: "postcode", isErrored: isError, maxLength: 10 }),
|
|
4424
4437
|
React.createElement(BinCollectionButtonStyles, null,
|
|
4425
4438
|
React.createElement(FormButton, { size: "large", type: "submit", "aria-label": "Submit", text: "Find" }))))),
|
|
4426
4439
|
addressOptions.length > 0 && (React.createElement(DropDownSelectContainer, null,
|
|
@@ -4428,13 +4441,17 @@ var BinCollection = function (_a) {
|
|
|
4428
4441
|
React.createElement("div", null, Object.entries(calendarEvents).map(function (_a) {
|
|
4429
4442
|
var apiTitle = _a[0], dates = _a[1];
|
|
4430
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);
|
|
4431
4450
|
return (React.createElement(React.Fragment, { key: title },
|
|
4432
|
-
React.createElement(
|
|
4433
|
-
React.createElement(UPRNPageSectionTitle, null, title)),
|
|
4451
|
+
React.createElement(Heading, { level: 3, text: title }),
|
|
4434
4452
|
dates
|
|
4435
4453
|
.sort(function (a, b) { return new Date(a).getTime() - new Date(b).getTime(); })
|
|
4436
|
-
.map(function (date) { return (React.createElement(
|
|
4437
|
-
React.createElement(UPRNPageUPRNTitle, null, date.toLocaleDateString('en-GB', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })))); })));
|
|
4454
|
+
.map(function (date) { return (React.createElement("p", null, date.toLocaleDateString('en-GB', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }))); })));
|
|
4438
4455
|
})),
|
|
4439
4456
|
Object.keys(calendarEvents).length > 0 && (React.createElement(FormButton, { size: "small", type: "button", "aria-label": "Reset", text: "Find a different address", onClick: resetForm }))));
|
|
4440
4457
|
};
|