Skip to content

Commit 4425b5c

Browse files
authored
PCLU update (#384)
* SB update for PCLU updates * Remove postcode validation now handled within the PCLU itself
1 parent b411a96 commit 4425b5c

6 files changed

Lines changed: 5 additions & 64 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"dependencies": {
66
"@babel/polyfill": "^7.11.5",
77
"@comicrelief/pattern-lab": "7.58.6",
8-
"@comicrelief/storybook": "1.33.3",
8+
"@comicrelief/storybook": "1.34.0",
99
"@snyk/protect": "^1.986.0",
1010
"autoprefixer": "10.0.0",
1111
"axios": "^0.21.1",

src/pages/GiftAid/GiftAid.js

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import {
1919
scrollToError,
2020
getPathParams,
2121
hiddenFields,
22-
GBPostCodePattern,
23-
OverseasPostCodePattern,
2422
justInTimeLinkText,
2523
validateForm,
2624
getFieldValidations,
@@ -40,12 +38,6 @@ function GiftAid(props) {
4038
const [formValidityState, setFormValidityState] = useState(initialFormValidity); // intitialise form validity states
4139
const [fieldValidation, setFieldValidation] = useState(getFieldValidations(update)); // intitialise field validation state based on form type
4240
const [isSubmitting, setIsSubmitting] = useState(false);
43-
// As GB is the default country, set the matching postcode regex pattern as default too
44-
const [currentPostcodePattern, setCurrentPostcodePattern] = useState(GBPostCodePattern);
45-
46-
// Simple counter to allow us to trigger the child 'revalidate postcode' function after regex updates
47-
const [postcodeRevalidate, setPostcodeRevalidate] = useState(0);
48-
4941
const inputRef = useRef(null);
5042

5143
// initialise URL token state if available
@@ -79,29 +71,6 @@ function GiftAid(props) {
7971
}
8072
}, []);
8173

82-
/**
83-
* Crummy workaround to trigger a revalidation
84-
* as the bespoke validation here has issues
85-
*/
86-
const revalidatePostcode = () => {
87-
// Store the current postcode to re-add
88-
const postcodeField = document.getElementById("field-input--postcode");
89-
const currentPostcodeValue = postcodeField.value;
90-
const blurEvent = new Event('blur', { bubbles: true });
91-
92-
// Temporarily reset the postcode field and programmatically
93-
// trigger a blur event to make the validation take notice
94-
postcodeField.value = '';
95-
postcodeField.dispatchEvent(blurEvent);
96-
97-
setTimeout(() => {
98-
// Immediately re-add the value and trigger another blur event
99-
postcodeField.value = currentPostcodeValue;
100-
postcodeField.dispatchEvent(blurEvent);
101-
}, 1);
102-
};
103-
104-
10574
/**
10675
* Fetches decrypted MSISDN using token
10776
* @param cipherText
@@ -151,20 +120,6 @@ function GiftAid(props) {
151120
(thisFieldsState.fieldValidation !== thisFieldsPreviousState.fieldValidation);
152121

153122
if ((thisFieldsPreviousState && isUpdatedState) || marketingConsentFieldsChanged === true) {
154-
155-
// Update postcode regex is 'Country' select value has changed
156-
if (thisFieldsName === 'country' && thisFieldsState.value !== thisFieldsPreviousState.value){
157-
158-
// Ignore the on-mount validation call
159-
if (thisFieldsPreviousState.value !== undefined) {
160-
// Switch regex patterns accordingly; if a non-GB value, this undefined value
161-
// will cause the PCLU to fallback to its default, much looser regex
162-
setCurrentPostcodePattern(thisFieldsState.value === 'GB' ? GBPostCodePattern : undefined);
163-
// Call our workaround to trigger a revalidation of the PCLU postcode field
164-
revalidatePostcode();
165-
}
166-
}
167-
168123
// Reset url transaction Id state
169124
if (thisFieldsName === 'transactionId' && thisFieldsState.valid) {
170125
setFormValidityState({
@@ -226,7 +181,6 @@ function GiftAid(props) {
226181
const contextProps = {
227182
urlTransactionId,
228183
hiddenFields,
229-
currentPostcodePattern,
230184
justInTimeLinkText,
231185
formValidityState,
232186
fieldValidation,
@@ -249,7 +203,6 @@ function GiftAid(props) {
249203
<SubmitForm
250204
title="Submit Form"
251205
msisdn={msisdn}
252-
postcodeRevalidate={postcodeRevalidate}
253206
/>
254207
)}
255208
</FormProvider>

src/pages/GiftAid/SubmitForm/SubmitForm.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function SubmitForm(props) {
3434
const {
3535
refs,
3636
setFieldValidity,
37-
currentPostcodePattern,
3837
justInTimeLinkText,
3938
formValidityState,
4039
fieldValidation,
@@ -99,8 +98,6 @@ function SubmitForm(props) {
9998
ref={refs}
10099
label="Home address"
101100
showErrorMessages={formValidityState.showErrorMessages}
102-
postcodePattern={currentPostcodePattern}
103-
invalidErrorText="Please enter a valid UK postcode, using a space and capital letters"
104101
isAddressValid={
105102
(validation) => {
106103
Object.keys(validation).map(key => setFieldValidity(validation[key], key));

src/pages/GiftAid/UpdateForm/UpdateForm.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function UpdateForm(props) {
2525
const {
2626
refs,
2727
setFieldValidity,
28-
currentPostcodePattern,
2928
justInTimeLinkText,
3029
formValidityState,
3130
fieldValidation,
@@ -83,8 +82,6 @@ function UpdateForm(props) {
8382
ref={refs}
8483
label="Home address"
8584
showErrorMessages={formValidityState.showErrorMessages}
86-
postcodePattern={currentPostcodePattern}
87-
invalidErrorText="Please enter a valid UK postcode, using a space and capital letters"
8885
isAddressValid={
8986
(validation) => {
9087
Object.keys(validation).map(key => setFieldValidity(validation[key], key));

src/pages/GiftAid/utils/Utils.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ const DONATION_TYPES = {
138138
*/
139139
export const hiddenFields = ['field-input--address1', 'field-input--town', 'field-wrapper--country'];
140140

141-
/*
142-
* REGEX for postcode fields:
143-
*/
144-
// HMRC-approved, GB-only pattern to ensure no invalid GiftAid submissions can slip through
145-
export const GBPostCodePattern = '(GIR 0AA)|((([A-Z][0-9][0-9]?)|(([A-Z][A-HJ-Y][0-9][0-9]?)|(([A-Z][0-9][A-Z])|([A-Z][A-HJ-Y][0-9]?[A-Z])))) [0-9][A-Z]{2})';
146-
147141
/*
148142
* Just In Time Link Text
149143
*

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,10 +1274,10 @@
12741274
susy "^2.2.12"
12751275
underscore.string "3.3.5"
12761276

1277-
"@comicrelief/storybook@1.33.3":
1278-
version "1.33.3"
1279-
resolved "https://registry.yarnpkg.com/@comicrelief/storybook/-/storybook-1.33.3.tgz#780ff6e9656b53098218918027f597e5ed334995"
1280-
integrity sha512-LbiW0wQ6+WlcKuXGQIy+z30uC1lJfDlnfp/J8r5+ku8ibV+fiJYilFNOC+gzDV2srWZhzEpTdf4/QH829TqQnQ==
1277+
"@comicrelief/storybook@1.34.0":
1278+
version "1.34.0"
1279+
resolved "https://registry.yarnpkg.com/@comicrelief/storybook/-/storybook-1.34.0.tgz#ac355b601280a45c076f7980806cc9f39f480373"
1280+
integrity sha512-/eK018inDqKdXhgkab40qwfI7VtQhtF46wjpMWtwkfNz3rJ/dA/utf2FsDZNVFegVw5sj1gJILXCgyyi7Rv26g==
12811281
dependencies:
12821282
"@comicrelief/pattern-lab" "*"
12831283
"@snyk/protect" "^1.1060.0"

0 commit comments

Comments
 (0)