Merged PR 1651: 16986 unsubscribe link

16986 unsubscribe link

Related work items: #16986
This commit is contained in:
Robert Bond
2025-06-02 16:43:22 +00:00
6 changed files with 351 additions and 9 deletions
+2
View File
@@ -61,6 +61,8 @@ const Header = (props) => {
"/myportal/representation",
"/myportal/viewall",
"/contactus",
"/unsubscribe/[watchlistid]",
"/unsubscribeall/[watchlistid]",
];
const hasContactLink = [
+5 -1
View File
@@ -85,5 +85,9 @@
"further-details-para-one": "Mae angen i PEDW gadarnhau ychydig mwy o wybodaeth amdanoch cyn y gallwch barhau.",
"further-details-para-two": "Ffoniwch 0300 123 1590 neu cysylltwch â ni ar ",
"login-modal-message": "Mae eich sesiwn ar fin dod i ben mewn {{remaining}} eiliad oherwydd anweithgarwch. Byddwch yn cael eich ailgyfeirio i'r dudalen fewngofnodi.",
"login-modal-button": "Arhoswch wedi mewngofnodi"
"login-modal-button": "Arhoswch wedi mewngofnodi",
"unsubscribe-case-title": "Wedi dad-danysgrifio i'r Achos",
"unsubscribe-case-all-label": "Rydych chi wedi dad-danysgrifio o dderbyn diweddariadau o'r achos canlynol",
"unsubscribe-case-none-label": "Dim byd i'w ddad-danysgrifio",
"unsubscribe-case-label": "Rydych chi wedi dad-danysgrifio o dderbyn diweddariadau e-bost ar gyfer"
}
+5 -1
View File
@@ -85,5 +85,9 @@
"further-details-para-one": "PEDW needs to confirm a bit more information about you before you can continue.",
"further-details-para-two": "Please call 0300 123 1590 or contact us on ",
"login-modal-message": "Your session is about to expire in {{remaining}} seconds due to inactivity. You will be redirected to the login page.",
"login-modal-button": "Stay logged in "
"login-modal-button": "Stay logged in ",
"unsubscribe-case-title": "Unsubscribed to Case",
"unsubscribe-case-all-label": "You have unsubscribed from receiving updates from the following case",
"unsubscribe-case-none-label": "Nothing to unsubscribe",
"unsubscribe-case-label": "You have unsubscribed from receiving email updates for"
}
+9 -7
View File
@@ -64,7 +64,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
const link =
process.env.NEXTAUTH_URL + doc.pinswg_hashlink ||
"[No Link]";
return ` - ${ref}: ${name} (${date})\n Link: ${link}`;
return ` - ${name} (${date})\n Link: ${link}`;
})
.join("\n");
@@ -105,7 +105,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
.map(([email, entries]) => {
const contactName =
entries[0].firstname + " " + entries[0].lastname;
const contactId = entries[0].contactId;
const contactId = entries[0].contactid;
const filteredEntries = entries.filter(
(entry) =>
@@ -140,9 +140,11 @@ const buildNotifyPayloads = (watchlistByEmail) => {
)}\n`
: "";
const caseUnsubscribelink = `Unsubscribe to updates on this case https://${process.env.NEXTAUTH_URL}/unsubscribe/${entry.pinswg_watchlistid}`;
const caseUnsubscribelink = `Unsubscribe to updates on this case ${process.env.NEXTAUTH_URL}/unsubscribe/${entry.pinswg_watchlistid}`;
return `Case: ${caseRef}\n${[
return `Case: ${caseRef}\nLink to case:${
process.env.NEXTAUTH_URL
}/case/${caseRef}\n\n${[
docSection,
sipSection,
repsSection,
@@ -153,7 +155,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
})
.join("\n\n"),
unsubscribeLink: `Unsubscribe by selecting this link if you no longer want to receive any updates ${
process.env.NEXTAUTH_URL + "unsubscribeall/" + "contactId"
process.env.NEXTAUTH_URL + "/unsubscribeall/" + contactId
}`,
};
@@ -163,7 +165,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
personalisation,
reference,
oneClickUnsubscribeURL:
process.env.NEXTAUTH_URL + "unsubscribe/" + "eee",
process.env.NEXTAUTH_URL + "/unsubscribeall/" + contactId,
};
})
.filter(Boolean); // Remove any nulls from filtered-out users
@@ -280,7 +282,7 @@ export default async function CombinedApiProxy(req, res) {
for (const payload of payloads) {
if (!payload) continue; // skip null entries
console.log(payload);
//console.log(payload);
const result = {
email: payload.email_address,
reference: payload.reference,
+156
View File
@@ -0,0 +1,156 @@
import { wrapper } from "../../store/store";
import { connect } from "react-redux";
import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import Link from "next/link";
import CookieBanner from "../../components/cookieBanner";
import Footer from "../../components/footer";
import Header from "../../components/header";
import {
hashAPIPath,
getToken,
azureHeaders,
consoleLogger,
} from "../../actions";
import axios from "axios";
const UnsubscribeCase = (props) => {
let { t, lang } = useTranslation();
const { footerLinks, pages } = props;
return (
<div>
<Head>
<title>
{t("common:unsubscribe-case-title")} -{" "}
{t("common:service-name")}
</title>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header />
<div className="govuk-width-container govuk-!-padding-bottom-9">
<main className="govuk-main-wrapper govuk-!-padding-top-9 govuk-!-padding-bottom-9">
<div className="govuk-grid-row">
<div className="govuk-grid-column-two-thirds ">
<h1>{t("common:unsubscribe-case-title")}</h1>
<p>
{props.caseRef == null
? t(
"common:unsubscribe-case-none-label"
)
: `You have unsubscribed from receiving email
updates for ${props.caseRef}`}
</p>
<Link href="/">
{t("common:logged-out-link")}
</Link>
</div>
</div>
</main>
</div>
<Footer footerLinks={footerLinks} ticketnumber={props} />
</div>
</div>
);
};
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
const getMailCaseById = async (watchedCaseID) => {
var token = await getToken();
var queryUrl =
"pinswg_watchlists?$count=true&$filter=pinswg_emailnotifications eq true and pinswg_watchlistid eq " +
watchedCaseID +
"&$select=_pinswg_contact_value,_pinswg_watchedcase_value";
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token)
)
.then(({ data }) => {
return data;
})
.catch((error) => {
consoleLogger(error);
res.status(400).json(error);
});
};
const deleteWatchedCases = async (watchedCaseID) => {
var watchedCaseID = watchedCaseID;
var token = await getToken();
var queryUrl = "pinswg_watchlists(" + watchedCaseID + ")";
console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
var config = {
method: "delete",
url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Authorization": "Bearer " + token.access_token,
"Content-Type": "application/json",
},
};
return axios(config)
.then(({ data }) => {
//console.log("deleted watched case - " + watchedCaseID);
res.status(200).json(data);
})
.catch((error) => {
console.log("err----:", error);
if (error.response && error.response.status === 404) {
console.warn("Record not found — nothing to delete.");
return { success: false, caseRef: "Not found" };
} else {
consoleLogger(error);
//res.status(400).json(error);
}
});
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
console.log("the query", query.watchlistid);
const searchResultsObj = await getMailCaseById(query.watchlistid);
let caseObj = searchResultsObj.value[0] || {};
let hasUnsubscribed = caseObj.hasOwnProperty("pinswg_watchlistid");
console.log("is there a caseObj", hasUnsubscribed);
//const deleteCase = await deleteWatchedCases(query.watchlistid);
hasUnsubscribed && (await deleteWatchedCases(query.watchlistid));
//console.log(deleteCase);
return {
props: {
caseRef: hasUnsubscribed
? caseObj[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
]
: null,
},
};
}
);
const mapStateToProps = (state) => {};
const mapDispatchToProps = (dispatch) => {};
export default connect(mapStateToProps, mapDispatchToProps)(UnsubscribeCase);
+174
View File
@@ -0,0 +1,174 @@
import { wrapper } from "../../store/store";
import { connect } from "react-redux";
import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import Link from "next/link";
import CookieBanner from "../../components/cookieBanner";
import Footer from "../../components/footer";
import Header from "../../components/header";
import {
hashAPIPath,
getToken,
azureHeaders,
consoleLogger,
} from "../../actions";
import axios from "axios";
const UnsubscribeCase = (props) => {
let { t, lang } = useTranslation();
const { footerLinks, pages } = props;
const casesArr = props.caseRef;
console.log(casesArr);
return (
<div>
<Head>
<title>
{t("common:unsubscribe-case-title")} -{" "}
{t("common:service-name")}
</title>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header />
<div className="govuk-width-container govuk-!-padding-bottom-9">
<main className="govuk-main-wrapper govuk-!-padding-top-9 govuk-!-padding-bottom-9">
<div className="govuk-grid-row">
<div className="govuk-grid-column-two-thirds ">
<h1>{t("common:unsubscribe-case-title")}</h1>
<p>
{t("common:unsubscribe-case-all-label")}
{casesArr.length > 0 ? "s" : ""}
</p>
<ul>
{casesArr.map((key, index) => (
<li key={index}>
<strong>
{
key[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
]
}
</strong>
</li>
))}
</ul>
<Link href="/">
{t("common:logged-out-link")}
</Link>
</div>
</div>
</main>
</div>
<Footer footerLinks={footerLinks} ticketnumber={props} />
</div>
</div>
);
};
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
const getMailCaseById = async (watchedCaseID) => {
var token = await getToken();
var queryUrl =
"pinswg_watchlists?$count=true&$filter=pinswg_emailnotifications eq true and _pinswg_contact_value eq " +
watchedCaseID;
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token)
)
.then(({ data }) => {
return data;
})
.catch((error) => {
consoleLogger(error);
res.status(400).json(error);
});
};
const deleteWatchedCases = async (watchedCaseID) => {
var watchedCaseID = watchedCaseID;
var token = await getToken();
var queryUrl = "pinswg_watchlists(" + watchedCaseID + ")";
console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
var config = {
method: "delete",
url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Authorization": "Bearer " + token.access_token,
"Content-Type": "application/json",
},
};
return axios(config)
.then(({ data }) => {
//console.log("deleted watched case - " + watchedCaseID);
res.status(200).json(data);
})
.catch((error) => {
console.log("err----:", error);
if (error.response && error.response.status === 404) {
console.warn("Record not found — nothing to delete.");
return { success: false, caseRef: "Not found" };
} else {
consoleLogger(error);
//res.status(400).json(error);
}
});
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
console.log("the query", query.watchlistid);
const searchResultsObj = await getMailCaseById(query.watchlistid);
let caseObj = searchResultsObj.value.length > 0 || {};
console.log("hwo many in caseObj", searchResultsObj.value.length);
let hasUnsubscribed = searchResultsObj.value.length > 0;
console.log("is there a caseObj", searchResultsObj.value.length > 0);
console.log("hasUnsubscribed ", hasUnsubscribed);
//const deleteCase = await deleteWatchedCases(query.watchlistid);
//hasUnsubscribed && (await deleteWatchedCases(query.watchlistid));
searchResultsObj.value.forEach(function (watchListID) {
console.log(watchListID.pinswg_watchlistid);
});
//console.log(deleteCase);
return {
props: {
caseRef: hasUnsubscribed ? searchResultsObj.value : null,
},
};
}
);
const mapStateToProps = (state) => {};
const mapDispatchToProps = (dispatch) => {};
export default connect(mapStateToProps, mapDispatchToProps)(UnsubscribeCase);