149 lines
4.9 KiB
JavaScript
149 lines
4.9 KiB
JavaScript
import useTranslation from "next-translate/useTranslation";
|
|
import Head from "next/head";
|
|
import { useRouter } from "next/router";
|
|
import { connect } from "react-redux";
|
|
import {
|
|
getBasicSearch,
|
|
getPortalModuleDetails,
|
|
getWatchedCases,
|
|
} from "../../actions";
|
|
import Breadcrumbs from "../../components/breadcrumbs";
|
|
import CookieBanner from "../../components/cookieBanner";
|
|
import Footer from "../../components/footer";
|
|
import Header from "../../components/header";
|
|
import SearchResults from "../../components/searchresults";
|
|
import {
|
|
getFormCollectionByID,
|
|
getSearchDetails,
|
|
} from "../../components/utils";
|
|
import { setSearch } from "../../store/search/action";
|
|
import {
|
|
setSearchDetails,
|
|
setSearchResults,
|
|
} from "../../store/searchOutput/action";
|
|
import { wrapper } from "../../store/store";
|
|
import {
|
|
setWatchedCases,
|
|
setWatchedCasesDetails,
|
|
} from "../../store/watchedCases/action";
|
|
|
|
const Home = (props) => {
|
|
const { footerLinks, pages, watchedCases } = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
const { appealtypes } = router.query;
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>
|
|
{t("search:page-title")} - {t("common:service-name")}
|
|
</title>
|
|
</Head>
|
|
<div id="page_wrapper">
|
|
<CookieBanner />
|
|
<Header courseName={t("common:service-name")} />
|
|
<div className="govuk-width-container">
|
|
<Breadcrumbs slug={appealtypes} />
|
|
<SearchResults
|
|
searchString={props.search.searchString}
|
|
searchResultsObj={props.searchResultsObj}
|
|
myportal={true}
|
|
watchedCases={watchedCases}
|
|
/>
|
|
</div>
|
|
<Footer footerLinks={footerLinks} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) => async (ctx) => {
|
|
const { query, req, res } = ctx;
|
|
console.log("query-", query);
|
|
|
|
const { cookies } = req;
|
|
|
|
let loggedInUser = cookies.pinsUser;
|
|
|
|
let [searchResultsObj, watchedCases] = await Promise.all([
|
|
await getBasicSearch(query.q),
|
|
await getWatchedCases(loggedInUser),
|
|
]);
|
|
|
|
searchResultsObj =
|
|
searchResultsObj.status == 502
|
|
? {
|
|
value: [],
|
|
errorCode: searchResultsObj.status,
|
|
errorMsg: searchResultsObj.statusText,
|
|
}
|
|
: searchResultsObj;
|
|
|
|
//console.log("sssss", searchResultsObj);
|
|
|
|
const [searchDetailsObj, watchedCasesDetails] = await Promise.all([
|
|
await getSearchDetails(searchResultsObj),
|
|
await getDetails(watchedCases, "myWatchedCases"),
|
|
]);
|
|
|
|
store.dispatch(setSearchResults(searchResultsObj));
|
|
store.dispatch(setSearchDetails(searchDetailsObj));
|
|
store.dispatch(setSearch(query.q));
|
|
store.dispatch(setWatchedCases(watchedCases));
|
|
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
|
}
|
|
);
|
|
|
|
const getDetails = (resultsObj, detailsType) => {
|
|
//console.log(resultsObj);
|
|
let detailsArr = [];
|
|
resultsObj = resultsObj.value;
|
|
const detailsObj = resultsObj.map((searchDetail, index) => {
|
|
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"
|
|
]
|
|
)
|
|
);
|
|
}
|
|
});
|
|
//console.log(detailsArr);
|
|
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);
|