From 2d97d6a1ce26daad702693a92555b597a92d09ec Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Thu, 24 Feb 2022 14:38:54 +0000 Subject: [PATCH 1/3] dns url redirects to case --- .env.local | 2 +- actions/index.js | 16 ++ components/breadcrumbs.js | 45 +++-- components/case/summary.js | 6 +- i18n.js | 3 +- .../api/endpoint/getbasicdnsurlsearch_api.js | 58 ++++++ pages/dns-not-found.js | 45 +++++ pages/dns/[developmentName].js | 173 ++++++++++++++++++ pages/dns/index.js | 18 +- store/store.js | 6 +- 10 files changed, 341 insertions(+), 31 deletions(-) create mode 100644 pages/api/endpoint/getbasicdnsurlsearch_api.js create mode 100644 pages/dns-not-found.js create mode 100644 pages/dns/[developmentName].js diff --git a/.env.local b/.env.local index 36e4aefc..5c3e0231 100644 --- a/.env.local +++ b/.env.local @@ -46,7 +46,7 @@ RELAYPATH = "prod-pedw-hc" GOOGLE_TAG_MANAGER = GTM-T78CBC3 SHOWLOGIN = "true" -SHOWREPRESENTATIONS = "false" +SHOWREPRESENTATIONS = false //BASIC_AUTH_CREDENTIALS = pinswg:password|pinswg2:password2 diff --git a/actions/index.js b/actions/index.js index 3f7a91e8..0161edfe 100644 --- a/actions/index.js +++ b/actions/index.js @@ -145,6 +145,22 @@ export const getBasicSearch = (searchString) => { }); }; +export const getBasicDNSURLSearch = (searchString) => { + return axios + .get( + BASE_URL + + "/api/endpoint/getbasicdnsurlsearch_api?searchString=" + + searchString + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + console.log(error); + return error.response; + }); +}; + export const getBasicSearchPaged = ( searchString, pageNumber, diff --git a/components/breadcrumbs.js b/components/breadcrumbs.js index d8f46e54..54a45396 100644 --- a/components/breadcrumbs.js +++ b/components/breadcrumbs.js @@ -13,6 +13,8 @@ const Breadcrumbs = (props) => { let { t } = useTranslation(); + console.log("asdadad", slug); + function Breadcrumb() { if (slug) { var coursePageURL = appealType + "/" + slug; @@ -64,17 +66,9 @@ const Breadcrumbs = (props) => { */}
  • - + - {router.pathname.includes("/dns/") - ? t("dnsCommon:service-name") - : t("common:service-name-breadcrumb")} + {t("common:service-name-breadcrumb")}
  • @@ -493,6 +487,33 @@ const Breadcrumbs = (props) => { ) : ( "" )} + {router.pathname == "/dns/[developmentName]" ? ( + <> +
  • + + + {t("dnsCommon:service-name")} + + +
  • +
  • + {t("common:breadcrumb-case-reference")}:{" "} + { + props.props.currentView.caseReference + .currentReference + } +
  • + + ) : ( + "" + )} {router.pathname == "/dnsapplications" ? ( <>
  • @@ -628,7 +649,7 @@ const Breadcrumbs = (props) => { ) : ( "" )} - {!_.isEmpty(slug) ? ( + {/* {!_.isEmpty(slug) ? ( <>
  • { ) : ( "" - )} + )} */} diff --git a/components/case/summary.js b/components/case/summary.js index e49cd42c..e3840173 100644 --- a/components/case/summary.js +++ b/components/case/summary.js @@ -63,7 +63,11 @@ const CaseSummary = (props) => { setCurrentReference, } = props; - const noRepresentationLink = ["/case", "/dnsdetails"]; + const noRepresentationLink = [ + "/case", + "/dnsdetails", + "/dns/[developmentName]", + ]; let setCaseQueryObj = props[currentType]; let setCaseDetailsObj = props[currentType + "Details"]; diff --git a/i18n.js b/i18n.js index 22905cb0..ecf361e3 100644 --- a/i18n.js +++ b/i18n.js @@ -27,7 +27,8 @@ module.exports = { "/newappeal": ["newappeal"], "/newappeal/*": ["newappeal"], "/newappeal/selectappeal": ["newappeal"], - "/dns/*": ["dnsCommon"], + "/dns/*": ["dnsCommon", "case", "common"], + "/dns/[developmentName]": ["dnsCommon", "case", "common"], "/dns": ["dnsCommon", "dnsHome"], "/dns/applications": ["dnsCommon", "dnsApplications"], "/dns/application-view": ["dnsCommon", "dnsApplicationView"], diff --git a/pages/api/endpoint/getbasicdnsurlsearch_api.js b/pages/api/endpoint/getbasicdnsurlsearch_api.js new file mode 100644 index 00000000..b315494b --- /dev/null +++ b/pages/api/endpoint/getbasicdnsurlsearch_api.js @@ -0,0 +1,58 @@ +import axios from "axios"; +import CryptoJS from "crypto-js"; +import _ from "lodash"; +import { getToken, azureHeadersPaged } 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 searchString = req.query.searchString; + var token = await getToken(); + + var queryUrl = + "incidents?$select=description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" + + searchString + + "') or contains(ticketnumber, '" + + searchString + + "')) and pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true"; + + // console.log("basic search ", queryUrl); + + var apiResponse = _.isEmpty(req.query) + ? res.status(400).json() + : searchString.length > 0 + ? axios + .get( + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), + azureHeadersPaged(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); + }) + : res.status(400).json(); + + return apiResponse; +} diff --git a/pages/dns-not-found.js b/pages/dns-not-found.js new file mode 100644 index 00000000..678bfdfa --- /dev/null +++ b/pages/dns-not-found.js @@ -0,0 +1,45 @@ +// 404.js +import useTranslation from "next-translate/useTranslation"; +import Head from "next/head"; +import Link from "next/link"; +import CookieBanner from "../components/cookieBanner"; +import Footer from "../components/footer"; +import Header from "../components/header"; + +const FourOhFour = (props) => { + let { t, lang } = useTranslation(); + const { footerLinks, pages } = props; + + return ( +
    + + + {t("common:404-not-found-title")} -{" "} + {t("common:service-name")} + + +
    + +
    +
    +
    +
    +
    +

    + Development of National Signifcance not + found +

    + + {t("common:404-not-found-link")} + +
    +
    +
    +
    +
    +
    +
    + ); +}; + +export default FourOhFour; diff --git a/pages/dns/[developmentName].js b/pages/dns/[developmentName].js new file mode 100644 index 00000000..4ee5df81 --- /dev/null +++ b/pages/dns/[developmentName].js @@ -0,0 +1,173 @@ +import useTranslation from "next-translate/useTranslation"; +import Head from "next/head"; +import { useRouter } from "next/router"; +import { connect } from "react-redux"; +import { getBasicDNSURLSearch } from "../../actions"; +import CookieBanner from "../../components/cookieBanner"; +import Footer from "../../components/footer"; +import Header from "../../components/header"; +import { getSearchDetails } from "../../components/utils"; +import { setCurrentReference } from "../../store/currentView/action"; +import { setSearch } from "../../store/search/action"; +import { + setSearchDetails, + setSearchResults, +} from "../../store/searchOutput/action"; +import { wrapper } from "../../store/store"; +import Case from "../../components/case"; +import Breadcrumbs from "../../components/breadcrumbs"; + +const CaseHome = (props) => { + const { footerLinks, pages } = props; + let { t, lang } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + const { developmentName } = router.query; + + return ( +
    + + + Reference:{" "} + {props.currentView.caseReference.currentReference}{" "} + Developments of National Significance + + +
    + +
    +
    + + + +
    +
    +
    +
    + ); +}; + +export const getServerSideProps = wrapper.getServerSideProps( + (store) => async (ctx) => { + const { query, req, res } = ctx; + const { cookies } = req; + + console.log(cookies); + console.log("the query", query.developmentName); + let loggedInUser = cookies.pinsUser; + + let developmentQuery = query.developmentName.split("-").join(" "); + + const searchResultsObj = await getBasicDNSURLSearch(developmentQuery); + const searchDetailsObj = await getSearchDetails(searchResultsObj); + + store.dispatch(setSearchResults(searchResultsObj)); + store.dispatch(setSearchDetails(searchDetailsObj)); + store.dispatch(setSearch(developmentQuery)); + + // console.log({ + // "currentReference": searchResultsObj.value[0].title, + // "currentType": "searchResultsObj", + // "incidentid": searchResultsObj.value[0].incidentid, + // "appealType": searchResultsObj.value[0].pinswg_appealcasetype, + // }); + console.log( + searchResultsObj["@odata.count"] > 1 || + searchResultsObj["@odata.count"] < 1 + ); + + if (searchResultsObj["@odata.count"] < 1) { + return { + redirect: { + destination: "/404", + permanent: false, + }, + }; + } else { + if (searchResultsObj["@odata.count"] > 1) { + return { + redirect: { + destination: "/dns-not-found", + permanent: false, + }, + }; + } else { + store.dispatch( + setCurrentReference({ + "currentReference": searchResultsObj.value[0].title, + "currentType": "searchResultsObj", + "incidentid": searchResultsObj.value[0].incidentid, + "appealType": + searchResultsObj.value[0].pinswg_appealcasetype, + }) + ); + } + } + // console.log(searchResultsObj); + } +); + +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, + }; +}; + +const mapDispatchToProps = (dispatch) => { + return { + setCurrentReference: (currentReference) => { + dispatch(setCurrentReference(refno)); + }, + }; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(CaseHome); diff --git a/pages/dns/index.js b/pages/dns/index.js index e197c914..f4ebc15d 100644 --- a/pages/dns/index.js +++ b/pages/dns/index.js @@ -1,18 +1,10 @@ -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 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 { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; +import Head from "next/head"; +import { useRouter } from "next/router"; +import CookieBanner from "../../components/cookieBanner"; import Main from "../../components/dns//main"; +import Footer from "../../components/footer"; +import Header from "../../components/header"; const Home = (props) => { const { footerLinks, pages } = props; diff --git a/store/store.js b/store/store.js index ff25d224..be78c0b1 100644 --- a/store/store.js +++ b/store/store.js @@ -108,9 +108,9 @@ const makeStore = ({ isServer }) => { const persistConfig = { key: "acp", whitelist: [ - "currentView", - "search", - "searchResultsObj", + // "currentView", + // "search", + // "searchResultsObj", "formData", "appealType", "LPAData", From 4d2e74514ed680fc69f0a5e264bf0628491a3b36 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Fri, 25 Feb 2022 08:51:12 +0000 Subject: [PATCH 2/3] pagination fix --- components/case/pagination.js | 13 ++++++++----- components/search/pagination.js | 9 ++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/components/case/pagination.js b/components/case/pagination.js index b44d38a8..20966176 100644 --- a/components/case/pagination.js +++ b/components/case/pagination.js @@ -36,6 +36,7 @@ const PaginationControl = (props) => { const paginationNumbers = (currentPage, pageCount) => { //console.log(currentPage); let delta; + if (pageCount <= 7) { // delta === 7: [1 2 3 4 5 6 7] delta = 7; @@ -43,7 +44,7 @@ const PaginationControl = (props) => { // delta === 2: [1 ... 4 5 6 ... 10] // delta === 4: [1 2 3 4 5 ... 10] //delta = currentPage > 4 && currentPage < pageCount - 3 ? 4 : 4; - delta = currentPage > 4 && currentPage < pageCount - 3 ? 2 : 4; + delta = currentPage > 4 && currentPage < pageCount - 3 ? 4 : 4; } const range = { @@ -79,15 +80,17 @@ const PaginationControl = (props) => { return pages; }; - const paginationArray = paginationNumbers(currentPage, pagesCount); - + const paginationArray = paginationNumbers( + props.currentView.currentPage, + pagesCount + ); return ( <> {pagesCount > 1 && (
    - {currentPage != 1 ? ( + {props.currentView.currentPage != 1 ? ( { @@ -114,7 +117,7 @@ const PaginationControl = (props) => {
    {paginationArray.map((e, i) => - props.currentView.currentPage == i + 1 ? ( + props.currentView.currentPage == e ? ( { }; const paginationNumbers = (currentPage, pageCount) => { + //console.log(currentPage); let delta; if (pageCount <= 7) { @@ -43,7 +44,7 @@ const PaginationControl = (props) => { // delta === 2: [1 ... 4 5 6 ... 10] // delta === 4: [1 2 3 4 5 ... 10] //delta = currentPage > 4 && currentPage < pageCount - 3 ? 4 : 4; - delta = currentPage > 4 && currentPage < pageCount - 3 ? 2 : 4; + delta = currentPage > 4 && currentPage < pageCount - 3 ? 4 : 4; } const range = { @@ -79,10 +80,12 @@ const PaginationControl = (props) => { return pages; }; - const paginationArray = paginationNumbers(currentPage, pagesCount); + const paginationArray = paginationNumbers( + props.currentView.currentPage, + pagesCount + ); return ( <> - {" "} {pagesCount > 1 && (
    From a78c8f92a87f4949abe5cd562d2b9cf013a9c3d1 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Fri, 25 Feb 2022 08:51:30 +0000 Subject: [PATCH 3/3] dns url redirect --- components/breadcrumbs.js | 2 -- pages/dns/[developmentName].js | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/breadcrumbs.js b/components/breadcrumbs.js index 54a45396..46b2d310 100644 --- a/components/breadcrumbs.js +++ b/components/breadcrumbs.js @@ -13,8 +13,6 @@ const Breadcrumbs = (props) => { let { t } = useTranslation(); - console.log("asdadad", slug); - function Breadcrumb() { if (slug) { var coursePageURL = appealType + "/" + slug; diff --git a/pages/dns/[developmentName].js b/pages/dns/[developmentName].js index 4ee5df81..22870c81 100644 --- a/pages/dns/[developmentName].js +++ b/pages/dns/[developmentName].js @@ -127,7 +127,8 @@ export const getServerSideProps = wrapper.getServerSideProps( if (searchResultsObj["@odata.count"] > 1) { return { redirect: { - destination: "/dns-not-found", + //destination: "/dns-not-found", + destination: "/404", permanent: false, }, };