Skip to content

Commit

Permalink
Remove all transactionID related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyEPhipps committed Apr 9, 2024
1 parent ba2f583 commit a135705
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 168 deletions.
39 changes: 0 additions & 39 deletions src/components/Buttons/DonationTypeButtons/DonationTypeButtons.js

This file was deleted.

11 changes: 1 addition & 10 deletions src/components/FormHeader/UpdateHeader/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React, { useContext } from 'react';
import React from 'react';

import FormContext from "../../../context/FormContext";
import SiteService from '../../../service/Site.service';

const UpdateHeader = (props) => {

const { urlTransactionId } = useContext(FormContext); // get states from context
const site = new SiteService();
let claimCopy = null;
switch(site.getSite()) {
Expand All @@ -25,13 +23,6 @@ const UpdateHeader = (props) => {
<p className="text-align-centre sub-title--copy">
{claimCopy}
</p>
{typeof urlTransactionId !== 'undefined' && urlTransactionId !== null ?
<p className="text-align-centre transaction-id">
Transaction ID: {urlTransactionId}
</p>
:
''
}
</React.Fragment>

);
Expand Down
22 changes: 2 additions & 20 deletions src/pages/GiftAid/GiftAid.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,12 @@ function GiftAid(props) {
// initialise MSISDN state
const [msisdn, setMSISDN] = useState(null);

// initialise URL transaction id state if available
// TO-DO: REMOVE THIS
const [urlTransactionId, setUrlTransactionId] = useState(props.match.params.transaction_id);

/**
* GiftAid component mounts
*/
useEffect(() => {
setPathParams(getPathParams(updating)); // update path states
setToken(props.match.params.token); // update token state
setUrlTransactionId(props.match.params.transaction_id); // update url transaction id state
if (token) {
decryptToken(token); // decrypt token to MSISDN
}
Expand All @@ -66,7 +61,6 @@ function GiftAid(props) {
setFormValidityState(initialFormValidity);
setFieldValidation({});
setUpdating(false);
setUrlTransactionId(null);
setToken(null);
setMSISDN(null);
}
Expand Down Expand Up @@ -121,16 +115,7 @@ function GiftAid(props) {
(thisFieldsState.fieldValidation !== thisFieldsPreviousState.fieldValidation);

if ((thisFieldsPreviousState && isUpdatedState) || marketingConsentFieldsChanged === true) {
// Reset url transaction Id state
// if (thisFieldsName === 'transactionId' && thisFieldsState.valid) {
// setFormValidityState({
// ...formValidityState,
// urlTransactionId: {
// ...formValidityState.urlTransactionId,
// valid: true,
// }
// });
// }

fieldValidation[thisFieldsName] = thisFieldsState;
setFieldValidation({...fieldValidation});

Expand All @@ -147,7 +132,7 @@ function GiftAid(props) {
*/
const submitForm = (e) => {
e.preventDefault();
const formValues = getFormValues(fieldValidation, urlTransactionId, updating); // get form values
const formValues = getFormValues(fieldValidation, updating); // get form values
console.log('formValues', formValues);
const { validity, validationState } = validateForm(fieldValidation, formValues, formValidityState); // validate form
setFormValidityState(validationState); // update form validation state
Expand All @@ -157,7 +142,6 @@ function GiftAid(props) {
// Rather than mess with the input field value itself (crummy UX), just sanitise the value on submission,
// removing any leading or trailing whitespace that the new regex brings allows for (see ENG-3193)
if (formValues.donationID) formValues.donationID = formValues.donationID.trim();
// if (formValues.transactionId) formValues.transactionId = formValues.transactionId.trim();

axios.post(pathParams.endpoint, formValues) // post form data and settings to endpoint
.then(() => {
Expand Down Expand Up @@ -186,7 +170,6 @@ function GiftAid(props) {

// Pass context props to child components
const contextProps = {
urlTransactionId,
hiddenFields,
justInTimeLinkText,
formValidityState,
Expand All @@ -204,7 +187,6 @@ function GiftAid(props) {
{ updating ? (
<UpdateForm
title="Update Form"
urlTransactionId={urlTransactionId}
/>
) : (
<SubmitForm
Expand Down
25 changes: 6 additions & 19 deletions src/pages/GiftAid/UpdateForm/UpdateForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import PostcodeLookup from "@comicrelief/storybook/src/components/PostcodeLookup
import Form from '../../../components/Form/index';
import FormHeader from '../../../components/FormHeader/FormHeader';
import FormButton from '../../../components/Buttons/FormButton/index';
import DonationTypeButtons from '../../../components/Buttons/DonationTypeButtons/DonationTypeButtons';
import GiftAidClaimChoiceButtons from '../../../components/Buttons/GiftAidClaimChoiceButtons/GiftAidClaimChoiceButtons';
import InputFields from '../../../components/InputFields/InputFields';
import JustInTime from '../../../components/JustInTime/index';
import UrlTransactionIdError from './UrlTransactionIdError';

// fields data
import { updateFormFields, donationTypeChoices, giftAidButtonChoices } from './UpdateFormFields';
import { updateFormFields, giftAidButtonChoices } from './UpdateFormFields';

// import context
import FormContext from '../../../context/FormContext';
Expand All @@ -30,25 +28,18 @@ function UpdateForm(props) {
submitForm,
} = useContext(FormContext); // get props from context

const { urlTransactionId } = props;

// Declare state variables
const [inputFieldProps, setInputFieldProps] = useState(updateFormFields); // initialise form inputFieldProps state

/**
* Component mounts and updates
*/
useEffect(() => {
// Delete if url trans Id if present
// on component mount or update
if (urlTransactionId !== undefined) {
// Delete transactionId form field
delete inputFieldProps.transactionId;
delete fieldValidation.transactionId;
} else {
// Else, delete the donation type radiobuttons
delete fieldValidation.donationType;
}

// Else, delete the donation type radiobuttons
// TO-DO: just remove this totally
delete fieldValidation.donationType;

setFieldValidation(fieldValidation);
// Reset states on component unmount
return () => {
Expand All @@ -62,12 +53,8 @@ function UpdateForm(props) {

<FormHeader page="update" />

<UrlTransactionIdError />

<div className="form-fields--wrapper">

<DonationTypeButtons donationTypeChoices={donationTypeChoices} />

<h3 className="form--update__title form--update__title--giftaid text-align-centre">
Who is changing their declaration?
</h3>
Expand Down
29 changes: 0 additions & 29 deletions src/pages/GiftAid/UpdateForm/UrlTransactionIdError.js

This file was deleted.

54 changes: 3 additions & 51 deletions src/pages/GiftAid/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ const ENDPOINT_URL = process.env.REACT_APP_ENDPOINT_URL;
* @param state Object
*/
export const scrollToError = (state = {}) => {
// Scroll to transactionId field / url parameter error message
// if present
if (state.urlTransactionId.valid === false) {
document.querySelector('#field-error--urlTransID').scrollIntoView({ behavior: 'smooth' });
}
// Scroll to the first erroring field and focus on its input field
const errorWrapper = document.querySelectorAll('.form__field--erroring')[0];
if (errorWrapper) {
Expand Down Expand Up @@ -89,14 +84,6 @@ export const getFormValues = (validation, urlId = null, update = false) => {
return fieldValues[key] = value;
});

// Create a Donation id field for Update Form
if ((typeof validation.transactionId !== 'undefined' && validation.transactionId) || urlId !== null) {

fieldValues.donationID = typeof validation.transactionId !== 'undefined'
&& validation.transactionId
? validation.transactionId.value : urlId;
}

// Create donation type field for Update Form
fieldValues.donationType = typeof validation.donationType !== 'undefined'
&& validation.donationType
Expand Down Expand Up @@ -144,12 +131,6 @@ export const hiddenFields = ['field-input--address1', 'field-input--town', 'fiel
*/
export const justInTimeLinkText = 'Why do we collect this info?';

/*
* REGEX for transactionId
*
*/
const transactionIdPattern = '^\\s*[a-zA-Z0-9-_]{5,}\\s*$';

/**
* Function to validate form
* @param validation Object
Expand All @@ -159,11 +140,6 @@ const transactionIdPattern = '^\\s*[a-zA-Z0-9-_]{5,}\\s*$';
*/
export const validateForm = (validation, formValues = {}, formValidity = {}) => {

const donationId = formValues.donationID !== undefined ? formValues.donationID : null;

// validate donation id if present
const transIdValidity = donationId !== null ? validateTransactionId(donationId) : null;

// validate form fields
const fieldValidity = getValidation(validation);

Expand All @@ -172,13 +148,9 @@ export const validateForm = (validation, formValues = {}, formValidity = {}) =>
formValidity: true,
showErrorMessages: false,
validating: false,
urlTransactionId: {
...formValidity.urlTransactionId,
valid: true,
}
};
// Validation fails for fields or transactionId
if (fieldValidity !== true || (transIdValidity !== true && transIdValidity !== null) ) {
// Validation fails for fields
if (fieldValidity !== true ) {

// set failed fields state
validationState = {
Expand All @@ -187,14 +159,6 @@ export const validateForm = (validation, formValues = {}, formValidity = {}) =>
showErrorMessages: true,
validating: true,
};
if (transIdValidity !== null && !transIdValidity && donationId !== undefined && donationId !== null) {

// set transaction id failed state
validationState.urlTransactionId = {
...formValidity.urlTransactionId,
valid: false,
}
}
}
const email = formValues.email && formValues.email !== "" ? formValues.email : 'N';
TagManager.dataLayer({
Expand All @@ -206,19 +170,11 @@ export const validateForm = (validation, formValues = {}, formValidity = {}) =>
},
});
return {
validity: fieldValidity && (transIdValidity === null || transIdValidity),
validity: fieldValidity,
validationState,
};
};

/**
* Validates transactionId using REGEX pattern
* @param donationID
* @returns Boolean
*/
const validateTransactionId = (donationID) => new RegExp(transactionIdPattern).test(donationID);


/**
* Checks if any field is invalid.
* If invalid fields: shows error sets state to show errorMessages.
Expand Down Expand Up @@ -254,10 +210,6 @@ export const initialFormValidity = {
showErrorMessages: false,
formDataError: null,
formDataSuccess: null,
urlTransactionId: {
valid: true,
errorMessage: 'This transaction ID doesn\'t seem to be valid, please check your donation confirmation email or letter'
}
};

/**
Expand Down

0 comments on commit a135705

Please sign in to comment.