refactor appeal for new and resume
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// lib/newappeal/hydrateNewAppealStore.js
|
||||
import {
|
||||
setContainerID,
|
||||
setLoggedInUserEmail,
|
||||
setLoggedInUserId,
|
||||
setAccountDetails,
|
||||
} from "../../store/accountDetails/action";
|
||||
import {
|
||||
setAppealLPA,
|
||||
setAppealType,
|
||||
setAppealTypeID,
|
||||
// IMPORTANT: avoid name collision in your page by importing as Action
|
||||
setCaseReference as setCaseReferenceAction,
|
||||
} from "../../store/appealType/action";
|
||||
import { setForm } from "../../store/formData/action";
|
||||
|
||||
/**
|
||||
* Dispatches all actions needed to hydrate Redux store for the page.
|
||||
*/
|
||||
export function hydrateNewAppealStore(store, query, data) {
|
||||
const {
|
||||
session,
|
||||
loggedInUser,
|
||||
loggedInUserEmail,
|
||||
appealTypeData,
|
||||
mandatoryFieldsData,
|
||||
pickListData,
|
||||
blobProgress,
|
||||
accountDetails,
|
||||
xmlStr,
|
||||
} = data;
|
||||
|
||||
const caseReference = {
|
||||
ticketnumber: query.id,
|
||||
incidentid: query.id,
|
||||
caseDetails: blobProgress,
|
||||
};
|
||||
|
||||
store.dispatch(setLoggedInUserId(loggedInUser));
|
||||
store.dispatch(setLoggedInUserEmail(loggedInUserEmail));
|
||||
store.dispatch(setAppealLPA(query.lpa));
|
||||
store.dispatch(setAppealTypeID(query.apt));
|
||||
store.dispatch(setCaseReferenceAction(caseReference));
|
||||
store.dispatch(setForm(xmlStr, mandatoryFieldsData, pickListData));
|
||||
store.dispatch(setAppealType(appealTypeData));
|
||||
store.dispatch(setContainerID(session.user.id));
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// lib/newappeal/loadNewAppealPage.js
|
||||
import { getSession } from "next-auth/react";
|
||||
import {
|
||||
getAppealsTypesForNewAppeal,
|
||||
getIP,
|
||||
getMandatoryFields,
|
||||
getPickLists,
|
||||
getProgressFromBlob,
|
||||
getPersonalAccount,
|
||||
} from "../../actions";
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user