17025 email notiofications fixes
This commit is contained in:
@@ -61,6 +61,7 @@ const Header = (props) => {
|
||||
"/myportal/representation",
|
||||
"/myportal/viewall",
|
||||
"/contactus",
|
||||
"/myportal/contactus",
|
||||
"/unsubscribe/[watchlistid]",
|
||||
"/unsubscribeall/[watchlistid]",
|
||||
];
|
||||
|
||||
@@ -115,6 +115,27 @@ const TopThree = (props) => {
|
||||
.then((data) => data)
|
||||
.then(() => {
|
||||
getWatchedCasesProxy(cookies.pinsUser).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) => {
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
getAwaitingSubmissionFromBlobProxy,
|
||||
getRepsFromBlobProxy,
|
||||
getWatchedCasesProxy,
|
||||
getWatchedCases,
|
||||
createWatchedCases,
|
||||
} from "../../actions";
|
||||
import { getDetailsProxy, getFormCollectionByID } from "../../components/utils";
|
||||
import transLookup from "../../data/lookuptranslations.json";
|
||||
@@ -272,12 +274,21 @@ const ViewAllResults = (props) => {
|
||||
/>
|
||||
{viewAllKey == "myRepresentations" && (
|
||||
<>
|
||||
<br />
|
||||
<span>
|
||||
<span className="govuk-body govuk-!-font-size-14">
|
||||
{resultsArr[key].representationType}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
{viewAllKey == "mySubmittedReps" && (
|
||||
<>
|
||||
<span className="govuk-body govuk-!-font-size-14">
|
||||
{item.pinswg_representationtype}{" "}
|
||||
{formatDates(
|
||||
item.pinswg_representationsubmitted
|
||||
)}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</dd>
|
||||
@@ -415,10 +426,15 @@ const ViewAllResults = (props) => {
|
||||
{/* Helper function to extract address lines based on current view and data */}
|
||||
{[
|
||||
"pinswg_siteaddressline1",
|
||||
"pinswg_addressline1",
|
||||
"pinswg_siteaddressline2",
|
||||
"pinswg_addressline2",
|
||||
"pinswg_siteaddresstown",
|
||||
"pinswg_addresstown",
|
||||
"pinswg_siteaddresscounty",
|
||||
"pinswg_siteaddresspostcode",
|
||||
"pinswg_postcode",
|
||||
"pinswg_projectlocation",
|
||||
].map((field, idx) => {
|
||||
const isAwaitingSubmission =
|
||||
viewAllKey === "awaitingSubmissionDetails";
|
||||
@@ -426,7 +442,7 @@ const ViewAllResults = (props) => {
|
||||
viewAllKey === "myRepresentations";
|
||||
const searchValue = _.get(
|
||||
searchDetailsObj,
|
||||
`${key}.${field}`
|
||||
`${key}.${field} `
|
||||
);
|
||||
const detailsValue = _.get(detailsObj, field);
|
||||
|
||||
@@ -738,12 +754,15 @@ const ViewAllResults = (props) => {
|
||||
)}
|
||||
|
||||
{viewAllKey == "watchedCases" && (
|
||||
<dd className="govuk-summary-list__value govuk-!-font-size-16 cardModuleItem ">
|
||||
<dd
|
||||
className="govuk-summary-list__value govuk-!-font-size-16 cardModuleItem govuk-!-font-size-14 govuk-summary-list__action"
|
||||
style={{ display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<button
|
||||
title={t(
|
||||
"case:do-you-want-to-delete-case-label"
|
||||
)}
|
||||
className=" cardModuleRemoveCase govuk-link govuk-link--no-underline govuk-link--inverse "
|
||||
className=" govuk-summary-list__actionLink watched_link"
|
||||
onClick={() => {
|
||||
confirm(
|
||||
t(
|
||||
@@ -761,13 +780,61 @@ const ViewAllResults = (props) => {
|
||||
>
|
||||
—
|
||||
</button>
|
||||
{item.pinswg_emailnotifications == true ? (
|
||||
<button
|
||||
className="govuk-summary-list__actionLink mailLink watched_link"
|
||||
title="Unsubscribe to email updates"
|
||||
onClick={() => {
|
||||
confirm(
|
||||
" Do you want to unsubscribe to email updates for " +
|
||||
item.pinswg_title +
|
||||
"?"
|
||||
) &&
|
||||
selectEmailNotifications(
|
||||
props.accountDetails
|
||||
.accountDetails
|
||||
.emailaddress1,
|
||||
props.accountDetails
|
||||
.loggedinUserId,
|
||||
item._pinswg_watchedcase_value,
|
||||
item.pinswg_appealcasetype,
|
||||
null
|
||||
);
|
||||
}}
|
||||
>
|
||||
<span className="mailicon icon"></span>
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
className="govuk-summary-list__actionLink mailLink"
|
||||
title="Email about changes"
|
||||
onClick={() => {
|
||||
confirm(
|
||||
" Do you want to be sent email updates for " +
|
||||
item.pinswg_title +
|
||||
"?"
|
||||
) &&
|
||||
selectEmailNotifications(
|
||||
props.accountDetails
|
||||
.accountDetails
|
||||
.emailaddress1,
|
||||
props.accountDetails
|
||||
.loggedinUserId,
|
||||
item._pinswg_watchedcase_value,
|
||||
item.pinswg_appealcasetype,
|
||||
true
|
||||
);
|
||||
}}
|
||||
>
|
||||
<span className="mailicon icon"></span>
|
||||
</button>
|
||||
)}
|
||||
</dd>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
};
|
||||
buildResultsRowArr();
|
||||
|
||||
const sortDataBy = (whichField) => {
|
||||
setOrderbyState(whichField);
|
||||
@@ -861,6 +928,7 @@ const ViewAllResults = (props) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const deleteItem = (caseID, topThreeType) => {
|
||||
let cookies = parseCookies();
|
||||
//console.log("sssss", caseID, topThreeType);
|
||||
@@ -884,6 +952,78 @@ const ViewAllResults = (props) => {
|
||||
});
|
||||
};
|
||||
|
||||
const isEmailSignUp = (whichIncident) => {
|
||||
let isEmail = jsonpath({
|
||||
path:
|
||||
"$[?(@ && @._pinswg_watchedcase_value=='" +
|
||||
whichIncident +
|
||||
"' && @.pinswg_emailnotifications==true)]",
|
||||
|
||||
json: resultsArr,
|
||||
eval: true,
|
||||
});
|
||||
return isEmail;
|
||||
};
|
||||
|
||||
const selectEmailNotifications = (
|
||||
emailaddress,
|
||||
loggedInUser,
|
||||
incidentID,
|
||||
appealType,
|
||||
updateEmailNotifications
|
||||
) => {
|
||||
let updateBody = {
|
||||
"pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")",
|
||||
"pinswg_Contact@odata.bind": "/contacts(" + loggedInUser + ")",
|
||||
"pinswg_appealcasetype": appealType,
|
||||
"pinswg_emailnotifications": updateEmailNotifications,
|
||||
};
|
||||
|
||||
console.log("Email signed up");
|
||||
createWatchedCases(updateBody)
|
||||
.then((data) => data)
|
||||
.then(() => {
|
||||
getWatchedCases(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) => {
|
||||
setWatchedCasesDetails(data);
|
||||
})
|
||||
.then(() => {
|
||||
setCurrentView({
|
||||
"viewName": "Watched Cases",
|
||||
"viewKey": "watchedCases",
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
buildResultsRowArr();
|
||||
return (
|
||||
<>
|
||||
<div className="govuk-grid-row">
|
||||
|
||||
@@ -91,7 +91,6 @@ const RepsOnResults = (props) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<br />
|
||||
<br />
|
||||
{(_.has(detailsObj, "pinswg_startdate") ||
|
||||
_.has(detailsObj, "pinswg_applicationacceptedasvalid") ||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* @swagger
|
||||
* /api/endpoint/createmywatchedcases_api:
|
||||
* post:
|
||||
* tags: [Portal,Case]
|
||||
* summary: Phase 2
|
||||
* description: Create my watched cases
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Success
|
||||
*/
|
||||
// /**
|
||||
// * @swagger
|
||||
// * /api/endpoint/createmywatchedcases_api:
|
||||
// * post:
|
||||
// * tags: [Portal,Case]
|
||||
// * summary: Phase 2
|
||||
// * description: Create my watched cases
|
||||
// * responses:
|
||||
// * 200:
|
||||
// * description: Success
|
||||
// */
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
@@ -32,31 +32,96 @@ const hashAPIPath = (queryPath) => {
|
||||
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var token = await getToken();
|
||||
var data = JSON.stringify(req.body);
|
||||
var queryUrl = "pinswg_watchlists";
|
||||
// export default async function ApiProxy(req, res) {
|
||||
// var token = await getToken();
|
||||
// var data = JSON.stringify(req.body);
|
||||
// var queryUrl = "pinswg_watchlists";
|
||||
|
||||
var config = {
|
||||
method: "post",
|
||||
// console.log(data);
|
||||
// var config = {
|
||||
// method: "put",
|
||||
// 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",
|
||||
// },
|
||||
// data: data,
|
||||
// };
|
||||
|
||||
// return axios(config)
|
||||
// .then(({ data }) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// consoleLogger(Object.assign(err, data));
|
||||
// res.status(400).json(error);
|
||||
// });
|
||||
// }
|
||||
const recordExists = async (incidentId, contactId, token) => {
|
||||
const filter = `$filter=pinswg_WatchedCase/incidentid eq ${incidentId} and pinswg_Contact/contactid eq ${contactId}`;
|
||||
const queryUrl = `pinswg_watchlists?${filter}`;
|
||||
const url = WEBAPI_URL + queryUrl + hashAPIPath(queryUrl);
|
||||
|
||||
try {
|
||||
const res = await axios.get(url, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + token.access_token,
|
||||
Accept: "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (res.data.value && res.data.value.length > 0) {
|
||||
return res.data.value[0]; // return the existing record
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
const token = await getToken();
|
||||
const data = req.body;
|
||||
|
||||
const incidentId =
|
||||
data["pinswg_WatchedCase@odata.bind"].match(/\(([^)]+)\)/)[1];
|
||||
const contactId = data["pinswg_Contact@odata.bind"].match(/\(([^)]+)\)/)[1];
|
||||
|
||||
const existingRecord = await recordExists(incidentId, contactId, token);
|
||||
|
||||
let method, queryUrl;
|
||||
|
||||
if (existingRecord) {
|
||||
method = "patch";
|
||||
queryUrl = `pinswg_watchlists(${existingRecord.pinswg_watchlistid})`; // adjust with your primary key logical name
|
||||
} else {
|
||||
method = "post";
|
||||
queryUrl = "pinswg_watchlists";
|
||||
}
|
||||
|
||||
const config = {
|
||||
method: method,
|
||||
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,
|
||||
Accept: "application/json",
|
||||
Prefer: 'odata.include-annotations="*",return=representation',
|
||||
Authorization: "Bearer " + token.access_token,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data: data,
|
||||
data: JSON.stringify(data),
|
||||
};
|
||||
|
||||
return axios(config)
|
||||
.then(({ data }) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(Object.assign(err, data));
|
||||
res.status(400).json(error);
|
||||
.then(({ data }) => res.status(200).json(data))
|
||||
.catch((err) => {
|
||||
consoleLogger(err);
|
||||
res.status(400).json(err.response?.data || err);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export default async function ApiProxy(req, res) {
|
||||
var queryUrl =
|
||||
"pinswg_watchlists?$filter= _pinswg_contact_value eq " +
|
||||
loggedInUserId +
|
||||
"&$select=pinswg_emailnotifications,modifiedon,pinswg_appealcasetype,pinswg_watchlistid,_pinswg_watchedcase_value,statuscode&$count=true&$orderby=createdon desc&$expand=pinswg_WatchedCase($select=pinswg_AssociatedLPA)";
|
||||
"&$select=pinswg_emailnotifications,modifiedon,pinswg_appealcasetype,pinswg_watchlistid,_pinswg_watchedcase_value,statuscode,pinswg_representationsubmitted,pinswg_representationtype&$count=true&$orderby=createdon desc&$expand=pinswg_WatchedCase($select=pinswg_AssociatedLPA)";
|
||||
|
||||
return axios
|
||||
.get(
|
||||
@@ -51,6 +51,32 @@ export default async function ApiProxy(req, res) {
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
data.value.forEach(function (element) {
|
||||
element.ticketnumber = element.pinswg_WatchedCase?.ticketnumber;
|
||||
element.pinswg_title =
|
||||
element[
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
];
|
||||
|
||||
element[
|
||||
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||
] =
|
||||
element.pinswg_WatchedCase?.[
|
||||
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||
];
|
||||
element._pinswg_associatedlpa_value =
|
||||
element.pinswg_WatchedCase?._pinswg_associatedlpa_value;
|
||||
element[
|
||||
"_ownerid_value@OData.Community.Display.V1.FormattedValue"
|
||||
] =
|
||||
element.pinswg_WatchedCase?.[
|
||||
"_ownerid_value@OData.Community.Display.V1.FormattedValue"
|
||||
];
|
||||
element._ownerid_value =
|
||||
element.pinswg_WatchedCase?._ownerid_value;
|
||||
|
||||
delete element.pinswg_WatchedCase;
|
||||
});
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user