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));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user