From 5f9d239b5091a259b5e3a5ee8121f35d657a0c6d Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Tue, 28 Sep 2021 13:36:19 +0100 Subject: [PATCH] language routing --- .env.local | 10 +++++ actions/index.js | 5 ++- components/breadcrumbs.js | 12 ++++-- components/case/documents.js | 10 +++-- components/crmError.js | 27 ++++++++++++ components/dnssearchresults.js | 35 ++++++++++++---- components/homepage/casesearch.js | 5 ++- components/homepage/dns.js | 11 ++++- components/search/dnssearchresults.js | 19 ++++----- components/search/searchresults.js | 9 +++- components/searchresults.js | 59 ++++++++++++++++++--------- i18n.json | 6 +++ next.config.js | 44 ++++++++++---------- package.json | 2 +- pages/_error.js | 1 + pages/dnsapplications.js | 11 ++++- pages/dnsdetails.js | 7 ++++ pages/searchresults.js | 10 ++++- store/store.js | 5 --- 19 files changed, 206 insertions(+), 82 deletions(-) create mode 100644 components/crmError.js diff --git a/.env.local b/.env.local index 01824053..74e6fb27 100644 --- a/.env.local +++ b/.env.local @@ -4,6 +4,16 @@ RELAYPATH = "dev-pedw-hc" SASKEY = "Ml0Y/S/nfRcmIrHFRkO4jNm2J3iH52TSxPiak7+E1+Y=" SASKEYNAME = "devpedwnspolicy" + +PORT= "3000" +DEFAULT_DOMAIN = "localhost" +I18N_DOMAIN = "cymru.local" +//I18N_DOMAIN ="dev-gwaithcynllunio.gwasanaeth.llyw.cymru" +//I18N_DOMAIN ="stage-gwaithcynllunio.gwasanaeth.llyw.cymru" +//I18N_DOMAIN ="pp-gwaithcynllunio.gwasanaeth.llyw.cymru" +//I18N_DOMAIN ="gwaithcynllunio.gwasanaeth.llyw.cymru" + + //RELAY_ROOT = https://test-pedw-ns.servicebus.windows.net/test-pedw-hc/ //RELAYURI = "test-pedw-ns.servicebus.windows.net" //RELAYPATH = "test-pedw-hc" diff --git a/actions/index.js b/actions/index.js index bffe969d..86a6e9e9 100644 --- a/actions/index.js +++ b/actions/index.js @@ -157,7 +157,8 @@ export const getBasicSearch = (token, searchString) => { return res.data; }) .catch((error) => { - console.log("thiserror", error); + //console.log("thiserror", error); + return error.response; }); }; @@ -170,7 +171,7 @@ export const getBasicDNSSearch = (token, searchString) => { ) .then((res) => res.data) .catch((error) => { - console.log("thiserror", error); + return error.response; }); }; diff --git a/components/breadcrumbs.js b/components/breadcrumbs.js index 9f950217..947a5ea6 100644 --- a/components/breadcrumbs.js +++ b/components/breadcrumbs.js @@ -107,7 +107,10 @@ const Breadcrumbs = (props) => { ) : ( "" )} - {router.pathname == "/searchresults" ? ( + {router.pathname == + (router.locale == "cy" + ? "/canlyniadauchwilio" + : "/searchresults") ? ( <>
  • {t("common:breadcrumb-search-results")} @@ -439,12 +442,15 @@ const Breadcrumbs = (props) => { ) : ( "" )} - {router.pathname == "/dnsdetails" ? ( + {router.pathname == + (router.locale == "cy" + ? "/manyliondns" + : "/dnsdetails") ? ( <>
  • { searchDetailsObj, documentDetailsObj, documentHistoryObj, + setDocumentDetails, + setDocumentHistory, } = props; const router = useRouter(); @@ -152,13 +154,13 @@ const DocumentDetails = (props) => { const docDetailsObj = async () => { let docObj = await getSearchDocumentDetails1(incidentid) .then((data) => { - props.setDocumentDetails(data); + setDocumentDetails(data); return data; }) .then((data) => { let historyObj = getDocumentHistory(data.value).then( (result) => { - props.setDocumentHistory(result); + setDocumentHistory(result); return result; } ); @@ -171,7 +173,7 @@ const DocumentDetails = (props) => { const getDocumentHistory = async (searchDocumentDetailsObj) => { let historyArr = []; - searchDocumentDetailsObj = searchDocumentDetailsObj; + searchDocumentDetailsObj = searchDocumentDetailsObj || []; const detailsObj = searchDocumentDetailsObj.map( (historyDetail, index) => { @@ -190,7 +192,7 @@ const DocumentDetails = (props) => { }; const searchDocumentResultsObj = docDetailsObj(); - }, []); + }, [incidentid, setDocumentHistory, setDocumentDetails]); return (
    diff --git a/components/crmError.js b/components/crmError.js new file mode 100644 index 00000000..49e40231 --- /dev/null +++ b/components/crmError.js @@ -0,0 +1,27 @@ +import Link from "next/link"; +import { useRouter } from "next/router"; +import useTranslation from "next-translate/useTranslation"; +import { DiagConsoleLogger } from "@opentelemetry/api"; + +const CRMError = (props) => { + let { t } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + const searchResultsObj = props.props.searchResultsObj.searchResultsObj; + console.log(searchResultsObj); + return ( +
    +
    +

    + Something has happened.... +

    +

    + {searchResultsObj.errorCode} - {searchResultsObj.errorMsg} +

    +
    +
    + ); +}; + +export default CRMError; diff --git a/components/dnssearchresults.js b/components/dnssearchresults.js index c3153f27..12a27db1 100644 --- a/components/dnssearchresults.js +++ b/components/dnssearchresults.js @@ -4,6 +4,7 @@ import { useContext } from "react"; import useTranslation from "next-translate/useTranslation"; import SearchForCase from "./search/searchforcase"; import DNSSearchResults from "./search/dnssearchresults"; +import CRMError from "./crmError"; export default function Search(props) { const { searchString, searchResultsObj } = props; @@ -12,21 +13,37 @@ export default function Search(props) { const router = useRouter(); const { locale } = router; + var hasError = _.has(searchResultsObj.searchResultsObj, "errorCode") + ? true + : false; + + console.log("has an error", hasError); + return (
    -
    -
    - -
    -
    + {hasError ? ( + + ) : ( + <> +
    +
    + +
    +
    + + )}
    ); } diff --git a/components/homepage/casesearch.js b/components/homepage/casesearch.js index 99f4c4b0..2740c0d9 100644 --- a/components/homepage/casesearch.js +++ b/components/homepage/casesearch.js @@ -77,7 +77,10 @@ let CaseSearch = (props) => { const onHandleSubmit = (values) => { spinnerState(); router.replace({ - pathname: "/searchresults", + pathname: + router.locale == "cy" + ? "/canlyniadauchwilio" + : "/searchresults", query: { q: values.basicSearch }, shallow: true, }); diff --git a/components/homepage/dns.js b/components/homepage/dns.js index 12b6504f..f6a5130e 100644 --- a/components/homepage/dns.js +++ b/components/homepage/dns.js @@ -8,6 +8,9 @@ export default function Dns() { let { t } = useTranslation(); const [showSpinnerState, setShowSpinnerState] = useState(false); + const router = useRouter(); + const { locale } = router; + let spinnerState = () => { showSpinnerState == true ? setShowSpinnerState(false) @@ -25,7 +28,13 @@ export default function Dns() {

    - + { diff --git a/components/search/dnssearchresults.js b/components/search/dnssearchresults.js index 763d95ea..d6e47e7d 100644 --- a/components/search/dnssearchresults.js +++ b/components/search/dnssearchresults.js @@ -19,15 +19,7 @@ const DNSSearchResults = (props) => { const router = useRouter(); const { locale } = router; - _.isEmpty(searchResultsObj); - - let newSearchResultsObj = _.isEmpty(searchResultsObj) - ? [{}] - : _.isEmpty(searchResultsObj.value) - ? [{}] - : searchResultsObj.value; - - var resultsArr = newSearchResultsObj || []; + var resultsArr = searchResultsObj.value || []; const ResultsView = (resultsArr) => { return ( @@ -52,7 +44,6 @@ const DNSSearchResults = (props) => { {t("search:searchresults-status-label")}
    - {console.log(newSearchResultsObj.length > 0)} {resultsArr.map((item, key) => { let detailsObj = jsonpath.query( @@ -69,7 +60,13 @@ const DNSSearchResults = (props) => { key={key} >
    - + { setCurrentReference({ diff --git a/components/search/searchresults.js b/components/search/searchresults.js index af6ceeb1..33ef3e27 100644 --- a/components/search/searchresults.js +++ b/components/search/searchresults.js @@ -55,7 +55,13 @@ const SearchResults = (props) => { return (
    - + { setCurrentReference({ @@ -177,6 +183,7 @@ const SearchResults = (props) => { ); }; + return (
    diff --git a/components/searchresults.js b/components/searchresults.js index 8e9a3834..02964fd9 100644 --- a/components/searchresults.js +++ b/components/searchresults.js @@ -4,6 +4,7 @@ import { useContext } from "react"; import useTranslation from "next-translate/useTranslation"; import SearchForCase from "./search/searchforcase"; import SearchResults from "./search/searchresults"; +import CRMError from "./crmError"; export default function Search(props) { const { searchString, searchResultsObj } = props; @@ -12,38 +13,56 @@ export default function Search(props) { const router = useRouter(); const { locale } = router; + var hasError = _.has(searchResultsObj.searchResultsObj, "errorCode") + ? true + : false; + + console.log("has an error", hasError); + return (
    -
    -
    - -
    -
    -
    ); } diff --git a/i18n.json b/i18n.json index ca56d3d8..7b60abb8 100644 --- a/i18n.json +++ b/i18n.json @@ -4,6 +4,12 @@ "cy" ], "defaultLocale": "en", + "domains": [ + { + "domain": "dev-gwaithcynllunio.gwasanaeth.llyw.cymru", + "defaultLocale": "cy" + } + ], "pages": { "*": [ "common" diff --git a/next.config.js b/next.config.js index c627d891..5f422840 100644 --- a/next.config.js +++ b/next.config.js @@ -3,20 +3,6 @@ const withStyles = require("@webdeb/next-styles"); //const { nextI18NextRewrites } = require("next-i18next/rewrites"); const nextTranslate = require("next-translate"); -//acp -// module.exports = { -// poweredByHeader: false, -// env: { -// API_ROOT: "http://pel-beta-backend", -// GRANT_TYPE: "password", -// USERNAME: "api", -// PASSWORD: "tJRq4o2ZBQ", -// CLIENT_ID: "2d3df41b-9b59-4bbd-85a7-9314125c1689", -// CLIENT_SECRET: "85H8qdrEvKEzbW5", -// }, -// ...nextTranslate(), -// }; - module.exports = withStyles({ sass: true, // use .scss files modules: true, // style.(m|module).css & style.(m|module).scss for module files @@ -37,13 +23,29 @@ module.exports = { return "pinswg-build-id"; }, poweredByHeader: false, - env: { - // GRANT_TYPE : 'password', - // USERNAME : 'api', - // API_ROOT : "https://api.dev.prevent.internal.rehab", - // PASSWORD : 'B69eQwv7rzPBNcA', - // CLIENT_ID : 'fa1f0ef2-f10f-462e-98a5-843359db6066', - // CLIENT_SECRET : 'B69eQwv7rzPBNcA', + async rewrites() { + return [ + { + source: "/ceisiadaudns", + destination: "/dnsapplications", // The :path parameter isn't used here so will be automatically passed in the query + }, + { + source: "/manyliondns", + destination: "/dnsdetails", // The :path parameter isn't used here so will be automatically passed in the query + }, + { + source: "/canlyniadauchwilio", + destination: "/searchresults", // The :path parameter isn't used here so will be automatically passed in the query + }, + { + source: "/achos", + destination: "/case", + }, + { + source: "/cy:path*", + destination: "http://cyrmu.local/:path*", + }, + ]; }, ...nextTranslate(), }; diff --git a/package.json b/package.json index e9a8bc4f..9b3c7b60 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,9 @@ "lodash": "^4.17.21", "moment": "^2.29.1", "next": "^11.0.1", - "next-i18next": "^8.5.1", "next-redux-wrapper": "^7.0.2", "next-translate": "^1.0.7", + "path": "^0.12.7", "pm2": "^5.1.0", "react": "17.0.2", "react-accessible-accordion": "^3.3.5", diff --git a/pages/_error.js b/pages/_error.js index 23377c1d..cb0e2547 100644 --- a/pages/_error.js +++ b/pages/_error.js @@ -45,6 +45,7 @@ function Error({ statusCode }, props) { Error.getInitialProps = ({ res, err }) => { const statusCode = res ? res.statusCode : err ? err.statusCode : 404; + console.log(res, err); return { statusCode }; }; diff --git a/pages/dnsapplications.js b/pages/dnsapplications.js index 4deb3b54..f303bb5d 100644 --- a/pages/dnsapplications.js +++ b/pages/dnsapplications.js @@ -67,8 +67,15 @@ export const getServerSideProps = wrapper.getServerSideProps( const token = await getSASToken(); - const searchResultsObj = await getBasicDNSSearch(token); - //console.log(searchResultsObj); + let searchResultsObj = await getBasicDNSSearch(token); + searchResultsObj = + searchResultsObj.status == 502 + ? { + value: [], + errorCode: searchResultsObj.status, + errorMsg: searchResultsObj.statusText, + } + : searchResultsObj; const searchDetailsObj = await getSearchDetails( token, diff --git a/pages/dnsdetails.js b/pages/dnsdetails.js index 11120215..7bc70e5c 100644 --- a/pages/dnsdetails.js +++ b/pages/dnsdetails.js @@ -48,6 +48,12 @@ const Home = (props) => { searchDetailsObj={ props.searchResultsObj.searchDetailsObj } + documentDetailsObj={ + props.searchResultsObj.documentDetailsObj + } + documentHistoryObj={ + props.searchResultsObj.documentHistoryObj + } myRepresentations={ props.myRepresentations.myRepresentations } @@ -61,6 +67,7 @@ const Home = (props) => { currentType={ props.currentView.caseReference.currentType } + incidentid={props.currentView.caseReference.incidentid} />