From c66883b4c52d47d6c4671b553dd903144254922f Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Mon, 5 Sep 2022 16:46:30 +0100 Subject: [PATCH] awaiting submissions from storage acc --- actions/azurestorage.js | 138 +++++++++++++++++- actions/index.js | 99 ++++++++++++- components/homepage/login.js | 14 +- components/myportal.js | 12 ++ .../myportal/awaitingsubmissionfromblob.js | 105 +++++++++++++ components/myportal/topthree.js | 3 +- components/newappeal/buildsection.js | 34 ++++- components/newappeal/complete.js | 11 +- components/newappeal/createCase.js | 3 +- package.json | 4 +- pages/api/email/index.js | 81 ++++++++++ pages/api/endpoint/createcase_api.js | 13 +- .../file/deleteawaitingsubmissionfromblob.js | 45 ++++++ .../api/file/getawaitingsubmissionfromblob.js | 44 ++++++ pages/api/file/getprogressobjblob.js | 8 +- pages/api/file/upload.js | 6 +- pages/auth/verify-request.js | 2 +- pages/index.js | 2 +- pages/myportal/[appealtypes].js | 44 +++--- pages/myportal/index.js | 8 + pages/newappeal/[appealtypes].js | 16 +- store/accountDetails/action.js | 9 +- store/accountDetails/reducer.js | 6 + store/awaitingSubmission/action.js | 9 ++ store/awaitingSubmission/reducer.js | 6 + 25 files changed, 653 insertions(+), 69 deletions(-) create mode 100644 components/myportal/awaitingsubmissionfromblob.js create mode 100644 pages/api/email/index.js create mode 100644 pages/api/file/deleteawaitingsubmissionfromblob.js create mode 100644 pages/api/file/getawaitingsubmissionfromblob.js diff --git a/actions/azurestorage.js b/actions/azurestorage.js index e8e7a002..9433aacb 100644 --- a/actions/azurestorage.js +++ b/actions/azurestorage.js @@ -120,7 +120,7 @@ export const getBlobs = async (containerName, casefolderID) => { ), }); } - console.log("blobObj:", blobObj); + //console.log("blobObj:", blobObj); return blobObj; }; @@ -230,13 +230,46 @@ export const downloadProgressFile = async ( ); const blobClient = containerClient.getBlobClient(blobName); - console.log("herher:", containerName, blobName, casefolderID); const downloadedBlob = await blobClient.download(0); const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody); return downloaded; }; +export const downloadAllProgressFiles = async ( + containerName, + progressBlobObj +) => { + //console.log(progressBlobObj); + const creds = new DefaultAzureCredential(); + + const containerClient = new ContainerClient( + `${STORAGE_PATH}/${containerName}`, + creds + ); + + let blobClient = {}; + let downloadedBlob = {}; + let downloaded = ""; + let blobCount = 0; + + for (const prop in progressBlobObj) { + //console.log(`${prop}: ${progressBlobObj[prop].path}`); + blobClient = containerClient.getBlobClient(progressBlobObj[prop].path); + downloadedBlob = await blobClient.download(0); + downloaded = + downloaded + + (await streamToBuffer(downloadedBlob.readableStreamBody)) + + ","; + blobCount++; + } + + downloaded = downloaded.substring(0, downloaded.length - 1); + + //console.log(downloaded); + return '{ "@odata.count": ' + blobCount + ',"value": [' + downloaded + "]}"; +}; + const streamToBuffer = async (readableStream) => { return new Promise((resolve, reject) => { const chunks = []; @@ -250,6 +283,42 @@ const streamToBuffer = async (readableStream) => { }); }; +export const getCaseBlob = async ( + containerName, + caseReference, + formContent +) => { + const creds = new DefaultAzureCredential(); + + const containerClient = new ContainerClient( + `${STORAGE_PATH}/${containerName}`, + creds + ); + + console.log("have got to create case"); + containerClient.createIfNotExists(); + + let blobCount = 0; + for await (const blob of containerClient.listBlobsFlat({ + prefix: caseReference, + })) { + blobCount++; + } + + const content = JSON.stringify(formContent); + const blobName = caseReference + "/case/" + caseReference + ".json"; + + console.log("blobName:", blobName); + const blockBlobClient = containerClient.getBlockBlobClient(blobName); + + const uploadBlobResponse = await blockBlobClient.upload( + content, + Buffer.byteLength(content) + ); + + return blobName; +}; + export const getProgressBlobs = async (containerName, caseReference) => { const creds = new DefaultAzureCredential(); @@ -260,7 +329,15 @@ export const getProgressBlobs = async (containerName, caseReference) => { containerClient.createIfNotExists(); - console.log("thisi s the caasefolder:", caseReference); + let blobCount = 0; + for await (const blob of containerClient.listBlobsFlat({ + prefix: caseReference, + })) { + blobCount++; + } + + //console.log("this is the caasefolder:", caseReference, blobCount); + let blobObj = []; for await (const blob of containerClient.listBlobsFlat({ prefix: caseReference + "/" + caseReference + ".json", @@ -304,7 +381,60 @@ export const getProgressBlobs = async (containerName, caseReference) => { }, ]).reverse()[0]; - console.log("blobObj:", blobObj); + //console.log("blobObjwwwww:", blobObj); + + return blobObj; +}; + +export const getAllProgressBlobs = async (containerName) => { + const creds = new DefaultAzureCredential(); + + const containerClient = new ContainerClient( + `${STORAGE_PATH}/${containerName}`, + creds + ); + + containerClient.createIfNotExists(); + + let blobCount = 0; + for await (const blob of containerClient.listBlobsFlat({ + // prefix: caseReference, + })) { + blobCount++; + } + + //console.log("this is the caasefolder:", caseReference, blobCount); + + let blobObj = []; + for await (const blob of containerClient.listBlobsFlat({ + //prefix: caseReference + "/" + caseReference + ".json", + })) { + blob.name.split("/")[1].indexOf(".json") > 0 && + blob.name.split("/")[1].indexOf("undefined") < 0 && + blobObj.push({ + "name": blob.name.split("/")[1], + "path": blob.name, + "versionId": blob.versionId, + "isCurrentVersion": blob.isCurrentVersion, + "contentLength": blob.properties.contentLength, + "contentType": blob.contentType, + "lastModified": blob.properties.lastModified, + // "hashedfilepath": hashAPIPath( + // "/api/file/downloadblob?container=" + + // containerName + + // ), + // "hasheddeletepath": hashAPIPath( + // "/api/file/deleteblob?container=" + + // containerName + + // ), + // "hashgetblobs": hashAPIPath( + // "/api/file/getbloblist?container=" + + // containerName + + // ), + }); + } + + //console.log("blobObj:", blobObj); return blobObj; }; diff --git a/actions/index.js b/actions/index.js index ffa1ac8f..e1193f0e 100644 --- a/actions/index.js +++ b/actions/index.js @@ -3,7 +3,8 @@ import https from "https"; import CryptoJS from "crypto-js"; import HmacSHA256 from "crypto-js/hmac-sha256"; import { getFormCollection } from "../components/utils"; -import { downloadFile } from "./azurestorage"; +import { downloadFile, getCaseBlob } from "./azurestorage"; + let BASE_URL; const port = parseInt(process.env.PORT, 10) || 3000; @@ -132,7 +133,6 @@ export const azureHeadersPagedCustom = (access_token, showNumberOfRecords) => { }; export const hashAPIPath = (queryPath) => { - console.log(queryPath); var hashlink = CryptoJS.HmacSHA256( queryPath, CryptoJS.enc.Hex.parse(WORDKEY) @@ -744,6 +744,11 @@ export const getAwaitingSubmissionProxy = (loggedInUserId) => { }; export const getAwaitingSubmission = (loggedInUserId) => { + console.log( + BASE_URL + + "/api/endpoint/getawaitingsubmission_api?loggedInUserId=" + + loggedInUserId + ); return axios .get( BASE_URL + @@ -758,6 +763,25 @@ export const getAwaitingSubmission = (loggedInUserId) => { }); }; +export const getAwaitingSubmissionFromBlob = (containerName) => { + return axios + .get( + BASE_URL + + "/api/file/getawaitingsubmissionfromblob?container=" + + containerName + + hashAPIPath( + "/api/file/getawaitingsubmissionfromblob?container=" + + containerName + ) + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + //console.log("API call error", error); + }); +}; + export const getPortalModuleDetails = (appealType, caseReference) => { //console.log( // BASE_URL + @@ -864,7 +888,13 @@ export const createWatchedCases = (formValues) => { }); }; -export const createNewCase = (appealTypeId, lpaID, contactid, createBody) => { +export const createNewCase = ( + appealTypeId, + lpaID, + contactid, + createBody, + containerName +) => { appealTypeId = parseInt(appealTypeId); var data = createBody; @@ -875,7 +905,9 @@ export const createNewCase = (appealTypeId, lpaID, contactid, createBody) => { "&lpaID=" + lpaID + "&contactid=" + - contactid; + contactid + + "&containername=" + + containerName; var config = { method: "post", @@ -1004,6 +1036,31 @@ export const deleteAwaitingSubmissions = (incidentID) => { }); }; +export const deleteAwaitingSubmissionsFromBlob = ( + containerID, + casefolderID +) => { + var queryUrl = + "/api/file/deleteawaitingsubmissionsfromblob?container=" + + containerID + + "&casefolderID=" + + casefolderID; + + var config = { + method: "get", + url: queryUrl, + }; + //console.log(config); + return axios(config) + .then((res) => { + //console.log("deleted ", res.data); + return res.data; + }) + .catch((error) => { + console.log("this serror", error); + }); +}; + export const deleteWatchedCases = (watchedCaseID) => { var queryUrl = "/api/endpoint/deletewatchedcases_api?watchedCaseID=" + watchedCaseID; @@ -1165,7 +1222,7 @@ export const downloadBlob = (containerName, blobName) => { { responseType: "blob" } ) .then((response) => { - console.log("Downloaded blob content:www"); + console.log("Downloaded blob content:"); res.setHeader( "content-disposition", @@ -1181,7 +1238,6 @@ export const downloadBlob = (containerName, blobName) => { }; export const getProgressFromBlob = async (containerName, casereference) => { - console.log("cont:", containerName); try { const res = await axios.get( BASE_URL + @@ -1201,3 +1257,34 @@ export const getProgressFromBlob = async (containerName, casereference) => { console.log("this serror", error); } }; + +export const sendEmail = async ( + emailToAddress, + emailSubject, + emailContentTitle, + emailContent +) => { + var mailData = { + "email": emailToAddress, + "subject": emailSubject, + "emailcontenttitle": emailContentTitle, + "emailcontent": emailContent, + }; + + var queryUrl = "/api/email"; + + var config = { + method: "post", + url: queryUrl, + data: mailData, + }; + + return axios(config) + .then((res) => { + //console.log("posted ", res.data); + return res.data; + }) + .catch((error) => { + console.log("this serror", error); + }); +}; diff --git a/components/homepage/login.js b/components/homepage/login.js index c47d0b0f..e97ef6ec 100644 --- a/components/homepage/login.js +++ b/components/homepage/login.js @@ -246,13 +246,13 @@ let Login = (props) => { )} {session && ( - + // )}
diff --git a/components/myportal.js b/components/myportal.js index 9df18b4b..9edb13ee 100644 --- a/components/myportal.js +++ b/components/myportal.js @@ -5,6 +5,8 @@ import { useRouter } from "next/router"; import { destroyCookie } from "nookies"; import TimeOut from "../components/timeout"; import AwaitingSubmission from "./myportal/awaitingsubmission"; +import AwaitingSubmissionFromBlob from "./myportal/awaitingsubmissionfromblob"; + import Dns from "./myportal/dns"; import MakeNewAppeal from "./myportal/makenewappeal"; import MyCases from "./myportal/mycases"; @@ -101,6 +103,16 @@ const MyPortal = (props) => { } /> )} + {props.awaitingSubmission + .awaitingSubmissionFromBlob["@odata.count"] > + 0 && ( + + )} {props.myCases.myCases["@odata.count"] > 0 && ( )} diff --git a/components/myportal/awaitingsubmissionfromblob.js b/components/myportal/awaitingsubmissionfromblob.js new file mode 100644 index 00000000..e2a060f2 --- /dev/null +++ b/components/myportal/awaitingsubmissionfromblob.js @@ -0,0 +1,105 @@ +import Link from "next/link"; +import { useRouter } from "next/router"; +import useTranslation from "next-translate/useTranslation"; +import TopThree from "./topthree"; +import { connect } from "react-redux"; +import { setCurrentView } from "../../store/currentView/action"; + +const AwaitingSubmissionFromBlob = (props) => { + let { t } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + const { setCurrentView } = props; + + let topthreeRow = []; + let showTopThreeArr = props.awaitingSubmissionFromBlob.value; + + let topThreeOnlyArr = showTopThreeArr; + Object.keys(topThreeOnlyArr).map((key, index) => { + topthreeRow.push( +
+
+
+ {t("myportal:case-reference")}: + {showTopThreeArr[index].pinswg_name} +
+ +
+ {t("myportal:case-address")}:{" "} + {_.isEmpty(showTopThreeArr) + ? t("myportal:case-address-not-entered") + : _.isEmpty(showTopThreeArr[index]) + ? t("myportal:case-address-not-entered") + : _.isEmpty(showTopThreeArr[index]) + ? t("myportal:case-address-not-entered") + : _.isEmpty( + showTopThreeArr[index].pinswg_siteaddressline1 + ) + ? t("myportal:case-address-not-entered") + : showTopThreeArr[index].pinswg_siteaddressline1 + + (!_.isEmpty( + showTopThreeArr[index].pinswg_siteaddressline2 + ) + ? ", " + + showTopThreeArr[index] + .pinswg_siteaddressline2 + : "") + + (!_.isEmpty( + showTopThreeArr[index].pinswg_siteaddresstown + ) + ? ", " + + showTopThreeArr[index] + .pinswg_siteaddresstown + : "")} +
+
+
+ ); + }); + + return ( +
+
+

+ {t("myportal:awatitingsubmission-card-title")} +

+
+ {topthreeRow} + {/* */} +
+ {props.awaitingSubmissionFromBlob["@odata.count"] > 3 && ( + + )} +
+
+ ); +}; + +const mapDispatchToProps = (dispatch) => { + return { + setCurrentView: (currentView) => { + dispatch(setCurrentView(currentView)); + }, + }; +}; + +export default connect(null, mapDispatchToProps)(AwaitingSubmissionFromBlob); diff --git a/components/myportal/topthree.js b/components/myportal/topthree.js index f3244e78..ad5efc92 100644 --- a/components/myportal/topthree.js +++ b/components/myportal/topthree.js @@ -142,7 +142,8 @@ const TopThree = (props) => { {t("myportal:case-reference")}: { }); }; - const updateCaseProgress = (values) => { + const updateCaseProgress = (values, sendSavedEmail) => { let incidentId = props.appealType.caseReference.incidentid; let updateBody = values || {}; @@ -183,8 +183,28 @@ let BuildSection = (props) => { primaryAttribute, props.appealType.caseReference.ticketnumber ); - //console.log("patching////////"); - //patchCase(incidentId); + + sendSavedEmail == true && + sendEmail( + props.props.accountDetails.loggedinUserEmail, + "Saved progress for appeal " + + props.appealType.caseReference.ticketnumber, + "Your saved appeal " + + props.appealType.caseReference.ticketnumber, + "You can resume your application at a later date from here " + ); }; const onHandleSubmit = (values) => { @@ -193,7 +213,7 @@ let BuildSection = (props) => { delete valuesObj["_pinswg_appellant_value"]; console.log("has errors:", props.invalid); - props.invalid == false && updateCaseProgress(valuesObj); + props.invalid == false && updateCaseProgress(valuesObj, false); setCurrentSection(currentSection + 1); }; @@ -309,7 +329,7 @@ let BuildSection = (props) => { delete valuesObj["_pinswg_appellant_value"]; //console.log("on save:", valuesObj); - updateCaseProgress(valuesObj); + updateCaseProgress(valuesObj, false); }} > {t("common:continue-button")} @@ -373,7 +393,7 @@ let BuildSection = (props) => { delete valuesObj["_pinswg_appellant_value"]; console.log("on save:", valuesObj); - updateCaseProgress(valuesObj); + updateCaseProgress(valuesObj, true); router.replace( router.locale != "en" ? router.locale + "/myportal" diff --git a/components/newappeal/complete.js b/components/newappeal/complete.js index cfedce36..4bb254d9 100644 --- a/components/newappeal/complete.js +++ b/components/newappeal/complete.js @@ -6,7 +6,7 @@ import { useEffect } from "react"; import { connect } from "react-redux"; import { formValueSelector } from "redux-form"; import xpath from "xpath"; -import { updateCase, patchCase } from "../../actions"; +import { updateCase, patchCase, sendEmail } from "../../actions"; import data from "../../data/collections.json"; import { setCurrentSection } from "../../store/appealType/action"; import { getFormCollectionByID } from "../utils"; @@ -49,6 +49,15 @@ let CompleteAppeal = (props) => { primaryAttribute, props.appealType.caseReference.ticketnumber ); + + sendEmail( + props.props.accountDetails.loggedinUserEmail, + "Saved progress for appeal " + + props.appealType.caseReference.ticketnumber, + "Your saved appeal " + props.appealType.caseReference.ticketnumber, + "You have now completed your appeal." + ); + console.log("patching////////"); patchCase(incidentId); }, [ diff --git a/components/newappeal/createCase.js b/components/newappeal/createCase.js index 86528bd4..51b93a17 100644 --- a/components/newappeal/createCase.js +++ b/components/newappeal/createCase.js @@ -454,7 +454,8 @@ let CreateCase = (props) => { appTypeCollection.appealTypeID, values.lpaTypes, props.loggedInUser, - values + values, + props.containerID ) .then((data) => { router.replace( diff --git a/package.json b/package.json index 74511df6..586bc6a8 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "next-redux-wrapper": "^7.0.5", "next-translate": "^1.2.0", "nextjs-basic-auth-middleware": "^0.2.1", - "nodemailer": "^6.7.3", + "nodemailer": "^6.7.8", "nookies": "^2.5.2", "ospoint": "^0.2.1", "path": "^0.12.7", @@ -86,4 +86,4 @@ "prettier": "2.5.1", "prisma": "^3.12.0" } -} \ No newline at end of file +} diff --git a/pages/api/email/index.js b/pages/api/email/index.js new file mode 100644 index 00000000..8576acbc --- /dev/null +++ b/pages/api/email/index.js @@ -0,0 +1,81 @@ +import nodemailer from "nodemailer"; + +export default function handler(req, res) { + const { email, subject, emailcontenttitle, emailcontent } = req.body; + console.log(email); + //console.log(process.env); + + const client = nodemailer.createTransport({ + auth: { + user: process.env.EMAIL_SERVER_USER, + pass: process.env.EMAIL_SERVER_PASSWORD, + }, + host: process.env.EMAIL_SERVER_HOST, + port: process.env.EMAIL_SERVER_PORT, + secure: true, + }); + + //console.log(client); + + // Some simple styling options + const backgroundColor = "#ffffff"; + const textColor = "#444444"; + const mainBackgroundColor = "#ffffff"; + const buttonBackgroundColor = "#aa1111"; + const buttonBorderColor = "#aa1111"; + const buttonTextColor = "#ffffff"; + const headerBackgroundColor = "#000000"; + const url = process.env.API_ROOT; + + let emailBodyContent = ` + + + + + + + + + + + + + + + +
+
+ ${emailcontenttitle} +
+ ${emailcontent} +
+ +
+ If you did not request this email you can safely ignore it. +
+`; + + const mailData = { + from: "no-reply@rdbdigital.com", + to: email, + subject: subject, + text: emailBodyContent, + html: emailBodyContent, + }; + + client.sendMail(mailData, (err, data) => { + if (err) { + console.log(err); + res.status(400); + } else { + console.log("mail sent"); + res.status(200).json(data); + } + }); +} diff --git a/pages/api/endpoint/createcase_api.js b/pages/api/endpoint/createcase_api.js index b3046f52..59c13bf4 100644 --- a/pages/api/endpoint/createcase_api.js +++ b/pages/api/endpoint/createcase_api.js @@ -2,7 +2,7 @@ import axios from "axios"; import CryptoJS from "crypto-js"; import _ from "lodash"; import { getToken, azureHeadersPaged, consoleLogger } from "../../../actions"; - +import { getCaseBlob } from "../../../actions/azurestorage"; const WORDKEY = process.env.HASHKEY; const WEBAPI_URL = @@ -25,6 +25,7 @@ export default async function ApiProxy(req, res) { var createCaseBody = req.body; var contactid = req.query.contactid; var appealTypeId = req.query.appealTypeId; + var containerName = req.query.containername; var lpaID = req.query.lpaID; var queryUrl = "incidents"; var token = await getToken(); @@ -42,7 +43,7 @@ export default async function ApiProxy(req, res) { delete newData.lpaTypes; delete newData.appealTypes; - console.log("/////Create Case:", newData); + console.log("/////Create Case:\n", newData, "\n//////////////"); var config = { method: "post", @@ -55,18 +56,18 @@ export default async function ApiProxy(req, res) { "Authorization": "Bearer " + token.access_token, "Content-Type": "application/json", }, - data: JSON.stringify(data), + data: JSON.stringify(newData), }; - var apiResponse = _.isEmpty(req.query) ? res.status(400).json() : axios(config) .then(({ data }) => { - console.log(data); + getCaseBlob(containerName, data.ticketnumber, createCaseBody); + res.status(200).json(data); }) .catch((err) => { - console.log(consoleLogger(err)); + //console.log(consoleLogger(err)); res.status(400).json(err); }); diff --git a/pages/api/file/deleteawaitingsubmissionfromblob.js b/pages/api/file/deleteawaitingsubmissionfromblob.js new file mode 100644 index 00000000..ab6b1b6d --- /dev/null +++ b/pages/api/file/deleteawaitingsubmissionfromblob.js @@ -0,0 +1,45 @@ +import { hashAPIPath } from "../../../actions"; +import { deleteBlob } from "../../../actions/azurestorage"; + +import nextConnect from "next-connect"; +import middleware from "../middleware/middleware"; + +const ApiProxy = nextConnect(); +ApiProxy.use(middleware); + +ApiProxy.get(async (req, res) => { + var containerName = req.query.container; + var casefolderID = req.query.casefolderID; + var blobName = req.query.blobname; + var checkHash = req.query.hash; + + var checkquerypath = + "/api/file/deleteblob?container=" + + containerName + + "&casefolderID=" + + casefolderID + + "&blobname=" + + blobName; + + // console.log(hashAPIPath(checkquerypath), checkHash); + // console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash); + + if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) { + await deleteBlob( + containerName, + casefolderID + "/files/" + blobName + ).then((data) => { + return res.status(200).json({ data: data }); + }); + } else { + return res.status(400).json(); + } +}); + +export const config = { + api: { + bodyParser: false, + }, +}; + +export default ApiProxy; diff --git a/pages/api/file/getawaitingsubmissionfromblob.js b/pages/api/file/getawaitingsubmissionfromblob.js new file mode 100644 index 00000000..9426ac29 --- /dev/null +++ b/pages/api/file/getawaitingsubmissionfromblob.js @@ -0,0 +1,44 @@ +import { + downloadAllProgressFiles, + getAllProgressBlobs, +} from "../../../actions/azurestorage"; +import _ from "lodash"; +import nextConnect from "next-connect"; +import middleware from "../middleware/middleware"; +import { hashAPIPath } from "../../../actions"; + +const ApiProxy = nextConnect(); +ApiProxy.use(middleware); + +ApiProxy.get(async (req, res) => { + var containerName = req.query.container; + var checkHash = req.query.hash; + + var checkquerypath = + "/api/file/getawaitingsubmissionfromblob?container=" + containerName; + + // console.log(req.url); + // console.log(hashAPIPath(checkquerypath), checkHash); + // console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash); + + if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) { + const blobObj = await getAllProgressBlobs(containerName) + .then((data) => { + //console.log(data); + return downloadAllProgressFiles(containerName, data); + }) + .then((data) => { + return res.status(200).json(data); + }); + } else { + return res.status(400).json(); + } +}); + +export const config = { + api: { + bodyParser: false, + }, +}; + +export default ApiProxy; diff --git a/pages/api/file/getprogressobjblob.js b/pages/api/file/getprogressobjblob.js index 97c18a69..bb76532b 100644 --- a/pages/api/file/getprogressobjblob.js +++ b/pages/api/file/getprogressobjblob.js @@ -2,7 +2,7 @@ import { downloadProgressFile, getProgressBlobs, } from "../../../actions/azurestorage"; - +import _ from "lodash"; import nextConnect from "next-connect"; import middleware from "../middleware/middleware"; @@ -25,9 +25,9 @@ ApiProxy.get(async (req, res) => { //if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) { const blobObj = await getProgressBlobs(containerName, casefolderID) - .then((data) => - downloadProgressFile(containerName, data.path, casefolderID) - ) + .then((data) => { + return downloadProgressFile(containerName, data.path, casefolderID); + }) .then((data) => { return res.status(200).json(data); }); diff --git a/pages/api/file/upload.js b/pages/api/file/upload.js index 8515da1d..43cdd573 100644 --- a/pages/api/file/upload.js +++ b/pages/api/file/upload.js @@ -32,11 +32,7 @@ ApiProxy.post(async (req, res) => { // if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) { //createContainer(containerID).then((containerName) => { - console.log( - "does this et folder name:", - appealData.pinswg_name, - casefolderID - ); + console.log("does this get folder name:", containerID, casefolderID); createBlob(appealData, containerID, casefolderID).then((data) => { Object.keys(req.files).length > 0 && uploadFile(req.files, containerID, casefolderID); diff --git a/pages/auth/verify-request.js b/pages/auth/verify-request.js index 53708db1..54dcac67 100644 --- a/pages/auth/verify-request.js +++ b/pages/auth/verify-request.js @@ -32,7 +32,7 @@ const SignIn = (props) => {
A link has been sent to your email so you can - continue + continue. Please close this window.
diff --git a/pages/index.js b/pages/index.js index 58eca470..3fc7c8ea 100644 --- a/pages/index.js +++ b/pages/index.js @@ -132,7 +132,7 @@ const Home = (props) => {
- {hasGGCode ? ( + {hasLoginCode ? ( <>

{ggLocale == "cy" diff --git a/pages/myportal/[appealtypes].js b/pages/myportal/[appealtypes].js index ec2234d8..ee1a9e03 100644 --- a/pages/myportal/[appealtypes].js +++ b/pages/myportal/[appealtypes].js @@ -7,7 +7,7 @@ import { useEffect } from "react"; import { connect } from "react-redux"; import xpath from "xpath"; import { - getAppealsTypes, + getAppealsTypesForNewAppeal, getMandatoryFields, getPickLists, getPartSavedAppeal, @@ -26,6 +26,7 @@ import TimeOut from "../../components/timeout"; import { setLoggedInUserId, + setLoggedInUserEmail, setContainerID, } from "../../store/accountDetails/action"; import { @@ -217,32 +218,32 @@ export const getServerSideProps = wrapper.getServerSideProps( const { query, req, res } = ctx; const { cookies } = req; - console.log(cookies); - console.log("the query", query.appealtypes); + //console.log(cookies); + //console.log("the query", query.appealtypes); let loggedInUser = cookies.pinsUser; let thisSession = await getSession(ctx); - console.log("nextAuth Session:", thisSession); + //console.log("nextAuth Session:", thisSession); let loggedInUserIdent = thisSession.user.id; + let loggedInUserEmail = thisSession.user.email; - console.log("logged ident:", loggedInUserIdent); + //console.log("logged ident:", loggedInUserIdent); - const [ - appealTypeData, - mandatoryFieldsData, - pickListData, - blobList, - blobProgress, - ] = await Promise.all([ - await getAppealsTypes(), - await getMandatoryFields(query.appealtypes), - await getPickLists(query.appealtypes), - await getFilesFromBlob(loggedInUserIdent, query.casereference), - await getProgressFromBlob(loggedInUserIdent, query.casereference), - ]); + const [appealTypeData, mandatoryFieldsData, pickListData, blobList] = + await Promise.all([ + await getAppealsTypesForNewAppeal(), + await getMandatoryFields(query.appealtypes), + await getPickLists(query.appealtypes), + await getFilesFromBlob(loggedInUserIdent, query.casereference), + ]); - console.log("has blobprogess:", loggedInUserIdent, query.casereference); + const blobProgress = await getProgressFromBlob( + loggedInUserIdent, + query.casereference + ); + + console.log("/////////\nappela tupe data:", appealTypeData); // // Removed to make progress from Blob not CRM @@ -288,6 +289,7 @@ export const getServerSideProps = wrapper.getServerSideProps( const providerConfig = await getProviderConfig(); store.dispatch(getGovGatewayConfig(providerConfig)); store.dispatch(setLoggedInUserId(loggedInUser)); + store.dispatch(setLoggedInUserEmail(loggedInUserEmail)); store.dispatch(setAppealLPA(query.lpa)); store.dispatch(setAppealTypeID(query.apt)); store.dispatch(setCaseReference(caseReference)); @@ -295,6 +297,10 @@ export const getServerSideProps = wrapper.getServerSideProps( store.dispatch(setAppealType(appealTypeData)); store.dispatch(setFilesForAppeal(blobList)); store.dispatch(setContainerID(thisSession.user.id)); + + return { + props: { url: process.env.API_ROOT }, + }; } ); diff --git a/pages/myportal/index.js b/pages/myportal/index.js index e7faad2c..56490674 100644 --- a/pages/myportal/index.js +++ b/pages/myportal/index.js @@ -5,6 +5,7 @@ import Head from "next/head"; import { useRouter } from "next/router"; import { connect } from "react-redux"; import { + getAwaitingSubmissionFromBlob, getAwaitingSubmission, getMyCases, getMyRepresentations, @@ -27,6 +28,7 @@ import { } from "../../store/accountDetails/action"; import { setAwaitingSubmission, + setAwaitingSubmissionFromBlob, setAwaitingSubmissionDetails, } from "../../store/awaitingSubmission/action"; import { getGovGatewayConfig } from "../../store/govgateway/action"; @@ -185,12 +187,14 @@ export const getServerSideProps = wrapper.getServerSideProps( myRepresentations, watchedCases, awaitingSubmission, + awaitingSubmissionFromBlob, ] = await Promise.all([ await getPersonalAccount(loggedInUser), await getMyCases(loggedInUser), await getMyRepresentations(loggedInUser), await getWatchedCases(loggedInUser), await getAwaitingSubmission(loggedInUser), + await getAwaitingSubmissionFromBlob(thisSession.user.id), ]); if (_.has(accountDetails, "errorCode") != false) { @@ -224,6 +228,10 @@ export const getServerSideProps = wrapper.getServerSideProps( store.dispatch(setWatchedCases(watchedCases)); store.dispatch(setWatchedCasesDetails(watchedCasesDetails)); store.dispatch(setAwaitingSubmission(awaitingSubmission)); + store.dispatch( + setAwaitingSubmissionFromBlob(awaitingSubmissionFromBlob) + ); + store.dispatch( setAwaitingSubmissionDetails(awaitingSubmissionDetails) ); diff --git a/pages/newappeal/[appealtypes].js b/pages/newappeal/[appealtypes].js index 8d27a684..7fd4e21e 100644 --- a/pages/newappeal/[appealtypes].js +++ b/pages/newappeal/[appealtypes].js @@ -26,6 +26,7 @@ import TimeOut from "../../components/timeout"; import { setLoggedInUserId, + setLoggedInUserEmail, setContainerID, } from "../../store/accountDetails/action"; import { @@ -226,8 +227,9 @@ export const getServerSideProps = wrapper.getServerSideProps( console.log("nextAuth Session:", thisSession); let loggedInUserIdent = thisSession.user.id; + let loggedInUserEmail = thisSession.user.email; - console.log("logged ident:", loggedInUserIdent); + console.log("logged ident:", loggedInUserIdent, loggedInUserEmail); const [ caseReferenceData, @@ -235,17 +237,20 @@ export const getServerSideProps = wrapper.getServerSideProps( mandatoryFieldsData, pickListData, //blobList, - blobProgress, ] = await Promise.all([ await getCase(query.id), await getAppealsTypes(), await getMandatoryFields(query.appealtypes), await getPickLists(query.appealtypes), - await getProgressFromBlob(loggedInUserIdent, query.casereference), //await getFilesFromBlob(query.casereference), ]); + const blobProgress = await getProgressFromBlob( + loggedInUserIdent, + caseReferenceData.ticketnumber + ); + console.log("anything here", loggedInUser, query.id, caseReferenceData); let caseReference = caseReferenceData; //caseReferenceData.ticketnumber; @@ -265,6 +270,7 @@ export const getServerSideProps = wrapper.getServerSideProps( const providerConfig = await getProviderConfig(); store.dispatch(getGovGatewayConfig(providerConfig)); store.dispatch(setLoggedInUserId(loggedInUser)); + store.dispatch(setLoggedInUserEmail(loggedInUserEmail)); store.dispatch(setAppealLPA(query.lpa)); store.dispatch(setAppealTypeID(query.apt)); store.dispatch(setCaseReference(caseReference)); @@ -273,6 +279,10 @@ export const getServerSideProps = wrapper.getServerSideProps( store.dispatch(setContainerID(thisSession.user.id)); //store.dispatch(setFilesForAppeal(blobList)); + + return { + props: { url: process.env.API_ROOT }, + }; } ); diff --git a/store/accountDetails/action.js b/store/accountDetails/action.js index 91241507..0b4bb462 100644 --- a/store/accountDetails/action.js +++ b/store/accountDetails/action.js @@ -3,13 +3,13 @@ export const AccountDetailsDataActionTypes = { GETACCOUNTDETAILSDATA: "GETACCOUNTDETAILSDATA", SETACCOUNTDETAILSDATA: "SETACCOUNTDETAILSDATA", SETLOGGEDINUSER: "SETLOGGEDINUSER", + SETLOGGEDINUSEREMAIL: "SETLOGGEDINUSEREMAIL", SETACCOUNTCREATED: "SETACCOUNTCREATED", USER_LOGOUT: "USER_LOGOUT", SETCONTAINERID: "SETCONTAINERID", }; export const setCookieConsent = (cookieObj) => (dispatch) => { - console.log("wertyewrtyt", cookieObj); return dispatch({ type: AccountDetailsDataActionTypes.SETCOOKIECONSENT, cookieObj: cookieObj, @@ -36,6 +36,13 @@ export const setLoggedInUserId = (loggedinUserId) => (dispatch) => { }); }; +export const setLoggedInUserEmail = (loggedinUserEmail) => (dispatch) => { + return dispatch({ + type: AccountDetailsDataActionTypes.SETLOGGEDINUSEREMAIL, + loggedinUserEmail: loggedinUserEmail, + }); +}; + export const setLogout = () => (dispatch) => { return dispatch({ type: "USER_LOGOUT", diff --git a/store/accountDetails/reducer.js b/store/accountDetails/reducer.js index ab0f3d0c..ab12c275 100644 --- a/store/accountDetails/reducer.js +++ b/store/accountDetails/reducer.js @@ -3,6 +3,7 @@ import { AccountDetailsDataActionTypes } from "./action"; const AccountDetailsDataInitialState = { accountDetails: {}, loggedinUserId: "", + loggedinUserEmail: "", accCr: false, cookieObj: "", containerID: "", @@ -23,6 +24,11 @@ export default function reducer( ...state, loggedinUserId: action.loggedinUserId, }; + case AccountDetailsDataActionTypes.SETLOGGEDINUSEREMAIL: + return { + ...state, + loggedinUserEmail: action.loggedinUserEmail, + }; case AccountDetailsDataActionTypes.SETACCOUNTCREATED: return { ...state, diff --git a/store/awaitingSubmission/action.js b/store/awaitingSubmission/action.js index 82905994..edc5edfd 100644 --- a/store/awaitingSubmission/action.js +++ b/store/awaitingSubmission/action.js @@ -1,6 +1,7 @@ export const awaitingSubmissionActionTypes = { GETAWAITINGSUBMISSION: "GETAWAITINGSUBMISSION", SETAWAITINGSUBMISSION: "SETAWAITINGSUBMISSION", + SETAWAITINGSUBMISSIONFROMBLOB: "SETAWAITINGSUBMISSIONFROMBLOB", SETAWAITINGSUBMISSIONDETAILS: "SETAWAITINGSUBMISSIONDETAILS", UPDATEAWAITINGSUBMISSION: "UPDATEAWAITINGSUBMISSION", }; @@ -18,6 +19,14 @@ export const setAwaitingSubmission = (awaitingSubmission) => (dispatch) => { }); }; +export const setAwaitingSubmissionFromBlob = + (awaitingSubmissionFromBlob) => (dispatch) => { + return dispatch({ + type: awaitingSubmissionActionTypes.SETAWAITINGSUBMISSIONFROMBLOB, + awaitingSubmissionFromBlob: awaitingSubmissionFromBlob, + }); + }; + export const setAwaitingSubmissionDetails = (awaitingSubmissionDetails) => (dispatch) => { return dispatch({ diff --git a/store/awaitingSubmission/reducer.js b/store/awaitingSubmission/reducer.js index 75c94f5d..2ced49a1 100644 --- a/store/awaitingSubmission/reducer.js +++ b/store/awaitingSubmission/reducer.js @@ -3,6 +3,7 @@ import { awaitingSubmissionActionTypes } from "./action"; const awaitingSubmissionInitialState = { awaitingSubmission: {}, awaitingSubmissionDetails: {}, + awaitingSubmissionFromBlob: {}, }; export default function reducer( @@ -15,6 +16,11 @@ export default function reducer( ...state, awaitingSubmission: action.awaitingSubmission, }; + case awaitingSubmissionActionTypes.SETAWAITINGSUBMISSIONFROMBLOB: + return { + ...state, + awaitingSubmissionFromBlob: action.awaitingSubmissionFromBlob, + }; case awaitingSubmissionActionTypes.SETAWAITINGSUBMISSIONDETAILS: return { ...state,