Files
pedwfrontend/pages/myportal/index.js
T

192 lines
6.3 KiB
JavaScript

import _ from "lodash";
import Cookies from "cookies";
import jsonpath from "jsonpath";
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 MyPortal from "../../components/myportal";
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 data from "../../data/collections.json";
import {
setLoggedInUserId,
setAccountDetails,
} from "../../store/accountDetails/action";
import { setMyCases, setMyCasesDetails } from "../../store/myCases/action";
import {
setMyRepresentations,
setMyRepresentationsDetails,
} from "../../store/myRepresentations/action";
import {
setWatchedCases,
setWatchedCasesDetails,
} from "../../store/watchedCases/action";
import {
setAwaitingSubmission,
setAwaitingSubmissionDetails,
} from "../../store/awaitingSubmission/action";
import {
getMyCases,
getMyRepresentations,
getWatchedCases,
getAwaitingSubmission,
getPortalModuelDetails,
} from "../../actions";
const Home = (props) => {
const {
footerLinks,
pages,
myCases,
myRepresentations,
watchedCases,
awaitingSubmission,
} = props;
let { t, lang } = useTranslation();
const router = useRouter();
const { locale } = router;
const { appealtypes } = router.query;
return (
<div>
<Head>
<title>
{t("myportal:page-title")} - {t("common:service-name")}
</title>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header courseName={t("common:service-name")} />
<div className="govuk-width-container">
<Banner />
<Breadcrumbs slug={appealtypes} />
<MyPortal
myCases={myCases}
myRepresentations={myRepresentations}
watchedCases={watchedCases}
awaitingSubmission={awaitingSubmission}
/>
</div>
<Footer footerLinks={footerLinks} />
</div>
</div>
);
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) =>
async ({ query, req, res }) => {
//console.log("the query", query);
const [
myCases,
myRepresentations,
watchedCases,
awaitingSubmission,
] = await Promise.all([
await getMyCases("f8b454ed-eded-eb11-aac7-00224800be9c"),
await getMyRepresentations(),
await getWatchedCases(),
await getAwaitingSubmission(),
]);
const cookies = new Cookies(req, res);
cookies.set("pinsUser", "f8b454ed-eded-eb11-aac7-00224800be9c", {
httpOnly: true, // true by default
});
//console.log("my cases ", myCases);
const [
myCasesDetails,
// myRepresentationsDetails,
// watchedCasesDetails,
// awaitingSubmissionDetails,
] = await Promise.all([
await getDetails(myCases),
// await getDetails(myRepresentations),
// await getDetails(watchedCases),
// await getDetails(awaitingSubmission),
]);
store.dispatch(
setLoggedInUserId("f8b454ed-eded-eb11-aac7-00224800be9c")
);
store.dispatch(setMyCases(myCases));
store.dispatch(setMyCasesDetails(myCasesDetails));
store.dispatch(setMyRepresentations(myRepresentations));
// store.dispatch(
// setMyRepresentationsDetails(myRepresentationsDetails)
// );
store.dispatch(setWatchedCases(watchedCases));
//store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
store.dispatch(setAwaitingSubmission(awaitingSubmission));
// store.dispatch(
// setAwaitingSubmissionDetails(awaitingSubmissionDetails)
// );
}
);
const getFormCollection = (formtype) => {
const collectionName = jsonpath.query(
data,
"$..[?(@.LogicalName=='" + formtype + "')].LogicalCollectionName"
);
//console.log(collectionName[0]);
return collectionName[0];
};
const getDetails = (resultsObj) => {
//console.log(resultsObj);
let detailsArr = [];
resultsObj = resultsObj.value;
const detailsObj = resultsObj.map((searchDetail, index) => {
if (searchDetail.pinswg_appealcasetype == null) {
console.log(searchDetail.ticketnumber);
} else {
detailsArr.push(
getPortalModuelDetails(
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) => {
//console.log(state);
return {
accountDetails: state.accountDetails,
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);