17025 unsub issues

This commit is contained in:
2025-06-10 11:25:32 +01:00
parent 5dee64dfec
commit 193da6af2f
9 changed files with 412 additions and 25 deletions
+147
View File
@@ -94,6 +94,36 @@ const SearchResults = (props) => {
});
};
const selectEmailNotifications = (
emailaddress,
loggedInUser,
incidentID,
appealType
) => {
let updateBody = {
"pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")",
"pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")",
"pinswg_appealcasetype": +appealType,
"pinswg_emailnotifications": true,
};
console.log("Email signed up");
createWatchedCases(updateBody)
.then((data) => data)
.then(() => {
getWatchedCasesProxy(props.accountDetails.loggedinUserId).then(
(data) => {
setWatchedCases(data),
getDetailsProxy(data, "myWatchedCases").then(
(data) => {
setWatchedCasesDetails(data);
}
);
}
);
});
};
const isWatchedCase = (whichIncident) => {
let isWatched = jsonpath({
path:
@@ -107,6 +137,19 @@ const SearchResults = (props) => {
return isWatched;
};
const isEmailSignUp = (whichIncident) => {
let isEmail = jsonpath({
path:
"$..value[?(@ && @._pinswg_watchedcase_value=='" +
whichIncident +
"' && @.pinswg_emailnotifications==true)]",
json: watchedCases,
eval: true,
});
return isEmail;
};
const deleteItem = (caseID, topThreeType) => {
let cookies = parseCookies();
topThreeType == "watchedCases" &&
@@ -116,6 +159,27 @@ const SearchResults = (props) => {
getWatchedCasesProxy(
props.accountDetails.loggedinUserId
).then((data) => {
let showWatchedCases = (submittedArr) => {
const required = submittedArr.value.filter((el) => {
return (
el.pinswg_representationsubmitted == null
);
});
let newObj = {};
return Object.assign(newObj, {
"@odata.count": required.length,
"value": required,
});
};
data = showWatchedCases(data);
data.value.sort(function compare(a, b) {
var dateA = new Date(a.createdon);
var dateB = new Date(b.createdon);
return dateB - dateA;
});
setWatchedCases(data),
getDetailsProxy(data, "myWatchedCases").then(
(data) => {
@@ -594,6 +658,61 @@ const SearchResults = (props) => {
<span className="eye"></span>
</button>
)}
{isEmailSignUp(item.incidentid)
.length >
0 ==
true ? (
<button
className="govuk-summary-list__actionLink mailLink watched_link"
title="Unsubscribe to email updates"
onClick={() => {
confirm(
t(
"case:summary-unsubscribe-mail-label"
) +
item.title +
"?"
) &&
deleteItem(
isEmailSignUp(
item.incidentid
)[0]
.pinswg_watchlistid,
"watchedCases"
);
}}
>
<span className="mailicon icon"></span>
</button>
) : (
<button
className="govuk-summary-list__actionLink mailLink"
title="Email about changes"
onClick={() => {
confirm(
t(
"case:summary-subscribe-mail-label"
) +
item.title +
"?"
) &&
selectEmailNotifications(
props
.accountDetails
.accountDetails
.emailaddress1,
props
.accountDetails
.loggedinUserId,
item.incidentid,
item.pinswg_appealcasetype
);
}}
>
<span className="mailicon icon"></span>
</button>
)}
</dd>
)}
@@ -639,6 +758,34 @@ const SearchResults = (props) => {
>
<span className="eye"></span>
</button>
<button
className="govuk-summary-list__actionLink mailLink"
title={t(
"common:subscribe-title-label"
)}
onClick={() => {
confirm(
t(
"case:summary-subscribe-mail-label"
) +
item.pinswg_name +
"?"
) &&
signIn(undefined, {
callbackUrl:
"/myportal/addresssearchresults?" +
new URLSearchParams(
searchString
) +
"&toWatch=" +
item.incidentid +
"_" +
item.pinswg_appealcasetype,
});
}}
>
<span className="mailicon icon"></span>
</button>
</dd>
)}
</div>