updated watch case logic for summary page
This commit is contained in:
+240
-70
@@ -7,14 +7,26 @@ import jsonpath from "jsonpath";
|
||||
import _ from "lodash";
|
||||
import transLookup from "../../data/lookuptranslations.json";
|
||||
|
||||
import { getLinkedCases } from "../../actions";
|
||||
import {
|
||||
getLinkedCases,
|
||||
createWatchedCases,
|
||||
getWatchedCasesProxy,
|
||||
getPortalModuleDetailsProxy,
|
||||
deleteWatchedCases,
|
||||
} from "../../actions";
|
||||
import {
|
||||
setCurrentLinkedCases,
|
||||
setCurrentReference,
|
||||
} from "../../store/currentView/action";
|
||||
|
||||
import {
|
||||
setWatchedCases,
|
||||
setWatchedCasesDetails,
|
||||
} from "../../store/watchedCases/action";
|
||||
|
||||
import { getFormCollectionByID } from "../utils";
|
||||
import { getSession, useSession } from "next-auth/react";
|
||||
import { getSession, useSession, signIn } from "next-auth/react";
|
||||
import { parseCookies, setCookie, destroyCookie } from "nookies";
|
||||
|
||||
import Pinswg_advertsid from "./summaryTypes/pinswg_advertsid";
|
||||
import Pinswg_callinss77id from "./summaryTypes/pinswg_callinss77id";
|
||||
@@ -61,12 +73,92 @@ const CaseSummary = (props) => {
|
||||
setCurrentLinkedCases,
|
||||
linkedCasesReference,
|
||||
setCurrentReference,
|
||||
setWatchedCases,
|
||||
setWatchedCasesDetails,
|
||||
showMap,
|
||||
showLoginCheck,
|
||||
} = props;
|
||||
|
||||
const { data: session, status } = useSession();
|
||||
//console.log("session status:", status, session);
|
||||
|
||||
const cookies = parseCookies();
|
||||
|
||||
const selectWatchedCase = (loggedInUser, incidentID, appealType) => {
|
||||
let updateBody = {
|
||||
"pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")",
|
||||
"pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")",
|
||||
"pinswg_appealcasetype": +appealType,
|
||||
};
|
||||
|
||||
createWatchedCases(updateBody)
|
||||
.then((data) => data)
|
||||
.then(() => {
|
||||
getWatchedCasesProxy(loggedInUser).then((data) => {
|
||||
setWatchedCases(data),
|
||||
getDetails(data, "myWatchedCases").then((data) => {
|
||||
setWatchedCasesDetails(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const getDetails = (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(
|
||||
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 isWatchedCase = (whichIncident) => {
|
||||
let isWatched = jsonpath.query(
|
||||
watchedCases,
|
||||
"$..value[?(@._pinswg_watchedcase_value=='" + whichIncident + "')]"
|
||||
);
|
||||
|
||||
return isWatched;
|
||||
};
|
||||
|
||||
const deleteItem = (caseID, topThreeType) => {
|
||||
let cookies = parseCookies();
|
||||
topThreeType == "watchedCases" &&
|
||||
deleteWatchedCases(caseID)
|
||||
.then((data) => data)
|
||||
.then(() => {
|
||||
getWatchedCasesProxy(cookies.pinsUser).then((data) => {
|
||||
setWatchedCases(data),
|
||||
getDetails(data, "myWatchedCases").then((data) => {
|
||||
setWatchedCasesDetails(data);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const noRepresentationLink = ["/dnsdetails", "/dns/[developmentName]"];
|
||||
|
||||
let setCaseQueryObj = props[currentType];
|
||||
@@ -291,81 +383,153 @@ const CaseSummary = (props) => {
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
{(props.currentView.showLogin == true ||
|
||||
props.currentView.showLogin == "true") && (
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<div className="govuk-button-group">
|
||||
{props.currentView.showReps == true ||
|
||||
(props.currentView.showReps == "true" &&
|
||||
_.has(detailsObj, "pinswg_startdate") &&
|
||||
hasEndDate &&
|
||||
showReps(
|
||||
detailsObj.pinswg_startdate,
|
||||
detailsObj.pinswg_representation_period_end_date
|
||||
) && (
|
||||
<>
|
||||
<Link
|
||||
href={{
|
||||
pathname:
|
||||
"/myportal/representation",
|
||||
query: {
|
||||
case:
|
||||
currentType ==
|
||||
"searchResultsObj"
|
||||
? detailsObj.pinswg_name
|
||||
: casesObj.reference,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<a className="govuk-button">
|
||||
{t(
|
||||
"case:summary-make-representation-label"
|
||||
)}
|
||||
</a>
|
||||
</Link>
|
||||
<a
|
||||
onClick={() => {
|
||||
//spinnerState();
|
||||
router.back();
|
||||
}}
|
||||
className="govuk-button govuk-button--secondary"
|
||||
>
|
||||
{t(
|
||||
"case:summary-back-button-label"
|
||||
)}
|
||||
</a>
|
||||
</>
|
||||
))}
|
||||
<div className="govuk-body">
|
||||
<Link href="">
|
||||
<a className="govuk-link">
|
||||
Watch this case
|
||||
</a>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
{props.currentView.showReps == true ||
|
||||
(props.currentView.showReps == "true" &&
|
||||
_.has(detailsObj, "pinswg_startdate") &&
|
||||
<div className="govuk-button-group">
|
||||
{_.has(detailsObj, "pinswg_startdate") &&
|
||||
hasEndDate &&
|
||||
showRepsEnded(
|
||||
showReps(
|
||||
detailsObj.pinswg_startdate,
|
||||
detailsObj.pinswg_representation_period_end_date
|
||||
) && (
|
||||
<div className="govuk-body">
|
||||
Representation Period ended on{" "}
|
||||
{formatDates(
|
||||
detailsObj.pinswg_representation_period_end_date
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<>
|
||||
<Link
|
||||
href={{
|
||||
pathname:
|
||||
"/myportal/representation",
|
||||
query: {
|
||||
case:
|
||||
currentType ==
|
||||
"searchResultsObj"
|
||||
? detailsObj.pinswg_name
|
||||
: casesObj.reference,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<a className="govuk-button">
|
||||
{t(
|
||||
"case:summary-make-representation-label"
|
||||
)}
|
||||
</a>
|
||||
</Link>
|
||||
<a
|
||||
onClick={() => {
|
||||
//spinnerState();
|
||||
router.back();
|
||||
}}
|
||||
className="govuk-button govuk-button--secondary"
|
||||
>
|
||||
{t(
|
||||
"case:summary-back-button-label"
|
||||
)}
|
||||
</a>
|
||||
</>
|
||||
)}
|
||||
<div className="govuk-body">
|
||||
{session &&
|
||||
(isWatchedCase(
|
||||
props.currentView.caseReference
|
||||
.incidentid
|
||||
).length >
|
||||
0 ==
|
||||
true ? (
|
||||
<span
|
||||
className="govuk-link"
|
||||
onClick={() => {
|
||||
deleteItem(
|
||||
isWatchedCase(
|
||||
props.currentView
|
||||
.caseReference
|
||||
.incidentid
|
||||
)[0].pinswg_watchlistid,
|
||||
|
||||
"watchedCases"
|
||||
);
|
||||
alert(
|
||||
"You have stopped watching case " +
|
||||
props.currentView
|
||||
.caseReference
|
||||
.currentReference
|
||||
);
|
||||
}}
|
||||
title="Stop watching this case"
|
||||
>
|
||||
Stop watching this case{" "}
|
||||
</span>
|
||||
) : (
|
||||
<span
|
||||
className=" govuk-link"
|
||||
onClick={() => {
|
||||
selectWatchedCase(
|
||||
props.accountDetails
|
||||
.loggedinUserId,
|
||||
props.currentView
|
||||
.caseReference
|
||||
.incidentid,
|
||||
props.currentView
|
||||
.caseReference
|
||||
.appealType
|
||||
);
|
||||
alert(
|
||||
"You are watching case " +
|
||||
props.currentView
|
||||
.caseReference
|
||||
.currentReference
|
||||
);
|
||||
}}
|
||||
>
|
||||
Watch this case
|
||||
</span>
|
||||
))}
|
||||
|
||||
{!session && (
|
||||
<span
|
||||
className="govuk-link"
|
||||
onClick={() => {
|
||||
// signIn("email");
|
||||
signIn("email", {
|
||||
callbackUrl:
|
||||
"/myportal/searchresults?q=" +
|
||||
props.currentView
|
||||
.caseReference
|
||||
.currentReference,
|
||||
});
|
||||
// selectWatchedCase(
|
||||
// cookies.pinsUser,
|
||||
// item.incidentid,
|
||||
// item.pinswg_appealcasetype
|
||||
// );
|
||||
// alert(
|
||||
// "Trying to watch case " +
|
||||
// item.title
|
||||
// );
|
||||
}}
|
||||
title="Watch this case"
|
||||
>
|
||||
Watch this case
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
{_.has(detailsObj, "pinswg_startdate") &&
|
||||
hasEndDate &&
|
||||
showRepsEnded(
|
||||
detailsObj.pinswg_startdate,
|
||||
detailsObj.pinswg_representation_period_end_date
|
||||
) && (
|
||||
<div className="govuk-body">
|
||||
Representation Period ended on{" "}
|
||||
{formatDates(
|
||||
detailsObj.pinswg_representation_period_end_date
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{/* 1{" "}
|
||||
@@ -849,6 +1013,12 @@ const mapDispatchToProps = (dispatch) => {
|
||||
setCurrentReference: (currentReference) => {
|
||||
dispatch(setCurrentReference(currentReference));
|
||||
},
|
||||
setWatchedCases: (watchedCases) => {
|
||||
dispatch(setWatchedCases(watchedCases));
|
||||
},
|
||||
setWatchedCasesDetails: (watchedCasesDetails) => {
|
||||
dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -533,7 +533,7 @@ const SearchResults = (props) => {
|
||||
)}
|
||||
</dd>
|
||||
)}
|
||||
{/* {showLoginCheck == "true" && !session && (
|
||||
{showLoginCheck == "true" && !session && (
|
||||
<dd>
|
||||
<span
|
||||
className="govuk-summary-list__actionLink watchLink"
|
||||
@@ -541,7 +541,7 @@ const SearchResults = (props) => {
|
||||
// signIn("email");
|
||||
signIn("email", {
|
||||
callbackUrl:
|
||||
"/myportal/searchresults?q=" +
|
||||
"/myportal/case?q=" +
|
||||
searchString,
|
||||
});
|
||||
// selectWatchedCase(
|
||||
@@ -559,7 +559,7 @@ const SearchResults = (props) => {
|
||||
<span className="eye"></span>
|
||||
</span>
|
||||
</dd>
|
||||
)} */}
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
* description: Success
|
||||
*/
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { getToken, azureHeadersPaged, consoleLogger } from "../../../actions";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { azureHeaders, getToken } from "../../../actions";
|
||||
import { azureHeaders, getToken, consoleLogger } from "../../../actions";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ const mapStateToProps = (state) => {
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
accountDetails: state.accountDetails,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
|
||||
const watchedCases = await getWatchedCases(loggedInUser);
|
||||
|
||||
//console.log("sssss", loggedInUser);
|
||||
console.log("sssss", loggedInUser);
|
||||
|
||||
const [accountDetails, searchDetailsObj, watchedCasesDetails] =
|
||||
await Promise.all([
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ const makeStore = ({ isServer }) => {
|
||||
//"searchResultsObj",
|
||||
"appealType",
|
||||
"LPAData",
|
||||
"accountDetails",
|
||||
//"accountDetails",
|
||||
"awaitingSubmission",
|
||||
"myCases",
|
||||
"myRepresentations",
|
||||
|
||||
Reference in New Issue
Block a user