moved alot of stuff from client side
This commit is contained in:
@@ -109,6 +109,49 @@ export default async function handler(req, res) {
|
||||
var checkHash = req.query.hash;
|
||||
let reqBodyobj = req.body; //JSON.parse(req.body);
|
||||
|
||||
const cleanFilesList = (blobList) => {
|
||||
let newblobList = blobList.filesList;
|
||||
function removeNullObjects(arr) {
|
||||
if (arr.length === 0) {
|
||||
return arr;
|
||||
}
|
||||
return arr.filter((obj) => obj !== null);
|
||||
}
|
||||
|
||||
function removeObjectsWithUndefinedKey(arr, key) {
|
||||
if (arr.length === 0) {
|
||||
return arr;
|
||||
}
|
||||
return arr.filter((obj) => obj[key] !== undefined);
|
||||
}
|
||||
|
||||
function removeEmptyObjects(arr) {
|
||||
if (arr.length === 0) {
|
||||
return arr;
|
||||
}
|
||||
return arr.filter(
|
||||
(obj) =>
|
||||
obj &&
|
||||
typeof obj === "object" &&
|
||||
Object.keys(obj).length > 0
|
||||
);
|
||||
}
|
||||
|
||||
newblobList = removeEmptyObjects(newblobList);
|
||||
newblobList = removeObjectsWithUndefinedKey(newblobList, "name");
|
||||
newblobList = removeNullObjects(newblobList);
|
||||
|
||||
Object.assign(blobList, {
|
||||
"filesList": newblobList,
|
||||
});
|
||||
|
||||
return blobList;
|
||||
};
|
||||
|
||||
reqBodyobj = reqBodyobj.hasOwnProperty("filesList")
|
||||
? cleanFilesList(reqBodyobj)
|
||||
: reqBodyobj;
|
||||
|
||||
console.log(
|
||||
"//////////////////////\nreqBodyobj" +
|
||||
req +
|
||||
|
||||
@@ -5,7 +5,16 @@ import { useEffect } from "react";
|
||||
import { getSession, useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/router";
|
||||
import { connect, useDispatch } from "react-redux";
|
||||
import { getPersonalAccount, getPortalLoginProxy } from "../../actions";
|
||||
import {
|
||||
getPersonalAccount,
|
||||
getPortalLoginProxy,
|
||||
getPortalLogin,
|
||||
getRepsFromBlob,
|
||||
getCase,
|
||||
getPortalModuleDetails,
|
||||
getBasicSearch,
|
||||
} from "../../actions";
|
||||
import { getFormCollectionByID } from "../../components/utils";
|
||||
import Breadcrumbs from "../../components/breadcrumbs";
|
||||
import CookieBanner from "../../components/cookieBanner";
|
||||
import Footer from "../../components/footer";
|
||||
@@ -16,13 +25,33 @@ import {
|
||||
setContainerID,
|
||||
setLoggedInUserId,
|
||||
} from "../../store/accountDetails/action";
|
||||
import { wrapper } from "../../store/store";
|
||||
import { getSearchDetails } from "../../components/utils";
|
||||
|
||||
import {
|
||||
setCurrentReference,
|
||||
setCurrentView,
|
||||
setRepresentationCapacity,
|
||||
} from "../../store/currentView/action";
|
||||
import {
|
||||
setSearchDetails,
|
||||
setSearchResults,
|
||||
} from "../../store/searchOutput/action";
|
||||
import { setSearch } from "../../store/search/action";
|
||||
|
||||
import NoSessionWarning from "../../components/nosession";
|
||||
import ServiceBanner from "../../components/myportal/servicebanner";
|
||||
import TimeOut from "../../components/timeout";
|
||||
|
||||
import {
|
||||
setMyRepresentations,
|
||||
setMyRepresentationsDetails,
|
||||
setMySubmittedReps,
|
||||
setMySubmittedRepsDetails,
|
||||
} from "../../store/myRepresentations/action";
|
||||
|
||||
const RepresentationF = (props) => {
|
||||
const { footerLinks, pages, accountDetails } = props;
|
||||
const { footerLinks, pages } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
@@ -31,34 +60,34 @@ const RepresentationF = (props) => {
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
const updateAccountStore = async () => {
|
||||
const thisSession = await getSession();
|
||||
// useEffect(() => {
|
||||
// const updateAccountStore = async () => {
|
||||
// const thisSession = await getSession();
|
||||
|
||||
if (thisSession) {
|
||||
let loggedInUser = await getPortalLoginProxy(
|
||||
thisSession.user.email
|
||||
);
|
||||
dispatch(
|
||||
setAccountDetails(
|
||||
await getPersonalAccount(
|
||||
loggedInUser.value[0].contactid
|
||||
)
|
||||
)
|
||||
);
|
||||
dispatch(setContainerID(thisSession.user.id));
|
||||
dispatch(setLoggedInUserId(loggedInUser.value[0].contactid));
|
||||
//dispatch(setRepresentationSubmit(true));
|
||||
}
|
||||
};
|
||||
updateAccountStore();
|
||||
}, [dispatch]);
|
||||
// if (thisSession) {
|
||||
// let loggedInUser = await getPortalLoginProxy(
|
||||
// thisSession.user.email
|
||||
// );
|
||||
// dispatch(
|
||||
// setAccountDetails(
|
||||
// await getPersonalAccount(
|
||||
// loggedInUser.value[0].contactid
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// dispatch(setContainerID(thisSession.user.id));
|
||||
// dispatch(setLoggedInUserId(loggedInUser.value[0].contactid));
|
||||
// //dispatch(setRepresentationSubmit(true));
|
||||
// }
|
||||
// };
|
||||
// updateAccountStore();
|
||||
// }, [dispatch]);
|
||||
|
||||
const { data: session, status } = useSession();
|
||||
|
||||
if (status === "loading") {
|
||||
return <NoSessionWarning loading={true} />;
|
||||
}
|
||||
// if (status === "loading") {
|
||||
// return <NoSessionWarning loading={true} />;
|
||||
// }
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -169,60 +198,241 @@ const RepresentationF = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
// export const getServerSideProps = wrapper.getServerSideProps(
|
||||
// (store) => async (ctx) => {
|
||||
// const { query, req, res } = ctx;
|
||||
// console.log("The query", query);
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
console.log("The query", query);
|
||||
|
||||
// const { cookies } = req;
|
||||
const { cookies } = req;
|
||||
|
||||
// let loggedInUserCookie = cookies.pinsUser;
|
||||
let loggedInUserCookie = cookies.pinsUser;
|
||||
|
||||
// let thisSession = await getSession(ctx);
|
||||
// let loggedInUser = {};
|
||||
let thisSession = await getSession(ctx);
|
||||
let loggedInUser = {};
|
||||
|
||||
// if (!thisSession) {
|
||||
// console.log("not has sesssion.......");
|
||||
// return {
|
||||
// redirect: {
|
||||
// destination: "/auth/signin",
|
||||
// permanent: false,
|
||||
// },
|
||||
// };
|
||||
// } else {
|
||||
// [loggedInUser] = await Promise.all([
|
||||
// await getPortalLogin(thisSession.user.email),
|
||||
// ]);
|
||||
if (!thisSession) {
|
||||
console.log("not has sesssion.......");
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
[loggedInUser] = await Promise.all([
|
||||
await getPortalLogin(thisSession.user.email),
|
||||
]);
|
||||
|
||||
// console.log(
|
||||
// "=====//////////=====",
|
||||
// thisSession,
|
||||
// thisSession.user.email,
|
||||
// loggedInUser
|
||||
// );
|
||||
// loggedInUser = loggedInUser.value[0].contactid;
|
||||
// }
|
||||
console.log(
|
||||
"=====//////////=====",
|
||||
thisSession,
|
||||
thisSession.user.email,
|
||||
loggedInUser
|
||||
);
|
||||
loggedInUser = loggedInUser.value[0].contactid;
|
||||
}
|
||||
|
||||
// const accountDetails = await getPersonalAccount(loggedInUser);
|
||||
const [accountDetails, myRepresentations] = await Promise.all([
|
||||
await getPersonalAccount(loggedInUser),
|
||||
await getRepsFromBlob(thisSession.user.id),
|
||||
]);
|
||||
|
||||
// console.log(accountDetails);
|
||||
// store.dispatch(setAccountDetails(accountDetails));
|
||||
// return {
|
||||
// props: {
|
||||
// containerID: thisSession.user.id,
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
// );
|
||||
const myRepresentationsDetails = await getDetails(
|
||||
myRepresentations,
|
||||
"myRepresentations"
|
||||
);
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
setAccountDetails: (loggedInUser) => {
|
||||
dispatch(setAccountDetails(loggedInUser));
|
||||
},
|
||||
};
|
||||
console.log(accountDetails);
|
||||
|
||||
const isLPA =
|
||||
accountDetails[
|
||||
"pinswg_typeofinvolvement@OData.Community.Display.V1.FormattedValue"
|
||||
] == "LPA"
|
||||
? true
|
||||
: false;
|
||||
|
||||
isLPA && store.dispatch(setRepresentationCapacity("lpa"));
|
||||
|
||||
if (query.hasOwnProperty("state")) {
|
||||
console.log("is lpa?:", isLPA);
|
||||
|
||||
store.dispatch(setContainerID(thisSession.user.id));
|
||||
store.dispatch(setMyRepresentations(myRepresentations));
|
||||
store.dispatch(
|
||||
setMyRepresentationsDetails(myRepresentationsDetails)
|
||||
);
|
||||
|
||||
function findObjectByKeyValue(arr, key, value) {
|
||||
return arr.find((obj) => obj[key] === value);
|
||||
}
|
||||
|
||||
const result = findObjectByKeyValue(
|
||||
myRepresentations.value,
|
||||
"repfile_name",
|
||||
query.created
|
||||
);
|
||||
|
||||
store.dispatch(
|
||||
setCurrentReference({
|
||||
"ticketnumber": result.ticketnumber,
|
||||
"currentReference": result.caseRef,
|
||||
"currentType": "myRepresentations",
|
||||
"incidentid": result.incidentID,
|
||||
"appealType": result.appealType,
|
||||
"repDetails": result,
|
||||
})
|
||||
);
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
|
||||
return {
|
||||
props: {
|
||||
containerID: thisSession.user.id,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
const searchResultsObj = await getBasicSearch(query.case);
|
||||
const searchDetailsObj = await getSearchDetails(searchResultsObj);
|
||||
|
||||
store.dispatch(setContainerID(thisSession.user.id));
|
||||
store.dispatch(setSearchResults(searchResultsObj));
|
||||
store.dispatch(setSearchDetails(searchDetailsObj));
|
||||
store.dispatch(setSearch(query.case));
|
||||
store.dispatch(
|
||||
setCurrentView({
|
||||
"viewName": "My Representations",
|
||||
"viewKey": "myRepresentations",
|
||||
})
|
||||
);
|
||||
store.dispatch(
|
||||
setCurrentReference({
|
||||
"ticketnumber": searchResultsObj.value[0].ticketnumber,
|
||||
"currentReference": searchResultsObj.value[0].title,
|
||||
"currentType": "myRepresentations",
|
||||
"incidentid": searchResultsObj.value[0].incidentid,
|
||||
"appealType":
|
||||
searchResultsObj.value[0].pinswg_appealcasetype,
|
||||
|
||||
"specialistProcess":
|
||||
searchDetailsObj[0].value[0]
|
||||
.pinswg_speacialistcaseprocess != null ||
|
||||
searchDetailsObj[0].value[0]
|
||||
.pinswg_specialistcaseprocess != null
|
||||
? searchDetailsObj[0].value[0]
|
||||
.pinswg_speacialistcaseprocess ||
|
||||
searchDetailsObj[0].value[0]
|
||||
.pinswg_specialistcaseprocess
|
||||
: "",
|
||||
})
|
||||
);
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
|
||||
// return {
|
||||
// props: {
|
||||
// searchResultsObj: {
|
||||
// searchResultsObj: searchResultsObj,
|
||||
// searchDetailsObj: searchDetailsObj,
|
||||
// },
|
||||
// containerID: thisSession.user.id,
|
||||
// },
|
||||
// };
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const getDetails = (resultsObj, detailsType) => {
|
||||
let detailsArr = [];
|
||||
|
||||
resultsObj =
|
||||
detailsType == "mySubmittedReps" ? resultsObj : resultsObj.value;
|
||||
|
||||
if (detailsType == "myRepresentations") {
|
||||
const repsObj = resultsObj.map((searchDetail, index) => {
|
||||
detailsArr.push(
|
||||
getCase(searchDetail["incidentID"]).then((data) => {
|
||||
let caseID = "";
|
||||
|
||||
switch (detailsType) {
|
||||
case "myCases":
|
||||
caseID = data.pinswg_title;
|
||||
break;
|
||||
case "myWatchedCases":
|
||||
case "mySubmittedReps":
|
||||
caseID =
|
||||
data[
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
];
|
||||
break;
|
||||
case "awaitingSubmission":
|
||||
case "myRepresentations":
|
||||
caseID = data.ticketnumber;
|
||||
break;
|
||||
default:
|
||||
caseID = data.pinswg_title;
|
||||
}
|
||||
return getPortalModuleDetails(
|
||||
getFormCollectionByID(data.pinswg_appealcasetype)
|
||||
.LogicalCollectionName,
|
||||
caseID
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// const detailsObj = resultsObj.map(async (searchDetail, index) => {
|
||||
// let caseID = "";
|
||||
|
||||
// switch (detailsType) {
|
||||
// case "myCases":
|
||||
// caseID = searchDetail.pinswg_title;
|
||||
// break;
|
||||
// case "myWatchedCases":
|
||||
// case "mySubmittedReps":
|
||||
// caseID =
|
||||
// searchDetail[
|
||||
// "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
// ];
|
||||
// break;
|
||||
// case "awaitingSubmission":
|
||||
// caseID = searchDetail.ticketnumber;
|
||||
// break;
|
||||
// case "myRepresentations":
|
||||
// caseID = searchDetail.casereference;
|
||||
// break;
|
||||
// default:
|
||||
// caseID = searchDetail.pinswg_title;
|
||||
// }
|
||||
|
||||
// console.log(detailsType, " case id : ", caseID);
|
||||
|
||||
// searchDetail.pinswg_appealcasetype != null &&
|
||||
// detailsArr.push(
|
||||
// getPortalModuleDetails(
|
||||
// getFormCollectionByID(searchDetail.pinswg_appealcasetype)
|
||||
// .LogicalCollectionName,
|
||||
// caseID
|
||||
// // detailsType != "myWatchedCases"
|
||||
// // ? searchDetail.ticketnumber
|
||||
// // : searchDetail[
|
||||
// // "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
// // ]
|
||||
// )
|
||||
// );
|
||||
// });
|
||||
|
||||
let detArr = Promise.all(detailsArr);
|
||||
console.log(detArr);
|
||||
return detArr;
|
||||
};
|
||||
|
||||
// const mapDispatchToProps = (dispatch) => {
|
||||
// return {
|
||||
// setAccountDetails: (loggedInUser) => {
|
||||
// dispatch(setAccountDetails(loggedInUser));
|
||||
// },
|
||||
// };
|
||||
// };
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
accountDetails: state.accountDetails,
|
||||
@@ -239,4 +449,4 @@ const mapStateToProps = (state) => {
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(RepresentationF);
|
||||
export default connect(mapStateToProps)(RepresentationF);
|
||||
|
||||
Reference in New Issue
Block a user