From 1f669a5efed078b2d46dbe6f05967aa77509e8bf Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Wed, 4 Oct 2023 14:28:56 +0100 Subject: [PATCH] reps pdf upload directory restructure --- actions/azurestorage.js | 118 +++++----- actions/index.js | 14 ++ components/case/representation/index copy.js | 212 ------------------ components/case/representation/index.js | 90 ++++++-- .../representation/representationAgent.js | 46 +++- .../representation/representationAppellant.js | 38 +++- .../representationCapacitySelection.js | 2 + .../representationCompleteSubmit.js | 58 +---- .../representation/representationDetails.js | 25 ++- .../representation/representationElements.js | 54 +---- .../case/representation/representationLPA.js | 26 +-- .../representationLPACapacitySelection.js | 1 + .../representationLPAComments.js | 13 +- .../representationLPADetails.js | 6 +- .../representationLPAQuestionnaire.js | 13 +- components/elements/index.js | 54 +---- components/myportal.js | 18 +- components/myportal/topthree_reps.js | 53 ++--- components/myportal/uploadFile.js | 12 +- components/newappeal/buildchecksection.js | 54 +---- components/pdftemplates/finalComments_pdf.js | 35 +-- .../pdftemplates/lpaQuestionnaire_pdf.js | 36 +-- components/pdftemplates/other_pdf.js | 35 +-- components/pdftemplates/statement_pdf.js | 35 +-- .../pdftemplates/writtenStatement_pdf.js | 35 +-- components/utils/index.js | 48 ++++ pages/api/email/notify.js | 2 +- pages/api/file/generatepdf.js | 38 ++-- pages/api/file/getrepsblob.js | 2 +- 29 files changed, 503 insertions(+), 670 deletions(-) delete mode 100644 components/case/representation/index copy.js diff --git a/actions/azurestorage.js b/actions/azurestorage.js index 10c41013..277fdcfd 100644 --- a/actions/azurestorage.js +++ b/actions/azurestorage.js @@ -276,16 +276,11 @@ export const createRepBlob = async (formContent, containerName, caseref) => { const containerClient = new ContainerClient(sasUrl); formContent = JSON.parse(formContent); - let caseID = ""; - - caseID = _.has(formContent, "pinswg_name") - ? formContent.pinswg_name - : caseref; const content = JSON.stringify(formContent); //console.log(content); - const blobName = caseref + "/" + caseID + "_rep.json"; + const blobName = caseref + "/" + formContent.repfile_name + "_rep.json"; console.log("blobName:", blobName); const blockBlobClient = containerClient.getBlockBlobClient(blobName); @@ -297,7 +292,7 @@ export const createRepBlob = async (formContent, containerName, caseref) => { const tags = { containerid: containerName, - caseID: caseID, + caseID: formContent.caseRef, blobType: "Representation", }; @@ -378,13 +373,18 @@ export const uploadFile = async (formContent, containerName, foldername) => { files[prop][0].path, files[prop].size ); + + console.log( + "////////////////////////\nfile name:", + files[prop][0].fieldName, + "\n////////////////////////////" + ); + const tags = { containerid: containerName, - caseID: foldername, - documentType: files[prop][0].fieldName.slice( - 0, - files[prop][0].fieldName.indexOf("_") - ), + caseID: foldername.split("/")[0], + documentType: files[prop][0].fieldName.split(".")[1], + blobType: "RepresentationFile", }; const withTags = await blockBlobClient.setTags(tags); const withMeta = await blockBlobClient.setMetadata(tags); @@ -410,21 +410,17 @@ export const uploadRepFiles = async ( 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 blobName = foldername + "/" + formContent.split("tmp/")[1]; const blockBlobClient = containerClient.getBlockBlobClient(blobName); const uploadBlobResponse = await blockBlobClient.uploadFile(formContent); const tags = { containerid: containerName, - caseID: foldername, - documentType: "rep content", + caseID: formContent.split("tmp/")[0], + documentType: "Rep docs", }; console.log(tags); - // const withTags = await blockBlobClient.setTags(tags); - // const withMeta = await blockBlobClient.setMetadata(tags); + const withTags = await blockBlobClient.setTags(tags); + const withMeta = await blockBlobClient.setMetadata(tags); console.log( `Uploaded block blob ${files} successfully`, @@ -432,11 +428,10 @@ export const uploadRepFiles = async ( ); }; -export const uploadPDFRepFiles = async ( +export const uploadPDFCaseFiles = async ( formContent, containerName, - foldername, - repType + foldername ) => { const containerToken = await createContainerSas(containerName); const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; @@ -446,28 +441,20 @@ export const uploadPDFRepFiles = async ( console.log(formContent, containerName, foldername); console.log( - "rep pdf files...", + "case 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 blobName = foldername + "/" + formContent.split("tmp/")[1]; const blockBlobClient = containerClient.getBlockBlobClient(blobName); const uploadBlobResponse = await blockBlobClient.uploadFile(formContent); const tags = { containerid: containerName, - caseID: foldername, - documentType: repType, - blobType: "RepresentationPDF", + caseID: foldername.split("/")[0], + blobType: "AppealPDF", }; console.log("the tags:", tags); @@ -481,7 +468,7 @@ export const uploadPDFRepFiles = async ( }; export const downloadFile = async (containerName, blobName) => { - //console.log.apply(containerName, blobName); + //console.log(containerName, blobName); const containerToken = await createContainerSas(containerName); const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; const containerClient = new ContainerClient(sasUrl); @@ -497,7 +484,7 @@ export const downloadProgressFile = async ( blobName, casefolderID ) => { - //console.log.apply(containerName, blobName); + console.log(containerName, blobName); const containerToken = await createContainerSas(containerName); const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; @@ -624,7 +611,7 @@ export const downloadAllRepsFiles = async (containerName, repsBlobObj) => { repBlobObj = JSON.parse(repBlobObj); - repBlobObj["casereference"] = repsBlobObj[prop].name.split("/")[0]; + repBlobObj["casereference"] = repsBlobObj[prop].name.split("/")[1]; // repBlobObj = JSON.stringify(repBlobObj); @@ -682,6 +669,17 @@ export const getCaseBlob = async ( content, Buffer.byteLength(content) ); + + const tags = { + containerid: containerName, + caseID: caseReference, + blobType: "Case", + }; + + console.log("the tags:", tags); + const withTags = await blockBlobClient.setTags(tags); + const withMeta = await blockBlobClient.setMetadata(tags); + return blobName; }; @@ -699,22 +697,22 @@ export const getProgressBlobs = async (containerName, caseReference) => { 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.listBlobsFlat({ prefix: caseReference + "/" + caseReference + "_appeal.json", })) { - //console.log("getProgressBlobs in here"); + console.log("getProgressBlobs in here", blob.name.split("/")); blobObj.push({ "name": blob.name.split("/")[1], "path": blob.name, "versionId": blob.versionId, - "caseObj": caseReference + "/" + caseReference + "_case.json", + "caseObj": caseReference + "/case/" + caseReference + "_case.json", "isCurrentVersion": blob.isCurrentVersion, "contentLength": blob.properties.contentLength, "contentType": blob.contentType, @@ -771,16 +769,16 @@ export const getAllProgressBlobs = async (containerName) => { blobObj.push({ "name": blob.name.split("/")[1], "path": blob.name, - "versionId": blob.versionId, + //"versionId": blob.versionId, "caseObj": blob.name.split("/")[0] + "/case/" + blob.name.split("/")[0] + "_case.json", - "isCurrentVersion": blob.isCurrentVersion, - "contentLength": blob.properties.contentLength, - "contentType": blob.contentType, - "lastModified": blob.properties.lastModified, + // "isCurrentVersion": blob.isCurrentVersion, + // "contentLength": blob.properties.contentLength, + // "contentType": blob.contentType, + // "lastModified": blob.properties.lastModified, }); } @@ -810,16 +808,26 @@ export const getRepsBlobs = async (containerName) => { blobCount ); + const listOptions = { + includeMetadata: true, + includeSnapshots: false, + includeTags: true, + includeVersions: true, + }; + let blobObj = []; for await (const blob of containerClient.findBlobsByTags( - "blobType='Representation'" + "blobType='Representation'", + listOptions )) { + const blobClient = await containerClient.getBlobClient(blob.name); console.log(blob); - blob.name.split("/")[1].indexOf("_rep.json") > 0 && - blob.name.split("/")[1].indexOf("undefined") < 0 && + blob.name.split("/")[2].indexOf("_rep.json") > 0 && + blob.name.split("/")[2].indexOf("undefined") < 0 && blobObj.push({ - "name": blob.name.split("/")[1], + "name": blob.name.split("/")[2], "path": blob.name, + "size": blobClient.getProperties().contentLength, }); } diff --git a/actions/index.js b/actions/index.js index 0fb2eda5..b363b70c 100644 --- a/actions/index.js +++ b/actions/index.js @@ -1497,6 +1497,20 @@ export const downloadBlob = (containerName, blobName) => { }; export const getProgressFromBlob = async (containerName, casereference) => { + console.log( + /////////////////\ngetProgressFromBlob", + BASE_URL + + "/api/file/getprogressobjblob?container=" + + containerName + + "&casefolderID=" + + casereference + + hashAPIPath( + "/api/file/getprogressobjblob?container=" + + containerName + + "&casefolderID=" + + casereference + ) + ); try { const res = await axios.get( BASE_URL + diff --git a/components/case/representation/index copy.js b/components/case/representation/index copy.js deleted file mode 100644 index 5eaff2cd..00000000 --- a/components/case/representation/index copy.js +++ /dev/null @@ -1,212 +0,0 @@ -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 _ from "lodash"; -import { Field, FieldArray, reduxForm, formValueSelector } from "redux-form"; -import { connect } from "react-redux"; -import { useDropzone } from "react-dropzone"; - -import { setRepresentationCapacity } from "../../../store/currentView/action"; -import RepCapacitySelection from "./representationCapacitySelection"; -import RepDetails from "./representationDetails"; -import RepAppellant from "./representationAppellant"; -import RepAgent from "./representationAgent"; -import RepInterestedPartyPerson from "./representationInterestedPartyPerson"; -import RepLandOwner from "./representationLandowner"; -import { - RenderPickList, - RenderRadioList, - RenderTextfield, -} from "./representationElements"; - -let MakeRepresentation = (props) => { - let { t } = useTranslation(); - const { acceptedFiles, getRootProps, getInputProps } = useDropzone(); - - const [clearRepForm, setClearRepForm] = useState(false); - - const router = useRouter(); - const { locale } = router; - const { - caseReference, - myCases, - myRepresentations, - watchedCases, - awaitingSubmission, - searchResultsObj, - currentType, - currentView, - setRepresentationCapacity, - } = props; - const formObj = props.props.form; - let setCaseQueryObj = props[currentType]; - var casesObj = {}; - - currentType == "searchResultsObj" - ? (casesObj = jsonpath.query( - setCaseQueryObj, - '$..[?(@.title=="' + caseReference + '")]' - )) - : (casesObj = jsonpath.query( - setCaseQueryObj, - '$..[?(@.reference=="' + caseReference + '")]' - )); - - casesObj = Object.assign({}, ...casesObj); - - const capacityOptionsArr = [ - "Appellant", - "Agent", - "Interested Party/Person", - "Land Owner", - ]; - - const appellantApplicantRepresentationArr = [ - "Other", - "Statement", - "Statement of common ground", - "Written statement of evidence", - ]; - - const interestedPersonRepresentationArr = [ - "Interested Party/Person correspondence", - ]; - - const landOwnerRepresentationArr = [ - "Other", - "Statement", - "Written statement of evidence", - ]; - - const repCapacityType = () => { - currentView.representationCapacity == false - ? false - : _.isEmpty(formObj["representationForm"]) - ? false - : _.isEmpty(formObj["representationForm"].values) - ? false - : _.isEmpty( - formObj["representationForm"].values.representationCapacity - ) - ? setRepresentationCapacity(false) - : setRepresentationCapacity( - formObj["representationForm"].values.representationCapacity - .replace(/(\band|[\s\-\+\(\)\,\&])/g, "") - .toLowerCase() - ); - - return currentView.representationCapacity; - }; - - const whichControl = () => { - repCapacityType(); - switch (currentView.representationCapacity) { - case false: - return ( - - ); - break; - case "appellant": - setRepresentationCapacity("appellant"); - return ( - - ); - break; - case "agent": - setRepresentationCapacity("agent"); - return ( - - ); - break; - case "interestedpartyperson": - setRepresentationCapacity("interestedpartyperson"); - return ( - - ); - break; - case "landowner": - setRepresentationCapacity("landowner"); - return ( - - ); - break; - default: - return ( - - ); - } - }; - - return ( -
- {whichControl()} - {props.firstValue} -
- ); -}; - -const mapStateToProps = (state) => { - return { - search: state.search, - searchResultsObj: state.searchResultsObj, - formData: state.formData, - appealType: state.appealType, - currentView: state.currentView, - //form: state.form, - }; -}; - -const mapDispatchToProps = (dispatch) => { - return { - setRepresentationCapacity: (representationCapacity) => { - dispatch(setRepresentationCapacity(representationCapacity)); - }, - }; -}; - -const selector = formValueSelector("representationForm"); - -export default connect( - mapStateToProps, - mapDispatchToProps -)( - reduxForm({ - form: "representationForm", - destroyOnUnmount: false, - })(MakeRepresentation) -); diff --git a/components/case/representation/index.js b/components/case/representation/index.js index a03a961a..ab9debcb 100644 --- a/components/case/representation/index.js +++ b/components/case/representation/index.js @@ -81,6 +81,7 @@ let MakeRepresentation = (props) => { handleSubmit, setRepresentationSubmitConfirmation, setRepresentationMessageSent, + initialValues, } = props; const formObj = props.props.form; let setCaseQueryObj = props[currentType] || {}; @@ -156,6 +157,7 @@ let MakeRepresentation = (props) => { currentView.representationCapacity, _.isEmpty(currentView.representationCapacity) ); + if (isLPA && _.isEmpty(currentView.representationCapacity)) { return ( { /> ); break; - case "interestedparty/person": + case "interestedparty": // setRepresentationCapacity("interestedpartyperson"); return ( { case "Land Owner": repType = "LO"; break; - case "LPA": + case "lpa": repType = "LPA"; break; @@ -344,19 +346,22 @@ let MakeRepresentation = (props) => { } Object.assign(updateBody, { + "repfile_name": updateBody.hasOwnProperty("repfile_name") + ? updateBody.repfile_name + : year + + "-" + + month + + "-" + + day + + "-" + + time + + "-" + + repType + + "-REP" + + "_" + + props.props.accountDetails.accountDetails.lastname, "pinswg_name": - year + - "-" + - month + - "-" + - day + - "-" + - time + - "-" + - repType + - "-REP" + - "_" + - props.props.accountDetails.accountDetails.lastname, + props.props.currentView.caseReference.currentReference, "containerID": props.props.accountDetails.containerID, "appealType": props.props.currentView.caseReference.appealType, "incidentID": props.props.currentView.caseReference.incidentid, @@ -408,7 +413,15 @@ let MakeRepresentation = (props) => { console.log("attached docs: - ", buildFileArray); - let setCaseDetailsObj = props.props.searchResultsObj.searchDetailsObj; + let setCaseDetailsObj = router.query.hasOwnProperty("state") + ? router.query.state == "edit" + ? props.props.myRepresentations.myRepresentations + : props.props.searchResultsObj.searchDetailsObj + : props.props.searchResultsObj.searchDetailsObj; + + router.query.hasOwnProperty("state") && + router.query.state == "edit" && + setRepresentationSubmit(true); var detailsObj = {}; @@ -438,6 +451,20 @@ let MakeRepresentation = (props) => { detailsObj.pinswg_siteaddresstown + " " + detailsObj.pinswg_siteaddresspostcode, + "pinswg_siteaddressline1": detailsObj.pinswg_siteaddressline1, + "pinswg_siteaddressline2": detailsObj.pinswg_siteaddressline2, + "pinswg_siteaddresstown": detailsObj.pinswg_siteaddresstown, + "pinswg_siteaddresspostcode": detailsObj.pinswg_siteaddresspostcode, + "_pinswg_appellant_value": detailsObj["_pinswg_appellant_value"], + "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue": + detailsObj[ + "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" + ], + "representationCapacity": router.query.hasOwnProperty("state") + ? router.query.state == "edit" + ? props.props.currentView.representationCapacity + : values.representationCapacity + : values.representationCapacity, }); console.log(values); currentView.representationSubmit != true @@ -455,10 +482,14 @@ let MakeRepresentation = (props) => { console.log("has errors:", props.invalid), props.invalid == false && updateRepresentation(values, false, false), - values.representationDocuments.map((Blob) => - buildFileArray.push({ "name": Blob.name, "size": Blob.size }) - ), - Object.assign(values, { "filesList": buildFileArray }), + values.hasOwnProperty("representationDocuments") && + (values.representationDocuments.map((Blob) => + buildFileArray.push({ + "name": Blob.name, + "size": Blob.size, + }) + ), + Object.assign(values, { "filesList": buildFileArray })), generateRepPDF( values, props.props.accountDetails.containerID, @@ -495,7 +526,7 @@ let MakeRepresentation = (props) => { dataObj, fileListObj, values.containerID, - props.caseReference + props.caseReference + "/" + dataObj.repfile_name ).then((data) => { //console.log("hello", data); @@ -507,9 +538,21 @@ let MakeRepresentation = (props) => { console.log( "what is representationSubmit state: " + - currentView.representationSubmit + currentView.representationSubmit, + props.initialValues ); + try { + let value = props.initialValues; + console.log("has props"), value; + setRepresentationCapacity( + props.initialValues.representationCapacity.toLowerCase() + ); + //setRepresentationSubmit(false); + } catch { + console.log("not has props"); + } + return (
@@ -567,12 +610,16 @@ let MakeRepresentation = (props) => { }; const mapStateToProps = (state) => { + console.log("\\\\\\\\\\\\\\\\\\\\\\\\\\\\/nin map state", state); + return { search: state.search, searchResultsObj: state.searchResultsObj, formData: state.formData, appealType: state.appealType, currentView: state.currentView, + myRepresentations: state.myRepresentations, + initialValues: state.currentView.caseReference.repDetails, //form: state.form, }; }; @@ -610,5 +657,6 @@ export default connect( reduxForm({ form: "representationForm", destroyOnUnmount: false, + enableReinitialize: true, })(MakeRepresentation) ); diff --git a/components/case/representation/representationAgent.js b/components/case/representation/representationAgent.js index 20c1e9e1..13640e0b 100644 --- a/components/case/representation/representationAgent.js +++ b/components/case/representation/representationAgent.js @@ -1,4 +1,5 @@ import Link from "next/link"; +import { connect } from "react-redux"; import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; import { Field, reduxForm } from "redux-form"; @@ -12,9 +13,11 @@ import { FileUploadField, } from "./representationElements"; import { - setRepresentationCapacity, - setRepresentationSubmit, -} from "../../../store/currentView/action"; + getFormCollectionByID, + getThumbnailIconByExtension, + bytesToSize, +} from "../../utils"; + import { useDropzone } from "react-dropzone"; const RepAgent = (props) => { @@ -117,7 +120,6 @@ const RepAgent = (props) => { aria-describedby={props.name + "-hint"} />
-
{ } />
+ {props.currentView.caseReference.hasOwnProperty( + "repDetails" + ) && + props.currentView.caseReference.repDetails.filesList + .length > 0 ? ( +
+ {props.currentView.caseReference.repDetails.filesList.map( + (blob, i) => ( +
+ {blob.name} + + + {blob.name} ( + {bytesToSize(blob.size)}) + +
+ ) + )} +
+ ) : ( + "" + )} {" "} @@ -146,13 +179,12 @@ const RepAgent = (props) => { {/* { - setRepresentationSubmit(false); + setRepresentationSubmit(true); }} className="govuk-button" > - Continue + Continue ww */} - { setRepresentationCapacity(); diff --git a/components/case/representation/representationAppellant.js b/components/case/representation/representationAppellant.js index 9714dff9..7782996b 100644 --- a/components/case/representation/representationAppellant.js +++ b/components/case/representation/representationAppellant.js @@ -14,6 +14,12 @@ import { RenderFileUpload, FileUploadField, } from "./representationElements"; +import { + getFormCollectionByID, + getThumbnailIconByExtension, + bytesToSize, +} from "../../utils"; + import { useDropzone } from "react-dropzone"; // import { // setRepresentationCapacity, @@ -97,7 +103,6 @@ const RepAppellant = (props) => { aria-describedby={props.name + "-hint"} /> -
{ } />
+ {props.currentView.caseReference.hasOwnProperty( + "repDetails" + ) && + props.currentView.caseReference.repDetails.filesList + .length > 0 ? ( +
+ {props.currentView.caseReference.repDetails.filesList.map( + (blob, i) => ( +
+ {blob.name} + + + {blob.name} ( + {bytesToSize(blob.size)}) + +
+ ) + )} +
+ ) : ( + "" + )} {" "} diff --git a/components/case/representation/representationCapacitySelection.js b/components/case/representation/representationCapacitySelection.js index 3ea08db6..44dc9667 100644 --- a/components/case/representation/representationCapacitySelection.js +++ b/components/case/representation/representationCapacitySelection.js @@ -49,6 +49,8 @@ let RepCapacitySelection = (props) => { casesObj={casesObj} caseReference={props.props.caseReference} searchResultsObj={props.props.searchResultsObj} + myRepresentations={props.props.myRepresentations} + props={props} />{" "}
diff --git a/components/case/representation/representationCompleteSubmit.js b/components/case/representation/representationCompleteSubmit.js index 537ddc7b..60fd6c5c 100644 --- a/components/case/representation/representationCompleteSubmit.js +++ b/components/case/representation/representationCompleteSubmit.js @@ -4,6 +4,11 @@ import { useRouter } from "next/router"; import { useDropzone } from "react-dropzone"; import RepComplete from "./representationComplete"; import RepLPAQuestionnaireCheck from "./representationLPAQuestionnaireCheck"; +import { + getFormCollectionByID, + getThumbnailIconByExtension, + bytesToSize, +} from "../../utils"; const RepCompleteSubmit = (props) => { let { t } = useTranslation(); @@ -30,54 +35,6 @@ const RepCompleteSubmit = (props) => { const repFormData = formObj.representationForm.values; - const getThumbnailIconByExtension = (blobName) => { - let fileType = blobName.slice(blobName.lastIndexOf(".") + 1); - - switch (fileType) { - case "html": - return "/assets/images/documenttypes/html.png"; - break; - case "txt": - return "/assets/images/documenttypes/txt.png"; - break; - case "doc": - return "/assets/images/documenttypes/doc.png"; - break; - case "pdf": - return "/assets/images/documenttypes/pdf.png"; - break; - case "docx": - return "/assets/images/documenttypes/docx.png"; - break; - case "csv": - return "/assets/images/documenttypes/csv.png"; - break; - case "xlsx": - return "/assets/images/documenttypes/xlsx.png"; - break; - - case "zip": - return "/assets/images/documenttypes/zip.png"; - break; - case "jpeg": - case "jpg": - return "/assets/images/documenttypes/jpg.png"; - case "png": - return "/assets/images/documenttypes/png.png"; - break; - default: - return "/assets/images/documenttypes/txt.png"; - break; - } - }; - - function bytesToSize(bytes) { - var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; - if (bytes == 0) return "0 Byte"; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; - } - console.log("///////// formObj:", formObj); return ( @@ -240,7 +197,10 @@ const RepCompleteSubmit = (props) => {
- {formObj.representationForm.values + {formObj.representationForm.values.hasOwnProperty( + "representationDocuments" + ) && + formObj.representationForm.values .representationDocuments.length > 0 ? formObj.representationForm.values.representationDocuments.map( (blob, i) => ( diff --git a/components/case/representation/representationDetails.js b/components/case/representation/representationDetails.js index 1c1282b1..67169b96 100644 --- a/components/case/representation/representationDetails.js +++ b/components/case/representation/representationDetails.js @@ -11,12 +11,24 @@ const RepDetails = (props) => { const router = useRouter(); const { locale } = router; - const { currentType, casesObj, caseReference } = props; + const { currentType, casesObj } = props; - let setCaseDetailsObj = props.searchResultsObj.searchDetailsObj; + let { caseReference } = props; + + let setCaseDetailsObj = router.query.hasOwnProperty("state") + ? router.query.state == "edit" + ? props.myRepresentations.myRepresentations + : props.searchResultsObj.searchDetailsObj + : props.searchResultsObj.searchDetailsObj; var detailsObj = {}; + caseReference = router.query.hasOwnProperty("state") + ? router.query.state == "edit" + ? router.query.case + : caseReference + : caseReference; + detailsObj = jsonpath.query( setCaseDetailsObj, '$..[?(@.pinswg_name=="' + caseReference + '")]' @@ -38,9 +50,14 @@ const RepDetails = (props) => {
{casesObj.appellantApplicant || ""} - {detailsObj.firstName + + { + detailsObj[ + "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" + ] + } + {/* {detailsObj.firstName + " " + - detailsObj.lastName || "not entered"} + detailsObj.lastName || "not entered"} */}
{/*
diff --git a/components/case/representation/representationElements.js b/components/case/representation/representationElements.js index 9aa404da..007c25dc 100644 --- a/components/case/representation/representationElements.js +++ b/components/case/representation/representationElements.js @@ -21,6 +21,12 @@ import { parseISO, } from "date-fns"; +import { + getFormCollectionByID, + getThumbnailIconByExtension, + bytesToSize, +} from "../../utils"; + import { useRouter } from "next/router"; export const RenderRadioList = ({ @@ -740,13 +746,6 @@ export const RenderFileUpload = (field) => {
)); - function bytesToSize(bytes) { - var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; - if (bytes == 0) return "0 Byte"; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; - } - const getThumbnailIcon = (fileObj, fileType) => { switch (fileType) { case "text/html": @@ -784,47 +783,6 @@ export const RenderFileUpload = (field) => { } }; - const getThumbnailIconByExtension = (blobName) => { - let fileType = blobName.slice(blobName.lastIndexOf(".") + 1); - - switch (fileType) { - case "html": - return "/assets/images/documenttypes/html.png"; - break; - case "txt": - return "/assets/images/documenttypes/txt.png"; - break; - case "doc": - return "/assets/images/documenttypes/doc.png"; - break; - case "pdf": - return "/assets/images/documenttypes/pdf.png"; - break; - case "docx": - return "/assets/images/documenttypes/docx.png"; - break; - case "csv": - return "/assets/images/documenttypes/csv.png"; - break; - case "xlsx": - return "/assets/images/documenttypes/xlsx.png"; - break; - - case "zip": - return "/assets/images/documenttypes/zip.png"; - break; - case "jpeg": - case "jpg": - return "/assets/images/documenttypes/jpg.png"; - case "png": - return "/assets/images/documenttypes/png.png"; - break; - default: - return "/assets/images/documenttypes/txt.png"; - break; - } - }; - const getDocumentType = (docCode) => { switch (docCode) { case "000001": diff --git a/components/case/representation/representationLPA.js b/components/case/representation/representationLPA.js index 2498a62c..92e1fad9 100644 --- a/components/case/representation/representationLPA.js +++ b/components/case/representation/representationLPA.js @@ -81,13 +81,8 @@ let RepLPA = (props) => {
*/} - {props.representationTypeValue} - {props.procedureTypeValue} -
- {console.log(props)} - typeof props.representationTypeValue == "undefined" {props.representationTypeValue != "Questionnaire" ? ( <>

@@ -924,24 +919,25 @@ let RepLPA = (props) => { const selector = formValueSelector("representationForm"); // <-- same as form name RepLPA = connect((state) => { - const representationTypeValue = selector(state, "representationType"); - const procedureTypeValue = selector(state, "procedureType"); + const representationType = selector(state, "representationType"); + const procedureType = selector(state, "procedureType"); return { - procedureTypeValue, - representationTypeValue, + procedureType, + representationType, }; })(RepLPA); const mapStateToProps = (state, props) => { console.log(); return { - initialValues: { - onBehalfOfLPA: - props.props.props.accountDetails.accountDetails[ - "pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue" - ], - }, + search: state.search, + searchResultsObj: state.searchResultsObj, + formData: state.formData, + appealType: state.appealType, + currentView: state.currentView, + myRepresentations: state.myRepresentations, + initialValues: state.currentView.caseReference.repDetails, }; }; diff --git a/components/case/representation/representationLPACapacitySelection.js b/components/case/representation/representationLPACapacitySelection.js index d1ef7b9d..a3e88cf4 100644 --- a/components/case/representation/representationLPACapacitySelection.js +++ b/components/case/representation/representationLPACapacitySelection.js @@ -50,6 +50,7 @@ let RepLPACapacitySelection = (props) => { casesObj={casesObj} caseReference={props.props.caseReference} searchResultsObj={props.props.searchResultsObj} + props={props.props} />{" "}

diff --git a/components/case/representation/representationLPAComments.js b/components/case/representation/representationLPAComments.js index 861dea57..720dad07 100644 --- a/components/case/representation/representationLPAComments.js +++ b/components/case/representation/representationLPAComments.js @@ -60,12 +60,13 @@ RepLPAQuestionnaire = connect((state) => { const mapStateToProps = (state, props) => { console.log(); return { - initialValues: { - onBehalfOfLPA: - props.props.props.props.accountDetails.accountDetails[ - "pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue" - ], - }, + search: state.search, + searchResultsObj: state.searchResultsObj, + formData: state.formData, + appealType: state.appealType, + currentView: state.currentView, + myRepresentations: state.myRepresentations, + initialValues: state.currentView.caseReference.repDetails, }; }; diff --git a/components/case/representation/representationLPADetails.js b/components/case/representation/representationLPADetails.js index a01dfb20..07afc82f 100644 --- a/components/case/representation/representationLPADetails.js +++ b/components/case/representation/representationLPADetails.js @@ -13,7 +13,11 @@ const RepLPADetails = (props) => { const { currentType, casesObj, caseReference } = props; - let setCaseDetailsObj = props.searchResultsObj.searchDetailsObj; + let setCaseDetailsObj = router.query.hasOwnProperty("state") + ? router.query.state == "edit" + ? props.props.myRepresentations.myRepresentations + : props.props.searchResultsObj.searchDetailsObj + : props.props.searchResultsObj.searchDetailsObj; var detailsObj = {}; diff --git a/components/case/representation/representationLPAQuestionnaire.js b/components/case/representation/representationLPAQuestionnaire.js index 0c02762e..959e896a 100644 --- a/components/case/representation/representationLPAQuestionnaire.js +++ b/components/case/representation/representationLPAQuestionnaire.js @@ -777,12 +777,13 @@ RepLPAQuestionnaire = connect((state) => { const mapStateToProps = (state, props) => { console.log(); return { - initialValues: { - onBehalfOfLPA: - props.props.props.props.accountDetails.accountDetails[ - "pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue" - ], - }, + search: state.search, + searchResultsObj: state.searchResultsObj, + formData: state.formData, + appealType: state.appealType, + currentView: state.currentView, + myRepresentations: state.myRepresentations, + initialValues: state.currentView.caseReference.repDetails, }; }; diff --git a/components/elements/index.js b/components/elements/index.js index 379dc12a..bf6412fe 100644 --- a/components/elements/index.js +++ b/components/elements/index.js @@ -20,6 +20,12 @@ import { import { setFilesForAppeal } from "../../store/appealType/action"; import Link from "next/link"; +import { + getFormCollectionByID, + getThumbnailIconByExtension, + bytesToSize, +} from "../utils"; + import { addYears, addMonths, @@ -1309,13 +1315,6 @@ const RenderFileUpload = (field) => {
)); - function bytesToSize(bytes) { - var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; - if (bytes == 0) return "0 Byte"; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; - } - const getThumbnailIcon = (fileObj, fileType) => { switch (fileType) { case "text/html": @@ -1353,47 +1352,6 @@ const RenderFileUpload = (field) => { } }; - const getThumbnailIconByExtension = (blobName) => { - let fileType = blobName.slice(blobName.lastIndexOf(".") + 1); - - switch (fileType) { - case "html": - return "/assets/images/documenttypes/html.png"; - break; - case "txt": - return "/assets/images/documenttypes/txt.png"; - break; - case "doc": - return "/assets/images/documenttypes/doc.png"; - break; - case "pdf": - return "/assets/images/documenttypes/pdf.png"; - break; - case "docx": - return "/assets/images/documenttypes/docx.png"; - break; - case "csv": - return "/assets/images/documenttypes/csv.png"; - break; - case "xlsx": - return "/assets/images/documenttypes/xlsx.png"; - break; - - case "zip": - return "/assets/images/documenttypes/zip.png"; - break; - case "jpeg": - case "jpg": - return "/assets/images/documenttypes/jpg.png"; - case "png": - return "/assets/images/documenttypes/png.png"; - break; - default: - return "/assets/images/documenttypes/txt.png"; - break; - } - }; - const getDocumentType = (docCode) => { switch (docCode) { case "000001": diff --git a/components/myportal.js b/components/myportal.js index f631e2bd..128492dc 100644 --- a/components/myportal.js +++ b/components/myportal.js @@ -155,17 +155,13 @@ const MyPortal = (props) => { watchedCases={props.watchedCases} /> )} - {isLPA - ? "" - : props.myRepresentations.myRepresentations[ - "@odata.count" - ] > 0 && ( - - )} + {props.myRepresentations.myRepresentations[ + "@odata.count" + ] > 0 && ( + + )} {isLPA ? "" : } {/* */} diff --git a/components/myportal/topthree_reps.js b/components/myportal/topthree_reps.js index 3154c692..ab70d0aa 100644 --- a/components/myportal/topthree_reps.js +++ b/components/myportal/topthree_reps.js @@ -130,6 +130,11 @@ const TopThree = (props) => { } }; + const repRaisedDate = (datePart) => { + var dateObj = new Date(parseInt(datePart.split("-")[3])); + return dateObj.toLocaleString(); + }; + let topThreeOnlyArr = showTopThreeArr; //.slice(0, 3); Object.keys(topThreeOnlyArr).map((key, index) => { topthreeRow.push( @@ -138,13 +143,14 @@ const TopThree = (props) => {
+
+ Capacity: + {" "} + {showTopThreeArr[key].representationCapacity} +
+
+ Date raised: + {" "} + {repRaisedDate(showTopThreeArr[key].repfile_name)} +
); diff --git a/components/myportal/uploadFile.js b/components/myportal/uploadFile.js index 8a5b96a8..1e06e535 100644 --- a/components/myportal/uploadFile.js +++ b/components/myportal/uploadFile.js @@ -9,6 +9,11 @@ import { connect } from "react-redux"; import Dropzone, { useDropzone } from "react-dropzone"; import { uploadFiles } from "../../actions"; import { getContainers } from "../../actions/azurestorage"; +import { + getFormCollectionByID, + getThumbnailIconByExtension, + bytesToSize, +} from "../utils"; const required = (errorMsg) => (value) => value || typeof value === "number" ? undefined : errorMsg; @@ -119,13 +124,6 @@ const RenderFileUpload = (field) => {
)); - function bytesToSize(bytes) { - var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; - if (bytes == 0) return "0 Byte"; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; - } - const getThumbnailIcon = (fileObj, fileType) => { switch (fileType) { case "text/html": diff --git a/components/newappeal/buildchecksection.js b/components/newappeal/buildchecksection.js index 56b690d9..644b8c26 100644 --- a/components/newappeal/buildchecksection.js +++ b/components/newappeal/buildchecksection.js @@ -11,6 +11,12 @@ import { setFormComplete, } from "../../store/appealType/action"; +import { + getFormCollectionByID, + getThumbnailIconByExtension, + bytesToSize, +} from "../utils"; + let BuildCheckSection = (props) => { useEffect(() => { setFormComplete(); @@ -64,54 +70,6 @@ let BuildCheckSection = (props) => { alert(1); }; - function bytesToSize(bytes) { - var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; - if (bytes == 0) return "0 Byte"; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; - } - - const getThumbnailIconByExtension = (blobName) => { - let fileType = blobName.slice(blobName.lastIndexOf(".") + 1); - - switch (fileType) { - case "html": - return "/assets/images/documenttypes/html.png"; - break; - case "txt": - return "/assets/images/documenttypes/txt.png"; - break; - case "doc": - return "/assets/images/documenttypes/doc.png"; - break; - case "pdf": - return "/assets/images/documenttypes/pdf.png"; - break; - case "docx": - return "/assets/images/documenttypes/docx.png"; - break; - case "csv": - return "/assets/images/documenttypes/csv.png"; - break; - case "xlsx": - return "/assets/images/documenttypes/xlsx.png"; - break; - - case "zip": - return "/assets/images/documenttypes/zip.png"; - break; - case "jpeg": - case "jpg": - return "/assets/images/documenttypes/jpg.png"; - case "png": - return "/assets/images/documenttypes/png.png"; - break; - default: - return "/assets/images/documenttypes/txt.png"; - break; - } - }; - return (
diff --git a/components/pdftemplates/finalComments_pdf.js b/components/pdftemplates/finalComments_pdf.js index be904405..aa3b9178 100644 --- a/components/pdftemplates/finalComments_pdf.js +++ b/components/pdftemplates/finalComments_pdf.js @@ -271,24 +271,25 @@ export const finalComments_pdf = ({ docProps }) => { { flexDirection: "column" }, ]} > - {values.filesList.map(function (p) { - return ( - - - {p.name} - {p.size} - - - ); - })} + + {p.name} - {p.size} + + + ); + })} diff --git a/components/pdftemplates/lpaQuestionnaire_pdf.js b/components/pdftemplates/lpaQuestionnaire_pdf.js index 23c56858..fd50ad3b 100644 --- a/components/pdftemplates/lpaQuestionnaire_pdf.js +++ b/components/pdftemplates/lpaQuestionnaire_pdf.js @@ -1328,24 +1328,26 @@ export const lpaQuestionnaire_pdf = ({ docProps }) => { { flexDirection: "column" }, ]} > - {values.filesList.map(function (p) { - return ( - - - {p.name} - {p.size} - - - ); - })} + + {p.name} - {p.size} + + + ); + })} diff --git a/components/pdftemplates/other_pdf.js b/components/pdftemplates/other_pdf.js index 9918e9bb..93fd7793 100644 --- a/components/pdftemplates/other_pdf.js +++ b/components/pdftemplates/other_pdf.js @@ -271,24 +271,25 @@ export const other_pdf = ({ docProps }) => { { flexDirection: "column" }, ]} > - {values.filesList.map(function (p) { - return ( - - - {p.name} - {p.size} - - - ); - })} + + {p.name} - {p.size} + + + ); + })} diff --git a/components/pdftemplates/statement_pdf.js b/components/pdftemplates/statement_pdf.js index 10960f36..035c12c7 100644 --- a/components/pdftemplates/statement_pdf.js +++ b/components/pdftemplates/statement_pdf.js @@ -271,24 +271,25 @@ export const statement_pdf = ({ docProps }) => { { flexDirection: "column" }, ]} > - {values.filesList.map(function (p) { - return ( - - - {p.name} - {p.size} - - - ); - })} + + {p.name} - {p.size} + + + ); + })} diff --git a/components/pdftemplates/writtenStatement_pdf.js b/components/pdftemplates/writtenStatement_pdf.js index cde4798f..cb732d7c 100644 --- a/components/pdftemplates/writtenStatement_pdf.js +++ b/components/pdftemplates/writtenStatement_pdf.js @@ -271,24 +271,25 @@ export const writtenStatement_pdf = ({ docProps }) => { { flexDirection: "column" }, ]} > - {values.filesList.map(function (p) { - return ( - - - {p.name} - {p.size} - - - ); - })} + + {p.name} - {p.size} + + + ); + })} diff --git a/components/utils/index.js b/components/utils/index.js index bafc989e..4246c828 100644 --- a/components/utils/index.js +++ b/components/utils/index.js @@ -369,3 +369,51 @@ export const getTempCaseRef = () => { randomString(6).toUpperCase() ); }; + +export const getThumbnailIconByExtension = (blobName) => { + let fileType = blobName.slice(blobName.lastIndexOf(".") + 1); + + switch (fileType) { + case "html": + return "/assets/images/documenttypes/html.png"; + break; + case "txt": + return "/assets/images/documenttypes/txt.png"; + break; + case "doc": + return "/assets/images/documenttypes/doc.png"; + break; + case "pdf": + return "/assets/images/documenttypes/pdf.png"; + break; + case "docx": + return "/assets/images/documenttypes/docx.png"; + break; + case "csv": + return "/assets/images/documenttypes/csv.png"; + break; + case "xlsx": + return "/assets/images/documenttypes/xlsx.png"; + break; + + case "zip": + return "/assets/images/documenttypes/zip.png"; + break; + case "jpeg": + case "jpg": + return "/assets/images/documenttypes/jpg.png"; + case "png": + return "/assets/images/documenttypes/png.png"; + break; + default: + return "/assets/images/documenttypes/txt.png"; + break; + } +}; + +export const bytesToSize = (bytes) => { + var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; + if (bytes == 0) return "0 Byte"; + var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; +}; diff --git a/pages/api/email/notify.js b/pages/api/email/notify.js index a800e5ac..63c635af 100644 --- a/pages/api/email/notify.js +++ b/pages/api/email/notify.js @@ -44,7 +44,7 @@ export default async function ApiProxy(req, res) { // emailReplyToId: emailReplyToId, }) .then((response) => { - console.log("thisis the response", response); + //console.log("thisis the response", response); return res.status(200).json(data); }) .catch((err) => { diff --git a/pages/api/file/generatepdf.js b/pages/api/file/generatepdf.js index 344c1e41..03e826dd 100644 --- a/pages/api/file/generatepdf.js +++ b/pages/api/file/generatepdf.js @@ -170,7 +170,7 @@ export default function handler(req, res) { case "Land Owner": repCapacity = "LO"; break; - case "LPA": + case "lpa": repCapacity = "LPA"; break; @@ -207,20 +207,20 @@ export default function handler(req, res) { // code block } - const repDate = new Date(); + // const repDate = new Date(); - let day = ("0" + repDate.getDate()).slice(-2); - let month = ("0" + (repDate.getMonth() + 1)).slice(-2); - let year = repDate.getFullYear(); - let time = - ("0" + repDate.getHours()).slice(-2) + - "" + - ("0" + repDate.getMinutes()).slice(-2); + // let day = ("0" + repDate.getDate()).slice(-2); + // let month = ("0" + (repDate.getMonth() + 1)).slice(-2); + // let year = repDate.getFullYear(); + // let time = + // ("0" + repDate.getHours()).slice(-2) + + // "" + + // ("0" + repDate.getMinutes()).slice(-2); - let repDateStamp = ""; - repDateStamp = year + "" + month + day; //+ "-" + time; + // let repDateStamp = ""; + // repDateStamp = year + "" + month + day; //+ "-" + time; - console.log(repDateStamp); + //console.log(reqBodyobj); //if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) { // //createContainer(containerID).then((containerName) => { @@ -228,21 +228,21 @@ export default function handler(req, res) { console.log( "///////////////////////////////////\n file created: \n" + - `tmp/${caseRef}_rep_${repDateStamp}_${repCapacity}_${repRaiser}_${repType}.pdf` + + `tmp/${reqBodyobj.repfile_name}.pdf` + "\n/////////////////////////" ); - createRepBlob(req.body, containerID, caseRef); + // createRepBlob(req.body, containerID, caseRef); ReactPDF.render( , - `tmp/${caseRef}_rep_${repDateStamp}_${repCapacity}_${repRaiser}_${repType}.pdf` + `tmp/${reqBodyobj.repfile_name}.pdf` ); uploadPDFRepFiles( - `tmp/${caseRef}_rep_${repDateStamp}_${repCapacity}_${repRaiser}_${repType}.pdf`, + `tmp/${reqBodyobj.repfile_name}.pdf`, containerID, - caseRef, + caseRef + "/" + reqBodyobj.repfile_name, repType ); @@ -250,11 +250,11 @@ export default function handler(req, res) { // then remove from local folder - // fs.unlinkSync( `tmp/${caseRef}_rep_${repDateStamp}_${repCapacity}_${repRaiser}_${repType}.pdf`,); + // fs.unlinkSync( `tmp/${reqBodyobj.repfile_name}.pdf`,); return res.status(200).json({ data: "success", - path: `tmp/${caseRef}_rep_${repDateStamp}_${repCapacity}_${repRaiser}_${repType}.pdf`, + path: `tmp/${reqBodyobj.repfile_name}.pdf`, }); // } else { // return res.status(400).json(); diff --git a/pages/api/file/getrepsblob.js b/pages/api/file/getrepsblob.js index d09daef3..730220ac 100644 --- a/pages/api/file/getrepsblob.js +++ b/pages/api/file/getrepsblob.js @@ -58,7 +58,7 @@ ApiProxy.get(async (req, res) => { if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) { const blobObj = await getRepsBlobs(containerName, casefolderID) .then(async (data) => { - // console.log("----------xxxxxx------", data); + console.log("----------xxxxxx------", data); let result = await downloadAllRepsFiles(containerName, data); return res.status(200).json(result); })