set case to watch on auth

This commit is contained in:
2023-10-26 07:38:10 +01:00
parent f3da69dc75
commit 1807749bba
4 changed files with 77 additions and 39 deletions
+57 -14
View File
@@ -23,6 +23,7 @@ import {
setSearchResults,
setSearchDetails,
} from "../../store/searchOutput/action";
import { setLoggedInUserId } from "../../store/accountDetails/action";
import {
setWatchedCases,
setWatchedCasesDetails,
@@ -75,6 +76,7 @@ const SearchResults = (props) => {
const [selectedOption, setSelectedOption] = useState(10);
const [orderByState, setOrderbyState] = useState("createdon");
const [fieldSortState, setfieldSortState] = useState("asc");
const [loginToWatch, setLoginToWatch] = useState("true");
let spinnerState = () => {
showSpinnerState == true
@@ -94,12 +96,14 @@ const SearchResults = (props) => {
createWatchedCases(updateBody)
.then((data) => data)
.then(() => {
getWatchedCasesProxy(cookies.pinsUser).then((data) => {
setWatchedCases(data),
getDetails(data, "myWatchedCases").then((data) => {
setWatchedCasesDetails(data);
});
});
getWatchedCasesProxy(props.accountDetails.loggedinUserId).then(
(data) => {
setWatchedCases(data),
getDetails(data, "myWatchedCases").then((data) => {
setWatchedCasesDetails(data);
});
}
);
});
};
@@ -118,7 +122,9 @@ const SearchResults = (props) => {
deleteWatchedCases(caseID)
.then((data) => data)
.then(() => {
getWatchedCasesProxy(cookies.pinsUser).then((data) => {
getWatchedCasesProxy(
props.accountDetails.loggedinUserId
).then((data) => {
setWatchedCases(data),
getDetails(data, "myWatchedCases").then((data) => {
setWatchedCasesDetails(data);
@@ -128,7 +134,7 @@ const SearchResults = (props) => {
};
const getDetails = (resultsObj, detailsType) => {
//console.log(resultsObj);
console.log(resultsObj);
let detailsArr = [];
resultsObj = resultsObj.value;
const detailsObj = resultsObj.map((searchDetail, index) => {
@@ -520,7 +526,8 @@ const SearchResults = (props) => {
className="govuk-summary-list__actionLink watchLink"
onClick={() => {
selectWatchedCase(
cookies.pinsUser,
props.accountDetails
.loggedinUserId,
item.incidentid,
item.pinswg_appealcasetype
);
@@ -545,13 +552,17 @@ const SearchResults = (props) => {
className="govuk-summary-list__actionLink watchLink"
onClick={() => {
// signIn("email");
signIn("email", {
signIn(undefined, {
callbackUrl:
"/myportal/case?q=" +
searchString,
"/myportal/searchresults?q=" +
searchString +
"&toWatch=" +
item.incidentid +
"_" +
item.pinswg_appealcasetype,
});
// selectWatchedCase(
// cookies.pinsUser,
// props.accountDetails.loggedinUserId,
// item.incidentid,
// item.pinswg_appealcasetype
// );
@@ -684,6 +695,30 @@ const SearchResults = (props) => {
} else {
setSearchLoaded(true);
}
if (loginToWatch && router.query.hasOwnProperty("toWatch")) {
console.log("am in here");
let now = new Date();
let expDate = new Date(now);
expDate.setDate(now.getDate() + 1);
setLoggedInUserId(props.accountDetails.loggedinUserId);
setCookie(null, "pinsUser", props.accountDetails.loggedinUserId, {
path: "/",
expires: expDate,
});
selectWatchedCase(
props.accountDetails.loggedinUserId,
router.query.toWatch.split("_")[0],
router.query.toWatch.split("_")[1]
);
getSearchPageResults(1, orderByState, fieldSortState);
setLoginToWatch(false);
} else {
console.log("or am in here");
setLoginToWatch(false);
}
}, [
selectedOption,
fieldSortState,
@@ -803,4 +838,12 @@ const mapDispatchToProps = (dispatch) => {
};
};
export default connect(null, mapDispatchToProps)(SearchResults);
const mapStateToProps = (state) => {
return {
// currentView: state.currentView,
accountDetails: state.accountDetails,
// search: state.search,
// searchResultsObj: state.searchResultsObj,
};
};
export default connect(mapStateToProps, mapDispatchToProps)(SearchResults);