Merge branch 'Development' into SIPS-Development

This commit is contained in:
2025-12-02 14:03:48 +00:00
14 changed files with 287 additions and 322 deletions
+42 -36
View File
@@ -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 (
<div>
@@ -94,7 +103,6 @@ const Home = (props) => {
property="twitter:site"
content="@UKGovWales"
/>
<meta
name="description"
content={t("common:service-description")}
@@ -135,6 +143,7 @@ const Home = (props) => {
/>
</>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header />
@@ -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);