diff --git a/actions/azurestorage.js b/actions/azurestorage.js
index e014febb..f407bcd8 100644
--- a/actions/azurestorage.js
+++ b/actions/azurestorage.js
@@ -55,7 +55,7 @@ export const createContainerSas = async (containerName) => {
);
// Need only list permission to list blobs
- const containerPermissions = "rcwltdf";
+ const containerPermissions = "rcwdltf";
// Best practice: SAS options are time-limited
const sasOptions = {
@@ -260,6 +260,7 @@ export const createBlob = async (formContent, containerName, caseref) => {
const tags = {
containerid: containerName,
caseID: caseID,
+ blobType: "Appeal",
};
console.log("the tags:", tags);
@@ -283,7 +284,7 @@ export const createRepBlob = async (formContent, containerName, caseref) => {
const content = JSON.stringify(formContent);
- console.log(content);
+ //console.log(content);
const blobName = caseref + "/" + caseID + "_rep.json";
console.log("blobName:", blobName);
@@ -395,6 +396,90 @@ export const uploadFile = async (formContent, containerName, foldername) => {
}
};
+export const uploadRepFiles = async (
+ formContent,
+ containerName,
+ foldername
+) => {
+ const containerToken = await createContainerSas(containerName);
+ const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
+ const containerClient = new ContainerClient(sasUrl);
+
+ const files = formContent;
+
+ console.log(...formContent);
+ console.log("rep files...", files, Object.keys(files).length, foldername);
+
+ // console.log(`files[${prop}] = ${files[prop][0].size}`);
+ const blobName = foldername + formContent.split("tmp/")[1];
+
+ console.log(blobName);
+
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
+ const uploadBlobResponse = await blockBlobClient.uploadFile(formContent);
+ const tags = {
+ containerid: containerName,
+ caseID: foldername,
+ documentType: "rep content",
+ };
+ console.log(tags);
+ // const withTags = await blockBlobClient.setTags(tags);
+ // const withMeta = await blockBlobClient.setMetadata(tags);
+
+ console.log(
+ `Uploaded block blob ${files} successfully`,
+ uploadBlobResponse.requestId
+ );
+};
+
+export const uploadPDFRepFiles = async (
+ formContent,
+ containerName,
+ foldername,
+ repType
+) => {
+ const containerToken = await createContainerSas(containerName);
+ const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
+ const containerClient = new ContainerClient(sasUrl);
+
+ const files = formContent;
+
+ console.log(formContent, containerName, foldername);
+ console.log(
+ "rep pdf files...",
+ files,
+ Object.keys(files).length,
+ foldername
+ );
+
+ // console.log(`files[${prop}] = ${files[prop][0].size}`);
+ console.log(foldername + "/files/" + formContent.split("tmp/")[1]);
+
+ const blobName = foldername + "/files/" + formContent.split("tmp/")[1];
+
+ console.log(blobName);
+
+ console.log(blobName);
+ const blockBlobClient = containerClient.getBlockBlobClient(blobName);
+ const uploadBlobResponse = await blockBlobClient.uploadFile(formContent);
+
+ const tags = {
+ containerid: containerName,
+ caseID: foldername,
+ documentType: repType,
+ blobType: "RepresentationPDF",
+ };
+
+ console.log("the tags:", tags);
+ const withTags = await blockBlobClient.setTags(tags);
+ const withMeta = await blockBlobClient.setMetadata(tags);
+
+ console.log(
+ `Uploaded block blob ${files} successfully`,
+ uploadBlobResponse.requestId
+ );
+};
+
export const downloadFile = async (containerName, blobName) => {
//console.log.apply(containerName, blobName);
const containerToken = await createContainerSas(containerName);
@@ -486,12 +571,32 @@ export const downloadAllProgressFiles = async (
);
};
+export const downloadRepFile = async (
+ containerName,
+ blobName,
+ casefolderID
+) => {
+ console.log(containerName, blobName);
+
+ const containerToken = await createContainerSas(containerName);
+ const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
+ const containerClient = new ContainerClient(sasUrl);
+ const blobClient = containerClient.getBlobClient(blobName);
+ const downloadedBlob = await blobClient.download();
+
+ const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody);
+
+ console.log("Downloaded blob content:", downloaded.toString());
+
+ return JSON.parse(downloaded.toString());
+};
+
export const downloadAllRepsFiles = async (containerName, repsBlobObj) => {
- // console.log(
- // "/////////////////////////\n downloading files: " +
- // JSON.stringify(repsBlobObj) +
- // "\n/////////////////////////\n"
- // );
+ console.log(
+ "/////////////////////////\n downloading files: " +
+ JSON.stringify(repsBlobObj) +
+ "\n/////////////////////////\n"
+ );
const containerToken = await createContainerSas(containerName);
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
@@ -500,14 +605,18 @@ export const downloadAllRepsFiles = async (containerName, repsBlobObj) => {
let blobClient = {};
let downloadedBlob = {};
let repArr = [];
- let downloaded = "";
+ let downloaded = [];
let caseBlob = {};
let caseDownloaded = "";
let blobCount = 0;
+ Array.isArray(repsBlobObj) &&
+ !repsBlobObj.length &&
+ console.log("is empt and an array");
+
for (const prop in repsBlobObj) {
- //console.log(`Progress - ${prop}: ${repsBlobObj[prop].name}`);
- blobClient = containerClient.getBlobClient(repsBlobObj[prop].name);
+ console.log(`Progress - ${prop}: ${repsBlobObj[prop].path}`);
+ blobClient = containerClient.getBlobClient(repsBlobObj[prop].path);
downloadedBlob = await blobClient.download(0);
let repBlobObj = await streamToBuffer(
downloadedBlob.readableStreamBody
@@ -517,17 +626,29 @@ export const downloadAllRepsFiles = async (containerName, repsBlobObj) => {
repBlobObj["casereference"] = repsBlobObj[prop].name.split("/")[0];
- repBlobObj = JSON.stringify(repBlobObj);
+ // repBlobObj = JSON.stringify(repBlobObj);
- downloaded = downloaded + repBlobObj + ",";
+ downloaded.push(repBlobObj);
blobCount++;
}
- downloaded = downloaded.substring(0, downloaded.length - 1);
+ //downloaded = downloaded.substring(0, downloaded.length - 1);
+ // console.log(
+ // "/////////////////////////\n downloaded : " +
+ // JSON.stringify(
+ // '{ "@odata.count": ' +
+ // blobCount +
+ // ',"value": ' +
+ // downloaded +
+ // "}"
+ // ) +
+ // "\n/////////////////////////\n"
+ // );
- return JSON.parse(
- '{ "@odata.count": ' + blobCount + ',"value": [' + downloaded + "]}"
- );
+ return {
+ "@odata.count": blobCount,
+ "value": downloaded,
+ };
};
const streamToBuffer = async (readableStream) => {
@@ -642,7 +763,9 @@ export const getAllProgressBlobs = async (containerName) => {
let blobCount = 0;
let blobObj = [];
- for await (const blob of containerClient.listBlobsFlat()) {
+ for await (const blob of containerClient.findBlobsByTags(
+ "blobType='Appeal'"
+ )) {
blob.name.split("/")[1].indexOf("_appeal.json") > 0 &&
blob.name.split("/")[1].indexOf("undefined") < 0 &&
blobObj.push({
@@ -661,12 +784,12 @@ export const getAllProgressBlobs = async (containerName) => {
});
}
- //console.log("blobObj:", blobObj);
+ console.log("blobObj:", blobObj);
return blobObj;
};
-export const getRepslobs = async (containerName, caseReference) => {
+export const getRepsBlobs = async (containerName) => {
const containerToken = await createContainerSas(containerName);
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
@@ -677,25 +800,30 @@ export const getRepslobs = async (containerName, caseReference) => {
for await (const blob of containerClient.findBlobsByTags(
"blobType='Representation'"
)) {
+ console.log(`-----Blob ${blobCount++}: ${blob.name}`);
blobCount++;
}
- // console.log(
- // "this is the casefolder and blobcount:",
- // caseReference,
- // blobCount
- // );
+ console.log(
+ "this is the casefolder and blobcount:",
+ //caseReference,
+ blobCount
+ );
let blobObj = [];
for await (const blob of containerClient.findBlobsByTags(
"blobType='Representation'"
)) {
- // console.log("getRepslobs in here");
- // console.log(blob);
- blobObj.push(blob);
+ console.log(blob);
+ blob.name.split("/")[1].indexOf("_rep.json") > 0 &&
+ blob.name.split("/")[1].indexOf("undefined") < 0 &&
+ blobObj.push({
+ "name": blob.name.split("/")[1],
+ "path": blob.name,
+ });
}
- //console.log("blobObjwwwww:", blobObj);
+ console.log("blobObjwwwww:", blobObj);
return blobObj;
};
diff --git a/actions/index.js b/actions/index.js
index a0fe4b06..0fb2eda5 100644
--- a/actions/index.js
+++ b/actions/index.js
@@ -782,11 +782,11 @@ export const getAwaitingSubmission = (loggedInUserId) => {
};
export const getAwaitingSubmissionFromBlob = (containerName) => {
- // console.log(
- // "///////////////////////\ngetAwaitingSubmissionFromBlob: " +
- // containerName +
- // "\n///////////////////////\n"
- // );
+ console.log(
+ "///////////////////////\ngetAwaitingSubmissionFromBlob: " +
+ containerName +
+ "\n///////////////////////\n"
+ );
return axios
.get(
BASE_URL +
@@ -807,9 +807,13 @@ export const getAwaitingSubmissionFromBlob = (containerName) => {
export const getRepsFromBlob = (containerName) => {
console.log(
- "///////////////////////\ngetRepsFromBlob: " +
+ "///////////////////////\ngetRepsFromBlob function: " +
containerName +
- "\n///////////////////////\n"
+ "\n///////////////////////\n",
+ BASE_URL +
+ "/api/file/getrepsblob?container=" +
+ containerName +
+ hashAPIPath("/api/file/getrepsblob?container=" + containerName)
);
return axios
@@ -823,7 +827,12 @@ export const getRepsFromBlob = (containerName) => {
return res.data;
})
.catch((error) => {
- //console.log("API call error", error);
+ console.log(
+ "///////////////////////\ngetRepsFromBlob error response: " +
+ error +
+ "\n///////////////////////\n"
+ );
+ console.log("API call error", error);
});
};
@@ -1346,6 +1355,37 @@ export const uploadRepFiles = async (
}
};
+export const generateRepPDF = async (formValues, containerID, casefolderID) => {
+ //let files = filesObj;
+
+ console.log("generateRepPDF function: " + formValues);
+ // var formData = new FormData();
+ // formValues.append("appealData", JSON.stringify(formValues));
+ // formValues.append("containerID", containerID);
+ // formValues.append("casefolderID", casefolderID);
+
+ // Object.assign(formValues, {
+ // "containerID": containerID,
+ // "casefolderID": casefolderID,
+ // });
+
+ var queryUrl = "/api/file/generatepdf";
+
+ const config = {
+ method: "post",
+ url: queryUrl,
+ data: formValues,
+ headers: { "content-type": "multipart/form-data" },
+ };
+
+ //console.log(config);
+ try {
+ const res = await axios(config);
+ return res.data;
+ } catch (error) {
+ console.log("this serror", error);
+ }
+};
export const getFilesFromBlob = (containerName, casefolderID) => {
console.log(
" get files from blob",
diff --git a/components/case/representation/index.js b/components/case/representation/index.js
index adf952b0..217e7b1a 100644
--- a/components/case/representation/index.js
+++ b/components/case/representation/index.js
@@ -2,7 +2,7 @@ import Link from "next/link";
import { useState, useEffect } from "react";
import { useRouter } from "next/router";
import useTranslation from "next-translate/useTranslation";
-import jsonpath from "jsonpath";
+import jsonpath, { value } from "jsonpath";
import _, { property } from "lodash";
import {
Field,
@@ -23,11 +23,13 @@ import {
setRepresentationReset,
} from "../../../store/currentView/action";
import RepCapacitySelection from "./representationCapacitySelection";
+import RepLPACapacitySelection from "./representationLPACapacitySelection";
import RepDetails from "./representationDetails";
import RepAppellant from "./representationAppellant";
import RepAgent from "./representationAgent";
import RepInterestedPartyPerson from "./representationInterestedPartyPerson";
import RepLandOwner from "./representationLandowner";
+import RepLPA from "./representationLPA";
import RepCompleteSubmit from "./representationCompleteSubmit";
import { useSession, signIn, signOut } from "next-auth/react";
import {
@@ -35,6 +37,7 @@ import {
patchCase,
uploadRepFiles,
sendEmail,
+ generateRepPDF,
} from "../../../actions";
import {
@@ -43,6 +46,16 @@ import {
RenderTextfield,
} from "./representationElements";
+import ReactPDF, {
+ Document,
+ Page,
+ Text,
+ View,
+ StyleSheet,
+ PDFViewer,
+} from "@react-pdf/renderer";
+import { object } from "prop-types";
+
let MakeRepresentation = (props) => {
let { t } = useTranslation();
const { acceptedFiles, getRootProps, getInputProps } = useDropzone();
@@ -87,28 +100,33 @@ let MakeRepresentation = (props) => {
var detailsObj = {};
- const capacityOptionsArr = [
- "Appellant",
- "Agent",
- "Interested Party/Person",
- "Land Owner",
- ];
+ const capacityOptionsArr = ["Appellant", "Agent", "Interested Party"];
const appellantApplicantRepresentationArr = [
- "Other",
"Statement",
- "Statement of common ground",
+ "Final comments",
"Written statement of evidence",
+ "Other",
];
const interestedPersonRepresentationArr = [
- "Interested Party/Person correspondence",
+ "Statement",
+ "Final comments",
+ "Other",
+ ];
+
+ const lpaRepresentationArr = [
+ "Questionnaire",
+ "Final comments",
+ "Written statement of evidence",
+ "Other",
];
const landOwnerRepresentationArr = [
- "Other",
"Statement",
+ "Final comments",
"Written statement of evidence",
+ "Other",
];
const repCapacityType = () => {
@@ -125,10 +143,38 @@ let MakeRepresentation = (props) => {
.toLowerCase();
};
+ const isLPA =
+ props.props.accountDetails.accountDetails[
+ "pinswg_typeofinvolvement@OData.Community.Display.V1.FormattedValue"
+ ] == "LPA"
+ ? true
+ : false;
+
const whichControl = () => {
- switch (currentView.representationCapacity) {
- case false:
- return (
+ console.log(isLPA);
+ console.log(
+ currentView.representationCapacity,
+ _.isEmpty(currentView.representationCapacity)
+ );
+ if (isLPA && _.isEmpty(currentView.representationCapacity)) {
+ return (
+
+ );
+ } else {
+ switch (currentView.representationCapacity) {
+ case false:
{
setSubmitBack={setSubmitBack}
props={props}
caseReference={caseReference}
- />
- );
- break;
- case "appellant":
- //setRepresentationCapacity("appellant");
- return (
-
- );
- break;
- case "agent":
- //setRepresentationCapacity("agent");
- return (
-
- );
- break;
- case "interestedparty/person":
- // setRepresentationCapacity("interestedpartyperson");
- return (
-
- );
- break;
- case "landowner":
- //setRepresentationCapacity("landowner");
- return (
-
- );
- break;
- default:
- return (
-
- );
+ />;
+ break;
+ case "appellant":
+ //setRepresentationCapacity("appellant");
+ return (
+
+ );
+ break;
+ case "lpa":
+ //setRepresentationCapacity("appellant");
+ return (
+
+ );
+ break;
+ case "agent":
+ //setRepresentationCapacity("agent");
+ return (
+
+ );
+ break;
+ case "interestedparty/person":
+ // setRepresentationCapacity("interestedpartyperson");
+ return (
+
+ );
+ break;
+ case "landowner":
+ //setRepresentationCapacity("landowner");
+ return (
+
+ );
+ break;
+ default:
+ return (
+
+ );
+ }
}
};
@@ -258,6 +335,9 @@ let MakeRepresentation = (props) => {
case "Land Owner":
repType = "LO";
break;
+ case "LPA":
+ repType = "LPA";
+ break;
default:
// code block
@@ -280,6 +360,7 @@ let MakeRepresentation = (props) => {
"containerID": props.props.accountDetails.containerID,
"appealType": props.props.currentView.caseReference.appealType,
"incidentID": props.props.currentView.caseReference.incidentid,
+ "caseRef": props.props.currentView.caseReference.currentReference,
});
updateBody = JSON.stringify(updateBody);
@@ -321,19 +402,40 @@ let MakeRepresentation = (props) => {
};
const onHandleSubmit = (values) => {
+ console.log("form values - ", JSON.stringify(values));
+ Object.assign(values, {
+ "containerID": props.props.accountDetails.containerID,
+ "appealType": props.props.currentView.caseReference.appealType,
+ "incidentID": props.props.currentView.caseReference.incidentid,
+ "caseRef": props.props.currentView.caseReference.currentReference,
+ "pinswg_name":
+ props.props.currentView.caseReference.currentReference,
+ "firstname": props.props.accountDetails.accountDetails.firstname,
+ "lastname": props.props.accountDetails.accountDetails.lastname,
+ "emailAddress":
+ props.props.accountDetails.accountDetails.emailaddress1,
+ });
+
currentView.representationSubmit != true
? _.isEmpty(currentView.representationCapacity)
- ? setRepresentationCapacity(
- values.representationCapacity
- .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
- .toLowerCase()
- )
+ ? isLPA
+ ? setRepresentationCapacity("lpa")
+ : setRepresentationCapacity(
+ values.representationCapacity
+ .replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
+ .toLowerCase()
+ )
: setRepresentationSubmit(true)
: currentView.representationSubmit == true
? (console.log("capacity", currentView.representationCapacity),
console.log("has errors:", props.invalid),
props.invalid == false &&
updateRepresentation(values, false, false),
+ generateRepPDF(
+ values,
+ props.props.accountDetails.containerID,
+ currentView.caseReference.currentReference
+ ),
uploadRepresentationFiles(values),
setRepresentationSubmitConfirmation(true))
: console.log("nit updated");
@@ -376,8 +478,8 @@ let MakeRepresentation = (props) => {
const repForm = props.props.form;
console.log(
- "waht is representationSubmit:",
- currentView.representationSubmit
+ "what is representationSubmit state: " +
+ currentView.representationSubmit
);
return (
diff --git a/components/case/representation/representationAgent.js b/components/case/representation/representationAgent.js
index c7a13195..20c1e9e1 100644
--- a/components/case/representation/representationAgent.js
+++ b/components/case/representation/representationAgent.js
@@ -7,6 +7,7 @@ import {
RenderTextfield,
RenderRadioList,
RenderMultiline,
+ RenderRichMultiline,
RenderCondtionalRadioList,
FileUploadField,
} from "./representationElements";
@@ -109,7 +110,7 @@ const RepAgent = (props) => {