From 5fa1c4a03f72c696247eecb510af548ac410f06b Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Wed, 22 Sep 2021 15:59:34 +0100 Subject: [PATCH] advances search on case lpa and appeal --- .env | 0 .env.local | 11 + actions/index.js | 46 ++ components/breadcrumbs.js | 58 ++ components/header.js | 3 +- components/homepage/casesearch.js | 11 +- components/search/advancedsearch.js | 1080 +++++++------------------ components/search/dnssearchresults.js | 61 +- components/search/searchresults.js | 358 ++++---- components/searchresults.js | 4 +- i18n.json | 8 +- locales/cy/common.json | 2 + locales/en/common.json | 2 + pages/advancedsearch.js | 36 +- pages/advancedsearchresults.js | 131 +++ pages/searchresults.js | 1 + 16 files changed, 824 insertions(+), 988 deletions(-) delete mode 100644 .env create mode 100644 .env.local create mode 100644 pages/advancedsearchresults.js diff --git a/.env b/.env deleted file mode 100644 index e69de29b..00000000 diff --git a/.env.local b/.env.local new file mode 100644 index 00000000..01824053 --- /dev/null +++ b/.env.local @@ -0,0 +1,11 @@ +RELAY_ROOT = https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/ +RELAYURI = "dev-pedw-ns.servicebus.windows.net" +RELAYPATH = "dev-pedw-hc" +SASKEY = "Ml0Y/S/nfRcmIrHFRkO4jNm2J3iH52TSxPiak7+E1+Y=" +SASKEYNAME = "devpedwnspolicy" + +//RELAY_ROOT = https://test-pedw-ns.servicebus.windows.net/test-pedw-hc/ +//RELAYURI = "test-pedw-ns.servicebus.windows.net" +//RELAYPATH = "test-pedw-hc" +//SASKEY = "kTLrs9UHwuW9Msc9uNfjf+89qLYT6ly80lK0zdTYJW4=" +//SASKEYNAME = "testpedwhcpolicy" diff --git a/actions/index.js b/actions/index.js index ee60e791..8734b0a6 100644 --- a/actions/index.js +++ b/actions/index.js @@ -143,6 +143,52 @@ export const getBasicDNSSearch = (searchString) => { }); }; +export const getAdvancedSearch = (searchString) => { + console.log(searchString.caseReference); + + var queryString = ""; + + queryString += + searchString.q != null + ? "contains(title, '" + searchString.q + "') " + : ""; + + queryString += + searchString.lpa != null + ? (typeof searchString.q == "undefined" ? "" : " and ") + + "_customerid_value eq " + + searchString.lpa + : ""; + queryString += + searchString.apt != null + ? (typeof searchString.q == "undefined" && + typeof searchString.lpa == "undefined" + ? "" + : " and ") + + "pinswg_appealcasetype eq " + + searchString.apt + : ""; + + console.log( + "incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=" + + queryString + + " &$count=true" + ); + return axios + .get( + WEBAPI_URL + + "incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=" + + queryString + + " &$count=true", + + azureHeaders + ) + .then((res) => res.data) + .catch((error) => { + console.log("thiserror", error); + }); +}; + export const getBasicSearchDetails = (appealType, caseReference) => { return axios .get( diff --git a/components/breadcrumbs.js b/components/breadcrumbs.js index 9c66724f..b9353e71 100644 --- a/components/breadcrumbs.js +++ b/components/breadcrumbs.js @@ -102,6 +102,38 @@ const Breadcrumbs = (props) => { ) : ( "" )} + {router.pathname == "/advancedsearch" ? ( + <> +
  • + {t("common:breadcrumb-advanced-search")} +
  • + + ) : ( + "" + )} + {router.pathname == "/advancedsearchresults" ? ( + <> + {" "} +
  • + + + {t("common:breadcrumb-advanced-search")} + + +
  • +
  • + {t("common:breadcrumb-advanced-search-results")} +
  • + + ) : ( + "" + )} {router.pathname == "/newappeal" ? ( <>
  • @@ -381,6 +413,32 @@ const Breadcrumbs = (props) => { ) : ( "" )} + {router.pathname == "/dnsdetails" ? ( + <> +
  • + + + {t("dnsCommon:service-name")} + + +
  • +
  • + {t("common:breadcrumb-case-reference")}:{" "} + { + props.props.currentView.caseReference + .currentReference + } +
  • + + ) : ( + "" + )} {router.pathname == "/dns/application-process" ? ( <>
  • diff --git a/components/header.js b/components/header.js index 51b3417a..0f351435 100644 --- a/components/header.js +++ b/components/header.js @@ -20,7 +20,8 @@ const Header = (props) => { "/dns/application-view", "/searchresults", "/case", - "advancedsearch", + "/advancedsearch", + "/advancedsearchresults", "/dnsapplications", "/dnsdetails", ]; diff --git a/components/homepage/casesearch.js b/components/homepage/casesearch.js index 9c58d970..6698d0c3 100644 --- a/components/homepage/casesearch.js +++ b/components/homepage/casesearch.js @@ -118,7 +118,16 @@ let CaseSearch = (props) => { const mapStateToProps = (state) => { return { - ...state, + 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, }; }; diff --git a/components/search/advancedsearch.js b/components/search/advancedsearch.js index 13fc9b43..64d97d3b 100644 --- a/components/search/advancedsearch.js +++ b/components/search/advancedsearch.js @@ -2,8 +2,12 @@ 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 from "jsonpath"; +import data from "../../data/collections.json"; -export default function AdvancedSearch(props) { +let AdvancedSearch = (props) => { let { t } = useTranslation(); const [query, setQuery] = useState(""); @@ -22,9 +26,237 @@ export default function AdvancedSearch(props) { const router = useRouter(); const { locale } = router; + + const { LPAData, onSubmit, handleSubmit } = 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 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 required = (value) => (value ? undefined : "Required"); + + const getFormCollection = (formtype) => { + formtype = + "pinswg_" + + (formtype.length > 39 ? formtype.slice(0, 39) : formtype); + + const collectionName = jsonpath.query( + data, + "$..[?(@.LogicalName=='" + formtype + "')].UrlName" + ); + //console.log(collectionName[0]); + return collectionName[0]; + }; + + const onHandleSubmit = (values) => { + event.preventDefault(); + console.log(values); + // var appTypeCollection = values.appealTypes.split(",")[1]; + + // appTypeCollection = getFormCollection( + // appTypeCollection.length > 39 + // ? appTypeCollection.slice(0, 39) + // : appTypeCollection + // ); + + var searchString = ""; + + searchString += values.caseRef != null ? "?q=" + values.caseRef : ""; + 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("/advancedsearchresults" + searchString, null, { + shallow: true, + }); + }; + return (
    -
    +
    @@ -38,18 +270,42 @@ export default function AdvancedSearch(props) {
    -
    + + +

    @@ -124,785 +380,11 @@ export default function AdvancedSearch(props) { />

    -
    - - -
    -
    - - -
    -
    - - -
    -
    -
    -
    -
    -
    - -

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

    -
    -
    - - -
    -
    - - -
    -
    -
    - {" "} -
    - - {t( - "search:hearing-date-label" - )} - -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    - -
    -
    - -
    - - -
    -
    -
    -
    -
    -
    -
    -
    - {" "} -
    - - {t( - "search:site-visit-date-label" - )} - -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    - -
    -
    - -
    - - -
    -
    -
    -
    -
    -
    -
    -
    - {" "} -
    - - {t( - "search:callin-date-label" - )} - -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    - -
    -
    - -
    - - -
    -
    -
    -
    -
    -
    -
    -
    - {" "} -
    - - {t("search:date-received")} - -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    - -
    -
    - -
    - - -
    -
    -
    -
    -
    -
    -
    -
    - {" "} -
    - - {t( - "search:start-date-label" - )} - -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    - -
    -
    - -
    - - -
    -
    -
    -
    -
    -
    -
    -
    - {" "} -
    - - {t( - "search:decision-date-label" - )} - -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    - -
    -
    - -
    - - -
    -
    -
    -
    -
    -
    -
    - - -
    -
    - - -
    -
    -
    -
    -
    -
    -
    @@ -919,4 +401,36 @@ export default function AdvancedSearch(props) {
    ); -} +}; + +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) +); diff --git a/components/search/dnssearchresults.js b/components/search/dnssearchresults.js index 968a5843..763d95ea 100644 --- a/components/search/dnssearchresults.js +++ b/components/search/dnssearchresults.js @@ -19,28 +19,18 @@ const DNSSearchResults = (props) => { const router = useRouter(); const { locale } = router; - var resultsArr = searchResultsObj.value || [{}]; + _.isEmpty(searchResultsObj); - return ( - <> -
    -
    -

    - {t("dnsCommon:service-name")}{" "} - {t("dnsApplications:page-title")} -

    -

    - {t("dnsApplications:page-intro-paragraph-1")} -

    -
      -
    • {t("dnsApplications:page-intro-list-item-1")}
    • + let newSearchResultsObj = _.isEmpty(searchResultsObj) + ? [{}] + : _.isEmpty(searchResultsObj.value) + ? [{}] + : searchResultsObj.value; -
    • {t("dnsApplications:page-intro-list-item-2")}
    • + var resultsArr = newSearchResultsObj || []; -
    • {t("dnsApplications:page-intro-list-item-3")}
    • -
    -
    -
    + const ResultsView = (resultsArr) => { + return (
    @@ -62,6 +52,7 @@ const DNSSearchResults = (props) => { {t("search:searchresults-status-label")}
    + {console.log(newSearchResultsObj.length > 0)} {resultsArr.map((item, key) => { let detailsObj = jsonpath.query( @@ -207,6 +198,38 @@ const DNSSearchResults = (props) => {
    + ); + }; + + return ( + <> +
    +
    +

    + {t("dnsCommon:service-name")}{" "} + {t("dnsApplications:page-title")} +

    +

    + {t("dnsApplications:page-intro-paragraph-1")} +

    +
      +
    • {t("dnsApplications:page-intro-list-item-1")}
    • + +
    • {t("dnsApplications:page-intro-list-item-2")}
    • + +
    • {t("dnsApplications:page-intro-list-item-3")}
    • +
    +
    +
    + {resultsArr.length > 0 ? ( + ResultsView(resultsArr) + ) : ( +
    +
    +

    There are no records

    +
    +
    + )} ); }; diff --git a/components/search/searchresults.js b/components/search/searchresults.js index dce2de78..b945a8f9 100644 --- a/components/search/searchresults.js +++ b/components/search/searchresults.js @@ -19,8 +19,163 @@ const SearchResults = (props) => { const router = useRouter(); const { locale } = router; - var resultsArr = searchResultsObj.value || [{}]; + var resultsArr = searchResultsObj.value || []; + const ResultsView = (resultsArr) => { + return ( +
    +
    +
    + {t("search:searchresults-case-reference-label")} +
    +
    + {t("search:searchresults-site-address-label")} +
    +
    + {t("search:searchresults-applicant-label")} +
    +
    + {t("search:searchresults-authority-label")} +
    +
    + {t("search:searchresults-case-type-label")} +
    +
    + {t("search:searchresults-status-label")} +
    +
    + + {resultsArr.map((item, key) => { + let detailsObj = jsonpath.query( + searchDetailsObj, + "$..value[?(@.pinswg_name=='" + item.title + "')]" + ); + detailsObj = detailsObj[0]; + + return ( +
    +
    + + { + setCurrentReference({ + "currentReference": item.title, + "currentType": + "searchResultsObj", + }); + }} + > + + {t( + "search:searchresults-case-reference-label" + )} + : + + {item.title} + + +
    +
    + + {t( + "search:searchresults-site-address-label" + )} + : + + {_.has(detailsObj, "pinswg_siteaddressline1") + ? detailsObj.pinswg_siteaddressline1 + : ""} +
    + {_.has(detailsObj, "pinswg_siteaddressline1") + ? detailsObj.pinswg_siteaddressline2 + : ""} +
    + {_.has(detailsObj, "pinswg_siteaddressline1") + ? detailsObj.pinswg_siteaddresstown + : ""} +
    + {_.has(detailsObj, "pinswg_siteaddressline1") + ? detailsObj.pinswg_siteaddresscounty + : ""} +
    + {_.has(detailsObj, "pinswg_siteaddressline1") + ? detailsObj.pinswg_siteaddresspostcode + : ""} +
    +
    + + {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, [ + "_customerid_value@OData.Community.Display.V1.FormattedValue", + ]) + ? router.locale == "cy" + ? jsonpath.query( + transLookup, + '$..[?(@.value=="' + + item[ + "_customerid_value@OData.Community.Display.V1.FormattedValue" + ] + + '")].value_cy' + ) + : item[ + "_customerid_value@OData.Community.Display.V1.FormattedValue" + ] || "N/A" + : ""} +
    +
    + + {t("search:searchresults-case-type-label")}: + + {router.locale == "cy" + ? jsonpath.query( + transLookup, + '$..[?(@.value=="' + + item[ + "pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue" + ] + + '")].value_cy' + ) + : item[ + "pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue" + ] || "N/A"} +
    +
    + + {t("search:searchresults-status-label")}: + + + {router.locale == "cy" + ? jsonpath.query( + transLookup, + '$..[?(@.value=="' + + item[ + "statuscode@OData.Community.Display.V1.FormattedValue" + ] + + '")].value_cy' + ) + : item[ + "statuscode@OData.Community.Display.V1.FormattedValue" + ] || "N/A"} +
    +
    + ); + })} +
    + ); + }; return (
    @@ -29,188 +184,31 @@ const SearchResults = (props) => {

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

    -
    -
    -
    - {t("search:searchresults-case-reference-label")} -
    -
    - {t("search:searchresults-site-address-label")} -
    -
    - {t("search:searchresults-applicant-label")} -
    -
    - {t("search:searchresults-authority-label")} -
    -
    - {t("search:searchresults-case-type-label")} -
    -
    - {t("search:searchresults-status-label")} -
    + + {resultsArr.length > 0 ? ( + ResultsView(resultsArr) + ) : ( +
    +
    +

    There are no records

    +
    - - {resultsArr.map((item, key) => { - let detailsObj = jsonpath.query( - searchDetailsObj, - "$..value[?(@.pinswg_name=='" + item.title + "')]" - ); - detailsObj = detailsObj[0]; - - return ( -
    -
    - - { - setCurrentReference({ - "currentReference": - item.title, - "currentType": - "searchResultsObj", - }); - }} - > - - {t( - "search:searchresults-case-reference-label" - )} - : - - {item.title} - - -
    -
    - - {t( - "search:searchresults-site-address-label" - )} - : - - {_.has( - detailsObj, - "pinswg_siteaddressline1" - ) - ? detailsObj.pinswg_siteaddressline1 - : ""} -
    - {_.has( - detailsObj, - "pinswg_siteaddressline1" - ) - ? detailsObj.pinswg_siteaddressline2 - : ""} -
    - {_.has( - detailsObj, - "pinswg_siteaddressline1" - ) - ? detailsObj.pinswg_siteaddresstown - : ""} -
    - {_.has( - detailsObj, - "pinswg_siteaddressline1" - ) - ? detailsObj.pinswg_siteaddresscounty - : ""} -
    - {_.has( - detailsObj, - "pinswg_siteaddressline1" - ) - ? detailsObj.pinswg_siteaddresspostcode - : ""} -
    -
    - - {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(detailsObj, [ - "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue", - ]) - ? router.locale == "cy" - ? jsonpath.query( - transLookup, - '$..[?(@.value=="' + - detailsObj[ - "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" - ] + - '")].value_cy' - ) - : detailsObj[ - "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" - ] || "N/A" - : ""} -
    -
    - - {t( - "search:searchresults-case-type-label" - )} - : - - {router.locale == "cy" - ? jsonpath.query( - transLookup, - '$..[?(@.value=="' + - item[ - "pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue" - ] + - '")].value_cy' - ) - : item[ - "pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue" - ] || "N/A"} -
    -
    - - {t("search:searchresults-status-label")} - : - - - {router.locale == "cy" - ? jsonpath.query( - transLookup, - '$..[?(@.value=="' + - item[ - "statuscode@OData.Community.Display.V1.FormattedValue" - ] + - '")].value_cy' - ) - : item[ - "statuscode@OData.Community.Display.V1.FormattedValue" - ] || "N/A"} -
    -
    - ); - })} -
    + )}
    ); diff --git a/components/searchresults.js b/components/searchresults.js index 02599187..8e9a3834 100644 --- a/components/searchresults.js +++ b/components/searchresults.js @@ -35,12 +35,12 @@ export default function Search(props) { {t("search:searchresults-search-button-label")} - router.back()} className="govuk-button govuk-button--secondary" > {t("search:searchresults-new-search-button-label")} - + */}
    diff --git a/i18n.json b/i18n.json index ca766d15..6e796bd4 100644 --- a/i18n.json +++ b/i18n.json @@ -29,6 +29,9 @@ "/advancedsearch": [ "search" ], + "/advancedsearchresults": [ + "search" + ], "/searchresults": [ "search" ], @@ -71,7 +74,10 @@ "dnsApplications" ], "/dnsdetails": [ - "case" + "case", + "search", + "dnsCommon", + "dnsApplications" ] } } \ No newline at end of file diff --git a/locales/cy/common.json b/locales/cy/common.json index 692f7a13..2aee7b1c 100644 --- a/locales/cy/common.json +++ b/locales/cy/common.json @@ -20,6 +20,8 @@ "social-bar-share-link": "Rhannu’r dudalen hon", "social-bar-share-via-link": "Rhannu’r dudalen hon ar", "breadcrumb-search-results": "Canlyniadau chwilio", + "breadcrumb-advanced-search": "Advanced search", + "breadcrumb-advanced-search-results": "Advanced search results", "breadcrumb-my-portal": "Fy mhorth", "breadcrumb-case-reference": "Cyfeirnod Achos" } \ No newline at end of file diff --git a/locales/en/common.json b/locales/en/common.json index 33b7b483..f629f392 100644 --- a/locales/en/common.json +++ b/locales/en/common.json @@ -20,6 +20,8 @@ "social-bar-share-link": "Share this page", "social-bar-share-via-link": "Share this page via", "breadcrumb-search-results": "Search results", + "breadcrumb-advanced-search": "Advanced search", + "breadcrumb-advanced-search-results": "Advanced search results", "breadcrumb-my-portal": "My portal", "breadcrumb-case-reference": "Case Reference" } \ No newline at end of file diff --git a/pages/advancedsearch.js b/pages/advancedsearch.js index d93d9094..a76cc9da 100644 --- a/pages/advancedsearch.js +++ b/pages/advancedsearch.js @@ -14,12 +14,23 @@ import Cookies from "cookies"; import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; +import { + setAppealType, + setAppealTypeTitle, + setAppealTypeID, + setAppealLPA, + getAppealTypeObj, +} from "../store/appealType/action"; +import { getAppealsTypes, getLPA, updateCase, createCase } from "../actions"; +import { setLPA } from "../store/lpa/action"; + const Home = (props) => { const { footerLinks, pages } = props; let { t, lang } = useTranslation(); const router = useRouter(); const { locale } = router; + const { appealtypes } = router.query; return (
    @@ -33,7 +44,11 @@ const Home = (props) => {
    - + +
    @@ -41,9 +56,28 @@ const Home = (props) => { ); }; +export const getServerSideProps = wrapper.getServerSideProps( + (store) => + async ({ query, req, res }) => { + const [appealTypeData, lpaData, caseData] = await Promise.all([ + await getAppealsTypes(), + await getLPA(), + ]); + + store.dispatch(setAppealType(appealTypeData)); + store.dispatch(setLPA(lpaData)); + } +); + 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, }; }; diff --git a/pages/advancedsearchresults.js b/pages/advancedsearchresults.js new file mode 100644 index 00000000..682f4177 --- /dev/null +++ b/pages/advancedsearchresults.js @@ -0,0 +1,131 @@ +import _ from "lodash"; +import Head from "next/head"; +import Header from "../components/header"; +import Banner from "../components/banner"; +import CookieBanner from "../components/cookieBanner"; +import Breadcrumbs from "../components/breadcrumbs"; +import SearchResults from "../components/searchresults"; +import Footer from "../components/footer"; +import Errorpage from "../components/errorpage"; +import styles from "../styles/Home.module.css"; +import { useSelector, shallowEqual, connect } from "react-redux"; +import { wrapper } from "../store/store"; +import Cookies from "cookies"; +import { useRouter } from "next/router"; +import useTranslation from "next-translate/useTranslation"; +import jsonpath from "jsonpath"; +import data from "../data/collections.json"; + +import { setSearch, getSearchObj } from "../store/search/action"; +import { + setSearchResults, + setSearchDetails, + getSearchResultsObj, +} from "../store/searchOutput/action"; +import { getAdvancedSearch, getBasicSearchDetails } from "../actions"; + +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")} + + +
    + +
    +
    + + + +
    +
    +
    + ); +}; + +export const getServerSideProps = wrapper.getServerSideProps( + (store) => + async ({ query, req, res }) => { + console.log("query-", query); + //console.log("search array:", Object.entries(query)); + + let querystring; + + const searchResultsObj = await getAdvancedSearch(query); + const searchDetailsObj = await getSearchDetails(searchResultsObj); + // console.log(searchDetailsObj); + store.dispatch(setSearchResults(searchResultsObj)); + store.dispatch(setSearchDetails(searchDetailsObj)); + //store.dispatch(setSearch(query.q)); + } +); + +const getFormCollection = (formtype) => { + const collectionName = jsonpath.query( + data, + "$..[?(@.LogicalName=='" + formtype + "')].LogicalCollectionName" + ); + //console.log(collectionName[0]); + return collectionName[0]; +}; + +const getSearchDetails = (searchResultsObj) => { + //console.log(searchResultsObj); + + let detailsArr = []; + //console.log("searcg results", searchResultsObj); + searchResultsObj = searchResultsObj.value; + const detailsObj = searchResultsObj.map((searchDetail, index) => { + if (searchDetail.pinswg_appealcasetype == null) { + console.log(searchDetail.ticketnumber); + } else { + detailsArr.push( + getBasicSearchDetails( + getFormCollection( + "pinswg_" + + searchDetail[ + "pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue" + ] + .replace(/(\band|[\s\-\+\(\)\,\&])/g, "") + .toLowerCase() + .slice(0, 39) + ), + searchDetail.ticketnumber + ) + ); + } + }); + //console.log(detailsArr); + return Promise.all(detailsArr); +}; + +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/searchresults.js b/pages/searchresults.js index 823aefed..9cfabdf1 100644 --- a/pages/searchresults.js +++ b/pages/searchresults.js @@ -87,6 +87,7 @@ const getSearchDetails = (searchResultsObj) => { //console.log(searchResultsObj); let detailsArr = []; + console.log("searcg results", searchResultsObj); searchResultsObj = searchResultsObj.value; const detailsObj = searchResultsObj.map((searchDetail, index) => { if (searchDetail.pinswg_appealcasetype == null) {