check form updates
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect } from "react-redux";
|
||||
import { Field, formValueSelector, reduxForm } from "redux-form";
|
||||
import { useEffect } from "react";
|
||||
import { Field, formValueSelector, reduxForm, change } from "redux-form";
|
||||
import {
|
||||
FieldsTranslations,
|
||||
Radiofield,
|
||||
@@ -15,7 +16,13 @@ let AboutYou = (props) => {
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
const { onSubmit, handleSubmit, appellantAgentValue, setFormStep } = props;
|
||||
const {
|
||||
onSubmit,
|
||||
handleSubmit,
|
||||
appellantAgentValue,
|
||||
setFormStep,
|
||||
updateField,
|
||||
} = props;
|
||||
|
||||
const yesNo = router.locale == "cy" ? ["Ydw", "Na"] : ["Yes", "No"];
|
||||
const appellantAgent =
|
||||
@@ -243,7 +250,7 @@ let AboutYou = (props) => {
|
||||
>
|
||||
<fieldset
|
||||
className="govuk-fieldset"
|
||||
aria-describedby={name + "-hint"}
|
||||
aria-describedby={datafieldname + "-hint"}
|
||||
>
|
||||
<legend className="govuk-fieldset__legend govuk-fieldset__legend--s govuk-!-font-weight-regular">
|
||||
<label
|
||||
@@ -272,11 +279,12 @@ let AboutYou = (props) => {
|
||||
}
|
||||
>
|
||||
{" "}
|
||||
{custom.hint != false && (
|
||||
<div className="govuk-hint">
|
||||
{t(custom.hint)}
|
||||
</div>
|
||||
)}
|
||||
{custom.hint != false ||
|
||||
(custom.hint != undefined && (
|
||||
<div className="govuk-hint">
|
||||
{t(custom.hint)}
|
||||
</div>
|
||||
))}
|
||||
{Object.keys(options).map((key, index) => (
|
||||
<div
|
||||
className="govuk-radios__item"
|
||||
@@ -424,6 +432,47 @@ let AboutYou = (props) => {
|
||||
console.log(JSON.stringify(values));
|
||||
setFormStep(1);
|
||||
};
|
||||
|
||||
const handlePartialUpdate = () => {
|
||||
if (appellantAgentValue == "846040001") {
|
||||
updateField("caseForm", "pinswg_appellantfirstname", "");
|
||||
updateField("caseForm", "pinswg_appellantlastname", "");
|
||||
updateField("caseForm", "pinswg_appellantemailaddress", "");
|
||||
updateField("caseForm", "pinswg_appellantaddress", "");
|
||||
updateField("caseForm", "pinswg_appellantphonenumber", "");
|
||||
} else {
|
||||
updateField(
|
||||
"caseForm",
|
||||
"pinswg_appellantfirstname",
|
||||
props.initialValues.pinswg_appellantfirstname
|
||||
);
|
||||
updateField(
|
||||
"caseForm",
|
||||
"pinswg_appellantlastname",
|
||||
props.initialValues.pinswg_appellantlastname
|
||||
);
|
||||
updateField(
|
||||
"caseForm",
|
||||
"pinswg_appellantemailaddress",
|
||||
props.initialValues.pinswg_appellantemailaddress
|
||||
);
|
||||
updateField(
|
||||
"caseForm",
|
||||
"pinswg_appellantaddress",
|
||||
props.initialValues.pinswg_appellantaddress
|
||||
);
|
||||
updateField(
|
||||
"caseForm",
|
||||
"pinswg_appellantphonenumber",
|
||||
props.initialValues.pinswg_appellantphonenumber
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
handlePartialUpdate();
|
||||
}, [appellantAgentValue]);
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onHandleSubmit)}>
|
||||
<Field
|
||||
@@ -723,11 +772,27 @@ const mapStateToProps = (state) => {
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
//form: state.form,
|
||||
|
||||
initialValues: {
|
||||
pinswg_appellantfirstname:
|
||||
state.accountDetails.accountDetails.firstname,
|
||||
pinswg_appellantlastname:
|
||||
state.accountDetails.accountDetails.lastname,
|
||||
pinswg_appellantemailaddress:
|
||||
state.accountDetails.accountDetails.emailaddress1,
|
||||
pinswg_appellantaddress:
|
||||
state.accountDetails.accountDetails.address1_composite,
|
||||
pinswg_appellantphonenumber:
|
||||
state.accountDetails.accountDetails.telephone1,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {};
|
||||
return {
|
||||
updateField: (form, field, newValue) =>
|
||||
dispatch(change(form, field, newValue)),
|
||||
};
|
||||
};
|
||||
|
||||
// AboutYou = reduxForm({
|
||||
@@ -754,6 +819,8 @@ export default connect(
|
||||
)(
|
||||
reduxForm({
|
||||
form: "caseForm",
|
||||
enableReinitialize: true, // this is needed!!
|
||||
|
||||
destroyOnUnmount: false,
|
||||
})(AboutYou)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user