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
+2 -8
View File
@@ -522,13 +522,7 @@ const CaseSummary = (props) => {
className="govuk-link" className="govuk-link"
onClick={() => { onClick={() => {
// signIn("email"); // signIn("email");
signIn("email", { signIn();
callbackUrl:
"/myportal/searchresults?q=" +
props.currentView
.caseReference
.currentReference,
});
// selectWatchedCase( // selectWatchedCase(
// cookies.pinsUser, // cookies.pinsUser,
// item.incidentid, // item.incidentid,
@@ -541,7 +535,7 @@ const CaseSummary = (props) => {
}} }}
title={t("case:watch-this-case-link")} title={t("case:watch-this-case-link")}
> >
{t("case:watch-this-case-link")} {t("case:watch-this-case-link")} dd
</span> </span>
)} )}
</div> </div>
+11 -17
View File
@@ -56,6 +56,16 @@ const Header = (props) => {
domainSwitch = process.env.I18N_DOMAIN; domainSwitch = process.env.I18N_DOMAIN;
} }
const handleLogout = () => {
console.info("////////////\n" + "logout" + "\n////////////");
window.localStorage.clear(),
destroyCookie(null, "next-auth.csrf-token"),
destroyCookie(null, "next-auth.callback-url"),
destroyCookie(null, "pedw_locale"),
destroyCookie(null, "pinsUser"),
signOut({ callbackUrl: "/logout" });
};
return ( return (
<header <header
className="govuk-header " className="govuk-header "
@@ -219,23 +229,7 @@ const Header = (props) => {
> >
<a <a
onClick={() => { onClick={() => {
window.localStorage.clear(), handleLogout();
destroyCookie(
null,
"next-auth.csrf-token"
),
destroyCookie(
null,
"next-auth.callback-url"
),
destroyCookie(null, "pedw_locale"),
destroyCookie(null, "pinsUser"),
signOut({
callbackUrl:
locale == "cy"
? "/allgofnodi"
: "/logout",
});
}} }}
className="govuk-header__link govuk-!-margin-right-3" className="govuk-header__link govuk-!-margin-right-3"
> >
+57 -14
View File
@@ -23,6 +23,7 @@ import {
setSearchResults, setSearchResults,
setSearchDetails, setSearchDetails,
} from "../../store/searchOutput/action"; } from "../../store/searchOutput/action";
import { setLoggedInUserId } from "../../store/accountDetails/action";
import { import {
setWatchedCases, setWatchedCases,
setWatchedCasesDetails, setWatchedCasesDetails,
@@ -75,6 +76,7 @@ const SearchResults = (props) => {
const [selectedOption, setSelectedOption] = useState(10); const [selectedOption, setSelectedOption] = useState(10);
const [orderByState, setOrderbyState] = useState("createdon"); const [orderByState, setOrderbyState] = useState("createdon");
const [fieldSortState, setfieldSortState] = useState("asc"); const [fieldSortState, setfieldSortState] = useState("asc");
const [loginToWatch, setLoginToWatch] = useState("true");
let spinnerState = () => { let spinnerState = () => {
showSpinnerState == true showSpinnerState == true
@@ -94,12 +96,14 @@ const SearchResults = (props) => {
createWatchedCases(updateBody) createWatchedCases(updateBody)
.then((data) => data) .then((data) => data)
.then(() => { .then(() => {
getWatchedCasesProxy(cookies.pinsUser).then((data) => { getWatchedCasesProxy(props.accountDetails.loggedinUserId).then(
setWatchedCases(data), (data) => {
getDetails(data, "myWatchedCases").then((data) => { setWatchedCases(data),
setWatchedCasesDetails(data); getDetails(data, "myWatchedCases").then((data) => {
}); setWatchedCasesDetails(data);
}); });
}
);
}); });
}; };
@@ -118,7 +122,9 @@ const SearchResults = (props) => {
deleteWatchedCases(caseID) deleteWatchedCases(caseID)
.then((data) => data) .then((data) => data)
.then(() => { .then(() => {
getWatchedCasesProxy(cookies.pinsUser).then((data) => { getWatchedCasesProxy(
props.accountDetails.loggedinUserId
).then((data) => {
setWatchedCases(data), setWatchedCases(data),
getDetails(data, "myWatchedCases").then((data) => { getDetails(data, "myWatchedCases").then((data) => {
setWatchedCasesDetails(data); setWatchedCasesDetails(data);
@@ -128,7 +134,7 @@ const SearchResults = (props) => {
}; };
const getDetails = (resultsObj, detailsType) => { const getDetails = (resultsObj, detailsType) => {
//console.log(resultsObj); console.log(resultsObj);
let detailsArr = []; let detailsArr = [];
resultsObj = resultsObj.value; resultsObj = resultsObj.value;
const detailsObj = resultsObj.map((searchDetail, index) => { const detailsObj = resultsObj.map((searchDetail, index) => {
@@ -520,7 +526,8 @@ const SearchResults = (props) => {
className="govuk-summary-list__actionLink watchLink" className="govuk-summary-list__actionLink watchLink"
onClick={() => { onClick={() => {
selectWatchedCase( selectWatchedCase(
cookies.pinsUser, props.accountDetails
.loggedinUserId,
item.incidentid, item.incidentid,
item.pinswg_appealcasetype item.pinswg_appealcasetype
); );
@@ -545,13 +552,17 @@ const SearchResults = (props) => {
className="govuk-summary-list__actionLink watchLink" className="govuk-summary-list__actionLink watchLink"
onClick={() => { onClick={() => {
// signIn("email"); // signIn("email");
signIn("email", { signIn(undefined, {
callbackUrl: callbackUrl:
"/myportal/case?q=" + "/myportal/searchresults?q=" +
searchString, searchString +
"&toWatch=" +
item.incidentid +
"_" +
item.pinswg_appealcasetype,
}); });
// selectWatchedCase( // selectWatchedCase(
// cookies.pinsUser, // props.accountDetails.loggedinUserId,
// item.incidentid, // item.incidentid,
// item.pinswg_appealcasetype // item.pinswg_appealcasetype
// ); // );
@@ -684,6 +695,30 @@ const SearchResults = (props) => {
} else { } else {
setSearchLoaded(true); 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, selectedOption,
fieldSortState, 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);
@@ -37,6 +37,8 @@ export default async function ApiProxy(req, res) {
var data = JSON.stringify(req.body); var data = JSON.stringify(req.body);
var queryUrl = "pinswg_watchlists"; var queryUrl = "pinswg_watchlists";
console.log(data);
var config = { var config = {
method: "post", method: "post",
url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
@@ -51,11 +53,16 @@ export default async function ApiProxy(req, res) {
data: data, data: data,
}; };
console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
console.log(data);
return axios(config) return axios(config)
.then(({ data }) => { .then(({ data }) => {
res.status(200).json(data); res.status(200).json(data);
}) })
.catch((err) => { .catch((err) => {
console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
console.log(data);
console.log(consoleLogger(err)); console.log(consoleLogger(err));
res.status(400).json(err); res.status(400).json(err);
}); });