Merged PR 2665: 25470 testing authentication handler
Related work items: #25470
This commit is contained in:
+327
-10
@@ -11,7 +11,63 @@ import ViewAll from "../../components/myportal/viewall";
|
||||
import NoSessionWarning from "../../components/nosession";
|
||||
import TimeOut from "../../components/timeout";
|
||||
import ServiceBanner from "../../components/myportal/servicebanner";
|
||||
import { getSession } from "next-auth/react";
|
||||
import pLimit from "p-limit";
|
||||
|
||||
import {
|
||||
getPersonalAccount,
|
||||
getPortalLogin
|
||||
} from "../../actions/services/accountService";
|
||||
|
||||
import { getPortalModuleDetails } from "../../actions/services/caseService";
|
||||
|
||||
import {
|
||||
getAwaitingSubmissionFromBlob,
|
||||
getRepsFromBlob
|
||||
} from "../../actions/services/documentService";
|
||||
|
||||
import {
|
||||
getMyCases,
|
||||
getMyLPACases,
|
||||
getWatchedCases
|
||||
} from "../../actions/services/portalService";
|
||||
|
||||
import { getBasicSearch } from "../../actions/services/searchService";
|
||||
|
||||
import { splitWatchedCasesBySubmissionState } from "../../lib/domain/dashboard-policy";
|
||||
|
||||
import { getFormCollectionByID } from "../../components/utils";
|
||||
|
||||
import {
|
||||
setAccountDetails,
|
||||
setContainerID,
|
||||
setLoggedInUserId
|
||||
} from "../../store/accountDetails/action";
|
||||
|
||||
import {
|
||||
setAwaitingSubmissionDetails,
|
||||
setAwaitingSubmissionFromBlob
|
||||
} from "../../store/awaitingSubmission/action";
|
||||
|
||||
import { setCurrentView } from "../../store/currentView/action";
|
||||
|
||||
import { setMyCases, setMyCasesDetails } from "../../store/myCases/action";
|
||||
|
||||
import {
|
||||
setMyRepresentations,
|
||||
setMyRepresentationsDetails,
|
||||
setMySubmittedReps,
|
||||
setMySubmittedRepsDetails
|
||||
} from "../../store/myRepresentations/action";
|
||||
|
||||
import {
|
||||
setWatchedCases,
|
||||
setWatchedCasesDetails
|
||||
} from "../../store/watchedCases/action";
|
||||
|
||||
import { setSearchResults } from "../../store/searchOutput/action";
|
||||
import { setSearch } from "../../store/search/action";
|
||||
import { wrapper } from "../../store/store";
|
||||
const Home = (props) => {
|
||||
const { footerLinks, pages } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
@@ -39,7 +95,7 @@ const Home = (props) => {
|
||||
),
|
||||
"myRepresentations": t("common:myrepresentations-viewall-title"),
|
||||
"watchedCases": t("common:watchedcases-viewall-title"),
|
||||
"mySubmittedReps": t("common:mysubmittedreps-viewall-title"),
|
||||
"mySubmittedReps": t("common:mysubmittedreps-viewall-title")
|
||||
};
|
||||
|
||||
function whichTitle(key) {
|
||||
@@ -83,14 +139,275 @@ const Home = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
// export const getServerSideProps = wrapper.getServerSideProps(
|
||||
// (store) =>
|
||||
// async ({ req, res }) => {
|
||||
// const searchResultsObj = (await getBasicSearch("View All")) || null;
|
||||
// store.dispatch(setSearchResults(searchResultsObj));
|
||||
// store.dispatch(setSearch("View All"));
|
||||
// }
|
||||
// );
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query } = ctx;
|
||||
|
||||
// The View All component uses router.query.key.
|
||||
const viewKey = Array.isArray(query.key) ? query.key[0] : query.key;
|
||||
console.log("[ViewAll SSR] Query:", ctx.query);
|
||||
console.log("[ViewAll SSR] Selected viewKey:", viewKey);
|
||||
const validViewKeys = [
|
||||
"myCases",
|
||||
"watchedCases",
|
||||
"mySubmittedReps",
|
||||
"myRepresentations",
|
||||
"awaitingSubmissionDetails"
|
||||
];
|
||||
|
||||
if (!validViewKeys.includes(viewKey)) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/myportal",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Authenticate before retrieving portal data.
|
||||
const thisSession = await getSession(ctx);
|
||||
|
||||
if (!thisSession?.user?.email) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const portalLogin = await getPortalLogin(thisSession.user.email);
|
||||
|
||||
const loggedInUser = portalLogin?.value?.[0]?.contactid;
|
||||
|
||||
if (!loggedInUser) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const accountDetails = await getPersonalAccount(loggedInUser);
|
||||
|
||||
if (!accountDetails || accountDetails.errorCode) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/myportal/error",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Preserve the LPA logic from MyPortal index.
|
||||
const isLPA = accountDetails.pinswg_typeofinvolvement === 846040012;
|
||||
|
||||
const lpaId =
|
||||
accountDetails[
|
||||
"pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue"
|
||||
];
|
||||
|
||||
// Full-list detail enrichment.
|
||||
// No dashboard limit is applied here.
|
||||
const getDetails = async (resultsObj, detailsType) => {
|
||||
const limitRequests = pLimit(5);
|
||||
|
||||
const list = Array.isArray(resultsObj)
|
||||
? resultsObj
|
||||
: (resultsObj?.value ?? []);
|
||||
|
||||
const tasks = list.map((item) =>
|
||||
limitRequests(async () => {
|
||||
try {
|
||||
let caseID = "";
|
||||
|
||||
switch (detailsType) {
|
||||
case "myCases":
|
||||
caseID = item.ticketnumber;
|
||||
break;
|
||||
|
||||
case "myWatchedCases":
|
||||
case "mySubmittedReps":
|
||||
caseID =
|
||||
item[
|
||||
"_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;
|
||||
}
|
||||
|
||||
if (!item.pinswg_appealcasetype || !caseID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const formCollection = getFormCollectionByID(
|
||||
item.pinswg_appealcasetype
|
||||
);
|
||||
|
||||
if (!formCollection?.LogicalCollectionName) {
|
||||
console.error(
|
||||
"Missing collection metadata for appeal type:",
|
||||
item.pinswg_appealcasetype
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
(await getPortalModuleDetails(
|
||||
formCollection.LogicalCollectionName,
|
||||
caseID
|
||||
)) || {}
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Error fetching View All details:", err);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
const details = await Promise.all(tasks);
|
||||
|
||||
// Retain the original result ordering.
|
||||
return details.filter(Boolean);
|
||||
};
|
||||
|
||||
// Shared account state.
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
store.dispatch(setLoggedInUserId(loggedInUser));
|
||||
store.dispatch(setContainerID(thisSession.user.id));
|
||||
|
||||
// Ensure the rendered View All category agrees
|
||||
// with the category loaded by this request.
|
||||
store.dispatch(
|
||||
setCurrentView({
|
||||
viewKey,
|
||||
viewName: viewKey
|
||||
})
|
||||
);
|
||||
|
||||
switch (viewKey) {
|
||||
case "myCases": {
|
||||
const myCases = isLPA
|
||||
? await getMyLPACases(lpaId)
|
||||
: await getMyCases(loggedInUser);
|
||||
|
||||
const myCasesDetails = await getDetails(myCases, "myCases");
|
||||
|
||||
store.dispatch(setMyCases(myCases));
|
||||
store.dispatch(setMyCasesDetails(myCasesDetails));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "watchedCases": {
|
||||
const watchedCases = await getWatchedCases(loggedInUser);
|
||||
|
||||
const { watchedCases: filteredWatchedCases } =
|
||||
splitWatchedCasesBySubmissionState(
|
||||
watchedCases.value ?? []
|
||||
);
|
||||
|
||||
const watchedCasesDetails = await getDetails(
|
||||
filteredWatchedCases,
|
||||
"myWatchedCases"
|
||||
);
|
||||
|
||||
store.dispatch(setWatchedCases(filteredWatchedCases));
|
||||
|
||||
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "mySubmittedReps": {
|
||||
const watchedCases = await getWatchedCases(loggedInUser);
|
||||
|
||||
const { submittedRepresentations: mySubmittedReps } =
|
||||
splitWatchedCasesBySubmissionState(
|
||||
watchedCases.value ?? []
|
||||
);
|
||||
|
||||
const mySubmittedRepsDetails = await getDetails(
|
||||
mySubmittedReps,
|
||||
"mySubmittedReps"
|
||||
);
|
||||
|
||||
store.dispatch(setMySubmittedReps(mySubmittedReps));
|
||||
|
||||
store.dispatch(
|
||||
setMySubmittedRepsDetails(mySubmittedRepsDetails)
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "myRepresentations": {
|
||||
const myRepresentations = await getRepsFromBlob(
|
||||
thisSession.user.id
|
||||
);
|
||||
|
||||
// The existing View All component reads
|
||||
// representation display data directly
|
||||
// from myRepresentations.value.
|
||||
store.dispatch(setMyRepresentations(myRepresentations));
|
||||
|
||||
// Preserve the existing Redux detail
|
||||
// collection contract.
|
||||
const myRepresentationsDetails = await getDetails(
|
||||
myRepresentations,
|
||||
"myRepresentations"
|
||||
);
|
||||
|
||||
store.dispatch(
|
||||
setMyRepresentationsDetails(myRepresentationsDetails)
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "awaitingSubmissionDetails": {
|
||||
const awaitingSubmissionFromBlob =
|
||||
await getAwaitingSubmissionFromBlob(thisSession.user.id);
|
||||
|
||||
// Awaiting submission already has its
|
||||
// own Blob-backed data structure.
|
||||
// Preserve the dashboard's existing
|
||||
// Redux dispatches.
|
||||
store.dispatch(
|
||||
setAwaitingSubmissionFromBlob(awaitingSubmissionFromBlob)
|
||||
);
|
||||
|
||||
store.dispatch(
|
||||
setAwaitingSubmissionDetails(awaitingSubmissionFromBlob)
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Preserve the original View All search state.
|
||||
const searchResultsObj = (await getBasicSearch("View All")) || null;
|
||||
|
||||
store.dispatch(setSearchResults(searchResultsObj));
|
||||
|
||||
store.dispatch(setSearch("View All"));
|
||||
|
||||
return {
|
||||
props: {}
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
@@ -105,7 +422,7 @@ const mapStateToProps = (state) => {
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
currentView: state.currentView,
|
||||
mySubmittedReps: state.myRepresentations.mySubmittedReps,
|
||||
mySubmittedReps: state.myRepresentations.mySubmittedReps
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user