import useTranslation from "next-translate/useTranslation";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import { connect } from "react-redux";
import { Field, change, formValueSelector, reduxForm } from "redux-form";
const RenderTextfield = ({
id,
className,
rows,
datafieldname,
name,
label,
input,
type,
errorMsg,
disabled,
meta: { touched, error },
...custom
}) => {
//console.log(custom);
return (
<>
{touched && error && (
Error:{" "}
{touched &&
((error && (
{errorMsg ? errorMsg : error}
)) ||
(warning && {warning}))}
)}
>
);
};
const RenderMultiline = ({
id,
className,
rows,
datafieldname,
name,
label,
input,
errorMsg,
meta: { touched, error },
...custom
}) => {
return (
<>
{touched && error && (
Error:{" "}
{touched &&
((error && (
{errorMsg ? errorMsg : error}
)) ||
(warning && {warning}))}
)}
>
);
};
const RenderYesNo = ({
datafieldname,
name,
label,
id,
errorMsg,
options,
input: { onChange, value },
meta: { touched, error },
...custom
}) => {
return (
<>
>
);
};
const RenderRadio = ({
datafieldname,
name,
label,
id,
errorMsg,
options,
input: { onChange, value },
meta: { touched, error },
...custom
}) => {
let { t } = useTranslation();
const required = (value) => (value ? undefined : "Required");
return (
<>
>
);
};
function Radiofield(props) {
const {
name,
label,
datafieldname,
parentField,
form,
formProps,
parentFieldShowOnValue,
validation,
hint
} = 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]
// );
let { t } = useTranslation();
return (
<>
{parentField != false ? (
showIfHasParentShowValue && (
)
) : (
)}
>
);
}
const RenderCheckBox = ({
datafieldname,
name,
label,
id,
errorMsg,
options,
input: { onChange, value },
meta: { touched, error },
...custom
}) => {
let { t } = useTranslation();
const required = (value) => (value ? undefined : "Required");
return (
<>
>
);
};
let AboutYou = (props) => {
let { t } = useTranslation();
const router = useRouter();
const { locale } = router;
const isWelsh = router.locale == "cy";
const {
onSubmit,
handleSubmit,
appellantAgentValue,
setFormStep,
updateField
} = props;
const [isAgent, setIsAgent] = useState(false);
const isAgentSelected = appellantAgentValue == "846040001";
const isAppellantSelected = appellantAgentValue == "846040000";
console.log(
"================",
props.initialValues.pinswg_typeofinvolvement
);
//props.initialValues.pinswg_typeofinvolvement === 846040000 &&
// setIsAgent(true);
const yesNo = isWelsh ? ["Ydw", "Na"] : ["Yes", "No"];
const appellantAgent = isWelsh
? ["Apelydd", "Asiant"]
: ["Appellant", "Agent"];
const contactPref = isWelsh ? ["Ebost", "Post"] : ["Email", "Post"];
const required = (value) =>
value ? undefined : t("newappeal:is-required-label");
const emojicheck = (value) => {
let errors;
// Check for emojis using a regular expression
const emojiRegex =
/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{2300}-\u{23FF}\u{2B50}\u{1F004}-\u{1F0CF}\u{1F0A0}-\u{1F0A5}\u{1F170}-\u{1F251}]/gu;
if (emojiRegex.test(value)) {
errors = t("newappeal:emojis-not-allowed-label");
}
return errors;
};
const emailRegex =
/(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/gi;
const email = (value) =>
value && !emailRegex.test(value)
? t("newappeal:emojis-not-allowed-label")
: undefined;
const phoneNumber = (value) =>
value &&
!/^(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?(?:\(?0\)?[\s-]?)?)|(?:\(?0))(?:(?:\d{5}\)?[\s-]?\d{4,5})|(?:\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3}))|(?:\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4})|(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}))(?:[\s-]?(?:x|ext\.?|\#)\d{3,4})?$/i.test(
value
)
? t("newappeal:invalid-phonenumber-label")
: undefined;
const onHandleSubmit = (values) => {
event.preventDefault();
window.scrollTo({ top: 0, behavior: "smooth" });
setFormStep(1);
};
const handlePartialUpdate = () => {
if (isAgentSelected && isAgent == false) {
updateField("caseForm", "pinswg_appellantfirstname", "");
updateField("caseForm", "pinswg_appellantlastname", "");
updateField("caseForm", "company", "");
updateField("caseForm", "pinswg_appellantemailaddress", "");
updateField("caseForm", "pinswg_appellantaddress", "");
updateField("caseForm", "pinswg_appellantphonenumber", "");
setIsAgent(true);
}
//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();
});
return (
);
};
const mapStateToProps = (state) => {
return {
search: state.search,
searchResultsObj: state.searchResultsObj,
formData: state.formData,
appealType: state.appealType,
//form: state.form,
initialValues: {
pinswg_appellantfirstname:
state.accountDetails.accountDetails.firstname,
pinswg_appellantlastname:
state.accountDetails.accountDetails.lastname,
pinswg_appellantcompany:
state.accountDetails.accountDetails.company,
pinswg_appellantemailaddress:
state.accountDetails.accountDetails.emailaddress1,
pinswg_appellantaddress:
state.accountDetails.accountDetails.address1_composite,
pinswg_appellantphonenumber:
state.accountDetails.accountDetails.telephone1,
pinswg_agentcompanyname:
state.accountDetails.accountDetails.company,
pinswg_agentfirstname:
state.accountDetails.accountDetails.firstname,
pinswg_agentlastname: state.accountDetails.accountDetails.lastname,
pinswg_agentemailaddress:
state.accountDetails.accountDetails.emailaddress1,
pinswg_agentaddress:
state.accountDetails.accountDetails.address1_composite,
pinswg_agentphonenumber:
state.accountDetails.accountDetails.telephone1,
pinswg_typeofinvolvement:
state.accountDetails.accountDetails.pinswg_typeofinvolvement
}
};
};
const mapDispatchToProps = (dispatch) => {
return {
updateField: (form, field, newValue) =>
dispatch(change(form, field, newValue))
};
};
// 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, "pinswg_appellantagent");
return {
appellantAgentValue
};
})(AboutYou);
//export default AboutYou;
export default connect(
mapStateToProps,
mapDispatchToProps
)(
reduxForm({
form: "caseForm",
enableReinitialize: true, // this is needed!!
destroyOnUnmount: false
})(AboutYou)
);