116 lines
3.7 KiB
JavaScript
116 lines
3.7 KiB
JavaScript
import _ from "lodash";
|
|
import Head from "next/head";
|
|
import Header from "../../components/header";
|
|
import Banner from "../../components/banner";
|
|
import CookieBanner from "../../components/cookieBanner";
|
|
import Breadcrumbs from "../../components/breadcrumbs";
|
|
import SearchResults from "../../components/searchresults";
|
|
import Footer from "../../components/footer";
|
|
import Errorpage from "../../components/errorpage";
|
|
import styles from "../../styles/Home.module.css";
|
|
import { useSelector, shallowEqual, connect } from "react-redux";
|
|
import { wrapper } from "../../store/store";
|
|
|
|
import { useRouter } from "next/router";
|
|
import useTranslation from "next-translate/useTranslation";
|
|
import jsonpath from "jsonpath";
|
|
import data from "../../data/collections.json";
|
|
|
|
import { getSearchDetails } from "../../components/utils";
|
|
import { setSearch, getSearchObj } from "../../store/search/action";
|
|
import {
|
|
setSearchResults,
|
|
setSearchDetails,
|
|
setDocumentDetails,
|
|
setDocumentHistory,
|
|
getSearchResultsObj,
|
|
} from "../../store/searchOutput/action";
|
|
import {
|
|
getBasicSearch,
|
|
getBasicSearchDetails,
|
|
getSearchDocumentDetails,
|
|
getSearchDocumentHistory,
|
|
getSASToken,
|
|
} from "../../actions";
|
|
|
|
const Home = (props) => {
|
|
const { footerLinks, pages } = 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"
|
|
/>
|
|
</div>
|
|
<Footer footerLinks={footerLinks} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) =>
|
|
async ({ query, req, res }) => {
|
|
console.log("query-", query);
|
|
|
|
const token = await getSASToken();
|
|
|
|
let searchResultsObj = await getBasicSearch(token, query.q);
|
|
|
|
searchResultsObj =
|
|
searchResultsObj.status == 502
|
|
? {
|
|
value: [],
|
|
errorCode: searchResultsObj.status,
|
|
errorMsg: searchResultsObj.statusText,
|
|
}
|
|
: searchResultsObj;
|
|
|
|
//console.log("sssss", searchResultsObj);
|
|
|
|
const searchDetailsObj = await getSearchDetails(
|
|
token,
|
|
searchResultsObj
|
|
);
|
|
|
|
store.dispatch(setSearchResults(searchResultsObj));
|
|
store.dispatch(setSearchDetails(searchDetailsObj));
|
|
store.dispatch(setSearch(query.q));
|
|
}
|
|
);
|
|
|
|
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);
|