added watched cases and remove watched cases
This commit is contained in:
@@ -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 (
|
||||
<>
|
||||
@@ -88,8 +195,6 @@ const SearchResults = (props) => {
|
||||
"$..value[?(@.pinswg_name=='" + item.title + "')]"
|
||||
);
|
||||
detailsObj = detailsObj[0];
|
||||
console.log(props.myportal);
|
||||
|
||||
return (
|
||||
<div className="govuk-summary-list__row" key={key}>
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16 ">
|
||||
@@ -274,15 +379,47 @@ const SearchResults = (props) => {
|
||||
</dd>
|
||||
{myportal == "true" && (
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-14 govuk-summary-list__action">
|
||||
<Link href="">
|
||||
<a
|
||||
{isWatchedCase(item.incidentid).length >
|
||||
0 ==
|
||||
true ? (
|
||||
<span
|
||||
className="govuk-summary-list__actionLink watched_link"
|
||||
onClick={() => {
|
||||
deleteItem(
|
||||
isWatchedCase(
|
||||
item.incidentid
|
||||
)[0].pinswg_watchlistid,
|
||||
|
||||
"watchedCases"
|
||||
);
|
||||
alert(
|
||||
"You have stopped watching case " +
|
||||
item.title
|
||||
);
|
||||
}}
|
||||
title="Stop watching this case"
|
||||
>
|
||||
−
|
||||
</span>
|
||||
) : (
|
||||
<span
|
||||
className="govuk-summary-list__actionLink"
|
||||
onClick={() => {}}
|
||||
onClick={() => {
|
||||
selectWatchedCase(
|
||||
cookies.pinsUser,
|
||||
item.incidentid,
|
||||
item.pinswg_appealcasetype
|
||||
);
|
||||
alert(
|
||||
"You are watching case " +
|
||||
item.title
|
||||
);
|
||||
}}
|
||||
title="Watch this case"
|
||||
>
|
||||
+
|
||||
</a>
|
||||
</Link>
|
||||
</span>
|
||||
)}
|
||||
</dd>
|
||||
)}
|
||||
</div>
|
||||
@@ -417,6 +554,12 @@ const mapDispatchToProps = (dispatch) => {
|
||||
setSearchDetails: (searchDetailsObj) => {
|
||||
dispatch(setSearchDetails(searchDetailsObj));
|
||||
},
|
||||
setWatchedCases: (watchedCases) => {
|
||||
dispatch(setWatchedCases(watchedCases));
|
||||
},
|
||||
setWatchedCasesDetails: (watchedCasesDetails) => {
|
||||
dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user