import { JSONPath as jsonpath } from "jsonpath-plus"; import useTranslation from "next-translate/useTranslation"; import { useRouter } from "next/router"; import { connect } from "react-redux"; import { Field, formValueSelector, reduxForm } from "redux-form"; import transLookup from "../../data/lookuptranslations.json"; const required = (errorMsg) => (value) => value || typeof value === "number" ? undefined : errorMsg; export const minLength = (errorMsg) => (value) => value && value.length < 4 ? errorMsg //`Must be ${min} characters or more` : undefined; let AdvancedSearch = (props) => { let { t } = useTranslation(); const router = useRouter(); const { locale } = router; const { LPAData, onSubmit, handleSubmit } = props; //console.log("props here:", props.props); const appealOptionsObj = _.isEmpty(props) ? [{}] : _.isEmpty(props.appealType) ? [{}] : _.isEmpty(props.appealType.appealTypeOptions) ? [{}] : _.isEmpty(props.appealType.appealTypeOptions.value) ? [{}] : props.appealType.appealTypeOptions.value; let lpaOptionsObj = _.isEmpty(props) ? [{}] : _.isEmpty(props.LPAData) ? [{}] : _.isEmpty(props.LPAData.LPAData) ? [{}] : _.isEmpty(props.LPAData.LPAData) ? [{}] : props.LPAData.LPAData.value; const RenderTextfield = ({ id, className, rows, datafieldname, name, label, input, hint1, hint2, hint3, meta: { touched, error }, ...custom }) => { return ( <>
{touched && error && ( Error: {" "} {error} )}
); }; const RenderLPAList = ({ name, id, input, optionsObj, meta: { touched, error }, label, errormsg, }) => { return ( <>
{" "} {touched && error && ( Error: {" "} {errormsg} )}
); }; const RenderAppealTypeList = ({ name, id, input, optionsObj, meta: { touched, error }, label, errormsg, }) => { return ( <>
{touched && error && ( Error: {" "} {errormsg} )}
); }; //const [showSpinnerState, setShowSpinnerState] = useState(false); // let spinnerState = () => { // showSpinnerState == true // ? setShowSpinnerState(false) // : setShowSpinnerState(true); // }; const onHandleSubmit = (values) => { event.preventDefault(); //spinnerState(); var searchString = ""; searchString += values.caseRef != null ? "?q=" + values.caseRef.trim() : ""; searchString += values.lpaTypes != null ? (typeof values.caseRef == "undefined" ? "?" : "&") + "lpa=" + values.lpaTypes : ""; searchString += values.appealTypes != null ? (typeof values.caseRef == "undefined" && typeof values.lpaTypes == "undefined" ? "?" : "&") + ("apt=" + values.appealTypes.split(",")[0]) : ""; router.replace( (router.locale == "cy" ? "/fymhorth/canlyniadauchwiliouwch" : "/myportal/advancedsearchresults") + searchString, null, { shallow: true, } ); }; return ( <>

{t("search:search-title-label")}

{/*

{t( "search:sitelocation-legend" )}

*/}
); }; const mapStateToProps = (state) => { return { currentView: state.currentView, search: state.search, searchResultsObj: state.searchResultsObj, formData: state.formData, appealType: state.appealType, LPAData: state.LPAData, //form: state.form, myCases: state.myCases, watchedCases: state.watchedCases, myRepresentations: state.myRepresentations, awaitingSubmission: state.awaitingSubmission, }; }; const mapDispatchToProps = (dispatch) => { return {}; }; const selector = formValueSelector("advancedSearchForm"); // <-- same as form name export default connect( mapStateToProps, mapDispatchToProps )( reduxForm({ form: "advancedSearchForm", destroyOnUnmount: false, })(AdvancedSearch) );