diff --git a/actions/index.js b/actions/index.js index 7ab6113b..5bf870de 100644 --- a/actions/index.js +++ b/actions/index.js @@ -838,24 +838,83 @@ export const getMyRepresentations = (token, loggedInUserId) => { }; export const getWatchedCases = (token, loggedInUserId) => { - return ( - axios + return axios + .get( + WEBAPI_URL + + "pinswg_watchlists?$filter= _pinswg_contact_value eq " + + loggedInUserId + + "&$count=true&$orderby=createdon desc", + azureHeaders(token) + ) + .then((res) => res.data) + .catch((error) => { + console.log("this serror", error); + }); +}; - // .get(BASE_URL + "/api/lookups/watchedCases", { - // httpsAgent: new https.Agent({ rejectUnauthorized: false }), - // }) - .get( - WEBAPI_URL + - "incidents?$select=ticketnumber,casetypecode,createdon,_customerid_value,description,incidentid,pinswg_appealcasetype,_pinswg_assignedinspectrids_value,statecode,statuscode,title&$filter=_customerid_value eq " + - loggedInUserId + - " and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true&$top=3", - azureHeaders(token) - ) - .then((res) => res.data) - .catch((error) => { - console.log("this serror", error); - }) - ); +export const getWatchedCasesProxy = (token, loggedInUserId) => { + return axios + .get( + "/api/proxy/pinswg_watchlists?$filter= _pinswg_contact_value eq " + + loggedInUserId + + "&$count=true&$orderby=createdon desc", + azureHeaders(token) + ) + .then((res) => res.data) + .catch((error) => { + console.log("this serror", error); + }); +}; + +export const createWatchedCases = (formValues) => { + var data = JSON.stringify(formValues); + + var config = { + method: "post", + url: "/api/proxy/pinswg_watchlists", + headers: { + "OData-MaxVersion": "4.0", + "OData-Version": "4.0", + "Accept": "application/json", + "Prefer": 'odata.include-annotations="*",return=representation', + "Content-Type": "application/json", + "ServiceBusAuthorization": getSASToken(), + }, + data: data, + }; + // console.log(config); + return axios(config) + .then((res) => { + //console.log("posted ", res.data); + return res.data; + }) + .catch((error) => { + console.log("this serror", error); + }); +}; + +export const deleteWatchedCases = (watchedCaseID) => { + var config = { + method: "delete", + url: "/api/proxy/pinswg_watchlists(" + watchedCaseID + ")", + headers: { + "OData-MaxVersion": "4.0", + "OData-Version": "4.0", + "Accept": "application/json", + "Prefer": 'odata.include-annotations="*",return=representation', + "Content-Type": "application/json", + "ServiceBusAuthorization": getSASToken(), + }, + }; + // console.log(config); + return axios(config) + .then((res) => { + //console.log("deleted ", res.data); + return res.data; + }) + .catch((error) => { + console.log("this serror", error); + }); }; export const getAwaitingSubmission = (token) => { @@ -885,6 +944,26 @@ export const getPortalModuleDetails = (token, appealType, caseReference) => { }); }; +export const getPortalModuleDetailsProxy = ( + token, + appealType, + caseReference +) => { + return axios + .get( + "/api/proxy/" + + appealType + + "?$filter=pinswg_name eq '" + + caseReference + + "'&$count=true", + azureHeaders(token) + ) + .then((res) => res.data) + .catch((error) => { + console.log("thiserror", error); + }); +}; + export const getEmailAccountCheck = (emailAddress) => { let token = getSASToken(); return axios @@ -945,7 +1024,7 @@ export const updateAccount = (contactId, updateBody) => { // console.log(config); return axios(config) .then((res) => { - console.log("posted ", res.data); + //console.log("posted ", res.data); return res.data; }) .catch((error) => { @@ -973,7 +1052,7 @@ export const updatePassword = (contactId, newpassword) => { // console.log(config); return axios(config) .then((res) => { - console.log("posted ", res.data); + //console.log("posted ", res.data); return res.data; }) .catch((error) => { diff --git a/components/case.js b/components/case.js index 3745b241..b2bfcdbe 100644 --- a/components/case.js +++ b/components/case.js @@ -24,6 +24,7 @@ const CaseSummary = (props) => { myCasesDetails={props.myCasesDetails} myRepresentations={props.myRepresentations} watchedCases={props.watchedCases} + watchedCasesDetails={props.watchedCasesDetails} awaitingSubmission={props.awaitingSubmission} caseReference={props.caseReference} currentType={props.currentType} diff --git a/components/header.js b/components/header.js index 7ee807ac..fe9f7e84 100644 --- a/components/header.js +++ b/components/header.js @@ -48,7 +48,6 @@ const Header = (props) => { domainSwitch = process.env.I18N_DOMAIN; } - console.log(_.isEmpty(router.query)); return (
{
- + gov.wales { > { - destroyCookie(null, "pinsUser"), + destroyCookie({}, "pinsUser"), window.localStorage.clear(); }} className="govuk-header__link govuk-!-margin-right-3" diff --git a/components/homepage/casesearch.js b/components/homepage/casesearch.js index faa4b5a5..738f2722 100644 --- a/components/homepage/casesearch.js +++ b/components/homepage/casesearch.js @@ -32,16 +32,19 @@ const RenderTextfield = ({ <>
- {hint1} - +
  • {hint2}
  • {hint3}
- +
-
- {hint1} -
+
+ {hint1} +
+ {touched && error && ( Error:{" "} @@ -181,7 +182,7 @@ let Login = (props) => { type="text" aria-describedby="basicSearch-hint" hint1={t("home:login-card-id-label")} - hint2={t("home:login-card-id-hint")} + label={t("home:login-card-id-hint")} />
-

+

{t("home:login-card-title-temp")} -

+

diff --git a/components/myportal.js b/components/myportal.js index 3ab63d77..63a7d9e5 100644 --- a/components/myportal.js +++ b/components/myportal.js @@ -17,11 +17,28 @@ const MyPortal = (props) => { const { locale } = router; return ( -

+
+
+

+ {router.locale + { +

+
diff --git a/components/myportal/makenewappeal.js b/components/myportal/makenewappeal.js index 94bae422..d2476b86 100644 --- a/components/myportal/makenewappeal.js +++ b/components/myportal/makenewappeal.js @@ -10,9 +10,9 @@ export default function MakeNewAppeal() { return (
-

+

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

+

{t("myportal:makenewappeal-card-paragraph-one")}

diff --git a/components/myportal/searchcases.js b/components/myportal/searchcases.js index d0ea6529..f43e5f3e 100644 --- a/components/myportal/searchcases.js +++ b/components/myportal/searchcases.js @@ -37,16 +37,21 @@ const RenderTextfield = ({ } >
- {hint1} +
{hint2} CAS-00009-W8N6W4
- + {touched && error && ( Error:{" "} @@ -76,7 +81,7 @@ let CaseSearch = (props) => { const onHandleSubmit = (values) => { spinnerState(); - router.replace({ + router.push({ pathname: router.locale == "cy" ? "/fymhorth/canlyniadauchwilio" diff --git a/components/myportal/topthree.js b/components/myportal/topthree.js index 2b4cfd1d..e84c0564 100644 --- a/components/myportal/topthree.js +++ b/components/myportal/topthree.js @@ -4,77 +4,93 @@ import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; import { setCurrentReference } from "../../store/currentView/action"; import { connect } from "react-redux"; +import { parseCookies } from "nookies"; +import { + getSASToken, + getWatchedCasesProxy, + getPortalModuleDetailsProxy, + deleteWatchedCases, +} from "../../actions"; + +import { + setWatchedCases, + setWatchedCasesDetails, +} from "../../store/watchedCases/action"; +import { getFormCollectionByID } from "../../components/utils"; const TopThree = (props) => { let { t } = useTranslation(); - const { showTopThree, showDetails, setCurrentReference, topThreeType } = - props; + const { + showTopThree, + showDetails, + setCurrentReference, + topThreeType, + setWatchedCases, + setWatchedCasesDetails, + } = props; const router = useRouter(); const { locale } = router; let topthreeRow = []; - // for (var i = 0; i < 3; i++) { - // (function (i) { - // topthreeRow.push( - //
- //
- // - // {topThreeType != "awaitingSubmission" ? ( - //
- // Addressaa: - // {showDetails[i].value[0] - // .pinswg_siteaddressline1 == null - // ? "not entered" - // : showDetails[i].value[0] - // .pinswg_siteaddressline1} - //
- // ) : ( - // "" - // )} - - // {topThreeType == "awaitingSubmission" ? ( - //
- // Make Representation on Case Incomplete, not - // submitted - //
- // ) : ( - // "" - // )} - //
- //
- //
- // ); - // })(i); - // } - let showTopThreeArr = showTopThree.value; - Object.keys(showTopThreeArr).map((key, index) => { + const deleteItem = (caseID, topThreeType) => { + let token = getSASToken(); + let cookies = parseCookies(); + topThreeType == "watchedCases" && + deleteWatchedCases(caseID) + .then((data) => data) + .then(() => { + getWatchedCasesProxy(token, cookies.pinsUser).then( + (data) => { + setWatchedCases(data), + getDetails(token, data, "myWatchedCases").then( + (data) => { + setWatchedCasesDetails(data); + } + ); + } + ); + }); + }; + + const getDetails = (token, 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( + token, + 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); + }; + + let topThreeOnlyArr = showTopThreeArr.slice(0, 3); + Object.keys(topThreeOnlyArr).map((key, index) => { topthreeRow.push(
@@ -96,17 +112,32 @@ const TopThree = (props) => { onClick={() => { setCurrentReference({ "currentReference": - showTopThreeArr[key].ticketnumber, + topThreeType != "watchedCases" + ? showTopThreeArr[key] + .ticketnumber + : showTopThreeArr[key][ + "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + ], "currentType": topThreeType, "incidentid": - showTopThreeArr[key].incidentid, + topThreeType != "watchedCases" + ? showTopThreeArr[key] + .incidentid + : showTopThreeArr[key][ + " _pinswg_watchedcase_value" + ], + "appealType": showTopThreeArr[key] .pinswg_appealcasetype, }); }} > - {showTopThreeArr[key].ticketnumber} + {topThreeType != "watchedCases" + ? showTopThreeArr[key].ticketnumber + : showTopThreeArr[key][ + "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + ]}
@@ -140,7 +171,30 @@ const TopThree = (props) => { "" )}
-
+ + {topThreeType == "watchedCases" && ( + + )}
); }); @@ -176,6 +230,12 @@ const mapDispatchToProps = (dispatch) => { setCurrentReference: (currentReference) => { dispatch(setCurrentReference(currentReference)); }, + setWatchedCases: (watchedCases) => { + dispatch(setWatchedCases(watchedCases)); + }, + setWatchedCasesDetails: (watchedCasesDetails) => { + dispatch(setWatchedCasesDetails(watchedCasesDetails)); + }, }; }; diff --git a/components/myportal/viewall.js b/components/myportal/viewall.js index f49d637a..f285b9a7 100644 --- a/components/myportal/viewall.js +++ b/components/myportal/viewall.js @@ -5,8 +5,13 @@ import { setCurrentReference } from "../../store/currentView/action"; import { connect } from "react-redux"; const ViewAllResults = (props) => { - const { searchString, searchResultsObj, currentView, setCurrentReference } = - props; + const { + searchString, + searchResultsObj, + currentView, + setCurrentReference, + myportal, + } = props; let { t } = useTranslation(); @@ -21,14 +26,35 @@ const ViewAllResults = (props) => { resultsRowArr.push(
- + { setCurrentReference({ "currentReference": - resultsArr[index].reference, + currentView.viewKey != "watchedCases" + ? resultsArr[index].ticketnumber + : resultsArr[index][ + "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + ], + "currentType": currentView.viewKey, - "incidentid": resultsArr[index].incidentid, + "incidentid": + currentView.viewKey != "watchedCases" + ? resultsArr[index].incidentid + : resultsArr[index][ + " _pinswg_watchedcase_value" + ], + "appealType": resultsArr[index].pinswg_appealcasetype, }); @@ -37,7 +63,12 @@ const ViewAllResults = (props) => { Case Reference: - {resultsArr[index].ticketnumber} + + {currentView.viewKey != "watchedCases" + ? resultsArr[index].ticketnumber + : resultsArr[index][ + "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + ]}
diff --git a/components/search/searchresults.js b/components/search/searchresults.js index 20b1ec9e..4fd291ec 100644 --- a/components/search/searchresults.js +++ b/components/search/searchresults.js @@ -23,10 +23,27 @@ import { setSearchResults, setSearchDetails, } from "../../store/searchOutput/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 } from "../utils"; +import { + getSearchDetailsPaged, + getFormCollection, + getFormCollectionByID, +} from "../utils"; + +import { + createWatchedCases, + getSASToken, + getWatchedCasesProxy, + getPortalModuleDetailsProxy, + deleteWatchedCases, +} from "../../actions"; const SearchResults = (props) => { const { @@ -38,6 +55,9 @@ const SearchResults = (props) => { setSearchDetails, advancedSearch, myportal, + watchedCases, + setWatchedCases, + setWatchedCasesDetails, } = props; let { t } = useTranslation(); @@ -54,6 +74,93 @@ const SearchResults = (props) => { : setShowSpinnerState(true); }; + const cookies = parseCookies(); + + const selectWatchedCase = (loggedInUser, incidentID, appealType) => { + let token = getSASToken(); + + let updateBody = { + "pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")", + "pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")", + "pinswg_appealcasetype": +appealType, + }; + + createWatchedCases(updateBody) + .then((data) => data) + .then(() => { + getWatchedCasesProxy(token, cookies.pinsUser).then((data) => { + setWatchedCases(data), + getDetails(token, data, "myWatchedCases").then( + (data) => { + setWatchedCasesDetails(data); + } + ); + }); + }); + }; + + const isWatchedCase = (whichIncident) => { + let isWatched = jsonpath.query( + watchedCases, + "$..value[?(@._pinswg_watchedcase_value=='" + whichIncident + "')]" + ); + + return isWatched; + }; + + const deleteItem = (caseID, topThreeType) => { + let token = getSASToken(); + let cookies = parseCookies(); + topThreeType == "watchedCases" && + deleteWatchedCases(caseID) + .then((data) => data) + .then(() => { + getWatchedCasesProxy(token, cookies.pinsUser).then( + (data) => { + setWatchedCases(data), + getDetails(token, data, "myWatchedCases").then( + (data) => { + setWatchedCasesDetails(data); + } + ); + } + ); + }); + }; + + const getDetails = (token, 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( + token, + 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 ResultsView = (resultsArr) => { return ( <> @@ -77,6 +184,9 @@ const SearchResults = (props) => {
{t("search:searchresults-status-label")}
+ {myportal == "true" && ( +
+ )}
{resultsArr.map((item, key) => { @@ -85,8 +195,6 @@ const SearchResults = (props) => { "$..value[?(@.pinswg_name=='" + item.title + "')]" ); detailsObj = detailsObj[0]; - console.log(props.myportal); - return (
@@ -115,7 +223,6 @@ const SearchResults = (props) => { }); }} > - mm {t( "search:searchresults-case-reference-label" @@ -270,6 +377,51 @@ const SearchResults = (props) => { "statuscode@OData.Community.Display.V1.FormattedValue" ] || "N/A"}
+ {myportal == "true" && ( +
+ {isWatchedCase(item.incidentid).length > + 0 == + true ? ( + { + deleteItem( + isWatchedCase( + item.incidentid + )[0].pinswg_watchlistid, + + "watchedCases" + ); + alert( + "You have stopped watching case " + + item.title + ); + }} + title="Stop watching this case" + > + − + + ) : ( + { + selectWatchedCase( + cookies.pinsUser, + item.incidentid, + item.pinswg_appealcasetype + ); + alert( + "You are watching case " + + item.title + ); + }} + title="Watch this case" + > + + + + )} +
+ )}
); })} @@ -402,6 +554,12 @@ const mapDispatchToProps = (dispatch) => { setSearchDetails: (searchDetailsObj) => { dispatch(setSearchDetails(searchDetailsObj)); }, + setWatchedCases: (watchedCases) => { + dispatch(setWatchedCases(watchedCases)); + }, + setWatchedCasesDetails: (watchedCasesDetails) => { + dispatch(setWatchedCasesDetails(watchedCasesDetails)); + }, }; }; diff --git a/components/searchresults.js b/components/searchresults.js index ad1555a7..0d8de4b1 100644 --- a/components/searchresults.js +++ b/components/searchresults.js @@ -7,7 +7,13 @@ import SearchResults from "./search/searchresults"; import CRMError from "./crmError"; export default function Search(props) { - const { searchString, searchResultsObj, advancedSearch, myportal } = props; + const { + searchString, + searchResultsObj, + advancedSearch, + myportal, + watchedCases, + } = props; let { t } = useTranslation(); const router = useRouter(); @@ -41,6 +47,7 @@ export default function Search(props) { searchResultsObj.searchDetailsObj } myportal={myportal} + watchedCases={watchedCases} />
diff --git a/components/servicebanner.js b/components/servicebanner.js index 7654ba9c..d963c7c3 100644 --- a/components/servicebanner.js +++ b/components/servicebanner.js @@ -16,6 +16,15 @@ export default function ServiceBanner() { } alt="Planning casework" /> + {
); diff --git a/pages/myportal/case.js b/pages/myportal/case.js index 8a449898..72cb3768 100644 --- a/pages/myportal/case.js +++ b/pages/myportal/case.js @@ -57,6 +57,9 @@ const Home = (props) => { props.myRepresentations.myRepresentations } watchedCases={props.watchedCases.watchedCases} + watchedCasesDetails={ + props.watchedCases.watchedCasesDetails + } awaitingSubmission={ props.awaitingSubmission.awaitingSubmission } diff --git a/pages/myportal/index.js b/pages/myportal/index.js index ca0eec35..ca260dae 100644 --- a/pages/myportal/index.js +++ b/pages/myportal/index.js @@ -154,11 +154,8 @@ export const getServerSideProps = wrapper.getServerSideProps( const token = await getSASToken(); - console.log("does it have ", cookies.pinsUser); let loggedInUser = cookies.pinsUser; - console.log("qweqe ", loggedInUser); - const [ accountDetails, myCases, @@ -174,36 +171,15 @@ export const getServerSideProps = wrapper.getServerSideProps( ]); //const cookiesMaker = nookies.get(ctx) - - let now = new Date(); - let expDate = new Date(now); - expDate.setDate(now.getDate() + 1); - - console.log( - "Check: ", - cookies, - cookies.pinsUser, - loggedInUser, - nookies.get("pinsUser") - ); - - // nookies.set(ctx, "pinsUser", loggedInUser, { - // expires: expDate, - // httpOnly: false, - // path: "/", - // }); - - console.log(" from cookie ", cookies); - const [ myCasesDetails, myRepresentationsDetails, watchedCasesDetails, // awaitingSubmissionDetails, ] = await Promise.all([ - await getDetails(token, myCases), - await getDetails(token, myRepresentations), - await getDetails(token, watchedCases), + await getDetails(token, myCases, "myCases"), + await getDetails(token, myRepresentations, "myRepresentations"), + await getDetails(token, watchedCases, "myWatchedCases"), // await getDetails(awaitingSubmission), ]); @@ -222,20 +198,30 @@ export const getServerSideProps = wrapper.getServerSideProps( } ); -const getDetails = (token, resultsObj) => { +const getDetails = (token, resultsObj, detailsType) => { //console.log(resultsObj); let detailsArr = []; resultsObj = resultsObj.value; const detailsObj = resultsObj.map((searchDetail, index) => { if (searchDetail.pinswg_appealcasetype == null) { - console.log(searchDetail.ticketnumber); + console.log( + detailsType != "myWatchedCases" + ? searchDetail.ticketnumber + : searchDetail[ + "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + ] + ); } else { detailsArr.push( getPortalModuleDetails( token, getFormCollectionByID(searchDetail.pinswg_appealcasetype) .LogicalCollectionName, - searchDetail.ticketnumber + detailsType != "myWatchedCases" + ? searchDetail.ticketnumber + : searchDetail[ + "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + ] ) ); } diff --git a/pages/myportal/searchresults.js b/pages/myportal/searchresults.js index f57fd500..4a33afa5 100644 --- a/pages/myportal/searchresults.js +++ b/pages/myportal/searchresults.js @@ -16,7 +16,10 @@ import useTranslation from "next-translate/useTranslation"; import jsonpath from "jsonpath"; import data from "../../data/collections.json"; -import { getSearchDetails } from "../../components/utils"; +import { + getSearchDetails, + getFormCollectionByID, +} from "../../components/utils"; import { setSearch, getSearchObj } from "../../store/search/action"; import { setSearchResults, @@ -25,16 +28,22 @@ import { setDocumentHistory, getSearchResultsObj, } from "../../store/searchOutput/action"; +import { + setWatchedCases, + setWatchedCasesDetails, +} from "../../store/watchedCases/action"; import { getBasicSearch, getBasicSearchDetails, getSearchDocumentDetails, getSearchDocumentHistory, + getWatchedCases, + getPortalModuleDetails, getSASToken, } from "../../actions"; const Home = (props) => { - const { footerLinks, pages } = props; + const { footerLinks, pages, watchedCases } = props; let { t, lang } = useTranslation(); const router = useRouter(); @@ -57,6 +66,7 @@ const Home = (props) => { searchString={props.search.searchString} searchResultsObj={props.searchResultsObj} myportal="true" + watchedCases={watchedCases} />
@@ -66,36 +76,77 @@ const Home = (props) => { }; export const getServerSideProps = wrapper.getServerSideProps( - (store) => - async ({ query, req, res }) => { - console.log("query-", query); + (store) => async (ctx) => { + const { query, req, res } = ctx; + console.log("query-", query); - const token = await getSASToken(); + const { cookies } = req; - let searchResultsObj = await getBasicSearch(token, query.q); + const token = await getSASToken(); - searchResultsObj = - searchResultsObj.status == 502 - ? { - value: [], - errorCode: searchResultsObj.status, - errorMsg: searchResultsObj.statusText, - } - : searchResultsObj; + let loggedInUser = cookies.pinsUser; - //console.log("sssss", searchResultsObj); + let [searchResultsObj, watchedCases] = await Promise.all([ + await getBasicSearch(token, query.q), + await getWatchedCases(token, loggedInUser), + ]); - const searchDetailsObj = await getSearchDetails( - token, - searchResultsObj - ); + searchResultsObj = + searchResultsObj.status == 502 + ? { + value: [], + errorCode: searchResultsObj.status, + errorMsg: searchResultsObj.statusText, + } + : searchResultsObj; - store.dispatch(setSearchResults(searchResultsObj)); - store.dispatch(setSearchDetails(searchDetailsObj)); - store.dispatch(setSearch(query.q)); - } + //console.log("sssss", searchResultsObj); + + const [searchDetailsObj, watchedCasesDetails] = await Promise.all([ + await getSearchDetails(token, searchResultsObj), + await getDetails(token, watchedCases, "myWatchedCases"), + ]); + + store.dispatch(setSearchResults(searchResultsObj)); + store.dispatch(setSearchDetails(searchDetailsObj)); + store.dispatch(setSearch(query.q)); + store.dispatch(setWatchedCases(watchedCases)); + store.dispatch(setWatchedCasesDetails(watchedCasesDetails)); + } ); +const getDetails = (token, 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( + getPortalModuleDetails( + token, + 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 mapStateToProps = (state) => { return { currentView: state.currentView, diff --git a/pages/myportal/viewall.js b/pages/myportal/viewall.js index dfdd04ee..c5753120 100644 --- a/pages/myportal/viewall.js +++ b/pages/myportal/viewall.js @@ -52,6 +52,7 @@ const Home = (props) => { watchedCases={props.watchedCases} myRepresentations={props.myRepresentations} awaitingSubmission={props.awaitingSubmission} + myportal="true" />