142 lines
4.6 KiB
JavaScript
142 lines
4.6 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 Cookies from "cookies";
|
|
import { useRouter } from "next/router";
|
|
import useTranslation from "next-translate/useTranslation";
|
|
import jsonpath from "jsonpath";
|
|
import data from "../../data/collections.json";
|
|
|
|
import { setSearch, getSearchObj } from "../../store/search/action";
|
|
import {
|
|
setSearchResults,
|
|
setSearchDetails,
|
|
setDocumentDetails,
|
|
setDocumentHistory,
|
|
getSearchResultsObj,
|
|
} from "../../store/searchOutput/action";
|
|
import {
|
|
getAdvancedSearch,
|
|
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}
|
|
advancedSearch={true}
|
|
/>
|
|
</div>
|
|
<Footer footerLinks={footerLinks} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) =>
|
|
async ({ query, req, res }) => {
|
|
console.log("query-", query);
|
|
//console.log("search array:", Object.entries(query));
|
|
|
|
const token = await getSASToken();
|
|
|
|
const searchResultsObj = await getAdvancedSearch(token, query);
|
|
const searchDetailsObj = await getSearchDetails(
|
|
token,
|
|
searchResultsObj
|
|
);
|
|
|
|
store.dispatch(setSearchResults(searchResultsObj));
|
|
store.dispatch(setSearchDetails(searchDetailsObj));
|
|
}
|
|
);
|
|
|
|
const getFormCollection = (formtype) => {
|
|
const collectionName = jsonpath.query(
|
|
data,
|
|
"$..[?(@.LogicalName=='" + formtype + "')].LogicalCollectionName"
|
|
);
|
|
//console.log(collectionName[0]);
|
|
return collectionName[0];
|
|
};
|
|
|
|
const getSearchDetails = (token, searchResultsObj) => {
|
|
//console.log(searchResultsObj);
|
|
|
|
let detailsArr = [];
|
|
//console.log("searcg results", searchResultsObj);
|
|
searchResultsObj = searchResultsObj.value;
|
|
const detailsObj = searchResultsObj.map((searchDetail, index) => {
|
|
if (searchDetail.pinswg_appealcasetype == null) {
|
|
console.log(searchDetail.ticketnumber);
|
|
} else {
|
|
detailsArr.push(
|
|
getBasicSearchDetails(
|
|
token,
|
|
getFormCollection(
|
|
"pinswg_" +
|
|
searchDetail[
|
|
"pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue"
|
|
]
|
|
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "")
|
|
.toLowerCase()
|
|
.slice(0, 39)
|
|
),
|
|
searchDetail.ticketnumber
|
|
)
|
|
);
|
|
}
|
|
});
|
|
//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,
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps)(Home);
|