diff --git a/actions/index.js b/actions/index.js index 1a043c14..daf46680 100644 --- a/actions/index.js +++ b/actions/index.js @@ -198,6 +198,36 @@ export const getBasicSearch = (searchString) => { }); }; +export const getIncidentbyID = (searchString) => { + return axios + .get( + BASE_URL + + "/api/endpoint/getincidentbyid_api?searchString=" + + searchString + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + //console.log(error); + return error.response; + }); +}; + +export const getIsPublishedbyID = (searchString) => { + return axios + .get( + "/api/endpoint/getispublishedbyid_api?searchString=" + searchString + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + //console.log(error); + return error.response; + }); +}; + export const getPartSavedAppeal = (searchString) => { return axios .get( @@ -230,6 +260,35 @@ export const getBasicDNSURLSearch = (searchString) => { }); }; +export const getAddressSearchPaged = ( + searchString, + pageNumber, + orderBy, + fieldSort, + showNumberOfRecords +) => { + //console.log(queryUrl); + return axios + .get( + "/api/endpoint/getbasicsearch_by_address_paged_api?searchString=" + + searchString + + "&pageNumber=" + + pageNumber + + "&orderby=" + + orderBy + + "&fieldSort=" + + fieldSort + + "&showNumberOfRecords=" + + showNumberOfRecords + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + return error.response; + }); +}; + export const getBasicSearchPaged = ( searchString, pageNumber, @@ -1732,3 +1791,26 @@ export const sendRepCompleteMessage = async (containerID, caseReference) => { consoleLogger(error); }); }; + +export const getAddressSearch = async (searchString) => { + const params = new URLSearchParams(searchString); + const str = params.toString(); + + console.log( + "the url", + BASE_URL + "/api/endpoint/getbasicsearch_by_address_api?" + str + ); + try { + const res = await axios.get( + BASE_URL + "/api/endpoint/getbasicsearch_by_address_api?" + str + ); + return res.data; + } catch (error) { + let ErrResponse = { + value: [], + errorCode: error.response.status, + errorMsg: error.response.statusText, + }; + return ErrResponse; + } +}; diff --git a/components/addresssearch.js b/components/addresssearch.js new file mode 100644 index 00000000..d855738f --- /dev/null +++ b/components/addresssearch.js @@ -0,0 +1,24 @@ +import Link from "next/link"; +import { useRouter } from "next/router"; +import { useContext } from "react"; +import useTranslation from "next-translate/useTranslation"; +import SearchForCase from "./search/searchforcase"; +import AddressSearch from "./search/addresssearch"; + +export default function Search(props) { + let { t } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + //console.log("props here:", props.myportal || false); + + return ( +
+ +
+ ); +} diff --git a/components/addresssearchresults.js b/components/addresssearchresults.js new file mode 100644 index 00000000..94c15a07 --- /dev/null +++ b/components/addresssearchresults.js @@ -0,0 +1,80 @@ +import Link from "next/link"; +import { useRouter } from "next/router"; +import { useContext } from "react"; +import useTranslation from "next-translate/useTranslation"; +import SearchForCase from "./search/searchforcase"; +import SearchResults from "./search/addresssearchresults"; +import CRMError from "./crmError"; + +export default function Search(props) { + const { + searchString, + searchResultsObj, + advancedSearch, + myportal, + watchedCases, + isLinkedCase, + showLoginCheck, + } = props; + let { t } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + + var hasError = _.has(searchResultsObj.searchResultsObj, "errorCode") + ? true + : false; + + //console.log("has an error", hasError); + + return ( +
+ {hasError ? ( + + ) : ( + <> +
+
+ +
+
+
+
+
+ + {t("common:breadcrumb-address-search")} + + {/* router.back()} + className="govuk-button govuk-button--secondary" + > + {t("search:searchresults-new-search-button-label")} + */} +
+
+
+ + )} +
+ ); +} diff --git a/components/breadcrumbs.js b/components/breadcrumbs.js index 4dca5cf2..025caf4c 100644 --- a/components/breadcrumbs.js +++ b/components/breadcrumbs.js @@ -123,6 +123,39 @@ const Breadcrumbs = (props) => { ) : ( "" )} + {router.pathname == "/addresssearch" ? ( + <> +
  • + {t("common:breadcrumb-address-search")} +
  • + + ) : ( + "" + )} + + {router.pathname == "/myportal/addresssearch" ? ( + <> +
  • + + {t("common:breadcrumb-my-portal")} + +
  • +
  • + {t("common:breadcrumb-address-search")} +
  • + + ) : ( + "" + )} {router.pathname == "/myportal/advancedsearch" ? ( <>
  • @@ -146,6 +179,31 @@ const Breadcrumbs = (props) => { ) : ( "" )} + {router.pathname == "/addresssearchresults" ? ( + <> + {" "} +
  • + + {t("common:breadcrumb-address-search")} + +
  • +
  • + {t( + "common:breadcrumb-address-search-results" + )} +
  • + + ) : ( + "" + )} {router.pathname == "/advancedsearchresults" ? ( <> {" "} @@ -210,6 +268,45 @@ const Breadcrumbs = (props) => { ) : ( "" )} + {router.pathname == "/myportal/addresssearchresults" ? ( + <> +
  • + + {t("common:breadcrumb-my-portal")} + +
  • +
  • + + {t("common:breadcrumb-address-search")} + +
  • +
  • + {t( + "common:breadcrumb-address-search-results" + )} +
  • + + ) : ( + "" + )} {router.pathname == "/newappeal" ? ( <>
  • @@ -433,6 +530,124 @@ const Breadcrumbs = (props) => { ) : ( "" )} + + {router.pathname == "/case/id/[incident]" ? ( + <> +
  • + + {t("common:breadcrumb-address-search")} + +
  • +
  • + { + // spinnerState(); + router.back(); + }} + className="govuk-breadcrumbs__link" + > + {t( + "common:breadcrumb-address-search-results" + )} + +
  • +
  • + {t("common:breadcrumb-case-reference")}:{" "} + { + props.props.currentView.caseReference + .currentReference + } +
  • + + ) : ( + "" + )} + {router.pathname == "/myportal/case/id/[incident]" ? ( + <> + {" "} +
  • + + {t("common:breadcrumb-my-portal")} + +
  • +
  • + + {t("common:breadcrumb-address-search")} + +
  • +
  • + { + // spinnerState(); + router.back(); + }} + className="govuk-breadcrumbs__link" + > + {t( + "common:breadcrumb-address-search-results" + )} + +
  • +
  • + {t("common:breadcrumb-case-reference")}:{" "} + { + props.props.currentView.caseReference + .currentReference + } +
  • + + ) : ( + "" + )} {router.pathname == "/myportal/dnsapplications" ? ( <> {" "} diff --git a/components/elements/index.js b/components/elements/index.js index eb743b3e..54c886a6 100644 --- a/components/elements/index.js +++ b/components/elements/index.js @@ -1419,7 +1419,6 @@ export const FieldsTranslations = (label) => { ? jsonpath('$..[?(@.value=="' + label + '")].value_cy', formObj) : label; - console.log(label, labelTrans); return labelTrans; }; diff --git a/components/footer.js b/components/footer.js index 3a97f47f..75ea5f4a 100644 --- a/components/footer.js +++ b/components/footer.js @@ -40,8 +40,17 @@ export default function Footer(props) { } }; + const origin = + typeof window !== "undefined" && window.location.origin + ? window.location.origin + : ""; + + const URL = `${origin}`; + const shareBodyStr = - t("common:service-home-url") + + // t("common:service-home-url") + + URL + + (locale == "cy" ? "/cy" : "") + (router.route == "/case" || router.route == "/dnsdetails" || router.route == "/myportal/case" diff --git a/components/homepage/casesearch.js b/components/homepage/casesearch.js index c3e34250..9585ea9b 100644 --- a/components/homepage/casesearch.js +++ b/components/homepage/casesearch.js @@ -105,11 +105,6 @@ let CaseSearch = (props) => { { {t("home:casesearch-card-button")} + + + {t("common:breadcrumb-address-search")} + + {router.locale == "cy" ? " neu " : " or "} (value) => + value || typeof value === "number" ? undefined : errorMsg; + +export const minLength = (errorMsg) => (value) => + value && value.length < 3 + ? errorMsg //`Must be ${min} characters or more` + : undefined; + +export const leastOneValue = (values, errorMsg) => (value) => + value ? console.log(values) : errorMsg; + +const validate = (values) => { + const errors = {}; + + if (values.appellantname) { + if ( + !( + values.addressline1 != null || + values.town != null || + values.county != null || + values.postcode != null + ) + ) { + errors.appellantname = + document.documentElement.lang == "cy" + ? "Angen rhan o'r cyfeiriad i chwilio gydag enw" + : "Need part of the address to search with a name"; + } + } + + return errors; +}; + +const RenderTextfield = ({ + id, + className, + rows, + datafieldname, + name, + label, + input, + hint1, + hint2, + hint3, + meta: { touched, error }, + ...custom +}) => { + let { t } = useTranslation(); + + return ( + <> +
    +
    + +
    + +
    + + {touched && error && ( + + + Error: + {" "} + {error} + + )} +
    +
    + + ); +}; + +let AddressSearch = (props) => { + let { t } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + + const { + LPAData, + onSubmit, + handleSubmit, + myportal, + error, + pristine, + reset, + submitting, + } = props; + + const onHandleSubmit = (values) => { + event.preventDefault(); + //spinnerState(); + + var searchString = ""; + + searchString += + values.appellantname != null + ? "appellantname=" + values.appellantname + "&" + : ""; + + searchString += + values.addressline1 != null + ? "addressline1=" + values.addressline1.trim() + "&" + : ""; + + searchString += values.town != null ? "town=" + values.town + "&" : ""; + + searchString += + values.county != null ? "county=" + values.county + "&" : ""; + + searchString += + values.postcode != null ? "postcode=" + values.postcode + "&" : ""; + + searchString = "?" + searchString.slice(0, -1); + + console.log(searchString); + + router.replace( + router.locale == "cy" + ? (myportal == true ? "/fymhorth" : "") + + "/canlyniadaucyfeiriadau" + + searchString + : (myportal == true ? "/myportal" : "") + + "/addresssearchresults" + + searchString + ); + }; + + return ( + <> +
    +
    +
    +
    +
    +
    +
    + +

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

    +
    + +
    + + + + + + +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + + ); +}; + +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("addressSearchForm"); // <-- same as form name + +export default connect( + mapStateToProps, + mapDispatchToProps +)( + reduxForm({ + form: "addressSearchForm", + destroyOnUnmount: false, + validate, + })(AddressSearch) +); diff --git a/components/myportal/searchcases.js b/components/myportal/searchcases.js index cd556f0b..f9e378c8 100644 --- a/components/myportal/searchcases.js +++ b/components/myportal/searchcases.js @@ -95,62 +95,73 @@ let CaseSearch = (props) => { }); }; - return <> -
    -
    -
    -

    - {t("myportal:searchcases-card-title")} -

    + return ( + <> +
    + +
    +

    + {t("myportal:searchcases-card-title")} +

    - + -
    - +
    + +
    + + {t("common:breadcrumb-address-search")} + + {router.locale == "cy" ? " neu " : " or "} + + {t("myportal:searchcases-card-advanced-link")} +
    - - - {t("myportal:searchcases-card-advanced-link")} - - -
    - -
    - ; + +
    + + ); }; const mapStateToProps = (state) => { diff --git a/components/search/addresssearch.js b/components/search/addresssearch.js new file mode 100644 index 00000000..f3bb6575 --- /dev/null +++ b/components/search/addresssearch.js @@ -0,0 +1,317 @@ +import Link from "next/link"; +import { useState } from "react"; +import { useRouter } from "next/router"; +import useTranslation from "next-translate/useTranslation"; +import { reduxForm, formValueSelector, Field } from "redux-form"; +import { useDispatch, useSelector, shallowEqual, connect } from "react-redux"; +import { JSONPath as jsonpath } from "jsonpath-plus"; +import data from "../../data/collections.json"; + +import transLookup from "../../data/lookuptranslations.json"; +import { values } from "lodash"; + +const required = (errorMsg) => (value) => + value || typeof value === "number" ? undefined : errorMsg; + +export const minLength = (errorMsg) => (value) => + value && value.length < 3 + ? errorMsg //`Must be ${min} characters or more` + : undefined; + +export const leastOneValue = (values, errorMsg) => (value) => + value ? console.log(values) : errorMsg; + +const validate = (values) => { + const errors = {}; + + console.log(document.documentElement.lang); + + if (values.appellantname) { + if ( + !( + values.addressline1 != null || + values.town != null || + values.county != null || + values.postcode != null + ) + ) { + errors.appellantname = + document.documentElement.lang == "cy" + ? "Angen rhan o'r cyfeiriad i chwilio gydag enw" + : "Need part of the address to search with a name"; + } + } + + return errors; +}; + +const RenderTextfield = ({ + id, + className, + rows, + datafieldname, + name, + label, + input, + hint1, + hint2, + hint3, + meta: { touched, error }, + ...custom +}) => { + let { t } = useTranslation(); + + return ( + <> +
    +
    + +
    + +
    + + {touched && error && ( + + + Error: + {" "} + {error} + + )} +
    +
    + + ); +}; + +let AddressSearch = (props) => { + let { t } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + + const { + LPAData, + onSubmit, + handleSubmit, + myportal, + error, + pristine, + reset, + submitting, + } = props; + + const onHandleSubmit = (values) => { + event.preventDefault(); + //spinnerState(); + + var searchString = ""; + + searchString += + values.appellantname != null + ? "appellantname=" + values.appellantname + "&" + : ""; + + searchString += + values.addressline1 != null + ? "addressline1=" + values.addressline1.trim() + "&" + : ""; + + searchString += values.town != null ? "town=" + values.town + "&" : ""; + + searchString += + values.county != null ? "county=" + values.county + "&" : ""; + + searchString += + values.postcode != null ? "postcode=" + values.postcode + "&" : ""; + + searchString = "?" + searchString.slice(0, -1); + + console.log(searchString); + + router.replace( + router.locale == "cy" + ? (myportal == true ? "/fymhorth" : "") + + "/canlyniadaucyfeiriadau" + + searchString + : (myportal == true ? "/myportal" : "") + + "/addresssearchresults" + + searchString + ); + }; + + return ( + <> +
    +
    +
    +
    +
    +
    +
    + +

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

    +
    + +
    + + + + + + + + +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + + ); +}; + +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("addressSearchForm"); // <-- same as form name + +export default connect( + mapStateToProps, + mapDispatchToProps +)( + reduxForm({ + form: "addressSearchForm", + destroyOnUnmount: false, + validate, + })(AddressSearch) +); diff --git a/components/search/addresssearchresults.js b/components/search/addresssearchresults.js new file mode 100644 index 00000000..24e82054 --- /dev/null +++ b/components/search/addresssearchresults.js @@ -0,0 +1,900 @@ +import Link from "next/link"; +import { useRouter } from "next/router"; +import useTranslation from "next-translate/useTranslation"; +import { + currentViewActionTypes, + setCurrentReference, +} from "../../store/currentView/action"; +import { connect } from "react-redux"; +import { JSONPath as jsonpath } from "jsonpath-plus"; +import _, { result } from "lodash"; +import transLookup from "../../data/lookuptranslations.json"; +import { + getBasicSearchPaged, + getSearchDocumentDetails, + getBasicSearchDetailsPaged, + getAdvancedSearchPaged, +} from "../../actions"; +import data from "../../data/collections.json"; +import { useCallback, useState } from "react"; + +import { + setSearchResults, + setSearchDetails, +} from "../../store/searchOutput/action"; +import { setLoggedInUserId } from "../../store/accountDetails/action"; +import { + setWatchedCases, + setWatchedCasesDetails, +} from "../../store/watchedCases/action"; +import { useEffect } from "react"; +import { parseCookies, setCookie, destroyCookie } from "nookies"; + +import PaginationControl from "./pagination"; +import { + getSearchDetailsPaged, + getFormCollection, + getFormCollectionByID, +} from "../utils"; + +import { + createWatchedCases, + getWatchedCasesProxy, + getPortalModuleDetailsProxy, + deleteWatchedCases, +} from "../../actions"; +import { useSession, signIn, signOut } from "next-auth/react"; + +const SearchResults = (props) => { + const { + searchString, + searchResultsObj, + searchDetailsObj, + setCurrentReference, + setSearchResults, + setSearchDetails, + advancedSearch, + myportal, + watchedCases, + setWatchedCases, + setWatchedCasesDetails, + isLinkedCase, + showLoginCheck, + } = props; + let { t } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + const { data: session } = useSession(); + + let [resultsArr, setResultsArr] = useState(searchResultsObj.value || []); + + const [currentPage, setCurrentPage] = useState(1); + const [searchLoaded, setSearchLoaded] = useState(false); + const [showSpinnerState, setShowSpinnerState] = useState(false); + const [selectedOption, setSelectedOption] = useState(10); + const [orderByState, setOrderbyState] = useState("createdon"); + const [fieldSortState, setfieldSortState] = useState("asc"); + const [loginToWatch, setLoginToWatch] = useState("true"); + + let spinnerState = () => { + showSpinnerState == true + ? setShowSpinnerState(false) + : setShowSpinnerState(true); + }; + + const cookies = parseCookies(); + + const selectWatchedCase = (loggedInUser, incidentID, appealType) => { + let updateBody = { + "pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")", + "pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")", + "pinswg_appealcasetype": +appealType, + }; + + createWatchedCases(updateBody) + .then((data) => data) + .then(() => { + getWatchedCasesProxy(props.accountDetails.loggedinUserId).then( + (data) => { + setWatchedCases(data), + getDetails(data, "myWatchedCases").then((data) => { + setWatchedCasesDetails(data); + }); + } + ); + }); + }; + + const isWatchedCase = (whichIncident) => { + let isWatched = jsonpath( + "$..value[?(@._pinswg_watchedcase_value=='" + whichIncident + "')]", + watchedCases + ); + + return isWatched; + }; + + const deleteItem = (caseID, topThreeType) => { + let cookies = parseCookies(); + topThreeType == "watchedCases" && + deleteWatchedCases(caseID) + .then((data) => data) + .then(() => { + getWatchedCasesProxy( + props.accountDetails.loggedinUserId + ).then((data) => { + setWatchedCases(data), + getDetails(data, "myWatchedCases").then((data) => { + setWatchedCasesDetails(data); + }); + }); + }); + }; + + const getDetails = (resultsObj, detailsType) => { + // console.log(resultsObj); + let detailsArr = []; + resultsObj = resultsObj.value; + const detailsObj = resultsObj.map((searchDetail, index) => { + if (searchDetail.pinswg_appealcasetype == null) { + console.log( + detailsType != "myWatchedCases" + ? searchDetail.ticketnumber + : searchDetail[ + "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + ] + ); + } else { + detailsArr.push( + getPortalModuleDetailsProxy( + getFormCollectionByID( + searchDetail.pinswg_appealcasetype + ).LogicalCollectionName, + detailsType != "myWatchedCases" + ? searchDetail.ticketnumber + : searchDetail[ + "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + ] + ) + ); + } + }); + //console.log(detailsArr); + return Promise.all(detailsArr); + }; + + const indexOfLastRecord = currentPage * selectedOption; + const indexOfFirstRecord = indexOfLastRecord - selectedOption; + + const ResultsView = (resultsArr) => { + var resultsArrPaged = resultsArr.slice( + indexOfFirstRecord, + indexOfLastRecord + ); + return ( + <> +
    +
    +
    + +
    +
    + {t("search:searchresults-site-address-label")} +
    +
    + +
    +
    + +
    +
    + +
    +
    + {/* {t("search:searchresults-status-label")} */} + +
    + +
    +
    + {showSpinnerState == true ? ( +
    +
    + {t("common:spinner-fetching-data")} + { +
    +
    + ) : ( + resultsArrPaged.map((item, key) => { + let detailsObj = jsonpath( + '$..value[?(@.pinswg_name=="' + + item.pinswg_name + + '")]', + searchDetailsObj + ); + detailsObj = detailsObj[0]; + return ( +
    +
    + { + // setCurrentReference({ + // "ticketnumber": + // item.ticketnumber, + // "currentReference": + // item.title, + // "currentType": + // "searchResultsObj", + // "incidentid": + // item.incidentid, + // "appealType": + // item.pinswg_appealcasetype, + // "showLoginCheck": + // props.showLoginCheck, + // }); + // }} + > + + {t( + "search:searchresults-case-reference-label" + )} + : + + {item.pinswg_name} + +
    +
    + + {t( + "search:searchresults-site-address-label" + )} + : + + {_.has( + detailsObj, + "pinswg_projectlocation" + ) + ? detailsObj.pinswg_projectlocation != + null + ? detailsObj.pinswg_projectlocation.indexOf( + ";" + ) < 0 + ? detailsObj.pinswg_projectlocation + : router.locale == "cy" + ? detailsObj.pinswg_projectlocation.split( + ";" + )[1] + : detailsObj.pinswg_projectlocation.split( + ";" + )[0] + : "" + : ""} + {_.has( + detailsObj, + "pinswg_siteaddressline1" + ) + ? detailsObj.pinswg_siteaddressline1 + : ""} + {_.has( + detailsObj, + "pinswg_addressline1" + ) + ? detailsObj.pinswg_addressline1 + : ""} + {/* {detailsObj.pinswg_siteaddressline1 != + null &&
    } */} + {_.has( + detailsObj, + "pinswg_siteaddressline1" + ) && + detailsObj.pinswg_siteaddressline1 != + null &&
    } + {_.has( + detailsObj, + "pinswg_addressline1" + ) && + detailsObj.pinswg_addressline1 != + null &&
    } + {_.has( + detailsObj, + "pinswg_siteaddressline1" + ) + ? detailsObj.pinswg_siteaddressline2 + : ""} + {_.has( + detailsObj, + "pinswg_addressline1" + ) + ? detailsObj.pinswg_addressline2 + : ""} + {_.has( + detailsObj, + "pinswg_siteaddressline2" + ) && + detailsObj.pinswg_siteaddressline2 != + null &&
    } + {_.has( + detailsObj, + "pinswg_addressline2" + ) && + detailsObj.pinswg_addressline2 != + null &&
    } + {_.has( + detailsObj, + "pinswg_siteaddresstown" + ) + ? detailsObj.pinswg_siteaddresstown + : ""} + {_.has(detailsObj, "pinswg_addresstown") + ? detailsObj.pinswg_addresstown + : ""} + {_.has( + detailsObj, + "pinswg_siteaddresstown" + ) && + detailsObj.pinswg_siteaddresstown != + null &&
    } + {_.has( + detailsObj, + "pinswg_addresstown" + ) && + detailsObj.pinswg_addresstown != + null &&
    } + {_.has( + detailsObj, + "pinswg_siteaddresscounty" + ) + ? detailsObj.pinswg_siteaddresscounty + : ""} + {_.has( + detailsObj, + "pinswg_addresscounty" + ) + ? detailsObj.pinswg_addresscounty + : ""} + {_.has( + detailsObj, + "pinswg_siteaddresscounty" + ) && + detailsObj.pinswg_siteaddresscounty != + null &&
    } + {_.has( + detailsObj, + "pinswg_addresscounty" + ) && + detailsObj.pinswg_addresscounty != + null &&
    } + {_.has( + detailsObj, + "pinswg_siteaddresspostcode" + ) + ? detailsObj.pinswg_siteaddresspostcode + : ""} + {_.has(detailsObj, "pinswg_postcode") + ? detailsObj.pinswg_postcode + : ""} +
    +
    + + {t( + "search:searchresults-applicant-label" + )} + : + + {_.has(detailsObj, [ + "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue", + ]) + ? detailsObj[ + "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" + ] + : ""} +
    +
    + + {t( + "search:searchresults-authority-label" + )} + : + + {_.has(item, [ + "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue", + ]) + ? router.locale == "cy" + ? jsonpath( + '$..[?(@.value=="' + + item[ + "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" + ] + + '")].value_cy', + transLookup + ) + : item[ + "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" + ] || "N/A" + : ""} +
    +
    + + {t( + "search:searchresults-case-type-label" + )} + : + + {router.locale == "cy" + ? jsonpath( + '$..[?(@.value=="' + + item[ + "pinswg_appealType" + ] + + '")].value_cy', + transLookup + ) + : item["pinswg_appealType"] || + "N/A"} +
    +
    + + {t( + "search:searchresults-status-label" + )} + : + + + {router.locale == "cy" + ? jsonpath( + '$..[?(@.value=="' + + item[ + "statuscode@OData.Community.Display.V1.FormattedValue" + ] + + '")].value_cy', + transLookup + ) + : item[ + "statuscode@OData.Community.Display.V1.FormattedValue" + ] || "N/A"} +
    + {myportal == true && ( +
    + {isWatchedCase(item.incidentid) + .length > + 0 == + true ? ( + + ) : ( + + )} +
    + )} + + {(showLoginCheck == "true" || + showLoginCheck == true) && + !session && ( +
    + + {t( + "case:watch-this-case-link" + )} + + + +
    + )} +
    + ); + }) + )} +
    + + + + ); + }; + + const pagesCount = Math.ceil(searchResultsObj["@odata.count"] / 10); + + const getSearchPageResults = useCallback( + (pageNumber, orderBy, fieldSort) => { + // setSearchDetails(data); + + setCurrentPage(pageNumber); + + resultsArr = _.sortBy(resultsArr, [ + function (o) { + return o[orderBy]; + }, + ]); + + fieldSort == "desc" && resultsArr.reverse(); + + setShowSpinnerState(false); + setResultsArr(resultsArr); + + console.log( + "================================\n", + resultsArr, + "sort done", + "\n=================================\n" + ); + }, + [] + ); + + const sortDataBy = (whichField) => { + setOrderbyState(whichField); + setfieldSortState("asc"); + + setShowSpinnerState(true); + console.log( + "================================\n", + "sort start", + "\n=================================\n" + ); + getSearchPageResults(1, whichField, fieldSortState); + whichField == orderByState + ? fieldSortState == "desc" + ? setfieldSortState("asc") + : setfieldSortState("desc") + : setfieldSortState("asc"); + setCurrentPage(1); + }; + + useEffect(() => { + const selectWatchedCase = (loggedInUser, incidentID, appealType) => { + let updateBody = { + "pinswg_WatchedCase@odata.bind": + "/incidents(" + incidentID + ")", + "pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")", + "pinswg_appealcasetype": +appealType, + }; + + createWatchedCases(updateBody) + .then((data) => data) + .then(() => { + getWatchedCasesProxy( + props.accountDetails.loggedinUserId + ).then((data) => { + setWatchedCases(data), + getDetails(data, "myWatchedCases").then((data) => { + setWatchedCasesDetails(data); + }); + }); + }); + }; + + // if (searchLoaded) { + // if (selectedOption) { + // setShowSpinnerState(true); + // getSearchPageResults(1, orderByState, fieldSortState); + // } + // } else { + // setSearchLoaded(true); + // } + if (loginToWatch && router.query.hasOwnProperty("toWatch")) { + console.log("am in here"); + let now = new Date(); + let expDate = new Date(now); + + expDate.setDate(now.getDate() + 1); + + setLoggedInUserId(props.accountDetails.loggedinUserId); + setCookie(null, "pinsUser", props.accountDetails.loggedinUserId, { + path: "/", + expires: expDate, + }); + selectWatchedCase( + props.accountDetails.loggedinUserId, + router.query.toWatch.split("_")[0], + router.query.toWatch.split("_")[1] + ); + getSearchPageResults(1, orderByState, fieldSortState); + setLoginToWatch(false); + } else { + //console.log("or am in here"); + setLoginToWatch(false); + } + }, [ + selectedOption, + fieldSortState, + orderByState, + searchLoaded, + loginToWatch, + setWatchedCases, + getSearchPageResults, + setWatchedCasesDetails, + props.accountDetails.loggedinUserId, + router.query, + ]); + + return ( + <> +
    +
    +

    + {isLinkedCase + ? t("search:searchresults-title-label-linked-case") + : t("search:searchresults-title-label")} +

    + + {!isLinkedCase && ( +

    + {resultsArr.length > 200 + ? t("search:searchresults-max-count-label") + : t("search:searchresults-count-label", { + count: searchResultsObj["@odata.count"], + })} + . + {advancedSearch != true ? ( + <> + + {t( + "search:searchresults-case-count-label" + )}{" "} + {" "} + "{searchString}" + + + ) : ( + "" + )} +

    + )} + {searchResultsObj["@odata.count"] > 5 && ( +
    +
    + +
    +
    + )} + {resultsArr.length > 0 ? ( + ResultsView(resultsArr) + ) : ( +
    +
    +

    + {t("search:searchresults-no-records-label")} +

    +
    +
    + )} +
    +
    + + ); +}; + +const mapDispatchToProps = (dispatch) => { + return { + setCurrentReference: (currentReference) => { + dispatch(setCurrentReference(currentReference)); + }, + setSearchResults: (searchResultsObj) => { + dispatch(setSearchResults(searchResultsObj)); + }, + setSearchDetails: (searchDetailsObj) => { + dispatch(setSearchDetails(searchDetailsObj)); + }, + setWatchedCases: (watchedCases) => { + dispatch(setWatchedCases(watchedCases)); + }, + setWatchedCasesDetails: (watchedCasesDetails) => { + dispatch(setWatchedCasesDetails(watchedCasesDetails)); + }, + // setCurrentPage: (currentPage) => { + // dispatch(setCurrentPage(currentPage)); + // }, + }; +}; + +const mapStateToProps = (state) => { + return { + // currentView: state.currentView, + accountDetails: state.accountDetails, + // search: state.search, + // searchResultsObj: state.searchResultsObj, + }; +}; +export default connect(mapStateToProps, mapDispatchToProps)(SearchResults); diff --git a/components/utils/index.js b/components/utils/index.js index ff458e05..2159127f 100644 --- a/components/utils/index.js +++ b/components/utils/index.js @@ -29,6 +29,14 @@ export const getFormCollectionByID = (appealTypeID) => { return collectionName[0]; }; +export const getFormIDByLogicalName = (appealTypeLogicalName) => { + const collectionName = jsonpath( + "$..[?(@.LogicalName =='" + appealTypeLogicalName + "')]", + data + ); + return collectionName[0]; +}; + export const getPickListLabel = (data, picklistType, picklistID) => { const pickListData = jsonpath( "$..[?(@.LogicalName=='" + picklistType + "')]", @@ -63,6 +71,7 @@ export const getSearchDetails = (searchResultsObj) => { //console.log(searchResultsObj); let detailsArr = []; + searchResultsObj = searchResultsObj.value; const detailsObj = searchResultsObj.map((searchDetail, index) => { if (searchDetail.pinswg_appealcasetype == null) { diff --git a/data/formsxml/commercialappealcas.xml b/data/formsxml/commercialappealcas.xml index 75b51a05..194ee723 100644 --- a/data/formsxml/commercialappealcas.xml +++ b/data/formsxml/commercialappealcas.xml @@ -163,7 +163,7 @@ - + diff --git a/data/formsxml/enforcementnoticeappeals174.xml b/data/formsxml/enforcementnoticeappeals174.xml index c65f3211..32e5ea2b 100644 --- a/data/formsxml/enforcementnoticeappeals174.xml +++ b/data/formsxml/enforcementnoticeappeals174.xml @@ -755,7 +755,7 @@ - + diff --git a/data/formsxml/householderappealhas.xml b/data/formsxml/householderappealhas.xml index d94d647d..4430b5b7 100644 --- a/data/formsxml/householderappealhas.xml +++ b/data/formsxml/householderappealhas.xml @@ -148,7 +148,7 @@ - + diff --git a/data/formsxml/planningappeals78.xml b/data/formsxml/planningappeals78.xml index 94984b94..17c8b2d5 100644 --- a/data/formsxml/planningappeals78.xml +++ b/data/formsxml/planningappeals78.xml @@ -154,7 +154,7 @@ - + diff --git a/i18n.js b/i18n.js index 79293dfd..66ee181c 100644 --- a/i18n.js +++ b/i18n.js @@ -28,12 +28,18 @@ module.exports = { "/advancedsearch": ["search", "myportal"], "/advancedsearchresults": ["search"], "/searchresults": ["search", "case"], + "/addresssearch": ["search", "case", "myportal"], + "/addresssearchresults": ["search", "case", "myportal"], "/viewall": ["search"], "/case": ["case"], "/case/*": ["case"], "/case/[ticketnumber]": ["case"], + "/case/id/[incident]": ["case"], "/myportal/representation": ["case", "myrepresentations", "common"], "/myportal/error": ["myportal", "common"], + "/myportal/case/id/[incident]": ["case"], + "/myportal/addresssearch": ["search", "case", "myportal"], + "/myportal/addresssearchresults": ["search", "case", "myportal"], "/newappeal": ["newappeal"], "/newappeal/*": ["newappeal"], "/newappeal/selectappeal": ["newappeal"], diff --git a/locales/cy/common.json b/locales/cy/common.json index 0df2ce08..8160859c 100644 --- a/locales/cy/common.json +++ b/locales/cy/common.json @@ -47,6 +47,8 @@ "breadcrumb-search-results": "Canlyniadau chwilio", "breadcrumb-advanced-search": "Chwilio uwch", "breadcrumb-advanced-search-results": "Canlyniadau chwilio uwch", + "breadcrumb-address-search": "Chwiliad cyfeiriad", + "breadcrumb-address-search-results": "Cyfeiriad canlyniadau chwilio", "breadcrumb-my-portal": "Fy mhorth", "breadcrumb-new-appeal": "Apêl newydd", "breadcrumb-case-reference": "Cyfeirnod Achos", diff --git a/locales/cy/search.json b/locales/cy/search.json index 6ad735c1..a246b5c4 100644 --- a/locales/cy/search.json +++ b/locales/cy/search.json @@ -25,6 +25,7 @@ "case-type-option-11": "Apeliadau Rhwymedigaethau Cynllunio", "case-type-option-12": "Apeliadau cynllunio adeiladau rhestredig ac ardal gadwraeth", "advanced-search-title-label": "Chwiliad manwl", + "address-search-title-label": "Chwilio am achosion yn ôl cyfeiriad", "applicant-label": "Apelydd/Ymgeisydd", "other-party-label": "Parti Arall", "hearing-date-label": "Dyddiad y Gwrandawaid/Ymchwiliad", @@ -64,5 +65,6 @@ "searchresults-no-records-label": "Nid oes unrhyw gofnodion", "searchresults-show-records-label-a": "Dangoswch", "searchresults-show-records-label-b": "cofnod", - "searchresults-created-on-label": "Creu ymlaen" + "searchresults-created-on-label": "Creu ymlaen", + "address-search-appellant-validation": "Angen rhan o'r cyfeiriad i chwilio gydag enw" } \ No newline at end of file diff --git a/locales/en/common.json b/locales/en/common.json index 927e916a..78c05b5b 100644 --- a/locales/en/common.json +++ b/locales/en/common.json @@ -47,6 +47,8 @@ "breadcrumb-search-results": "Search results", "breadcrumb-advanced-search": "Advanced search", "breadcrumb-advanced-search-results": "Advanced search results", + "breadcrumb-address-search": "Address search", + "breadcrumb-address-search-results": "Address search results", "breadcrumb-my-portal": "My portal", "breadcrumb-new-appeal": "New appeal", "breadcrumb-case-reference": "Case Reference", diff --git a/locales/en/search.json b/locales/en/search.json index d42f5bc3..4748ee53 100644 --- a/locales/en/search.json +++ b/locales/en/search.json @@ -25,6 +25,7 @@ "case-type-option-11": "Planning Obligation Appeals", "case-type-option-12": "Planning Listed Building and Conservation Area Appeals", "advanced-search-title-label": "Advanced search", + "address-search-title-label": "Search for cases by address", "applicant-label": "Appellant/Applicant", "other-party-label": "Other Party", "hearing-date-label": "Hearing/Enquiry date", @@ -64,5 +65,6 @@ "searchresults-no-records-label": "There are no records", "searchresults-show-records-label-a": "Show", "searchresults-show-records-label-b": "records", - "searchresults-created-on-label": "Created on" + "searchresults-created-on-label": "Created on", + "address-search-appellant-validation": "Need part of the address to search with a name" } \ No newline at end of file diff --git a/next.config.js b/next.config.js index a7d1ed26..a9453122 100644 --- a/next.config.js +++ b/next.config.js @@ -103,18 +103,34 @@ module.exports = { source: "/chwiliouwch", destination: "/advancedsearch", }, + { + source: "/chwiliadcyfeiriadau", + destination: "/addresssearch", + }, { source: "/fymhorth/chwiliouwch", destination: "/myportal/advancedsearch", }, + { + source: "/fymhorth/chwiliadcyfeiriadau", + destination: "/myportal/addresssearch", + }, { source: "/canlyniadauchwiliouwch", destination: "/advancedsearchresults", }, + { + source: "/canlyniadaucyfeiriadau", + destination: "/addresssearchresults", + }, { source: "/fymhorth/canlyniadauchwiliouwch", destination: "/myportal/advancedsearchresults", }, + { + source: "/fymhorth/canlyniadaucyfeiriadau", + destination: "/myportal/addresssearchresults", + }, { source: "/fymhorth", destination: "/myportal", @@ -123,10 +139,18 @@ module.exports = { source: "/achos", destination: "/case", }, + { + source: "/achos/id/:slug", + destination: "/case/id/:slug", + }, { source: "/fymhorth/achos", destination: "/myportal/case", }, + { + source: "/fymhorth/achos/id/:slug", + destination: "/myportal/case/id/:slug", + }, { source: "/fymhorth/gweldpopeth", destination: "/myportal/viewall", diff --git a/pages/addresssearch.js b/pages/addresssearch.js new file mode 100644 index 00000000..cacc729e --- /dev/null +++ b/pages/addresssearch.js @@ -0,0 +1,130 @@ +//import fs from "fs"; +import _ from "lodash"; +import useTranslation from "next-translate/useTranslation"; +import Head from "next/head"; +import { useRouter } from "next/router"; +import { connect } from "react-redux"; +import { getAppealsTypes, getLPA } from "../actions"; +import Breadcrumbs from "../components/breadcrumbs"; +import CookieBanner from "../components/cookieBanner"; +import CRMError from "../components/crmError"; +import Footer from "../components/footer"; +import Header from "../components/header"; +import Search from "../components/addresssearch"; +import { setAppealType } from "../store/appealType/action"; +import { setLPA } from "../store/lpa/action"; +import { wrapper } from "../store/store"; + +const Home = (props) => { + const { footerLinks, pages } = props; + let { t, lang } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + const { appealtypes } = router.query; + + var hasError = + _.has(props.LPAData.LPAData, "errorCode") || + _.has(props.appealType.appealType, "errorCode") + ? true + : false; + + return ( +
    + + + {t("search:page-title")} - {t("common:service-name")} + + {/* Language by default is EN, if multilingual site this will need updated */} + <> + + + {/* If they have a Twitter Handle, include the meta details below */} + + + + + + + + + + + + + + + + +
    + +
    +
    + + {hasError ? ( + + ) : ( + + )} +
    +
    +
    +
    + ); +}; + +const mapStateToProps = (state) => { + return { + search: state.search, + searchResultsObj: state.searchResultsObj, + formData: state.formData, + appealType: state.appealType, + LPAData: state.LPAData, + //form: state.form, + accountDetails: state.accountDetails, + }; +}; + +export default connect(mapStateToProps)(Home); diff --git a/pages/addresssearchresults.js b/pages/addresssearchresults.js new file mode 100644 index 00000000..179c94cf --- /dev/null +++ b/pages/addresssearchresults.js @@ -0,0 +1,160 @@ +import useTranslation from "next-translate/useTranslation"; +import Head from "next/head"; +import { useRouter } from "next/router"; +import { connect } from "react-redux"; +import { + getAddressSearch, + getIncidentbyID, + getIsPublishedbyID, +} from "../actions"; +import Breadcrumbs from "../components/breadcrumbs"; +import CookieBanner from "../components/cookieBanner"; +import Footer from "../components/footer"; +import Header from "../components/header"; +import SearchResults from "../components/addresssearchresults"; +import { getSearchDetails } from "../components/utils"; +import { setSearch } from "../store/search/action"; +import { + setSearchDetails, + setSearchResults, +} from "../store/searchOutput/action"; +import { setShowReps } from "../store/currentView/action"; + +import { wrapper } from "../store/store"; + +const Home = (props) => { + const { footerLinks, pages } = props; + let { t, lang } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + const { appealtypes } = router.query; + + return ( +
    + + + {t("search:page-title")} - {t("common:service-name")} + + <> + + + {/* If they have a Twitter Handle, include the meta details below */} + + + + + + + + + + + + + + + + +
    + +
    +
    + + +
    +
    +
    +
    + ); +}; + +export const getServerSideProps = wrapper.getServerSideProps( + (store) => + async ({ query, req, res }) => { + const searchResultsObj = await getAddressSearch(query); + const searchDetailsObj = searchResultsObj; + const showLoginCheck = process.env.SHOWLOGIN || false; + const showReps = process.env.SHOWREPRESENTATIONS || false; + store.dispatch(setShowReps(showReps, showLoginCheck)); + + // store.dispatch(setSearchResults(searchResultsObj)); + // store.dispatch(setSearchDetails(searchDetailsObj)); + store.dispatch(setSearch(Object.entries(query))); + + return { + props: { + searchResultsObj: { + searchResultsObj: searchResultsObj, + searchDetailsObj: searchDetailsObj, + }, + currentType: "directResultsObj", + showLoginCheck: showLoginCheck, + }, + }; + } +); + +const mapStateToProps = (state) => { + return { + currentView: state.currentView, + search: state.search, + //searchResultsObj: state.searchResultsObj, + formData: state.formData, + appealType: state.appealType, + form: state.form, + myCases: state.myCases, + watchedCases: state.watchedCases, + myRepresentations: state.myRepresentations, + awaitingSubmission: state.awaitingSubmission, + }; +}; + +export default connect(mapStateToProps)(Home); diff --git a/pages/advancedsearchresults.js b/pages/advancedsearchresults.js index 4264387f..97e51b38 100644 --- a/pages/advancedsearchresults.js +++ b/pages/advancedsearchresults.js @@ -103,6 +103,7 @@ const Home = (props) => { searchString={props.search.searchString} searchResultsObj={props.searchResultsObj} advancedSearch={true} + showLoginCheck={props.showLoginCheck} />