cleared debug, updated new appeal add about you
This commit is contained in:
@@ -2,6 +2,12 @@ import useTranslation from "next-translate/useTranslation";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect } from "react-redux";
|
||||
import { Field, formValueSelector, reduxForm } from "redux-form";
|
||||
import {
|
||||
FieldsTranslations,
|
||||
Radiofield,
|
||||
Textfield,
|
||||
MultiLinefield,
|
||||
} from "../elements";
|
||||
|
||||
let AboutYou = (props) => {
|
||||
let { t } = useTranslation();
|
||||
@@ -9,7 +15,7 @@ let AboutYou = (props) => {
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
const { onSubmit, handleSubmit, appellantAgentValue } = props;
|
||||
const { onSubmit, handleSubmit, appellantAgentValue, setFormStep } = props;
|
||||
|
||||
const yesNo = router.locale == "cy" ? ["Ydw", "Na"] : ["Yes", "No"];
|
||||
const appellantAgent =
|
||||
@@ -161,18 +167,268 @@ let AboutYou = (props) => {
|
||||
</>
|
||||
);
|
||||
};
|
||||
const RenderMultiline = ({
|
||||
id,
|
||||
className,
|
||||
rows,
|
||||
datafieldname,
|
||||
name,
|
||||
label,
|
||||
input,
|
||||
errorMsg,
|
||||
meta: { touched, error },
|
||||
...custom
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={
|
||||
touched && error
|
||||
? "govuk-form-group govuk-form-group--error"
|
||||
: "govuk-form-group "
|
||||
}
|
||||
>
|
||||
<label
|
||||
className="govuk-label "
|
||||
htmlFor={id}
|
||||
id={id + "_label"}
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
{touched && error && (
|
||||
<span
|
||||
id={id + "-error"}
|
||||
className="govuk-error-message"
|
||||
>
|
||||
<span className="govuk-visually-hidden">
|
||||
Error:
|
||||
</span>{" "}
|
||||
{touched &&
|
||||
((error && (
|
||||
<span>{errorMsg ? errorMsg : error}</span>
|
||||
)) ||
|
||||
(warning && <span>{warning}</span>))}
|
||||
</span>
|
||||
)}
|
||||
<textarea
|
||||
{...input}
|
||||
rows={rows}
|
||||
className={className}
|
||||
></textarea>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const RenderRadio = ({
|
||||
datafieldname,
|
||||
name,
|
||||
label,
|
||||
id,
|
||||
errorMsg,
|
||||
options,
|
||||
input: { onChange, value },
|
||||
meta: { touched, error },
|
||||
...custom
|
||||
}) => {
|
||||
let { t } = useTranslation();
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={
|
||||
touched && error
|
||||
? "govuk-form-group govuk-form-group--error"
|
||||
: "govuk-form-group "
|
||||
}
|
||||
>
|
||||
<fieldset
|
||||
className="govuk-fieldset"
|
||||
aria-describedby={name + "-hint"}
|
||||
>
|
||||
<legend className="govuk-fieldset__legend govuk-fieldset__legend--s govuk-!-font-weight-regular">
|
||||
<label
|
||||
className="govuk-fieldset__heading govuk-body-m"
|
||||
id={id + "_label"}
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
</legend>
|
||||
{touched && error && (
|
||||
<span
|
||||
id={id + "-error"}
|
||||
className="govuk-error-message"
|
||||
>
|
||||
<span className="govuk-visually-hidden">
|
||||
Error:
|
||||
</span>{" "}
|
||||
{errorMsg}
|
||||
</span>
|
||||
)}
|
||||
<div
|
||||
className={
|
||||
custom.inline == false
|
||||
? "govuk-radios govuk-radios--small"
|
||||
: "govuk-radios govuk-radios--inline govuk-radios--small"
|
||||
}
|
||||
>
|
||||
{" "}
|
||||
{custom.hint != false && (
|
||||
<div className="govuk-hint">
|
||||
{t(custom.hint)}
|
||||
</div>
|
||||
)}
|
||||
{Object.keys(options).map((key, index) => (
|
||||
<div
|
||||
className="govuk-radios__item"
|
||||
data-children-count={key}
|
||||
key={key}
|
||||
>
|
||||
<Field
|
||||
id={id + "_" + index}
|
||||
name={id}
|
||||
component="input"
|
||||
type="radio"
|
||||
className="govuk-radios__input"
|
||||
value={options[key].split("|")[0]}
|
||||
// checked={
|
||||
// value ==
|
||||
// parseInt(options[key].split("|")[0])
|
||||
// }
|
||||
onChange={(e) => {
|
||||
let docListObj =
|
||||
custom.documentList;
|
||||
if (
|
||||
custom.requiredDocumentValue ==
|
||||
"Yes"
|
||||
) {
|
||||
e.target.value != "846040000"
|
||||
? (docListObj =
|
||||
Object.assign(
|
||||
docListObj,
|
||||
{
|
||||
["documentCheckList_" +
|
||||
id]:
|
||||
custom.requiredDocumentLabel,
|
||||
}
|
||||
))
|
||||
: delete docListObj[
|
||||
"documentCheckList_" +
|
||||
id
|
||||
];
|
||||
custom.setDocumentsList(
|
||||
docListObj
|
||||
);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<label
|
||||
className="govuk-label govuk-radios__label"
|
||||
htmlFor={id + "_" + index}
|
||||
>
|
||||
{t(options[key].split("|")[1])}
|
||||
</label>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
function Radiofield(props) {
|
||||
const {
|
||||
name,
|
||||
label,
|
||||
datafieldname,
|
||||
parentField,
|
||||
form,
|
||||
formProps,
|
||||
parentFieldShowOnValue,
|
||||
validation,
|
||||
} = props;
|
||||
|
||||
const router = useRouter();
|
||||
const required = (value) => (value ? undefined : "Required");
|
||||
// console.log(props.options);
|
||||
|
||||
const fieldOptions = props.options
|
||||
.slice(1, props.options.length - 1)
|
||||
.split(",");
|
||||
|
||||
//parentFieldShowOnValue
|
||||
var showIfHasParentShowValue = parentField != false;
|
||||
//debugger;
|
||||
// parentField != false &&
|
||||
// !_.isEmpty(formProps[form]) &&
|
||||
// _.has(formProps[form].values, parentField) &&
|
||||
// parentFieldShowOnValue.indexOf(
|
||||
// formProps[form].values[parentField].toString()
|
||||
// ) > -1;
|
||||
|
||||
(showIfHasParentShowValue == parentField) != false &&
|
||||
showIfHasParentShowValue;
|
||||
|
||||
// console.log(
|
||||
// datafieldname,
|
||||
// showIfHasParentShowValue,
|
||||
// formProps[form].values[parentField]
|
||||
// );
|
||||
|
||||
return (
|
||||
<>
|
||||
{parentField != false ? (
|
||||
showIfHasParentShowValue && (
|
||||
<Field
|
||||
name={name}
|
||||
datafieldname={datafieldname}
|
||||
label={label}
|
||||
options={fieldOptions}
|
||||
id={name}
|
||||
//validate={[required]}
|
||||
errorMsg="Select an option"
|
||||
component={RenderRadio}
|
||||
inline={props.inline}
|
||||
hint={props.hint}
|
||||
validate={eval(validation)}
|
||||
requiredDocumentLabel={props.requiredDocumentLabel}
|
||||
requiredDocumentValue={props.requiredDocumentValue}
|
||||
setDocumentsList={props.setDocumentsList}
|
||||
documentList={props.documentList}
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
<Field
|
||||
name={name}
|
||||
datafieldname={datafieldname}
|
||||
label={label}
|
||||
options={fieldOptions}
|
||||
id={name}
|
||||
//validate={[required]}
|
||||
errorMsg="Select an option"
|
||||
component={RenderRadio}
|
||||
inline={props.inline}
|
||||
hint={props.hint}
|
||||
validate={eval(validation)}
|
||||
requiredDocumentLabel={props.requiredDocumentLabel}
|
||||
requiredDocumentValue={props.requiredDocumentValue}
|
||||
setDocumentsList={props.setDocumentsList}
|
||||
documentList={props.documentList}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
const onHandleSubmit = (values) => {
|
||||
event.preventDefault();
|
||||
|
||||
console.log(values);
|
||||
router.replace("/newappeal");
|
||||
console.log(JSON.stringify(values));
|
||||
setFormStep(1);
|
||||
};
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onHandleSubmit)}>
|
||||
<Field
|
||||
name={"onbehalfof"}
|
||||
id={"onbehalfof"}
|
||||
name={"pinswg_onbehalfof"}
|
||||
id={"pinswg_onbehalfof"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -183,37 +439,34 @@ let AboutYou = (props) => {
|
||||
<details className="govuk-details" data-module="govuk-details">
|
||||
<summary className="govuk-details__summary">
|
||||
<span className="govuk-details__summary-text">
|
||||
Who can appeal?
|
||||
{t("newappeal:about-you-who-can-appeal-label")}
|
||||
</span>
|
||||
</summary>
|
||||
<div className="govuk-details__text">
|
||||
Only those named as an applicant on the original
|
||||
application form can submit an appeal. if you are
|
||||
submitting an appeal on behalf of a company state the
|
||||
name of the company you are representing,
|
||||
{t("newappeal:about-you-who-can-appeal-paragraph")}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<Field
|
||||
name={"appellantAgent"}
|
||||
datafieldname={"appellantAgent"}
|
||||
|
||||
<Radiofield
|
||||
name={"pinswg_appellantagent"}
|
||||
datafieldname={"pinswg_appellantagent"}
|
||||
label={t("newappeal:about-you-who-are-you-label")}
|
||||
options={appellantAgent}
|
||||
id={"appellantAgent"}
|
||||
options="[846040000|newappeal:about-you-who-are-you-label-appellant,846040001|newappeal:about-you-who-are-you-label-agent]"
|
||||
id={"pinswg_appellantagent"}
|
||||
className="govuk-radios__input"
|
||||
validate={[required]}
|
||||
//validate={[required]}
|
||||
errorMsg="Select an option"
|
||||
component={RenderYesNo}
|
||||
/>
|
||||
{(appellantAgentValue == "Appellant" ||
|
||||
appellantAgentValue == "Apelydd") && (
|
||||
|
||||
{appellantAgentValue == "846040000" && (
|
||||
<>
|
||||
<h2 className="govuk-heading-s">
|
||||
{t("newappeal:about-you-appellant-contact-details")}
|
||||
</h2>
|
||||
<Field
|
||||
name={"appellantfirstname"}
|
||||
id={"appellantfirstname"}
|
||||
name={"[pinswg_appellantfirstname"}
|
||||
id={"pinswg_appellantfirstname"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -223,8 +476,8 @@ let AboutYou = (props) => {
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
name={"appellantlastname"}
|
||||
id={"appellantlastname"}
|
||||
name={"pinswg_appellantlastname"}
|
||||
id={"pinswg_appellantlastname"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -232,10 +485,22 @@ let AboutYou = (props) => {
|
||||
label={t(
|
||||
"newappeal:about-you-appellant-contact-details-lastname-label"
|
||||
)}
|
||||
/>{" "}
|
||||
/>
|
||||
<Field
|
||||
name={"appellantemailaddress"}
|
||||
id={"appellantemailaddress"}
|
||||
name={"pinswg_appellantaddress"}
|
||||
id={"pinswg_appellantaddress"}
|
||||
component={RenderMultiline}
|
||||
type="textarea"
|
||||
className="govuk-textarea govuk-input--width-20"
|
||||
validate={[required]}
|
||||
label={t(
|
||||
"newappeal:about-you-appellant-contact-details-address-label"
|
||||
)}
|
||||
rows={4}
|
||||
/>
|
||||
<Field
|
||||
name={"pinswg_appellantemailaddress"}
|
||||
id={"pinswg_appellantemailaddress"}
|
||||
component={RenderTextfield}
|
||||
type="email"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -245,39 +510,50 @@ let AboutYou = (props) => {
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
name={"appellantphonenumber"}
|
||||
id={"appellantphonenumber"}
|
||||
name={"pinswg_appellantphonenumber"}
|
||||
id={"pinswg_appellantphonenumber"}
|
||||
component={RenderTextfield}
|
||||
type="numberz"
|
||||
type="number"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
validate={[required, phoneNumber]}
|
||||
label={t(
|
||||
"newappeal:about-you-appellant-contact-details-phone-label"
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
name={"contactPrefs"}
|
||||
datafieldname={"contactPrefs"}
|
||||
|
||||
<Radiofield
|
||||
name={"pinswg_contactprefs"}
|
||||
datafieldname={"pinswg_contactprefs"}
|
||||
label={t(
|
||||
"newappeal:about-you-agent-contact-preferences-label"
|
||||
)}
|
||||
options={contactPref}
|
||||
id={"contactPrefs"}
|
||||
options="[846040000|newappeal:about-you-agent-contact-preferences-value-email,846040001|newappeal:about-you-agent-contact-preferences-value-post]"
|
||||
id={"pinswg_contactprefs"}
|
||||
className="govuk-radios__input"
|
||||
//validate={[required]}
|
||||
validate={[required]}
|
||||
errorMsg="Select an option"
|
||||
/>
|
||||
<Radiofield
|
||||
name={"pinswg_languagepreference"}
|
||||
datafieldname={"pinswg_languagepreference"}
|
||||
label={t(
|
||||
"newappeal:about-you-appellant-language-preferences-label"
|
||||
)}
|
||||
options="[846040000|newappeal:about-you-agent-language-preferences-value-english,846040001|newappeal:about-you-agent-language-preferences-value-welsh]"
|
||||
id={"pinswg_languagepreference"}
|
||||
className="govuk-radios__input"
|
||||
validate={[required]}
|
||||
errorMsg="Select an option"
|
||||
component={RenderYesNo}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{(appellantAgentValue == "Agent" ||
|
||||
appellantAgentValue == "Asiant") && (
|
||||
{appellantAgentValue == "846040001" && (
|
||||
<>
|
||||
<h2 className="govuk-heading-s">
|
||||
{t("newappeal:about-you-appellant-contact-details")}
|
||||
</h2>
|
||||
<Field
|
||||
name={"appellantfirstname"}
|
||||
name={"pinswg_appellantfirstname"}
|
||||
id={"appellantfirstname"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
@@ -288,8 +564,8 @@ let AboutYou = (props) => {
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
name={"appellantlastname"}
|
||||
id={"appellantlastname"}
|
||||
name={"pinswg_appellantlastname"}
|
||||
id={"pinswg_appellantlastname"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -297,25 +573,37 @@ let AboutYou = (props) => {
|
||||
label={t(
|
||||
"newappeal:about-you-appellant-contact-details-lastname-label"
|
||||
)}
|
||||
/>{" "}
|
||||
/>
|
||||
<Field
|
||||
name={"appellantemailaddress"}
|
||||
id={"appellantemailaddress"}
|
||||
name={"pinswg_appellantaddress"}
|
||||
id={"pinswg_appellantaddress"}
|
||||
component={RenderMultiline}
|
||||
type="textarea"
|
||||
className="govuk-textarea govuk-input--width-20"
|
||||
validate={[required]}
|
||||
label={t(
|
||||
"newappeal:about-you-appellant-contact-details-address-label"
|
||||
)}
|
||||
rows={4}
|
||||
/>
|
||||
<Field
|
||||
name={"pinswg_appellantemailaddress"}
|
||||
id={"pinswg_appellantemailaddress"}
|
||||
component={RenderTextfield}
|
||||
type="email"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
validate={[required, email]}
|
||||
validate={[required]}
|
||||
label={t(
|
||||
"newappeal:about-you-appellant-contact-details-email-label"
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
name={"appellantphonenumber"}
|
||||
id={"appellantphonenumber"}
|
||||
name={"pinswg_appellantphonenumber"}
|
||||
id={"pinswg_appellantphonenumber"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
validate={[required]}
|
||||
validate={[required, phoneNumber]}
|
||||
label={t(
|
||||
"newappeal:about-you-appellant-contact-details-phone-label"
|
||||
)}
|
||||
@@ -324,8 +612,8 @@ let AboutYou = (props) => {
|
||||
{t("newappeal:about-you-agent-contact-details")}
|
||||
</h2>{" "}
|
||||
<Field
|
||||
name={"agentcompanyname"}
|
||||
id={"agentcompanyname"}
|
||||
name={"pinswg_agentcompanyname"}
|
||||
id={"pinswg_agentcompanyname"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -335,8 +623,8 @@ let AboutYou = (props) => {
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
name={"agentfirstname"}
|
||||
id={"agentfirstname"}
|
||||
name={"pinswg_agentfirstname"}
|
||||
id={"pinswg_agentfirstname"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -346,8 +634,8 @@ let AboutYou = (props) => {
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
name={"agentlastname"}
|
||||
id={"agentlastname"}
|
||||
name={"pinswg_agentlastname"}
|
||||
id={"pinswg_agentlastname"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -357,8 +645,20 @@ let AboutYou = (props) => {
|
||||
)}
|
||||
/>{" "}
|
||||
<Field
|
||||
name={"agentemailaddress"}
|
||||
id={"agentemailaddress"}
|
||||
name={"pinswg_agentaddress"}
|
||||
id={"pinswg_agentaddress"}
|
||||
component={RenderMultiline}
|
||||
type="textarea"
|
||||
className="govuk-textarea govuk-input--width-20"
|
||||
validate={[required]}
|
||||
label={t(
|
||||
"newappeal:about-you-agent-contact-details-address-label"
|
||||
)}
|
||||
rows={4}
|
||||
/>
|
||||
<Field
|
||||
name={"pinswg_agentemailaddress"}
|
||||
id={"pinswg_agentemailaddress"}
|
||||
component={RenderTextfield}
|
||||
type="text"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -368,8 +668,8 @@ let AboutYou = (props) => {
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
name={"agentphonenumber"}
|
||||
id={"agentphonenumber"}
|
||||
name={"pinswg_agentphonenumber"}
|
||||
id={"pinswg_agentphonenumber"}
|
||||
component={RenderTextfield}
|
||||
type="number"
|
||||
className="govuk-input govuk-input--width-20"
|
||||
@@ -378,18 +678,29 @@ let AboutYou = (props) => {
|
||||
"newappeal:about-you-agent-contact-details-phone-label"
|
||||
)}
|
||||
/>
|
||||
<Field
|
||||
name={"contactPrefs"}
|
||||
datafieldname={"contactPrefs"}
|
||||
<Radiofield
|
||||
name={"pinswg_contactprefs"}
|
||||
datafieldname={"pinswg_contactprefs"}
|
||||
label={t(
|
||||
"newappeal:about-you-agent-contact-preferences-label"
|
||||
)}
|
||||
options={contactPref}
|
||||
id={"contactPrefs"}
|
||||
options="[846040000|newappeal:about-you-agent-contact-preferences-value-email,846040001|newappeal:about-you-agent-contact-preferences-value-post]"
|
||||
id={"pinswg_contactprefs"}
|
||||
className="govuk-radios__input"
|
||||
//validate={[required]}
|
||||
validate={[required]}
|
||||
errorMsg="Select an option"
|
||||
/>
|
||||
<Radiofield
|
||||
name={"pinswg_languagepreference"}
|
||||
datafieldname={"pinswg_languagepreference"}
|
||||
label={t(
|
||||
"newappeal:about-you-agent-language-preferences-label"
|
||||
)}
|
||||
options="[846040000|newappeal:about-you-agent-language-preferences-value-english,846040001|newappeal:about-you-agent-language-preferences-value-welsh]"
|
||||
id={"pinswg_languagepreference"}
|
||||
className="govuk-radios__input"
|
||||
validate={[required]}
|
||||
errorMsg="Select an option"
|
||||
component={RenderYesNo}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
@@ -419,30 +730,30 @@ const mapDispatchToProps = (dispatch) => {
|
||||
return {};
|
||||
};
|
||||
|
||||
AboutYou = reduxForm({
|
||||
form: "caseForm", // a unique identifier for this form
|
||||
destroyOnUnmount: false,
|
||||
})(AboutYou);
|
||||
// AboutYou = reduxForm({
|
||||
// form: "caseForm", // a unique identifier for this form
|
||||
// destroyOnUnmount: false,
|
||||
// })(AboutYou);
|
||||
|
||||
const selector = formValueSelector("caseForm"); // <-- same as form name
|
||||
|
||||
AboutYou = connect((state) => {
|
||||
// can select values individually
|
||||
const appellantAgentValue = selector(state, "appellantAgent");
|
||||
const appellantAgentValue = selector(state, "pinswg_appellantagent");
|
||||
|
||||
return {
|
||||
appellantAgentValue,
|
||||
};
|
||||
})(AboutYou);
|
||||
|
||||
export default AboutYou;
|
||||
//export default AboutYou;
|
||||
|
||||
// export default connect(
|
||||
// mapStateToProps,
|
||||
// mapDispatchToProps
|
||||
// )(
|
||||
// reduxForm({
|
||||
// form: "caseForm",
|
||||
// destroyOnUnmount: false,
|
||||
// })(AboutYou)
|
||||
// );
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(
|
||||
reduxForm({
|
||||
form: "caseForm",
|
||||
destroyOnUnmount: false,
|
||||
})(AboutYou)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user