92 lines
2.5 KiB
JavaScript
92 lines
2.5 KiB
JavaScript
// lib/myportal/loadMyPortalAppealPage.js
|
|
import { getSession } from "next-auth/react";
|
|
import {
|
|
getAppealsTypesForNewAppeal,
|
|
getAwaitingSubmissionFromBlob,
|
|
getFilesFromBlob,
|
|
getIP,
|
|
getMandatoryFields,
|
|
getPickLists,
|
|
getProgressFromBlob,
|
|
getPersonalAccount,
|
|
} from "../../actions";
|
|
|
|
import { readFormXml } from "../forms/readFormXml";
|
|
import { requireQueryParams } from "../routing/requireQueryParams";
|
|
|
|
/**
|
|
* Loader for "resume appeal" in /myportal/[appealtypes]
|
|
*/
|
|
export async function loadMyPortalAppealPage(ctx) {
|
|
const { query, req } = ctx;
|
|
|
|
getIP(req);
|
|
|
|
// Required params for resume flow (adjust if your routes always provide them)
|
|
// casereference is the main identifier here
|
|
const required = requireQueryParams(query, [
|
|
"appealtypes",
|
|
"apt",
|
|
"casereference",
|
|
]);
|
|
if (!required.ok) {
|
|
return { redirect: required.redirect };
|
|
}
|
|
|
|
const session = await getSession(ctx);
|
|
if (!session) {
|
|
return {
|
|
redirect: {
|
|
destination: "/auth/signin",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
const { cookies } = req;
|
|
const loggedInUser = cookies?.pinsUser;
|
|
const loggedInUserIdent = session.user.id;
|
|
const loggedInUserEmail = session.user.email;
|
|
|
|
const accountDetails = await getPersonalAccount(loggedInUser);
|
|
|
|
// Fetch config + blob assets in parallel
|
|
const [appealTypeData, mandatoryFieldsData, pickListData, blobList] =
|
|
await Promise.all([
|
|
getAppealsTypesForNewAppeal(),
|
|
getMandatoryFields(query.appealtypes),
|
|
getPickLists(query.appealtypes),
|
|
getFilesFromBlob(loggedInUserIdent, query.casereference),
|
|
]);
|
|
|
|
const blobProgress = await getProgressFromBlob(
|
|
loggedInUserIdent,
|
|
query.casereference
|
|
);
|
|
|
|
// Optional: awaiting-submission view setup when query.key exists
|
|
let awaitingSubmissionFromBlob = null;
|
|
if (Object.prototype.hasOwnProperty.call(query, "key")) {
|
|
awaitingSubmissionFromBlob = await getAwaitingSubmissionFromBlob(
|
|
session.user.id
|
|
);
|
|
}
|
|
|
|
const { xmlStr } = readFormXml(query.appealtypes);
|
|
|
|
return {
|
|
session,
|
|
loggedInUser,
|
|
loggedInUserIdent,
|
|
loggedInUserEmail,
|
|
appealTypeData,
|
|
mandatoryFieldsData,
|
|
pickListData,
|
|
blobList,
|
|
blobProgress,
|
|
accountDetails,
|
|
awaitingSubmissionFromBlob,
|
|
xmlStr,
|
|
};
|
|
}
|