153 lines
4.6 KiB
JavaScript
153 lines
4.6 KiB
JavaScript
import _ from "lodash";
|
|
import useTranslation from "next-translate/useTranslation";
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/router";
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
import { setAccCr, setLogout } from "../../store/accountDetails/action";
|
|
|
|
import {
|
|
createAccount,
|
|
getEmailAccountCheck
|
|
} from "../../actions/services/accountService";
|
|
|
|
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;
|
|
|
|
// was an appellant "pinswg_typeofinvolvement": 846040001,
|
|
Object.assign(accountBody, {
|
|
"pinswg_typeofinvolvement": 846040061
|
|
});
|
|
|
|
accountBody = _.omit(accountBody, ["custom_password_check"]);
|
|
|
|
let checkEmailObj = {};
|
|
|
|
console.log("props.accountDetails.accCr :", props.accountDetails.accCr);
|
|
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) => {
|
|
setAccCr("created");
|
|
}
|
|
));
|
|
});
|
|
break;
|
|
}
|
|
});
|
|
|
|
var registerBody = "";
|
|
switch (props.accountDetails.accCr) {
|
|
case "created":
|
|
return (registerBody = (
|
|
<>
|
|
<p className="govuk-body">
|
|
{t("account:register-new-account-confirmation-email")}
|
|
</p>
|
|
|
|
<h2 className="govuk-heading-m">
|
|
{t(
|
|
"account:register-new-account-sub-heading-what-next"
|
|
)}
|
|
</h2>
|
|
|
|
<p className="govuk-body">
|
|
{t("account:register-new-account-paragraph-what-next")}
|
|
</p>
|
|
|
|
<p className="govuk-body">
|
|
{t("account:register-new-account-paragraph-thanks")}
|
|
</p>
|
|
|
|
<p className="govuk-body">
|
|
<Link href="/" className="govuk-link">
|
|
{t("account:register-new-account-my-portal-link")}
|
|
</Link>
|
|
</p>
|
|
</>
|
|
));
|
|
|
|
break;
|
|
|
|
case "exists":
|
|
return (registerBody = (
|
|
<>
|
|
<h2 className="govuk-heading-m">
|
|
{t("account:register-new-account-account-failed")}
|
|
</h2>
|
|
<p className="govuk-body">
|
|
<a
|
|
onClick={() => {
|
|
(setRegisterFormComplete(false),
|
|
setAccountCreatedComplete(false),
|
|
setAccCr(false));
|
|
}}
|
|
className="govuk-link"
|
|
>
|
|
Try registering again
|
|
</a>
|
|
</p>
|
|
</>
|
|
));
|
|
|
|
default:
|
|
return (registerBody = "");
|
|
break;
|
|
}
|
|
return registerBody;
|
|
};
|
|
|
|
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);
|