import useTranslation from "next-translate/useTranslation"; import Head from "next/head"; import { useRouter } from "next/router"; import { connect } from "react-redux"; import { getBasicSearch, getIP, getPortalLogin, getPersonalAccount, getWatchedCases, getPortalModuleDetails, getMyCases, getMyLPACases, } from "../../../actions"; import { getFormCollectionByID } from "../../../components/utils"; import CookieBanner from "../../../components/cookieBanner"; import Footer from "../../../components/footer"; import Header from "../../../components/header"; import { getSearchDetails } from "../../../components/utils"; import { setCurrentReference, setCurrentView, } from "../../../store/currentView/action"; import { setSearch } from "../../../store/search/action"; import { setSearchDetails, setSearchResults, } from "../../../store/searchOutput/action"; import { wrapper } from "../../../store/store"; import Case from "../../../components/case"; import Breadcrumbs from "../../../components/breadcrumbs"; import { getSession, useSession } from "next-auth/react"; import { setAccountDetails, setContainerID, setLoggedInUserId, } from "../../../store/accountDetails/action"; import { setMyRepresentations, setMyRepresentationsDetails, setMySubmittedReps, setMySubmittedRepsDetails, } from "../../../store/myRepresentations/action"; import { setWatchedCases, setWatchedCasesDetails, } from "../../../store/watchedCases/action"; import { setMyCases, setMyCasesDetails } from "../../../store/myCases/action"; const CaseHome = (props) => { const { footerLinks, pages, setSearchResults, setSearchDetails } = props; let { t, lang } = useTranslation(); const router = useRouter(); const { locale } = router; const { ticketnumber } = router.query; return (
Reference:{" "} {props.currentView.caseReference.currentReference}{" "}
); }; export const getServerSideProps = wrapper.getServerSideProps( (store) => async (ctx) => { const { query, req, res } = ctx; getIP(req); const { cookies } = req; console.log(cookies); console.log("the query :", query.ticketnumber); console.log("viewkey:" + query.hasOwnProperty("key") ? "yes" : "no"); const showLoginCheck = process.env.SHOWLOGIN || false; let thisSession = await getSession(ctx); let loggedInUser = {}; if (thisSession) { console.log(" has sesssion......."); [loggedInUser] = await Promise.all([ await getPortalLogin(thisSession.user.email), ]); loggedInUser = loggedInUser.value[0].contactid; } else { console.log("not has sesssion......."); return { redirect: { destination: "/auth/signin", permanent: false, }, }; } const accountDetails = await getPersonalAccount(loggedInUser); store.dispatch(setContainerID(thisSession.user.id)); store.dispatch(setAccountDetails(accountDetails)); store.dispatch(setLoggedInUserId(loggedInUser)); let developmentQuery = query.ticketnumber.indexOf("CAS-") == 0 ? query.ticketnumber : query.ticketnumber.split("-").join(" "); const searchResultsObj = await getBasicSearch(developmentQuery); const searchDetailsObj = await getSearchDetails(searchResultsObj); //console.log( // "\n======================================\n", // searchResultsObj, // "\n======================================\n" // ); //console.log( // "\n======================================\n", // searchDetailsObj[0], // "\n======================================\n" // ); store.dispatch(setSearch(developmentQuery)); console.log( searchResultsObj["@odata.count"] > 1 || searchResultsObj["@odata.count"] < 1 ); if (searchResultsObj["@odata.count"] < 1) { return { redirect: { destination: "/404", permanent: false, }, }; } else { if (searchResultsObj["@odata.count"] > 1) { return { redirect: { //destination: "/dns-not-found", destination: "/404", permanent: false, }, }; } else { if (query.hasOwnProperty("key")) { let whichViewKey = query.key; switch (whichViewKey) { case "awaitingSubmissionDetails": store.dispatch( setCurrentView({ "viewName": "Awaiting Submission", "viewKey": "awaitingSubmissionDetails", }) ); break; case "watchedCases": const watchedCases = await getWatchedCases( loggedInUser ); let showWatchedCases = (submittedArr) => { const required = submittedArr.value.filter( (el) => { return ( el.pinswg_representationsubmitted == null ); } ); let newObj = {}; return Object.assign(newObj, { "@odata.count": required.length, "value": required, }); }; let filteredWatchedCases = showWatchedCases(watchedCases); const watchedCasesDetails = await getDetails( filteredWatchedCases, "myWatchedCases" ); store.dispatch( setWatchedCases(filteredWatchedCases) ); store.dispatch( setWatchedCasesDetails(watchedCasesDetails) ); store.dispatch( setCurrentView({ "viewName": "Watched Cases", "viewKey": "watchedCases", }) ); break; case "myCases": const myCases = accountDetails.pinswg_typeofinvolvement == 846040012 ? await getMyLPACases(lpaid) : await getMyCases(loggedInUser); const myCasesDetails = await getDetails( myCases, "myCases" ); store.dispatch(setMyCases(myCases)); store.dispatch(setMyCasesDetails(myCasesDetails)); store.dispatch( setCurrentView({ "viewName": "My Cases", "viewKey": "myCases", }) ); break; case "myRepresentations": const myRepresentations = await getRepsFromBlob( thisSession.user.id ); const myRepresentationsDetails = await getDetails( myRepresentations, "myRepresentations" ); store.dispatch( setMyRepresentations(myRepresentations) ); store.dispatch( setMyRepresentationsDetails( myRepresentationsDetails ) ); store.dispatch( setCurrentView({ "viewName": "My Representations", "viewKey": "myRepresentations", }) ); default: // code block } } store.dispatch(setSearchResults(searchResultsObj)); store.dispatch(setSearchDetails(searchDetailsObj)); store.dispatch( setCurrentReference({ "ticketnumber": searchResultsObj.value[0].ticketnumber, "currentReference": searchResultsObj.value[0].title, "currentType": "searchResultsObj", "incidentid": searchResultsObj.value[0].incidentid, "appealType": searchResultsObj.value[0].pinswg_appealcasetype, "showLoginCheck": showLoginCheck, "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 : "", }) ); } } //console.log(searchResultsObj); //console.log(loggedInUser); return { props: { // searchResultsObj: { // searchResultsObj: searchResultsObj, // searchDetailsObj: searchDetailsObj, // }, currentType: "directResultsObj", }, }; } ); const getDetails = (resultsObj, detailsType) => { let detailsArr = []; //console.log( // "//////////////////////////////////\n", // resultsObj, // //"\n", // detailsType, // "\n//////////////////////////////////\n" // ); resultsObj = detailsType == "mySubmittedReps" ? resultsObj : resultsObj.value; //console.log( // "////////////////////////////////// resultsobj\n", // detailsType, // "\n", // resultsObj.length + "\n//////////////////////////////////\n" // ); if (detailsType == "myRepresentations") { const repsObj = resultsObj.map((searchDetail, index) => { //console.log(".......... ", searchDetail); 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": caseID = data.ticketnumber; break; case "myRepresentations": caseID = data.ticketnumber; break; default: caseID = data.pinswg_title; } return getPortalModuleDetails( getFormCollectionByID(data.pinswg_appealcasetype) .LogicalCollectionName, caseID ); }) ); }); } const detailsObj = resultsObj.map((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 mapStateToProps = (state) => { return { accountDetails: state.accountDetails, currentView: state.currentView, search: state.search, searchResultsObj: state.searchResultsObj, documentDetailsObj: state.searchResultsObj.documentDetailsObj, formData: state.formData, appealType: state.appealType, form: state.form, myCases: state.myCases, watchedCases: state.watchedCases, myRepresentations: state.myRepresentations, awaitingSubmission: state.awaitingSubmission, }; }; const mapDispatchToProps = (dispatch) => { return { setCurrentReference: (currentReference) => { dispatch(setCurrentReference(refno)); }, setSearchResults: (searchResults) => { dispatch(setSearchResults(searchResults)); }, setSearchDetails: (searchDetails) => { dispatch(setSearchDetails(searchDetails)); }, setLoggedInUserId: (loggedInUser) => { dispatch(setLoggedInUserId(loggedInUser)); }, }; }; export default connect(mapStateToProps, mapDispatchToProps)(CaseHome);