From 2c6d110d9bcd28ddf0179f1534b3ff88fff0d902 Mon Sep 17 00:00:00 2001
From: robbond
Date: Mon, 9 Mar 2026 12:13:24 +0000
Subject: [PATCH] chekc box to download questionnaire
---
actions/azurestorage.js | 4 +-
actions/index.js | 286 +++++++++---------
components/case/representation/index.js | 134 ++++----
.../representationCompleteSubmit.js | 131 ++++++--
locales/cy/myrepresentations.json | 1 +
locales/en/myrepresentations.json | 1 +
pages/api/file/generatepdf.js | 44 ++-
7 files changed, 375 insertions(+), 226 deletions(-)
diff --git a/actions/azurestorage.js b/actions/azurestorage.js
index f52bb013..e4cedfe4 100644
--- a/actions/azurestorage.js
+++ b/actions/azurestorage.js
@@ -411,7 +411,9 @@ export const createRepPDFBlob = async (
console.log("blobName:", blobName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
- const uploadBlobResponse = await blockBlobClient.uploadStream(content);
+ const uploadBlobResponse = Buffer.isBuffer(content)
+ ? await blockBlobClient.uploadData(content)
+ : await blockBlobClient.uploadStream(content);
let whichLocation =
repName.indexOf("_IP_") > 0
diff --git a/actions/index.js b/actions/index.js
index c099b55e..a988fc54 100644
--- a/actions/index.js
+++ b/actions/index.js
@@ -34,7 +34,7 @@ export const getIP = (req) => {
console.info(
"\n====================\n Client IP address: " + ip,
- "\n=====================\n",
+ "\n=====================\n"
);
};
@@ -42,7 +42,7 @@ export const consoleLogger = (err) => {
console.log(
"\n\n/////////////////////////////////////////////////\nRaw Error " +
err +
- "\n\n/////////////////////////////////////////////////\n",
+ "\n\n/////////////////////////////////////////////////\n"
);
var errStr =
"\n\n/////////////////////////////////////////////////\nServer Error " +
@@ -102,7 +102,7 @@ export const getToken = () => {
.post(
`${accessTokenEndpoint}${tenantId}/oauth2/v2.0/token`,
tokenBody,
- tokenConfig,
+ tokenConfig
)
.then((res) => res.data)
.then((data) => {
@@ -130,8 +130,8 @@ const tokenBody =
const tokenConfig = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
- "Cache-Control": "no-cache",
- },
+ "Cache-Control": "no-cache"
+ }
};
export const azureHeaders = (access_token) => {
@@ -142,8 +142,8 @@ export const azureHeaders = (access_token) => {
"Accept": "application/json;odata.metadata=none",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
- "Authorization": "Bearer " + access_token,
- },
+ "Authorization": "Bearer " + access_token
+ }
};
};
@@ -155,8 +155,8 @@ export const azureHeadersNoOdata = (access_token) => {
//"Accept": "application/json;odata.metadata=none",
//"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
- "Authorization": "Bearer " + access_token,
- },
+ "Authorization": "Bearer " + access_token
+ }
};
};
@@ -169,8 +169,8 @@ export const azureHeadersPaged = (access_token) => {
"Prefer":
'odata.include-annotations="*",return=representation, odata.maxpagesize=10',
"Content-Type": "application/json",
- "Authorization": "Bearer " + access_token,
- },
+ "Authorization": "Bearer " + access_token
+ }
};
};
export const azureHeadersPagedCustom = (access_token, showNumberOfRecords) => {
@@ -183,15 +183,15 @@ export const azureHeadersPagedCustom = (access_token, showNumberOfRecords) => {
'odata.include-annotations="*",return=representation, odata.maxpagesize=' +
showNumberOfRecords,
"Content-Type": "application/json",
- "Authorization": "Bearer " + access_token,
- },
+ "Authorization": "Bearer " + access_token
+ }
};
};
export const hashAPIPath = (queryPath) => {
var hashlink = CryptoJS.HmacSHA256(
queryPath,
- CryptoJS.enc.Hex.parse(WORDKEY),
+ CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString(CryptoJS.enc.Hex);
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
@@ -216,7 +216,7 @@ export const getBasicSearch = (searchString) => {
.get(
BASE_URL +
"/api/endpoint/getbasicsearch_api?searchString=" +
- searchString,
+ searchString
)
.then((res) => {
return res.data;
@@ -244,7 +244,7 @@ export const getIncidentbyID = (searchString) => {
.get(
BASE_URL +
"/api/endpoint/getincidentbyid_api?searchString=" +
- searchString,
+ searchString
)
.then((res) => {
return res.data;
@@ -258,7 +258,7 @@ export const getIncidentbyID = (searchString) => {
export const getIsPublishedbyID = (searchString) => {
return axios
.get(
- "/api/endpoint/getispublishedbyid_api?searchString=" + searchString,
+ "/api/endpoint/getispublishedbyid_api?searchString=" + searchString
)
.then((res) => {
return res.data;
@@ -274,7 +274,7 @@ export const getPartSavedAppeal = (searchString) => {
.get(
BASE_URL +
"/api/endpoint/getpartsavedappeal_api?searchString=" +
- searchString,
+ searchString
)
.then((res) => {
return res.data;
@@ -290,7 +290,7 @@ export const getBasicDNSURLSearch = (searchString) => {
.get(
BASE_URL +
"/api/endpoint/getbasicdnsurlsearch_api?searchString=" +
- searchString,
+ searchString
)
.then((res) => {
return res.data;
@@ -330,7 +330,7 @@ export const getAddressSearchPaged = (
pageNumber,
orderBy,
fieldSort,
- showNumberOfRecords,
+ showNumberOfRecords
) => {
return axios
.get(
@@ -343,7 +343,7 @@ export const getAddressSearchPaged = (
"&fieldSort=" +
fieldSort +
"&showNumberOfRecords=" +
- showNumberOfRecords,
+ showNumberOfRecords
)
.then((res) => {
return res.data;
@@ -359,7 +359,7 @@ export const getBasicSearchPaged = (
pageNumber,
orderBy,
fieldSort,
- showNumberOfRecords,
+ showNumberOfRecords
) => {
return axios
.get(
@@ -372,7 +372,7 @@ export const getBasicSearchPaged = (
"&fieldSort=" +
fieldSort +
"&showNumberOfRecords=" +
- showNumberOfRecords,
+ showNumberOfRecords
)
.then((res) => {
return res.data;
@@ -394,7 +394,7 @@ export const getDNSCoords = () => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
- errorMsg: error.response.statusText,
+ errorMsg: error.response.statusText
};
return ErrResponse;
@@ -425,7 +425,7 @@ export const getBasicDNSSearchPaged = (
pageNumber,
orderBy,
fieldSort,
- showNumberOfRecords,
+ showNumberOfRecords
) => {
return axios
.get(
@@ -436,7 +436,7 @@ export const getBasicDNSSearchPaged = (
"&fieldSort=" +
fieldSort +
"&showNumberOfRecords=" +
- showNumberOfRecords,
+ showNumberOfRecords
)
.then((res) => res.data)
.catch((error) => {
@@ -450,7 +450,7 @@ export const getAdvancedSearch = (searchString) => {
.get(
BASE_URL +
"/api/endpoint/getadvancedsearch_api?searchstring=" +
- JSON.stringify(searchString),
+ JSON.stringify(searchString)
)
.then((res) => res.data)
.catch((error) => {
@@ -458,7 +458,7 @@ export const getAdvancedSearch = (searchString) => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
- errorMsg: error.response.statusText,
+ errorMsg: error.response.statusText
};
return ErrResponse;
@@ -470,7 +470,7 @@ export const getAdvancedSearchPaged = (
pageNumber,
orderBy,
fieldSort,
- showNumberOfRecords,
+ showNumberOfRecords
) => {
return axios
.get(
@@ -483,7 +483,7 @@ export const getAdvancedSearchPaged = (
"&fieldSort=" +
fieldSort +
"&showNumberOfRecords=" +
- showNumberOfRecords,
+ showNumberOfRecords
)
.then((res) => res.data)
.catch((error) => {
@@ -491,7 +491,7 @@ export const getAdvancedSearchPaged = (
let ErrResponse = {
value: [],
errorCode: error.response.status,
- errorMsg: error.response.statusText,
+ errorMsg: error.response.statusText
};
return ErrResponse;
@@ -502,7 +502,7 @@ export const getBasicSearchDetails = async (
appealTypeName,
caseReference,
primaryIdAttribute,
- incidentID,
+ incidentID
) => {
return axios
.get(
@@ -512,7 +512,7 @@ export const getBasicSearchDetails = async (
"&primaryIdAttribute=" +
primaryIdAttribute +
"&incidentID=" +
- incidentID,
+ incidentID
)
.then((res) => res.data)
.catch((error) => {
@@ -524,7 +524,7 @@ export const getBasicPartSavedDetails = (
appealTypeName,
caseReference,
primaryIdAttribute,
- incidentID,
+ incidentID
) => {
//console.log(
// "///////api call: ",
@@ -544,7 +544,7 @@ export const getBasicPartSavedDetails = (
"&primaryIdAttribute=" +
primaryIdAttribute +
"&incidentID=" +
- incidentID,
+ incidentID
)
.then((res) => res.data)
.catch((error) => {
@@ -556,7 +556,7 @@ export const getBasicSearchDetailsPaged = async (
appealTypeName,
caseReference,
primaryIdAttribute,
- incidentIDs,
+ incidentIDs
) => {
if (!incidentIDs || incidentIDs.length === 0) return [];
@@ -578,11 +578,11 @@ export const getBasicSearchDetailsPaged = async (
.join(" or ");
const url = `/api/endpoint/getbasicsearchdetailspaged_api?appealTypeName=${appealTypeName}&primaryIdAttribute=${primaryIdAttribute}&incidentID=${encodeURIComponent(
- filter,
+ filter
)}`;
console.log(
- `Fetching ${incidentIDs.length} incidents for appeal type: ${appealTypeName}`,
+ `Fetching ${incidentIDs.length} incidents for appeal type: ${appealTypeName}`
);
try {
@@ -598,7 +598,7 @@ export const getSearchDocumentDetails = (incidentID) => {
return axios
.get(
"/api/endpoint/getsearchdocumentdetails_api?incidentid=" +
- incidentID,
+ incidentID
)
.then((res) => res.data)
.catch((error) => {
@@ -610,7 +610,7 @@ export const getSearchDocumentDetails = (incidentID) => {
export const getSearchDocumentTypes = (incidentID) => {
return axios
.get(
- "/api/endpoint/getsearchdocumentTypes_api?incidentid=" + incidentID,
+ "/api/endpoint/getsearchdocumentTypes_api?incidentid=" + incidentID
)
.then((res) => res.data)
.catch((error) => {
@@ -623,7 +623,7 @@ export const getAppealPDFDocs = (incidentID) => {
.get(
BASE_URL +
"/api/endpoint/getappealpdfdocuments_api?incidentid=" +
- incidentID,
+ incidentID
)
.then((res) => res.data)
.catch((error) => {
@@ -637,7 +637,7 @@ export const getSearchDocumentDetailsPaged = (
orderBy,
fieldSort,
showNumberOfRecords,
- documentType,
+ documentType
) => {
//console.log("to api:", documentType);
return axios
@@ -653,7 +653,7 @@ export const getSearchDocumentDetailsPaged = (
"&showNumberOfRecords=" +
showNumberOfRecords +
"&documentType=" +
- documentType,
+ documentType
)
.then((res) => res.data)
.catch((error) => {
@@ -665,7 +665,7 @@ export const getLinkedCases = (parentIncidentid) => {
return axios
.get(
"/api/endpoint/getlinkedcases_api?parentincidentid=" +
- parentIncidentid,
+ parentIncidentid
)
.then((res) => {
return res.data;
@@ -684,7 +684,7 @@ export const getAppealsTypes = () => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
- errorMsg: error.response.statusText,
+ errorMsg: error.response.statusText
};
return ErrResponse;
@@ -700,7 +700,7 @@ export const getProjectTypes = () => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
- errorMsg: error.response.statusText,
+ errorMsg: error.response.statusText
};
return ErrResponse;
@@ -716,7 +716,7 @@ export const getAppealsTypesForNewAppeal = () => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
- errorMsg: error.response.statusText,
+ errorMsg: error.response.statusText
};
return ErrResponse;
@@ -734,7 +734,7 @@ export const getLPA = () => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
- errorMsg: error.response.statusText,
+ errorMsg: error.response.statusText
};
return ErrResponse;
@@ -757,7 +757,7 @@ export const getMandatoryFields = (whichForm) => {
.get(
BASE_URL +
"/api/endpoint/getmandatoryfields_api?whichForm=" +
- whichForm,
+ whichForm
)
.then((res) => res.data)
.catch((error) => {
@@ -779,7 +779,7 @@ export const getPersonalAccount = (contactid) => {
.get(
BASE_URL +
"/api/endpoint/getpersonalaccount_api?contactid=" +
- contactid,
+ contactid
)
.then((res) => {
return res.data;
@@ -799,7 +799,7 @@ export const getPersonalAccount = (contactid) => {
export const getAppealID = (
caseReference,
updateFormCollection,
- primaryAttribute,
+ primaryAttribute
) => {
//console.log(
// "is this the collection?:",
@@ -815,11 +815,11 @@ export const getAppealID = (
"&primaryAttribute=" +
primaryAttribute +
"&caseReference=" +
- caseReference,
+ caseReference
)
.then((res) => {
const result = Object.entries(res.data.value[0]).filter(
- ([key]) => !key.startsWith("_"),
+ ([key]) => !key.startsWith("_")
)[0][1];
// console.log("result:", res.data);
var appealID = result;
@@ -836,7 +836,7 @@ export const getLogin = (emailAddress, pwd) => {
"/api/endpoint/getlogin_api?emailAddress=" +
emailAddress +
"&pwd=" +
- pwd,
+ pwd
)
.then((res) => res.data)
.catch((error) => {
@@ -849,7 +849,7 @@ export const getMyCases = (loggedInUserId) => {
.get(
BASE_URL +
"/api/endpoint/getmycases_api?loggedInUserId=" +
- loggedInUserId,
+ loggedInUserId
)
.then((res) => {
return res.data;
@@ -864,7 +864,7 @@ export const getMyInvolvements = async (loggedInUserId) => {
const res = await axios.get(
BASE_URL +
"/api/endpoint/getmyinvolvements_api?loggedInUserId=" +
- loggedInUserId,
+ loggedInUserId
);
return res.data;
} catch (error) {
@@ -888,7 +888,7 @@ export const getMyRepresentations = (loggedInUserId) => {
.get(
BASE_URL +
"/api/endpoint/getmyrepresentations_api?loggedInUserId=" +
- loggedInUserId,
+ loggedInUserId
)
.then((res) => res.data)
.catch((error) => {
@@ -900,7 +900,7 @@ export const getMyRepresentationsProxy = (loggedInUserId) => {
return axios
.get(
"/api/endpoint/getmyrepresentationsproxy_api?loggedInUserId=" +
- loggedInUserId,
+ loggedInUserId
)
.then((res) => res.data)
.catch((error) => {
@@ -920,8 +920,7 @@ export const getRepresentations = (incidentID) => {
export const getRepresentationsProxy = (incidentID) => {
return axios
.get(
- "/api/endpoint/getrepresentationsproxy_api?incidentID=" +
- incidentID,
+ "/api/endpoint/getrepresentationsproxy_api?incidentID=" + incidentID
)
.then((res) => res.data)
.catch((error) => {
@@ -934,7 +933,7 @@ export const getWatchedCases = (loggedInUserId) => {
.get(
BASE_URL +
"/api/endpoint/getwatchedcases_api?loggedInUserId=" +
- loggedInUserId,
+ loggedInUserId
)
.then((res) => res.data)
.catch((error) => {
@@ -946,7 +945,7 @@ export const getWatchedCasesProxy = (loggedInUserId) => {
return axios
.get(
"/api/endpoint/getwatchedcasesproxy_api?loggedInUserId=" +
- loggedInUserId,
+ loggedInUserId
)
.then((res) => res.data)
.catch((error) => {
@@ -958,7 +957,7 @@ export const getAwaitingSubmissionProxy = (loggedInUserId) => {
return axios
.get(
"/api/endpoint/getawaitingsubmissionproxy_api?loggedInUserId=" +
- loggedInUserId,
+ loggedInUserId
)
.then((res) => res.data)
.catch((error) => {
@@ -971,7 +970,7 @@ export const getAwaitingSubmission = (loggedInUserId) => {
.get(
BASE_URL +
"/api/endpoint/getawaitingsubmission_api?loggedInUserId=" +
- loggedInUserId,
+ loggedInUserId
)
.then((res) => {
return res.data;
@@ -1001,8 +1000,8 @@ export const getAwaitingSubmissionFromBlob = (containerName) => {
containerName +
hashAPIPath(
"/api/file/getawaitingsubmissionfromblob?container=" +
- containerName,
- ),
+ containerName
+ )
)
.then((res) => {
return res.data;
@@ -1028,7 +1027,7 @@ export const getRepsFromBlob = (containerName) => {
BASE_URL +
"/api/file/getrepsblob?container=" +
containerName +
- hashAPIPath("/api/file/getrepsblob?container=" + containerName),
+ hashAPIPath("/api/file/getrepsblob?container=" + containerName)
)
.then((res) => {
return res.data;
@@ -1055,7 +1054,7 @@ export const getRepsFromBlobProxy = async (containerName) => {
try {
const res = await axios.get(
// BASE_URL +
- "/api/file/getrepsblobproxy?container=" + containerName,
+ "/api/file/getrepsblobproxy?container=" + containerName
// +
// hashAPIPath(
// "/api/file/getawaitingsubmissionfromblob?container=" +
@@ -1074,14 +1073,14 @@ export const getAwaitingSubmissionFromBlobProxy = async (containerName) => {
containerName,
"/api/file/getawaitingsubmissionfromblobproxy?container=" +
containerName,
- "\n///////////////////////\n",
+ "\n///////////////////////\n"
);
try {
const res = await axios.get(
BASE_URL +
"/api/file/getawaitingsubmissionfromblobproxy?container=" +
- containerName,
+ containerName
// +
// hashAPIPath(
// "/api/file/getawaitingsubmissionfromblob?container=" +
@@ -1124,7 +1123,7 @@ export const getPortalModuleDetails = async (appealType, caseReference) => {
"/api/endpoint/getportalmoduledetails_api?appealType=" +
appealType +
"&caseReference=" +
- encodeURI(caseReference),
+ encodeURI(caseReference)
};
try {
@@ -1142,7 +1141,7 @@ export const getPortalModuleDetailsProxy = (appealType, caseReference) => {
"/api/endpoint/getportalmoduledetailsproxy_api?appealType=" +
appealType +
"&caseReference=" +
- caseReference.replace(/\'/g, "''"),
+ caseReference.replace(/\'/g, "''")
)
.then((res) => res.data)
.catch((error) => {
@@ -1154,7 +1153,7 @@ export const getEmailAccountCheck = (emailAddress) => {
return axios
.get(
"/api/endpoint/getemailaccountcheck_api?emailAddress=" +
- emailAddress,
+ emailAddress
)
.then((res) => res.data)
.catch((error) => {
@@ -1170,7 +1169,7 @@ export const updatePassword = (contactId, newpassword) => {
var config = {
method: "post",
url: queryUrl,
- data: data,
+ data: data
};
return axios(config)
@@ -1191,7 +1190,7 @@ export const updateAccount = async (contactId, updateBody, ssr) => {
var config = {
method: "post",
url: queryUrl,
- data: data,
+ data: data
};
return axios(config)
.then((res) => {
@@ -1210,7 +1209,7 @@ export const createWatchedCases = async (formValues) => {
var config = {
method: "post",
url: queryUrl,
- data: data,
+ data: data
};
try {
@@ -1226,7 +1225,7 @@ export const createNewCase = (
lpaID,
contactid,
createBody,
- containerName,
+ containerName
) => {
appealTypeId = parseInt(appealTypeId);
@@ -1245,7 +1244,7 @@ export const createNewCase = (
var config = {
method: "post",
url: BASE_URL + queryUrl,
- data: data,
+ data: data
};
return axios(config)
@@ -1263,7 +1262,7 @@ export const createNewCaseBlob = (
contactid,
createBody,
containerName,
- lpaName,
+ lpaName
) => {
appealTypeId = parseInt(appealTypeId);
@@ -1296,7 +1295,7 @@ export const createNewCaseBlob = (
var config = {
method: "post",
url: queryUrl,
- data: data,
+ data: data
};
//console.log("the query url for crearte csase:", queryUrl);
@@ -1315,14 +1314,14 @@ export const updateCase = async (
updateBody,
updateFormCollection,
primaryAttribute,
- caseReference,
+ caseReference
) => {
var data = updateBody;
var appealObj = await getAppealID(
caseReference,
updateFormCollection,
- primaryAttribute,
+ primaryAttribute
);
var queryUrl =
@@ -1334,7 +1333,7 @@ export const updateCase = async (
var config = {
method: "post",
url: queryUrl,
- data: updateBody,
+ data: updateBody
};
//console.log(data);
@@ -1353,14 +1352,14 @@ export const updateCaseBlob = async (
updateBody,
updateFormCollection,
primaryAttribute,
- caseReference,
+ caseReference
) => {
var data = updateBody;
var appealObj = await getAppealID(
caseReference,
updateFormCollection,
- primaryAttribute,
+ primaryAttribute
);
var queryUrl =
@@ -1372,7 +1371,7 @@ export const updateCaseBlob = async (
var config = {
method: "post",
url: queryUrl,
- data: updateBody,
+ data: updateBody
};
//console.log(data);
@@ -1390,7 +1389,7 @@ export const patchCase = async (incidentid) => {
var queryUrl = "/api/endpoint/patchcase_api?incidentid=" + incidentid;
var config = {
method: "get",
- url: queryUrl,
+ url: queryUrl
};
return axios(config)
@@ -1428,7 +1427,7 @@ export const getCaseByID = (incidentID) => {
// );
return axios
.get(
- BASE_URL + "/api/endpoint/getcasebyid_api?incidentID=" + incidentID,
+ BASE_URL + "/api/endpoint/getcasebyid_api?incidentID=" + incidentID
)
.then((res) => {
return res.data;
@@ -1451,8 +1450,8 @@ export const deleteMyRepresentations = (myRepresentationsID) => {
"OData-Version": "4.0",
"Accept": "application/json;odata.metadata=none",
"Prefer": 'odata.include-annotations="*",return=representation',
- "Content-Type": "application/json",
- },
+ "Content-Type": "application/json"
+ }
};
//console.log(config);
return axios(config)
@@ -1471,7 +1470,7 @@ export const deleteAwaitingSubmissions = (incidentID) => {
var config = {
method: "delete",
- url: queryUrl,
+ url: queryUrl
};
//console.log(config);
return axios(config)
@@ -1486,7 +1485,7 @@ export const deleteAwaitingSubmissions = (incidentID) => {
export const deleteAwaitingSubmissionsFromBlob = (
containerID,
- casefolderID,
+ casefolderID
) => {
var queryUrl =
"/api/file/deleteblobcase?container=" +
@@ -1496,7 +1495,7 @@ export const deleteAwaitingSubmissionsFromBlob = (
var config = {
method: "get",
- url: queryUrl,
+ url: queryUrl
};
//console.log(config);
return axios(config)
@@ -1512,7 +1511,7 @@ export const deleteAwaitingSubmissionsFromBlob = (
export const deleteMyRepresentationsFromBlob = (
containerID,
casefolderID,
- repfile,
+ repfile
) => {
var queryUrl =
"/api/file/deleteblobrep?container=" +
@@ -1524,7 +1523,7 @@ export const deleteMyRepresentationsFromBlob = (
var config = {
method: "get",
- url: queryUrl,
+ url: queryUrl
};
//console.log(config);
return axios(config)
@@ -1542,7 +1541,7 @@ export const deleteWatchedCases = async (watchedCaseID) => {
"/api/endpoint/deletewatchedcases_api?watchedCaseID=" + watchedCaseID;
var config = {
method: "delete",
- url: queryUrl,
+ url: queryUrl
};
try {
@@ -1559,7 +1558,7 @@ export const createAccount = (formValues) => {
var config = {
method: "post",
url: queryUrl,
- data: data,
+ data: data
};
return axios(config)
@@ -1576,7 +1575,7 @@ export const uploadFiles = async (
formValues,
filesObj,
containerID,
- casefolderID,
+ casefolderID
) => {
let files = filesObj;
@@ -1603,7 +1602,7 @@ export const uploadFiles = async (
method: "post",
url: queryUrl,
data: formData,
- headers: { "content-type": "multipart/form-data" },
+ headers: { "content-type": "multipart/form-data" }
};
//console.log(config);
@@ -1641,7 +1640,7 @@ export const uploadSingleFile = async (filesObj, containerID, casefolderID) => {
method: "post",
url: queryUrl,
data: formData,
- headers: { "content-type": "multipart/form-data" },
+ headers: { "content-type": "multipart/form-data" }
};
//console.log(config);
@@ -1657,7 +1656,7 @@ export const uploadRepFiles = async (
formValues,
filesObj,
containerID,
- casefolderID,
+ casefolderID
) => {
let files = filesObj;
@@ -1685,7 +1684,7 @@ export const uploadRepFiles = async (
method: "post",
url: queryUrl,
data: formData,
- headers: { "content-type": "multipart/form-data" },
+ headers: { "content-type": "multipart/form-data" }
};
//console.log(config);
@@ -1697,7 +1696,12 @@ export const uploadRepFiles = async (
}
};
-export const generateRepPDF = async (formValues, containerID, casefolderID) => {
+export const generateRepPDF = async (
+ formValues,
+ containerID,
+ casefolderID,
+ options = {}
+) => {
//let files = filesObj;
console.log("generateRepPDF function: " + formValues);
@@ -1711,12 +1715,14 @@ export const generateRepPDF = async (formValues, containerID, casefolderID) => {
// "casefolderID": casefolderID,
// });
- var queryUrl = "/api/file/generatepdf";
+ var queryUrl =
+ "/api/file/generatepdf" + (options.download ? "?download=true" : "");
const config = {
method: "post",
url: queryUrl,
data: formValues,
+ ...(options.download ? { responseType: "blob" } : {})
//headers: { "content-type": "multipart/form-data" },
};
@@ -1734,7 +1740,7 @@ export const generateAppealPDF = async (
containerID,
casefolderID,
appealType,
- fileList,
+ fileList
) => {
//let files = filesObj;
@@ -1745,7 +1751,7 @@ export const generateAppealPDF = async (
//formValues.append("filesList", fileList);
Object.assign(formValues, {
- "filesList": fileList,
+ "filesList": fileList
});
var queryUrl = "/api/file/generateappealpdf?appealType=" + appealType;
@@ -1753,7 +1759,7 @@ export const generateAppealPDF = async (
const config = {
method: "post",
url: queryUrl,
- data: formValues,
+ data: formValues
//headers: { "content-type": "multipart/form-data" },
};
@@ -1792,8 +1798,8 @@ export const getFilesFromBlob = (containerName, casefolderID) => {
"/api/file/getbloblist?container=" +
containerName +
"&casefolderID=" +
- casefolderID,
- ),
+ casefolderID
+ )
)
.then((res) => {
//console.log("//////////----", res.data);
@@ -1811,7 +1817,7 @@ export const getFilesFromBlobproxy = (containerName, casefolderID) => {
"/api/file/getbloblistproxy?container=" +
containerName +
"&casefolderID=" +
- casefolderID,
+ casefolderID
)
.then((res) => {
//console.log("//////////----", res.data);
@@ -1825,7 +1831,7 @@ export const getFilesFromBlobproxy = (containerName, casefolderID) => {
export const getFilesFromBlobHashed = (
containerName,
getblobshash,
- casefolderID,
+ casefolderID
) => {
return axios
.get(
@@ -1833,7 +1839,7 @@ export const getFilesFromBlobHashed = (
containerName +
"&casefolderID=" +
casefolderID +
- getblobshash,
+ getblobshash
)
.then((res) => {
//console.log("//////////----", res.data);
@@ -1848,7 +1854,7 @@ export const deleteBlob = async (
containerName,
blobName,
deleteblobhash,
- casefolderID,
+ casefolderID
) => {
try {
const res = await axios.get(
@@ -1858,7 +1864,7 @@ export const deleteBlob = async (
encodeURIComponent(casefolderID) +
"&blobname=" +
encodeURIComponent(blobName) +
- deleteblobhash,
+ deleteblobhash
);
return res.data;
} catch (error) {
@@ -1871,7 +1877,7 @@ export const deleteRepBlob = async (
blobName,
deleteblobhash,
casefolderID,
- filenamePrefix,
+ filenamePrefix
) => {
try {
const res = await axios.get(
@@ -1881,7 +1887,7 @@ export const deleteRepBlob = async (
encodeURIComponent(casefolderID + "/" + filenamePrefix) +
"&blobname=" +
encodeURIComponent(blobName) +
- deleteblobhash,
+ deleteblobhash
);
return res.data;
} catch (error) {
@@ -1897,14 +1903,14 @@ export const downloadBlob = (containerName, blobName) => {
containerName.toLowerCase() +
"&blobname=" +
blobName,
- { responseType: "blob" },
+ { responseType: "blob" }
)
.then((response) => {
//console.log("Downloaded blob content:");
res.setHeader(
"content-disposition",
- "attachment; filename=" + blobName,
+ "attachment; filename=" + blobName
);
//console.log("has downloaded");
@@ -1941,8 +1947,8 @@ export const getProgressFromBlob = async (containerName, casereference) => {
"/api/file/getprogressobjblob?container=" +
encodeURIComponent(containerName) +
"&casefolderID=" +
- encodeURIComponent(casereference),
- ),
+ encodeURIComponent(casereference)
+ )
);
return res.data;
} catch (error) {
@@ -1954,13 +1960,13 @@ export const sendEmail = async (
templateId,
emailAddress,
personalisation,
- reference,
+ reference
) => {
var mailData = {
"templateId": templateId,
"emailAddress": emailAddress,
"reference": reference,
- "personalisation": personalisation,
+ "personalisation": personalisation
};
//console.log(
@@ -2055,7 +2061,7 @@ export const createContainerProxy = (containerName) => {
export const sendCaseCompleteMessage = async (
containerID,
caseReference,
- inv,
+ inv
) => {
var queryUrl =
"/api/file/createappealcompletemessage_api?container=" +
@@ -2067,7 +2073,7 @@ export const sendCaseCompleteMessage = async (
var config = {
method: "get",
- url: queryUrl,
+ url: queryUrl
};
//console.log(data);
@@ -2084,7 +2090,7 @@ export const sendCaseCompleteMessage = async (
export const sendCaseCompleteMessageProxy = async (
containerID,
- caseReference,
+ caseReference
) => {
var queryUrl =
"/api/file/createappealcompletemessageproxy_api?container=" +
@@ -2094,7 +2100,7 @@ export const sendCaseCompleteMessageProxy = async (
var config = {
method: "get",
- url: queryUrl,
+ url: queryUrl
};
//console.log(data);
@@ -2111,7 +2117,7 @@ export const sendCaseCompleteMessageProxy = async (
export const sendRepCompleteMessage = async (
containerID,
caseReference,
- fileName,
+ fileName
) => {
var queryUrl =
"/api/file/createrepcompletemessage_api?container=" +
@@ -2123,7 +2129,7 @@ export const sendRepCompleteMessage = async (
var config = {
method: "get",
- url: queryUrl,
+ url: queryUrl
};
//console.log(data);
@@ -2144,7 +2150,7 @@ export const setRepInvolvment = async (caseid, contactid) => {
var config = {
method: "post",
url: queryUrl,
- data: data,
+ data: data
};
try {
@@ -2162,7 +2168,7 @@ export const setCaseInvolvment = async (caseid, contactid) => {
var config = {
method: "post",
url: queryUrl,
- data: data,
+ data: data
};
try {
@@ -2182,7 +2188,7 @@ export const getAddressSearch = async (searchString) => {
var config = {
method: "get",
- url: queryUrl,
+ url: queryUrl
};
return axios(config)
@@ -2194,7 +2200,7 @@ export const getAddressSearch = async (searchString) => {
let ErrResponse = {
value: [],
errorCode: error.response.status,
- errorMsg: error.response.statusText,
+ errorMsg: error.response.statusText
};
return ErrResponse;
});
@@ -2207,7 +2213,7 @@ export const createCRMTask = async (formValues) => {
var config = {
method: "post",
url: queryUrl,
- data: data,
+ data: data
};
try {
@@ -2223,7 +2229,7 @@ export const getPreferredLanguage = async (email) => {
.get(
BASE_URL +
"/api/endpoint/getpreferredlanguage_api?emailAddress=" +
- email,
+ email
)
.then((res) => {
return res.data;
@@ -2239,7 +2245,7 @@ export const getAppealPDFDocument = async (incidentid) => {
.get(
BASE_URL +
"/api/endpoint/getappealpdfdocuments_api?incidentid=" +
- incidentid,
+ incidentid
)
.then((res) => {
return res.data;
@@ -2264,7 +2270,7 @@ export const getNewAppealsPage = async (
pageNumber,
orderBy,
fieldSort,
- showNumberOfRecords,
+ showNumberOfRecords
) => {
return axios
.get(
@@ -2277,7 +2283,7 @@ export const getNewAppealsPage = async (
"&fieldSort=" +
fieldSort +
"&showNumberOfRecords=" +
- showNumberOfRecords,
+ showNumberOfRecords
)
.then((res) => {
return res.data;
@@ -2295,7 +2301,7 @@ export const getNewDocumentsPaged = async (
showNumberOfRecords,
documentType,
documentOrigin,
- selectedWeeks,
+ selectedWeeks
) => {
console.log(
"/api/admin/getlatestdocuments_api?pageNumber=" +
@@ -2311,7 +2317,7 @@ export const getNewDocumentsPaged = async (
"&numberWeeks=" +
selectedWeeks +
"&documentOrigin=" +
- documentOrigin,
+ documentOrigin
);
return axios
.get(
@@ -2328,7 +2334,7 @@ export const getNewDocumentsPaged = async (
"&numberWeeks=" +
selectedWeeks +
"&documentOrigin=" +
- documentOrigin,
+ documentOrigin
)
.then((res) => {
return res.data;
diff --git a/components/case/representation/index.js b/components/case/representation/index.js
index e5dc32f7..d35c7d81 100644
--- a/components/case/representation/index.js
+++ b/components/case/representation/index.js
@@ -1,10 +1,9 @@
import { JSONPath as jsonpath } from "jsonpath-plus";
import useTranslation from "next-translate/useTranslation";
import { useRouter } from "next/router";
-import { useState } from "react";
-import { useDropzone } from "react-dropzone";
+import { useEffect, useState } from "react";
import { connect } from "react-redux";
-import { formValueSelector, reduxForm } from "redux-form";
+import { reduxForm } from "redux-form";
import { useSession } from "next-auth/react";
import { generateRepPDF, sendEmail, uploadRepFiles } from "../../../actions";
@@ -33,9 +32,7 @@ import RepresentationProgress_s78 from "./representationProgress/representationP
let MakeRepresentation = (props) => {
let { t } = useTranslation();
- const { acceptedFiles, getRootProps, getInputProps } = useDropzone();
- const [clearRepForm, setClearRepForm] = useState(false);
const [savingStatus, setSavingStatus] = useState(false);
const [finaliseAppealProcess, setFinaliseAppealProcess] = useState(false);
@@ -97,7 +94,7 @@ let MakeRepresentation = (props) => {
let questionnaireCount = updateQuestionnaireCount();
const isLPA =
- accountDetails[
+ accountDetails?.[
"pinswg_typeofinvolvement@OData.Community.Display.V1.FormattedValue"
] == "LPA"
? true
@@ -164,7 +161,39 @@ let MakeRepresentation = (props) => {
return values;
};
- isLPA && setRepresentationCapacity("LPA");
+ useEffect(() => {
+ if (isLPA && !currentView?.representationCapacity) {
+ setRepresentationCapacity("LPA");
+ }
+ }, [isLPA, currentView?.representationCapacity, setRepresentationCapacity]);
+
+ const normalizeCapacity = (rawCapacity) => {
+ const normalized = (rawCapacity || "")
+ .toString()
+ .toLowerCase()
+ .replace(/(\band|[\s\-\+\(\)\,\&])/g, "");
+
+ const capacityMap = {
+ appellant: "appellant",
+ apelydd: "appellant",
+ agent: "agent",
+ asiant: "agent",
+ interestedparty: "interestedparty",
+ lpa: "lpa",
+ landowner: "landowner",
+ [t("myrepresentations:capacity-options-arr-appellant")
+ .toLowerCase()
+ .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")]: "appellant",
+ [t("myrepresentations:capacity-options-arr-agent")
+ .toLowerCase()
+ .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")]: "agent",
+ [t("myrepresentations:capacity-options-arr-interested")
+ .toLowerCase()
+ .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")]: "interestedparty"
+ };
+
+ return capacityMap[normalized] || normalized || "false";
+ };
const getCasePath = () => {
switch (currentType) {
@@ -257,6 +286,9 @@ let MakeRepresentation = (props) => {
})[0];
}
+ const safeDetailsObj = detailsObj || {};
+ const safeResultsObj = resultsObj || {};
+
const buildRepsArr = (detailsObj) => {
const buildArr = [];
const todaysDate = new Date();
@@ -440,15 +472,10 @@ let MakeRepresentation = (props) => {
);
}
- const capacity = getNormalizedCapacity();
+ const capacity = normalizeCapacity(getNormalizedCapacity());
switch (capacity) {
- case "appellant":
- case "apelydd":
- case "apelydd":
- case t(
- "myrepresentations:capacity-options-arr-appellant"
- ).toLowerCase(): {
+ case "appellant": {
const Component =
appealType === 846040002
? ConsultationAppellant
@@ -463,7 +490,6 @@ let MakeRepresentation = (props) => {
);
}
- case "lpa":
case "lpa": {
return (
{
);
}
- case "agent":
- case "asiant":
- case "asiant":
- case t(
- "myrepresentations:capacity-options-arr-agent"
- ).toLowerCase(): {
+ case "agent": {
const Component =
appealType === 846040002 ? ConsultationAgent : RepAgent;
return (
@@ -498,10 +519,7 @@ let MakeRepresentation = (props) => {
);
}
- case "interestedparty":
- case t(
- "myrepresentations:capacity-options-arr-interested"
- ).toLowerCase(): {
+ case "interestedparty": {
const Component =
appealType === 846040002
? ConsultationInterestedPartyPerson
@@ -642,7 +660,7 @@ let MakeRepresentation = (props) => {
pinswg_siteaddressline2,
pinswg_siteaddresstown,
pinswg_siteaddresspostcode
- } = detailsObj;
+ } = safeDetailsObj;
return [
pinswg_siteaddressline1,
pinswg_siteaddressline2,
@@ -671,26 +689,28 @@ let MakeRepresentation = (props) => {
caseReferenceObj.repDetails.incidentid,
caseRef: currentRef,
casereference: currentRef,
- pinswg_questionnaireduedate: detailsObj.pinswg_questionnaireduedate,
+ pinswg_questionnaireduedate:
+ safeDetailsObj.pinswg_questionnaireduedate,
pinswg_statementduedate:
- detailsObj.pinswg_statementduedate ||
- detailsObj.pinswg_endofrepresentationperiod,
+ safeDetailsObj.pinswg_statementduedate ||
+ safeDetailsObj.pinswg_endofrepresentationperiod,
pinswg_statementsduedate:
- detailsObj.pinswg_statementsduedate ||
- detailsObj.pinswg_endofrepresentationperiod,
+ safeDetailsObj.pinswg_statementsduedate ||
+ safeDetailsObj.pinswg_endofrepresentationperiod,
pinswg_finalcommentsduedate:
- detailsObj.pinswg_finalcommentsduedate ||
- detailsObj.pinswg_endofrepresentationperiod,
+ safeDetailsObj.pinswg_finalcommentsduedate ||
+ safeDetailsObj.pinswg_endofrepresentationperiod,
pinswg_name: currentRef,
firstname: accountDetails.firstname,
lastname: accountDetails.lastname,
emailAddress: accountDetails.emailaddress1,
siteAddress: getSiteAddress(),
- pinswg_siteaddressline1: detailsObj.pinswg_siteaddressline1,
- pinswg_siteaddressline2: detailsObj.pinswg_siteaddressline2,
- pinswg_siteaddresstown: detailsObj.pinswg_siteaddresstown,
- pinswg_siteaddresspostcode: detailsObj.pinswg_siteaddresspostcode,
- pinswg_lpareference: resultsObj?.pinswg_lpareference,
+ pinswg_siteaddressline1: safeDetailsObj.pinswg_siteaddressline1,
+ pinswg_siteaddressline2: safeDetailsObj.pinswg_siteaddressline2,
+ pinswg_siteaddresstown: safeDetailsObj.pinswg_siteaddresstown,
+ pinswg_siteaddresspostcode:
+ safeDetailsObj.pinswg_siteaddresspostcode,
+ pinswg_lpareference: safeResultsObj?.pinswg_lpareference,
representationCapacity: getRepresentationCapacity(),
locale: router.locale
};
@@ -698,19 +718,19 @@ let MakeRepresentation = (props) => {
const formattedValues = {
...values,
...baseBody,
- _pinswg_appellant_value: detailsObj._pinswg_appellant_value,
+ _pinswg_appellant_value: safeDetailsObj._pinswg_appellant_value,
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue":
- detailsObj[
+ safeDetailsObj[
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
],
_pinswg_localplanningauthority_value:
- detailsObj._pinswg_localplanningauthority_value ||
- detailsObj._pinswg_associatedlpa_value,
+ safeDetailsObj._pinswg_localplanningauthority_value ||
+ safeDetailsObj._pinswg_associatedlpa_value,
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue":
- detailsObj[
+ safeDetailsObj[
"_pinswg_localplanningauthority_value@OData.Community.Display.V1.FormattedValue"
] ||
- detailsObj[
+ safeDetailsObj[
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
]
};
@@ -769,7 +789,9 @@ let MakeRepresentation = (props) => {
uploadRepresentationFiles(filesWithLinks);
};
- const isSubmitted = currentView.representationSubmit === "true";
+ const isSubmitted =
+ currentView.representationSubmit === true ||
+ currentView.representationSubmit === "true";
if (isSubmitted) {
sendEmailIfNeeded();
@@ -787,6 +809,10 @@ let MakeRepresentation = (props) => {
const onHandleSubmit = (values) => {
values = setRepFileName(values);
+ if (!caseReferenceObj?.currentReference) {
+ return;
+ }
+
// Determine case data source
const getCaseDetailsSource = () => {
if (router.query?.state === "edit") {
@@ -905,9 +931,7 @@ let MakeRepresentation = (props) => {
if (hasNoCapacity) {
const capacity = isLPA
? "LPA"
- : values.representationCapacity
- .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
- .toLowerCase();
+ : normalizeCapacity(values.representationCapacity);
setRepresentationCapacity(capacity);
} else {
if (repType === "Questionnaire") {
@@ -1038,9 +1062,9 @@ let MakeRepresentation = (props) => {
{t("myrepresentations:statements-due-label")}:{" "}
{formatDates(
- detailsObj.pinswg_statementduedate ||
- detailsObj.pinswg_statementsduedate ||
- detailsObj.pinswg_endofrepresentationperiod
+ safeDetailsObj.pinswg_statementduedate ||
+ safeDetailsObj.pinswg_statementsduedate ||
+ safeDetailsObj.pinswg_endofrepresentationperiod
)}
@@ -1052,7 +1076,7 @@ let MakeRepresentation = (props) => {
{t("myrepresentations:marine-impact-report")}:{" "}
- {formatDates(detailsObj.pinswg_consultationclose)}
+ {formatDates(safeDetailsObj.pinswg_consultationclose)}
);
@@ -1062,7 +1086,7 @@ let MakeRepresentation = (props) => {
{t("myrepresentations:consultation-close-label")}:{" "}
- {formatDates(detailsObj.pinswg_consultationclose)}
+ {formatDates(safeDetailsObj.pinswg_consultationclose)}
);
@@ -1075,7 +1099,7 @@ let MakeRepresentation = (props) => {
{t("myrepresentations:final-comments-due-label")}:{" "}
- {formatDates(detailsObj.pinswg_finalcommentsduedate)}
+ {formatDates(safeDetailsObj.pinswg_finalcommentsduedate)}
);
@@ -1207,8 +1231,6 @@ const mapDispatchToProps = (dispatch) => {
};
};
-const selector = formValueSelector("representationForm");
-
export default connect(
mapStateToProps,
mapDispatchToProps
diff --git a/components/case/representation/representationCompleteSubmit.js b/components/case/representation/representationCompleteSubmit.js
index b51830ab..7a572ca4 100644
--- a/components/case/representation/representationCompleteSubmit.js
+++ b/components/case/representation/representationCompleteSubmit.js
@@ -4,6 +4,7 @@ import { useRouter } from "next/router";
import { useState } from "react";
import { useDropzone } from "react-dropzone";
import { connect } from "react-redux";
+import { generateRepPDF } from "../../../actions";
import RepComplete from "./representationComplete";
import RepLPAQuestionnaireCheck_enforcement from "./representationQuestionnairesCheck/representationLPAQuestionnaireCheck_enforcement";
import RepLPAQuestionnaireCheck_s78 from "./representationQuestionnairesCheck/representationLPAQuestionnaireCheck_s78";
@@ -13,17 +14,19 @@ import {
getThumbnailIconByExtension,
formatDates,
updateLinks,
- getDocLink,
+ getDocLink
} from "../../utils";
import {
setCurrentReference,
- setCurrentView,
+ setCurrentView
} from "../../../store/currentView/action";
const RepCompleteSubmit = (props) => {
let { t } = useTranslation();
const [confirmSections, setConfirmSections] = useState(false);
+ const [downloadQuestionnaire, setDownloadQuestionnaire] = useState(false);
+ const [downloadInProgress, setDownloadInProgress] = useState(false);
const router = useRouter();
const { locale } = router;
@@ -42,7 +45,7 @@ const RepCompleteSubmit = (props) => {
questionnaireCount,
finaliseAppealProcess,
setCurrentReference,
- docsOffline,
+ docsOffline
} = props;
let ShowDocLinks = getDocLink(docsOffline);
@@ -169,7 +172,7 @@ const RepCompleteSubmit = (props) => {
typeof filesUploadObj[key].name != "undefined" &&
buildAppealFilesArray.push({
"name": filesUploadObj[key].name,
- "size": filesUploadObj[key].contentLength,
+ "size": filesUploadObj[key].contentLength
});
}
@@ -185,7 +188,7 @@ const RepCompleteSubmit = (props) => {
// : [];
let arrUniq = [
- ...new Map(buildAppealFilesArray.map((v) => [v.name, v])).values(),
+ ...new Map(buildAppealFilesArray.map((v) => [v.name, v])).values()
];
buildAppealFilesArray = buildAppealFilesArray.filter(function (el) {
@@ -217,7 +220,7 @@ const RepCompleteSubmit = (props) => {
arrUniq = removeEmptyObjects(arrUniq);
Object.assign(formObj.representationForm.values, {
- "filesList": arrUniq,
+ "filesList": arrUniq
});
let filterFiles = [];
@@ -235,7 +238,6 @@ const RepCompleteSubmit = (props) => {
}
const checkRepDatePassed = () => {
- return false;
if (repFormData.representationType == "Questionnaire") {
return false;
} else {
@@ -255,6 +257,62 @@ const RepCompleteSubmit = (props) => {
}
};
+ const triggerQuestionnaireDownload = async () => {
+ if (
+ repFormData.representationType !== "Questionnaire" ||
+ !downloadQuestionnaire
+ ) {
+ return;
+ }
+
+ if (downloadInProgress) {
+ return;
+ }
+
+ try {
+ setDownloadInProgress(true);
+
+ const containerID =
+ props.accountDetails?.containerID ||
+ props.props?.accountDetails?.containerID ||
+ props.props?.props?.accountDetails?.containerID;
+ const caseRef =
+ currentView?.caseReference?.ticketnumber ||
+ repFormData?.caseRef ||
+ repFormData?.ticketnumber;
+
+ if (!containerID || !caseRef) {
+ console.error(
+ "Questionnaire download skipped: missing containerID or case reference",
+ { containerID, caseRef }
+ );
+ return;
+ }
+
+ const pdfBlob = await generateRepPDF(
+ repFormData,
+ containerID,
+ caseRef,
+ { download: true }
+ );
+
+ if (pdfBlob) {
+ const blobUrl = window.URL.createObjectURL(pdfBlob);
+ const anchor = document.createElement("a");
+ anchor.href = blobUrl;
+ anchor.download = `${repFormData.repfile_name || "questionnaire"}.pdf`;
+ document.body.appendChild(anchor);
+ anchor.click();
+ anchor.remove();
+ window.URL.revokeObjectURL(blobUrl);
+ }
+ } catch (error) {
+ console.error("Questionnaire download failed", error);
+ } finally {
+ setDownloadInProgress(false);
+ }
+ };
+
return (
<>
{currentView.representationSubmitConfirmation == true ? (
@@ -305,12 +363,12 @@ const RepCompleteSubmit = (props) => {
"Questionnaire"
? "Holiadur"
: repFormData.representationType ==
- "Statement"
- ? "Datganiad"
- : repFormData.representationType ==
- "Final comments"
- ? "Sylwadau terfynol"
- : repFormData.representationType
+ "Statement"
+ ? "Datganiad"
+ : repFormData.representationType ==
+ "Final comments"
+ ? "Sylwadau terfynol"
+ : repFormData.representationType
: repFormData.representationType}
@@ -368,7 +426,7 @@ const RepCompleteSubmit = (props) => {
"appealType":
repFormData.appealType,
"repDetails":
- repFormData,
+ repFormData
});
setRepresentationSubmit(
false
@@ -421,7 +479,7 @@ const RepCompleteSubmit = (props) => {
"appealType":
repFormData.appealType,
"repDetails":
- repFormData,
+ repFormData
}
);
setRepresentationSubmit(
@@ -458,7 +516,7 @@ const RepCompleteSubmit = (props) => {
@@ -482,7 +540,7 @@ const RepCompleteSubmit = (props) => {
"appealType":
repFormData.appealType,
"repDetails":
- repFormData,
+ repFormData
});
setRepresentationSubmit(
false
@@ -562,7 +620,7 @@ const RepCompleteSubmit = (props) => {
"appealType":
repFormData.appealType,
"repDetails":
- repFormData,
+ repFormData
}),
setRepresentationSubmit(
false
@@ -609,6 +667,7 @@ const RepCompleteSubmit = (props) => {
"myrepresentations:rep-check-tandc-para-three"
)}
+
{checkRepDatePassed() ? (
@@ -676,6 +735,35 @@ const RepCompleteSubmit = (props) => {
>
) : (
<>
+ {repFormData.representationType ==
+ "Questionnaire" && (
+
+
+ {
+ setDownloadQuestionnaire(
+ e.target.checked
+ );
+ }}
+ />
+
+ {t(
+ "myrepresentations:rep-check-tandc-para-five"
+ )}
+
+
+
+ )}
@@ -714,10 +802,11 @@ const RepCompleteSubmit = (props) => {
type="submit"
className="govuk-button"
data-module="govuk-button"
- onClick={() => {
+ onClick={async () => {
// setRepresentationSubmitConfirmation(
// true
// );
+ await triggerQuestionnaireDownload();
setRepresentationSubmit(
true
);
@@ -754,7 +843,7 @@ const mapStateToProps = (state) => {
currentView: state.currentView,
myRepresentations: state.myRepresentations,
initialValues: state.currentView.caseReference.repDetails,
- accountDetails: state.accountDetails,
+ accountDetails: state.accountDetails
//form: state.form,
};
};
@@ -763,7 +852,7 @@ const mapDispatchToProps = (dispatch) => {
return {
setCurrentReference: (currentReference) => {
dispatch(setCurrentReference(currentReference));
- },
+ }
};
};
diff --git a/locales/cy/myrepresentations.json b/locales/cy/myrepresentations.json
index e39e7422..bcaf58c5 100644
--- a/locales/cy/myrepresentations.json
+++ b/locales/cy/myrepresentations.json
@@ -54,6 +54,7 @@
"rep-check-tandc-para-two": "Mae Penderfyniadau Cynllunio a'r Amgylchedd Cymru yn cymryd ei chyfrifoldebau diogelu data am y wybodaeth a roddwch i ni o ddifrif. I ddarganfod mwy am sut rydym yn defnyddio ac yn rheoli eich data personol, ewch i ein",
"rep-check-tandc-para-three": "Cadarnhaf fod pob adran o’r ffurflen hon wedi’u llenwi’n llawn a bod y manylion yn gywir hyd eithaf fy ngwybodaeth.",
"rep-check-tandc-para-four": "Cadarnhaf fy mod wedi darllen yr uchod.",
+ "rep-check-tandc-para-five": "Hoffwn lawrlwytho copi o'r holiadur hwn ar gyfer fy nghofnodion",
"rep-complete-heading": "Cyflwyno Sylwadau",
"rep-complete-para-one": "Diolch am gyflwyno eich sylw/sylwadau gan ddefnyddio'r Porth Gwaith Achos Apeliadau.",
"rep-complete-para-two": "Cofiwch fod angen i ni dderbyn unrhyw ddogfennau ategol o fewn y terfyn amser priodol ar gyfer yr achos. Rhaid i unrhyw beth y byddwch yn ei anfon atom gael ei farcio'n glir gyda chyfeirnod yr achos a chyfeiriad y safle (gan gynnwys y cod post, os yw'n hysbys).",
diff --git a/locales/en/myrepresentations.json b/locales/en/myrepresentations.json
index 2ede7c8f..1cd9efc6 100644
--- a/locales/en/myrepresentations.json
+++ b/locales/en/myrepresentations.json
@@ -54,6 +54,7 @@
"rep-check-tandc-para-two": "Planning and Environment Decisions Wales takes its data protection responsibilities for the information you provide us with very seriously. To find out more about how we use and manage your personal data, please go to our",
"rep-check-tandc-para-three": "I confirm that all sections of this form have been fully completed and that the details are correct to the best of my knowledge.",
"rep-check-tandc-para-four": "I confirm I have read the above.",
+ "rep-check-tandc-para-five": "I wish to download a copy of this questionaire for my records",
"rep-complete-heading": "Submission of Representation",
"rep-complete-para-one": "Thank you for submitting your representation(s) using the Appeals Casework Portal.",
"rep-complete-para-two": "Please remember that any supporting documentation needs to be received by us within the appropriate deadline for the case. Anything you send to us must be clearly marked with the case reference number and the site address (including the postcode, where known).",
diff --git a/pages/api/file/generatepdf.js b/pages/api/file/generatepdf.js
index 9c232980..d67b197f 100644
--- a/pages/api/file/generatepdf.js
+++ b/pages/api/file/generatepdf.js
@@ -107,27 +107,31 @@ import { consoleLogger } from "../../../actions";
// ApiProxy.post(async (req, res) => {
export default async function handler(req, res) {
+ const shouldDownload = req.query.download === "true";
var checkHash = req.query.hash;
- let reqBodyobj = req.body; //JSON.parse(req.body);
+ let reqBodyobj =
+ typeof req.body === "string" ? JSON.parse(req.body) : req.body;
const cleanFilesList = (blobList) => {
- let newblobList = blobList.filesList;
+ let newblobList = Array.isArray(blobList?.filesList)
+ ? blobList.filesList
+ : [];
function removeNullObjects(arr) {
- if (arr.length === 0) {
+ if (!Array.isArray(arr) || arr.length === 0) {
return arr;
}
return arr.filter((obj) => obj !== null);
}
function removeObjectsWithUndefinedKey(arr, key) {
- if (arr.length === 0) {
+ if (!Array.isArray(arr) || arr.length === 0) {
return arr;
}
return arr.filter((obj) => obj[key] !== undefined);
}
function removeEmptyObjects(arr) {
- if (arr.length === 0) {
+ if (!Array.isArray(arr) || arr.length === 0) {
return arr;
}
return arr.filter(
@@ -149,7 +153,7 @@ export default async function handler(req, res) {
return blobList;
};
- reqBodyobj = reqBodyobj.hasOwnProperty("filesList")
+ reqBodyobj = reqBodyobj?.hasOwnProperty("filesList")
? cleanFilesList(reqBodyobj)
: reqBodyobj;
@@ -296,12 +300,26 @@ export default async function handler(req, res) {
// process.cwd() + `/tmp/${reqBodyobj.repfile_name}.pdf`
// );
- const renderedPDF = await ReactPDF.renderToStream(
+ const streamToBuffer = async (readableStream) => {
+ return new Promise((resolve, reject) => {
+ const chunks = [];
+ readableStream.on("data", (chunk) => {
+ chunks.push(
+ Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)
+ );
+ });
+ readableStream.on("end", () => resolve(Buffer.concat(chunks)));
+ readableStream.on("error", reject);
+ });
+ };
+
+ const renderedPDFStream = await ReactPDF.renderToStream(
);
+ const renderedPDFBuffer = await streamToBuffer(renderedPDFStream);
await createRepPDFBlob(
- renderedPDF,
+ renderedPDFBuffer,
containerID,
caseRef,
reqBodyobj.repfile_name
@@ -312,6 +330,16 @@ export default async function handler(req, res) {
`${caseRef}/files/${reqBodyobj.repfile_name}.pdf`,
"\n/////////////////////////"
);
+ if (shouldDownload) {
+ const filename = `${reqBodyobj.repfile_name || "questionnaire"}.pdf`;
+ res.setHeader("Content-Type", "application/pdf");
+ res.setHeader(
+ "Content-Disposition",
+ `attachment; filename="${filename}"`
+ );
+ return res.status(200).send(renderedPDFBuffer);
+ }
+
return res.status(200).json({
status: "success",
data: data,