146 lines
4.1 KiB
JavaScript
146 lines
4.1 KiB
JavaScript
import _ from "lodash";
|
|
import Link from "next/link";
|
|
import React, { useEffect, useState } from "react";
|
|
import { useRouter } from "next/router";
|
|
import useTranslation from "next-translate/useTranslation";
|
|
|
|
import jsonpath from "jsonpath";
|
|
import {
|
|
Field,
|
|
reduxForm,
|
|
formValueSelector,
|
|
getFormSubmitErrors,
|
|
} from "redux-form";
|
|
import {
|
|
useDispatch,
|
|
useSelector,
|
|
shallowEqual,
|
|
connect,
|
|
setRegisterFormComplete,
|
|
setAccountCreatedComplete,
|
|
} from "react-redux";
|
|
|
|
import { setAccCr, setLogout } from "../../store/accountDetails/action";
|
|
|
|
import { getEmailAccountCheck, createAccount } from "../../actions";
|
|
|
|
const RegisterComplete = (props) => {
|
|
const {
|
|
footerLinks,
|
|
pages,
|
|
handleSubmit,
|
|
value,
|
|
setRegisterFormComplete,
|
|
setAccountCreatedComplete,
|
|
setAccCr,
|
|
} = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
|
|
const [accountCreated, setAccountCreated] = useState(false);
|
|
|
|
useEffect(() => {
|
|
let accountBody = props.props.props.form.accountRegisterForm.values;
|
|
let emailAddress =
|
|
props.props.props.form.accountRegisterForm.values.emailaddress1;
|
|
Object.assign(accountBody, {
|
|
"pinswg_typeofinvolvement": 846040001,
|
|
});
|
|
|
|
accountBody = _.omit(accountBody, ["custom_password_check"]);
|
|
|
|
let checkEmailObj = {};
|
|
|
|
switch (props.accountDetails.accCr) {
|
|
case "created":
|
|
case "exists":
|
|
break;
|
|
|
|
default:
|
|
let emailExists = getEmailAccountCheck(
|
|
accountBody.emailaddress1
|
|
).then((data) => {
|
|
data["@odata.count"] > 0
|
|
? setAccCr("exists")
|
|
: (checkEmailObj = createAccount(accountBody).then(
|
|
(data) => {
|
|
//console.log(data);
|
|
setAccCr("created");
|
|
}
|
|
));
|
|
});
|
|
break;
|
|
}
|
|
});
|
|
|
|
return props.accountDetails.accCr == "created" ? (
|
|
<>
|
|
<p className="govuk-body">We have sent you a confirmation email.</p>
|
|
|
|
<h2 className="govuk-heading-m">What happens next</h2>
|
|
|
|
<p className="govuk-body">
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi a
|
|
metus non quam mollis egestas. Integer ac leo cursus, laoreet
|
|
nulla sed, tempus tellus. Mauris condimentum erat arcu.
|
|
</p>
|
|
|
|
<p className="govuk-body">
|
|
<a
|
|
href="/"
|
|
className="govuk-link"
|
|
onClick={() => {
|
|
setLogout(), window.localStorage.clear();
|
|
}}
|
|
>
|
|
Login to My Portal
|
|
</a>
|
|
</p>
|
|
</>
|
|
) : (
|
|
<>
|
|
<h2 className="govuk-heading-m">
|
|
Please try again with a different email address
|
|
</h2>
|
|
<p className="govuk-body">
|
|
<a
|
|
onClick={() => {
|
|
setRegisterFormComplete(false),
|
|
setAccountCreatedComplete(false),
|
|
setAccCr("false");
|
|
}}
|
|
className="govuk-link"
|
|
>
|
|
Try registering again
|
|
</a>
|
|
</p>
|
|
</>
|
|
);
|
|
};
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
search: state.search,
|
|
searchResultsObj: state.searchResultsObj,
|
|
formData: state.formData,
|
|
appealType: state.appealType,
|
|
accountDetails: state.accountDetails,
|
|
//form: state.form,
|
|
};
|
|
};
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
return {
|
|
setAccCr: (accountCreated) => {
|
|
dispatch(setAccCr(accountCreated));
|
|
},
|
|
setLogout: () => {
|
|
dispatch(setLogout());
|
|
},
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(RegisterComplete);
|