import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { getIP } from "../../actions/core/logger";
import { getPersonalAccount } from "../../actions/services/accountService";
import { getPortalModuleDetails } from "../../actions/services/caseService";
import {
getBasicDNSSearch,
getDNSCoords
} from "../../actions/services/searchService";
import { getWatchedCases } from "../../actions/services/portalService";
import Breadcrumbs from "../../components/breadcrumbs";
import CookieBanner from "../../components/cookieBanner";
import DNSSearchResults from "../../components/dnssearchresults";
import Footer from "../../components/footer";
import Header from "../../components/header";
import {
getFormCollectionByID,
getSearchDetails
} from "../../components/utils";
import {
setLoggedInUserId,
setAccountDetails
} from "../../store/accountDetails/action";
import { setSearch } from "../../store/search/action";
import {
setDNSCoords,
setSearchDetails,
setSearchResults
} from "../../store/searchOutput/action";
import { wrapper } from "../../store/store";
import {
setWatchedCases,
setWatchedCasesDetails
} from "../../store/watchedCases/action";
import { getSession } from "next-auth/react";
import ServiceBanner from "../../components/myportal/servicebanner";
const Home = (props) => {
const { footerLinks, pages, watchedCases, showMap } = props;
let { t, lang } = useTranslation();
const router = useRouter();
const { appealtypes } = router.query;
return (
{t("search:page-title")} - {t("common:service-name")}
<>
{/* If they have a Twitter Handle, include the meta details below */}
>
);
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
getIP(req);
console.log("query-", query);
res.setHeader(
"Cache-Control",
"public, s-maxage=10, stale-while-revalidate=59"
);
let loggedInUser = req.cookies.pinsUser;
let thisSession = await getSession(ctx);
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
} else {
let [accountDetails, watchedCases] = await Promise.all([
getPersonalAccount(loggedInUser),
getWatchedCases(loggedInUser)
]);
// searchResultsObj =
// searchResultsObj.status == 502
// ? {
// value: [],
// errorCode: searchResultsObj.status,
// errorMsg: searchResultsObj.statusText,
// }
// : searchResultsObj;
const showMapCheck = process.env.SHOWMAPS || false;
const watchedCasesDetails = await getDetails(
watchedCases,
"myWatchedCases"
);
const dnsCoords = await getDNSCoords();
// store.dispatch(setSearchResults(searchResultsObj));
// store.dispatch(setSearchDetails(searchDetailsObj));
store.dispatch(setSearch("DNS"));
store.dispatch(setDNSCoords(dnsCoords));
store.dispatch(setWatchedCases(watchedCases));
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
store.dispatch(setLoggedInUserId(loggedInUser));
store.dispatch(setAccountDetails(accountDetails));
return {
props: { showMap: showMapCheck }
};
}
}
);
const getDetails = (resultsObj, detailsType) => {
let detailsArr = [];
resultsObj = resultsObj.value;
const detailsObj = resultsObj.map((searchDetail) => {
if (searchDetail.pinswg_appealcasetype == null) {
console.log(
detailsType != "myWatchedCases"
? searchDetail.ticketnumber
: searchDetail[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
]
);
} else {
detailsArr.push(
getPortalModuleDetails(
getFormCollectionByID(searchDetail.pinswg_appealcasetype)
.LogicalCollectionName,
detailsType != "myWatchedCases"
? searchDetail.ticketnumber
: searchDetail[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
]
)
);
}
});
return Promise.all(detailsArr);
};
const mapStateToProps = (state) => {
return {
currentView: state.currentView,
search: state.search,
searchResultsObj: state.searchResultsObj,
formData: state.formData,
appealType: state.appealType,
form: state.form,
myCases: state.myCases,
watchedCases: state.watchedCases,
myRepresentations: state.myRepresentations,
awaitingSubmission: state.awaitingSubmission,
accountDetails: state.accountDetails
};
};
export default connect(mapStateToProps)(Home);