70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
// lib/newappeal/loadNewAppealPage.js
|
|
import { getSession } from "next-auth/react";
|
|
import {
|
|
getAppealsTypesForNewAppeal,
|
|
getMandatoryFields,
|
|
getPickLists
|
|
} from "../../actions/services/referenceDataService";
|
|
import { getProgressFromBlob } from "../../actions/services/documentService";
|
|
import { getPersonalAccount } from "../../actions/services/accountService";
|
|
import { getIP } from "../../actions/core/logger";
|
|
import { readFormXml } from "../forms/readFormXml";
|
|
import { requireQueryParams } from "../routing/requireQueryParams";
|
|
|
|
/**
|
|
* Loads everything needed for New Appeal SSR.
|
|
* Returns { redirect } on auth/query issues, otherwise returns a data object.
|
|
*/
|
|
export async function loadNewAppealPage(ctx) {
|
|
const { query, req } = ctx;
|
|
|
|
// Preserve existing behaviour
|
|
getIP(req);
|
|
|
|
// Validate required params early (adjust keys if needed)
|
|
const required = requireQueryParams(query, ["appealtypes", "apt", "id"]);
|
|
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; // existing cookie usage
|
|
const loggedInUserIdent = session.user.id;
|
|
const loggedInUserEmail = session.user.email;
|
|
|
|
const [appealTypeData, mandatoryFieldsData, pickListData] =
|
|
await Promise.all([
|
|
getAppealsTypesForNewAppeal(),
|
|
getMandatoryFields(query.appealtypes),
|
|
getPickLists(query.appealtypes)
|
|
]);
|
|
|
|
const blobProgress = await getProgressFromBlob(loggedInUserIdent, query.id);
|
|
const accountDetails = await getPersonalAccount(loggedInUser);
|
|
|
|
const { xmlStr } = readFormXml(query.appealtypes);
|
|
|
|
return {
|
|
session,
|
|
loggedInUser,
|
|
loggedInUserIdent,
|
|
loggedInUserEmail,
|
|
appealTypeData,
|
|
mandatoryFieldsData,
|
|
pickListData,
|
|
blobProgress,
|
|
accountDetails,
|
|
xmlStr
|
|
};
|
|
}
|