diff --git a/actions/index.js b/actions/index.js index 0161edfe..f158154c 100644 --- a/actions/index.js +++ b/actions/index.js @@ -190,6 +190,15 @@ export const getBasicSearchPaged = ( }); }; +export const getDNSList = (searchString) => { + return axios + .get(BASE_URL + "/api/endpoint/getdnslist_api") + .then((res) => res.data) + .catch((error) => { + return error.response; + }); +}; + export const getBasicDNSSearch = (searchString) => { return axios .get(BASE_URL + "/api/endpoint/getbasicdnssearch_api") diff --git a/components/breadcrumbs.js b/components/breadcrumbs.js index 46b2d310..85783cec 100644 --- a/components/breadcrumbs.js +++ b/components/breadcrumbs.js @@ -469,17 +469,7 @@ const Breadcrumbs = (props) => { {router.pathname == "/dns" ? ( <>
  • - - - {t("dnsCommon:service-name")} - - + {t("dnsCommon:service-name")}
  • ) : ( @@ -491,9 +481,8 @@ const Breadcrumbs = (props) => { diff --git a/components/dns/homepage/dnsLinks.js b/components/dns/homepage/dnsLinks.js index ec4aeac4..c9dd151b 100644 --- a/components/dns/homepage/dnsLinks.js +++ b/components/dns/homepage/dnsLinks.js @@ -13,7 +13,7 @@ const DNSLinks = (props) => {
    diff --git a/components/dns/homepage/latestApplications.js b/components/dns/homepage/latestApplications.js index 422aea48..986fbca9 100644 --- a/components/dns/homepage/latestApplications.js +++ b/components/dns/homepage/latestApplications.js @@ -4,9 +4,13 @@ import useTranslation from "next-translate/useTranslation"; const LatestApplications = (props) => { let { t } = useTranslation(); + const { dnsList } = props; + dnsList = dnsList.value; + let dnsListArr = dnsList.slice(0, 3); const router = useRouter(); const { locale } = router; + return (

    @@ -15,32 +19,23 @@ const LatestApplications = (props) => {

    diff --git a/components/dns/homepage/titleContent.js b/components/dns/homepage/titleContent.js index 594ed44b..d4682be0 100644 --- a/components/dns/homepage/titleContent.js +++ b/components/dns/homepage/titleContent.js @@ -1,75 +1,21 @@ -import Link from "next/link"; -import { useState } from "react"; -import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; +import Link from "next/link"; +import { useRouter } from "next/router"; +import { useState } from "react"; import AutoSuggest from "react-autosuggest"; -const dnsSites = [ - { id: 1, name: "30MW Energy Plant - Wrexham" }, - { id: 1, name: "Abertillery Wind Farm" }, - { id: 1, name: "Alaw Mon Solar Farm" }, - { id: 1, name: "Alwen Forest - Wind" }, - { id: 1, name: "Blackberry Lane Solar Park" }, - { id: 1, name: "Bretton Hall Solar Farm" }, - { id: 1, name: "Brynllewelyn Farm - Renewable Energy Project" }, - { id: 1, name: "Brynrhyd Solar Farm" }, - { id: 1, name: "Brynwell Farm Renewable Energy Hub" }, - { id: 1, name: "Buttington Quarry - ERF" }, - { id: 1, name: "Coed Darcy - STOR" }, - { id: 1, name: "Coity Road - STOR" }, - { id: 1, name: "Craig Y Perchyll Solar" }, - { id: 1, name: "Egnedol - Sustainable Energy" }, - { id: 1, name: "Elwy Solar Energy" }, - { id: 1, name: "Erebus - Floating Offshore Wind Demonstration Project" }, - { id: 1, name: "Felindre Road - STOR" }, - { id: 1, name: "Gaerwen Wind Farm" }, - { id: 1, name: "Garn Fach Wind Farm" }, - { id: 1, name: "Holyhead Harbour Revision Order" }, - { id: 1, name: "Holyhead Marina Harbour Revision Order" }, - { id: 1, name: "Holyhead Waterfront Regeneration Scheme HRO" }, - { id: 1, name: "Legacy Substation Gas Peaking Plant" }, - { id: 1, name: "Llantarnam - SToR" }, - { id: 1, name: "Llanwern - Solar" }, - { id: 1, name: "Lluest y Gwynt Wind Farm" }, - { id: 1, name: "Llynfi Energy Recovery Facility" }, - { id: 1, name: "Manmoel Wind Farm" }, - { id: 1, name: "Môn Solar Farm" }, - { id: 1, name: "Mor Hafren: Energy Recovery Facility" }, - { id: 1, name: "Mynydd Carn-y-Cefn Wind Farm" }, - { id: 1, name: "Mynydd Llanhilleth Wind Farm" }, - { id: 1, name: "Pancross & Oaklands Solar Farm" }, - { id: 1, name: "Parc Dyffryn Solar Park" }, - { id: 1, name: "Parc Solar Traffwll" }, - { id: 1, name: "Pen March Wind Farm" }, - { id: 1, name: "Pen-y-Fan - Power Plant" }, - { id: 1, name: "Pencaerlan Solar Farm" }, - { id: 1, name: "Penderi Solar Farm" }, - { id: 1, name: "Penpergwm Solar Farm" }, - { id: 1, name: "Pentre Bach Solar Farm" }, - { id: 1, name: "Plas Power Estate Solar Farm" }, - { id: 1, name: "Project Valorous" }, - { id: 1, name: "Rhoscrowther Wind Farm" }, - { id: 1, name: "Rush Wall Solar Park Ltd" }, - { id: 1, name: "Sudbrook - Peaking Gas" }, - { id: 1, name: "TWA - Morlais Demonstration Zone" }, - { id: 1, name: "Twyn Hywel Energy Park" }, - { id: 1, name: "Tycroes Solar" }, - { id: 1, name: "Upper Ogmore - Wind Turbines" }, - { id: 1, name: "Valero - Cogeneration Facility" }, - { id: 1, name: "Vattenfall - Renewable Energy" }, - { id: 1, name: "Wauntysswg - Solar" }, - { id: 1, name: "Wentlooge - renewable energy hub" }, - { id: 1, name: "Y Bryn Wind Farm" }, -]; - -const lowerCasedCompanies = dnsSites.map((company) => { - return { - id: company.id, - name: company.name, - }; -}); - const TitleContent = (props) => { + const { dnsList } = props; + + const dnsSites = dnsList.value; + + const lowerCasedCompanies = dnsSites.map((company) => { + return { + id: company.ticketnumber, + name: company.title, + }; + }); + let { t } = useTranslation(); const router = useRouter(); @@ -92,12 +38,11 @@ const TitleContent = (props) => {

    {t("dnsHome:title-paragraph")}

    -
    +
    setSuggestions([])} onSuggestionsFetchRequested={({ value }) => { - console.log(value); setValue(value); setSuggestions(getSuggestions(value)); }} @@ -120,8 +65,15 @@ const TitleContent = (props) => { }} highlightFirstSuggestion={true} /> - - + 0 + ? value.split(" - ")[1].split(" ").join("-") + : "") + } + > + {t("dnsHome:title-application-search-button")} diff --git a/components/dns/main.js b/components/dns/main.js index cc66c90c..2e905b86 100644 --- a/components/dns/main.js +++ b/components/dns/main.js @@ -7,7 +7,7 @@ import LatestApplications from "./homepage/latestApplications"; import DNSLinks from "./homepage/dnsLinks"; import ApplicationsForComment from "./homepage/applicationsForComment"; -export default function Main({ children, pages }) { +export default function Main({ children, pages, props }) { let { t } = useTranslation(); const router = useRouter(); @@ -22,8 +22,12 @@ export default function Main({ children, pages }) {
    - - + +
    @@ -31,7 +35,7 @@ export default function Main({ children, pages }) {
    - + {/* */}
    diff --git a/components/header.js b/components/header.js index 228df3e4..15a73590 100644 --- a/components/header.js +++ b/components/header.js @@ -35,7 +35,6 @@ const Header = (props) => { "/details-about-cookies", ]; const hasContactLink = [ - "/dns", "/dns/application-process", "/dns/help", "/dns/contact-us", diff --git a/pages/api/endpoint/getdnslist_api.js b/pages/api/endpoint/getdnslist_api.js new file mode 100644 index 00000000..0426e727 --- /dev/null +++ b/pages/api/endpoint/getdnslist_api.js @@ -0,0 +1,47 @@ +import axios from "axios"; +import CryptoJS from "crypto-js"; +import _ from "lodash"; +import { getToken, azureHeaders } from "../../../actions"; + +const WORDKEY = process.env.HASHKEY; + +const WEBAPI_URL = + process.env.RELAY_ROOT || + "https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/"; + +const hashAPIPath = (queryPath) => { + var hashlink = CryptoJS.HmacSHA256( + queryPath, + CryptoJS.enc.Hex.parse(WORDKEY) + ); + hashlink = hashlink.toString(CryptoJS.enc.Hex); + + //return "&hash=" + hashlink; + + return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink; +}; + +export default async function ApiProxy(req, res) { + var token = await getToken(); + + var queryUrl = + "incidents?$select=_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,statuscode,ticketnumber,title &$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true"; + + //console.log(queryUrl); + + return axios + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeaders(token.access_token) + ) + .then(({ data }) => { + var dataStr; + _.has(data, "@odata.nextLink") == true && + ((dataStr = JSON.stringify(data["@odata.nextLink"])), + (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1])); + res.status(200).json(data); + }) + .catch(({ err }) => { + res.status(400).json(err); + }); +} diff --git a/pages/dns/index.js b/pages/dns/index.js index f4ebc15d..e107eb6c 100644 --- a/pages/dns/index.js +++ b/pages/dns/index.js @@ -5,6 +5,18 @@ import CookieBanner from "../../components/cookieBanner"; import Main from "../../components/dns//main"; import Footer from "../../components/footer"; import Header from "../../components/header"; +import { connect } from "react-redux"; +import { wrapper } from "../../store/store"; +import { getDNSList } from "../../actions"; + +import { getSearchDetails } from "../../components/utils"; +import { setSearch } from "../../store/search/action"; +import { + setSearchDetails, + setSearchResults, +} from "../../store/searchOutput/action"; + +import Breadcrumbs from "../../components/breadcrumbs"; const Home = (props) => { const { footerLinks, pages } = props; @@ -22,7 +34,8 @@ const Home = (props) => {
    -
    + +
    @@ -34,4 +47,46 @@ const Home = (props) => { } }; -export default Home; //connect(mapStateToProps)(Home); +export const getServerSideProps = wrapper.getServerSideProps( + (store) => + async ({ query, req, res }) => { + console.log("query-", query); + + res.setHeader( + "Cache-Control", + "public, s-maxage=10, stale-while-revalidate=59" + ); + + let searchResultsObj = await getDNSList(); + searchResultsObj = + searchResultsObj.status == 502 + ? { + value: [], + errorCode: searchResultsObj.status, + errorMsg: searchResultsObj.statusText, + } + : searchResultsObj; + + const searchDetailsObj = await getSearchDetails(searchResultsObj); + store.dispatch(setSearchResults(searchResultsObj)); + store.dispatch(setSearchDetails(searchDetailsObj)); + store.dispatch(setSearch("DNS")); + } +); + +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/styles/sass/welshgov/_application.scss b/styles/sass/welshgov/_application.scss index 587a0ca5..d5075043 100644 --- a/styles/sass/welshgov/_application.scss +++ b/styles/sass/welshgov/_application.scss @@ -1468,10 +1468,22 @@ ul#sharePageLinks.active { } // dns autocomplete search - +.react-autosuggest { + .govuk-button { + @media screen and (min-width: 768px) { + margin-left: 10px; + } + } +} .react-autosuggest__container { position: relative; - width: 50%; + width: 100%; + margin-bottom: 20px; + + @media screen and (min-width: 768px) { + width: 50%; + margin-bottom: 0px; + } } .react-autosuggest__input {