diff --git a/components/case/representation/representationElements.js b/components/case/representation/representationElements.js index 737506f7..65c38700 100644 --- a/components/case/representation/representationElements.js +++ b/components/case/representation/representationElements.js @@ -939,10 +939,6 @@ export const RenderFileUpload = (field) => { case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": return "/assets/images/documenttypes/xlsx.png"; break; - - case "application/zip": - return "/assets/images/documenttypes/zip.png"; - break; case "image/jpeg": return "/assets/images/documenttypes/jpg.png"; case "image/png": @@ -1091,7 +1087,6 @@ export const RenderFileUpload = (field) => { [".docx"], "image/tiff": [".tif", ".tiff"], "image/jpeg": [".jpg", ".jpeg"], - "application/zip": [".zip"], "image/png": [".png"], "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [".xlsx"], @@ -1338,7 +1333,7 @@ export const RenderFileUpload = (field) => { ?.values?.repfile_name ) + "&blobname=" + - blob.name + + encodeURIComponent(blob.name) + blob.hashedfilepath } className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5 govuk-link" diff --git a/components/case/summary.js b/components/case/summary.js index c82cf6c5..ed5aa7ff 100644 --- a/components/case/summary.js +++ b/components/case/summary.js @@ -104,6 +104,38 @@ const CaseSummary = (props) => { ? true : false; + let ShowDocLinks = false; + let checkShowDocLinks = docsOffline != false ? true : false; + + const getDocLink = (docsOffline) => { + var startTime = docsOffline.split(",")[0]; + var endTime = docsOffline.split(",")[1]; + + // console.log(startTime); + // console.log(endTime); + + var currentDate = new Date(); + + var startDate = new Date(currentDate.getTime()); + startDate.setHours(startTime.split(":")[0]); + startDate.setMinutes(startTime.split(":")[1]); + startDate.setSeconds(startTime.split(":")[2]); + + var endDate = new Date(currentDate.getTime()); + endDate.setHours(endTime.split(":")[0]); + endDate.setMinutes(endTime.split(":")[1]); + endDate.setSeconds(endTime.split(":")[2]); + + // console.log(startDate); + // console.log(endDate); + // console.log(currentDate); + + var valid = startDate < currentDate && endDate > currentDate; + ShowDocLinks = valid; + }; + + checkShowDocLinks && getDocLink(docsOffline); + const selectWatchedCase = (loggedInUser, incidentID, appealType) => { let updateBody = { "pinswg_WatchedCase@odata.bind": "/incidents(" + incidentID + ")", @@ -122,7 +154,7 @@ const CaseSummary = (props) => { }); }); - setCaseInvolvment(incidentid, loggedInUser); + //setCaseInvolvment(incidentid, loggedInUser); }; const selectEmailNotifications = ( @@ -770,115 +802,6 @@ const CaseSummary = (props) => {
- {getFormCollectionByID( - appealTypeID - ).PrimaryIdAttribute == - "pinswg_sipscase" && - showReps( - detailsObj.pinswg_consultationopen, - detailsObj.pinswg_consultationclose - ) && ( - <> - {showRepButton( - props - .currentView - .caseReference - .appealType - ) ? ( - <> - - {props - .currentView - .caseReference - .appealType == - 846040002 - ? t( - "case:summary-make-consultation-label" - ) - : t( - "case:summary-make-representation-label" - )} - - - { - //spinnerState(); - router.back(); - }} - className="govuk-button govuk-button--secondary" - > - {t( - "case:summary-back-button-label" - )} - - - ) : !isLPA && - props.currentView - .caseReference - .appealType == - 846040004 ? ( - "" - ) : ( - <> -
-
-

- {t( - "case:representation-date-passed-label", - { - startDate: - formatDates( - detailsObj.pinswg_consultationopen - ), - endDate: - formatDates( - detailsObj.pinswg_consultationclose - ), - } - )} -
{" "} - {t( - "case:representation-date-passed-additional-label" - )}{" "} - - {t( - "home:login-contact-email" - )} - -

-
-
- - )} - - )} - {(_.has( detailsObj, "pinswg_startdate" @@ -914,29 +837,21 @@ const CaseSummary = (props) => { case: currentType == "searchResultsObj" - ? detailsObj.pinswg_name + ? detailsObj.ticketnumber : currentType == "watchedCases" ? casesObj.pinswg_title : currentType == "directResultsObj" - ? detailsObj.pinswg_name + ? detailsObj.ticketnumber : casesObj.reference, }, }} className="govuk-button" > - {props - .currentView - .caseReference - .appealType == - 846040002 - ? t( - "case:summary-make-consultation-label" - ) - : t( - "case:summary-make-representation-label" - )} + {t( + "case:summary-make-representation-label" + )} { ).length > 0 == true ? ( - <> - - + setCurrentReference( + { + "ticketnumber": + props + .currentView + .caseReference + .currentReference, + "currentReference": + props + .currentView + .caseReference + .currentReference, + "currentType": + "searchResultsObj", + "incidentid": + props + .currentView + .caseReference + .incidentid, + "appealType": + props + .currentView + .caseReference + .appealType, + "showMap": + showMap, + } + ); + }} + title={t( + "case:stop-watching-case-link" + )} + > + {t( + "case:stop-watching-case-link" + )}{" "} + ) : ( <>
)} - {resultsArr.length > 0 ? ( + + {!searchLoaded ? ( +
+
+

Loading...

+
+
+ ) : resultsArr.length > 0 ? ( ResultsView(resultsArr) ) : (
@@ -1018,6 +1025,16 @@ const DNSSearchResults = (props) => {
)} + + {/* {resultsArr.length > 0 ? ( + ResultsView(resultsArr) + ) : ( +
+
+

{t("search:searchresults-no-records-label")}

+
+
+ )} */} ); }; diff --git a/components/utils/index.js b/components/utils/index.js index 606cf400..97a6cd64 100644 --- a/components/utils/index.js +++ b/components/utils/index.js @@ -179,6 +179,92 @@ export const getPartSavedDetails = (searchResultsObj) => { * Get the details of a case from the appeal type * @param object searchResultsObj */ +// export const getSearchDetailsPaged = (searchResultsObj) => { +// let detailsArr = []; +// searchResultsObj = searchResultsObj.value; +// const detailsObj = searchResultsObj.map((searchDetail, index) => { +// if (searchDetail.pinswg_appealcasetype == null) { +// console.log(searchDetail.title); +// } else { +// let formMeta = getFormCollectionByID( +// searchDetail.pinswg_appealcasetype +// ); +// formMeta?.LogicalCollectionName && +// formMeta?.LogicalCollectionName != "pinswg_sipses" && +// detailsArr.push( +// getBasicSearchDetailsPaged( +// formMeta.LogicalCollectionName, +// searchDetail.title, +// formMeta.PrimaryIdAttribute, +// searchDetail.incidentid +// ) +// ); +// } +// }); +// return Promise.all(detailsArr); +// }; + +// export const getSearchDetailsPaged = async (searchResultsObj) => { +// const searchResults = searchResultsObj.value; + +// //Group incidents by appeal type +// const groupedByAppealType = {}; + +// searchResults.forEach((incident) => { +// const appealType = incident.pinswg_appealcasetype; +// if (!appealType) return; + +// const formMeta = getFormCollectionByID(appealType); +// if ( +// !formMeta?.LogicalCollectionName || +// formMeta.LogicalCollectionName === "pinswg_sipses" +// ) +// return; + +// const key = formMeta.LogicalCollectionName; +// if (!groupedByAppealType[key]) groupedByAppealType[key] = []; +// groupedByAppealType[key].push({ +// incidentID: incident.incidentid, +// caseReference: incident.title, +// primaryIdAttribute: formMeta.PrimaryIdAttribute, +// }); +// }); + +// // Make all API calls in parallel per appeal type +// const allDetails = await Promise.all( +// Object.entries(groupedByAppealType).map( +// async ([appealTypeName, incidents]) => { +// console.log( +// `Fetching details for appeal type: ${appealTypeName}, incidents: ${incidents.length}` +// ); + +// // Fully parallel for each incident +// const results = await Promise.all( +// incidents.map((i) => +// getBasicSearchDetailsPaged( +// appealTypeName, +// i.caseReference, +// i.primaryIdAttribute, +// i.incidentID +// ).catch((err) => { +// console.error( +// `Error fetching incident ${i.caseReference}:`, +// err +// ); +// return null; // continue other calls even if one fails +// }) +// ) +// ); + +// return results.filter((r) => r); // remove nulls from failed calls +// } +// ) +// ); + +// //Flatten all results into a single array +// return allDetails.flat(); +// }; + export const getSearchDetailsPaged = async (searchResultsObj) => { searchResultsObj = searchResultsObj.value; @@ -233,24 +319,6 @@ export const getSearchDetailsPaged = async (searchResultsObj) => { return allDetails; }; -// export const absoluteUrl = (req, setLocalhost) => { -// var protocol = "https:"; -// var host = req -// ? req.headers["x-forwarded-host"] || req.headers["host"] -// : window.location.host; - -// if (host.indexOf("localhost") > -1) { -// if (setLocalhost) host = setLocalhost; -// protocol = "http:"; -// } - -// return { -// protocol: protocol, -// host: host, -// origin: protocol + "//" + host, -// }; -// }; - export const getProgressObj = ( formObjXML, titleList, diff --git a/pages/api/endpoint/getbasicsearchdetailspaged_api.js b/pages/api/endpoint/getbasicsearchdetailspaged_api.js index 417203c2..9bc01067 100644 --- a/pages/api/endpoint/getbasicsearchdetailspaged_api.js +++ b/pages/api/endpoint/getbasicsearchdetailspaged_api.js @@ -90,7 +90,7 @@ export default async function ApiProxy(req, res) { ? "pinswg_sipscase_value" : primaryIdAttribute + "s_value"); - //console.log("query: ", queryUrl, "<<< { "/api/file/deleteblob?container=" + containerName + "&casefolderID=" + - casefolderID + + encodeURIComponent(casefolderID) + "&blobname=" + - blobName; - - //console.log(hashAPIPath(checkquerypath), checkHash); - //console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash); + encodeURIComponent(blobName); if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) { await deleteBlob( diff --git a/pages/api/file/downloadblob.js b/pages/api/file/downloadblob.js index 5ad78d18..9e43fdb7 100644 --- a/pages/api/file/downloadblob.js +++ b/pages/api/file/downloadblob.js @@ -20,15 +20,9 @@ ApiProxy.get(async (req, res) => { "/api/file/downloadblob?container=" + containerName + "&casefolderID=" + - casefolderID + + encodeURIComponent(casefolderID) + "&blobname=" + - blobName.trim(); - - // console.log(checkquerypath); - - // console.log(hashAPIPath(checkquerypath)); - - // console.log(req.query); + encodeURIComponent(blobName.trim()); if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) { const bloblocation = diff --git a/pages/myportal/advancedsearchresults.js b/pages/myportal/advancedsearchresults.js index fd5129b9..3884a1fb 100644 --- a/pages/myportal/advancedsearchresults.js +++ b/pages/myportal/advancedsearchresults.js @@ -107,17 +107,14 @@ export const getServerSideProps = wrapper.getServerSideProps( loggedInUser = loggedInUser.value[0].contactid; - const [accountDetails, searchResultsObj, watchedCases] = - await Promise.all([ - await getPersonalAccount(loggedInUser), - await getAdvancedSearch(query), - await getWatchedCases(loggedInUser), - ]); + const [accountDetails, watchedCases] = await Promise.all([ + await getPersonalAccount(loggedInUser), + await getWatchedCases(loggedInUser), + ]); console.log(accountDetails); - const [searchDetailsObj, watchedCasesDetails] = await Promise.all([ - await getSearchDetails(searchResultsObj), + const [watchedCasesDetails] = await Promise.all([ await getDetails(watchedCases, "myWatchedCases"), ]); @@ -126,8 +123,6 @@ export const getServerSideProps = wrapper.getServerSideProps( store.dispatch(setShowReps(showReps, showLoginCheck)); store.dispatch(setAccountDetails(accountDetails)); - store.dispatch(setSearchResults(searchResultsObj)); - store.dispatch(setSearchDetails(searchDetailsObj)); store.dispatch(setWatchedCases(watchedCases)); store.dispatch(setWatchedCasesDetails(watchedCasesDetails)); store.dispatch(setSearch(Object.entries(query))); diff --git a/pages/myportal/dnsapplications.js b/pages/myportal/dnsapplications.js index 4cf11cbb..8f0741ad 100644 --- a/pages/myportal/dnsapplications.js +++ b/pages/myportal/dnsapplications.js @@ -162,31 +162,28 @@ export const getServerSideProps = wrapper.getServerSideProps( }, }; } else { - let [accountDetails, searchResultsObj, watchedCases] = - await Promise.all([ - await getPersonalAccount(loggedInUser), - await getBasicDNSSearch(), - await getWatchedCases(loggedInUser), - ]); + let [accountDetails, watchedCases] = await Promise.all([ + await getPersonalAccount(loggedInUser), + await getWatchedCases(loggedInUser), + ]); - searchResultsObj = - searchResultsObj.status == 502 - ? { - value: [], - errorCode: searchResultsObj.status, - errorMsg: searchResultsObj.statusText, - } - : searchResultsObj; + // searchResultsObj = + // searchResultsObj.status == 502 + // ? { + // value: [], + // errorCode: searchResultsObj.status, + // errorMsg: searchResultsObj.statusText, + // } + // : searchResultsObj; const showMapCheck = process.env.SHOWMAPS || false; - const [searchDetailsObj, watchedCasesDetails] = await Promise.all([ - await getSearchDetails(searchResultsObj), + const [watchedCasesDetails] = await Promise.all([ await getDetails(watchedCases, "myWatchedCases"), ]); const dnsCoords = await getDNSCoords(); - store.dispatch(setSearchResults(searchResultsObj)); - store.dispatch(setSearchDetails(searchDetailsObj)); + // store.dispatch(setSearchResults(searchResultsObj)); + // store.dispatch(setSearchDetails(searchDetailsObj)); store.dispatch(setSearch("DNS")); store.dispatch(setDNSCoords(dnsCoords)); store.dispatch(setWatchedCases(watchedCases)); diff --git a/pages/myportal/index.js b/pages/myportal/index.js index 33540836..9bfd8b69 100644 --- a/pages/myportal/index.js +++ b/pages/myportal/index.js @@ -3,6 +3,8 @@ import useTranslation from "next-translate/useTranslation"; import Head from "next/head"; import { useRouter } from "next/router"; import { connect } from "react-redux"; +import pLimit from "p-limit"; + import { createContainerProxy, getAwaitingSubmissionFromBlob, @@ -16,35 +18,42 @@ import { getRepsFromBlob, getWatchedCases, } from "../../actions"; + import Breadcrumbs from "../../components/breadcrumbs"; import CookieBanner from "../../components/cookieBanner"; import Footer from "../../components/footer"; import Header from "../../components/header"; import MyPortal from "../../components/myportal"; import { getFormCollectionByID } from "../../components/utils"; + import { setAccountDetails, setContainerID, setLoggedInUserId, } from "../../store/accountDetails/action"; + import { setAwaitingSubmissionDetails, setAwaitingSubmissionFromBlob, } from "../../store/awaitingSubmission/action"; + import { setShowReps, setLocale } from "../../store/currentView/action"; + import { setMyCases, setMyCasesDetails } from "../../store/myCases/action"; + import { setMyRepresentations, setMyRepresentationsDetails, setMySubmittedReps, setMySubmittedRepsDetails, } from "../../store/myRepresentations/action"; + import { wrapper } from "../../store/store"; + import { setWatchedCases, setWatchedCasesDetails, } from "../../store/watchedCases/action"; -import pLimit from "p-limit"; const Home = (props) => { const { @@ -61,12 +70,12 @@ const Home = (props) => { docsOffline, } = props; - let { t, lang } = useTranslation(); + const { t } = useTranslation(); const router = useRouter(); const { locale, query } = router; const { appealtypes } = query; - const { data: session } = useSession(); + useSession(); // keeping original hook usage, even if not directly referenced return (
@@ -94,7 +103,6 @@ const Home = (props) => { property="twitter:site" content="@UKGovWales" /> - { /> +
@@ -162,7 +171,7 @@ const Home = (props) => { export const getServerSideProps = wrapper.getServerSideProps( (store) => async (ctx) => { - const { query, req, locale } = ctx; + const { req, locale } = ctx; getIP(req); const cookies = req.cookies || {}; @@ -170,10 +179,7 @@ export const getServerSideProps = wrapper.getServerSideProps( if (!thisSession) { return { - redirect: { - destination: "/auth/signin", - permanent: false, - }, + redirect: { destination: "/auth/signin", permanent: false }, }; } @@ -199,6 +205,12 @@ export const getServerSideProps = wrapper.getServerSideProps( await createContainerProxy(thisSession.user.id); const accountDetails = await getPersonalAccount(loggedInUser); + if (accountDetails?.errorCode) { + return { + redirect: { destination: "/myportal/error", permanent: false }, + }; + } + const lpaId = accountDetails[ "pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue" @@ -206,7 +218,6 @@ export const getServerSideProps = wrapper.getServerSideProps( const isLPA = accountDetails.pinswg_typeofinvolvement === 846040012; - // Fetch cases, reps, watched cases, awaiting submission concurrently const [ myCases, myRepresentations, @@ -219,20 +230,16 @@ export const getServerSideProps = wrapper.getServerSideProps( getAwaitingSubmissionFromBlob(thisSession.user.id), ]); - // Set locale to store + // put current locale into store (this is the URL locale) store.dispatch(setLocale(locale)); - // Determine preferred locale (cookie overrides) + // Determine preferred locale (cookie overrides account preference) let preferredLocale = accountDetails.pinswg_preferredlanguage === 846040000 ? "cy" : "en"; - if (cookies.pedw_locale) { - preferredLocale = cookies.pedw_locale; - } - - // Strip the current locale from the URL path - const pathWithoutLocale = ctx.resolvedUrl.replace(/^\/(cy|en)/, ""); - //console.log("==============================", pathWithoutLocale); + if (cookies.pedw_locale) preferredLocale = cookies.pedw_locale; + // (Optional) redirect logic (kept commented as in your newer file) + // const pathWithoutLocale = ctx.resolvedUrl.replace(/^\/(cy|en)/, ""); // if (preferredLocale !== locale) { // return { // redirect: { @@ -246,7 +253,7 @@ export const getServerSideProps = wrapper.getServerSideProps( const showReps = Boolean(process.env.SHOWREPRESENTATIONS); store.dispatch(setShowReps(showReps, showLoginCheck)); - // Filter watched cases where reps not submitted + // watched cases that are NOT submitted const filteredWatchedCases = { "@odata.count": watchedCases.value.filter( (c) => c.pinswg_representationsubmitted == null @@ -256,37 +263,31 @@ export const getServerSideProps = wrapper.getServerSideProps( ), }; - // Get submitted reps from watched cases - const mySubmittedReps = watchedCases.value.filter((el) => { - return el.pinswg_representationsubmitted != null; - }); + // submitted reps derived from watched cases + const mySubmittedReps = watchedCases.value.filter( + (el) => el.pinswg_representationsubmitted != null + ); - if (accountDetails.errorCode) { - return { - redirect: { - destination: "/myportal/error", - permanent: false, - }, - }; - } - - // Helper function for fetching details with concurrency limit + // Newer getDetails implementation (bounded concurrency, fewer edge-case bugs) const getDetails = async (resultsObj, detailsType) => { const limitRequests = pLimit(5); const arr = []; - resultsObj = + + const list = detailsType === "mySubmittedReps" ? resultsObj : resultsObj.value; - const tasks = resultsObj.map((item) => + const tasks = list.map((item) => limitRequests(async () => { try { let caseID = ""; + switch (detailsType) { case "myCases": caseID = item.pinswg_title; break; + case "myWatchedCases": case "mySubmittedReps": caseID = @@ -294,12 +295,15 @@ export const getServerSideProps = wrapper.getServerSideProps( "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" ]; break; + case "awaitingSubmission": caseID = item.ticketnumber; break; + case "myRepresentations": caseID = item.casereference; break; + default: caseID = item.pinswg_title; } @@ -309,10 +313,12 @@ export const getServerSideProps = wrapper.getServerSideProps( const collectionName = getFormCollectionByID( item.pinswg_appealcasetype ).LogicalCollectionName; + const details = await getPortalModuleDetails( collectionName, caseID ); + arr.push(details); } catch (err) { console.error("Error fetching details:", err); diff --git a/pages/myportal/representation.js b/pages/myportal/representation.js index 0ac8a33a..de7bce6e 100644 --- a/pages/myportal/representation.js +++ b/pages/myportal/representation.js @@ -317,7 +317,7 @@ export const getServerSideProps = wrapper.getServerSideProps( const repsFileListObj = await getRepsFilesBlobs( result.containerID, - result.caseRef, + result.ticketnumber, result.repfile_name ); diff --git a/pages/myportal/searchresults.js b/pages/myportal/searchresults.js index 839d2bbf..f263d7dd 100644 --- a/pages/myportal/searchresults.js +++ b/pages/myportal/searchresults.js @@ -100,20 +100,10 @@ export const getServerSideProps = wrapper.getServerSideProps( }, }; } else { - let [searchResultsObj, loggedInUser] = await Promise.all([ - await getBasicSearch(query.q), + let [loggedInUser] = await Promise.all([ await getPortalLogin(thisSession.user.email), ]); - searchResultsObj = - searchResultsObj.status == 502 - ? { - value: [], - errorCode: searchResultsObj.status, - errorMsg: searchResultsObj.statusText, - } - : searchResultsObj; - //console.log("sssss", searchResultsObj); loggedInUser = loggedInUser.value[0].contactid; @@ -122,15 +112,11 @@ export const getServerSideProps = wrapper.getServerSideProps( //console.log("sssss", loggedInUser); - const [accountDetails, searchDetailsObj, watchedCasesDetails] = - await Promise.all([ - await getPersonalAccount(loggedInUser), - await getSearchDetails(searchResultsObj), - await getDetails(watchedCases, "myWatchedCases"), - ]); + const [accountDetails, watchedCasesDetails] = await Promise.all([ + await getPersonalAccount(loggedInUser), + await getDetails(watchedCases, "myWatchedCases"), + ]); store.dispatch(setAccountDetails(accountDetails)); - store.dispatch(setSearchResults(searchResultsObj)); - store.dispatch(setSearchDetails(searchDetailsObj)); store.dispatch(setSearch(query.q)); store.dispatch(setWatchedCases(watchedCases)); store.dispatch(setWatchedCasesDetails(watchedCasesDetails));