323 lines
11 KiB
JavaScript
323 lines
11 KiB
JavaScript
import _ from "lodash";
|
|
import { getSession, useSession } from "next-auth/react";
|
|
import useTranslation from "next-translate/useTranslation";
|
|
import Head from "next/head";
|
|
import { useRouter } from "next/router";
|
|
import { connect } from "react-redux";
|
|
import {
|
|
getAwaitingSubmissionFromBlob,
|
|
getAwaitingSubmission,
|
|
getMyCases,
|
|
getMyRepresentations,
|
|
getPersonalAccount,
|
|
getPortalModuleDetails,
|
|
getWatchedCases,
|
|
consoleLogger,
|
|
getCase,
|
|
} from "../../actions";
|
|
import { createContainer } from "../../actions/azurestorage";
|
|
import { getProviderConfig } from "../../actions/govgateway";
|
|
import Breadcrumbs from "../../components/breadcrumbs";
|
|
import CookieBanner from "../../components/cookieBanner";
|
|
import Footer from "../../components/footer";
|
|
import Header from "../../components/header";
|
|
import MyPortal from "../../components/myportal";
|
|
import { getFormCollectionByID } from "../../components/utils";
|
|
import {
|
|
setAccountDetails,
|
|
setContainerID,
|
|
setLoggedInUserId,
|
|
} from "../../store/accountDetails/action";
|
|
import {
|
|
setAwaitingSubmission,
|
|
setAwaitingSubmissionFromBlob,
|
|
setAwaitingSubmissionDetails,
|
|
} from "../../store/awaitingSubmission/action";
|
|
import { getGovGatewayConfig } from "../../store/govgateway/action";
|
|
import { setMyCases, setMyCasesDetails } from "../../store/myCases/action";
|
|
import {
|
|
setMyRepresentations,
|
|
setMyRepresentationsDetails,
|
|
} from "../../store/myRepresentations/action";
|
|
import { wrapper } from "../../store/store";
|
|
import {
|
|
setWatchedCases,
|
|
setWatchedCasesDetails,
|
|
} from "../../store/watchedCases/action";
|
|
|
|
const Home = (props) => {
|
|
const {
|
|
footerLinks,
|
|
pages,
|
|
myCases,
|
|
myRepresentations,
|
|
watchedCases,
|
|
awaitingSubmission,
|
|
accountDetails,
|
|
govGateway,
|
|
showFileUpload,
|
|
} = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
const { appealtypes } = router.query;
|
|
|
|
const { data: session } = useSession();
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>
|
|
{t("myportal:page-title")} - {t("common:service-name")}
|
|
</title>
|
|
<>
|
|
<link
|
|
rel="canonical"
|
|
href={t("common:gov-wales-link") + router.asPath}
|
|
/>
|
|
<meta
|
|
key="og:locale"
|
|
property="og:locale"
|
|
content={router.locale}
|
|
/>
|
|
{/* If they have a Twitter Handle, include the meta details below */}
|
|
<meta
|
|
key="og:site_name"
|
|
property="og:site_name"
|
|
content={t("common:service-name")}
|
|
/>
|
|
<meta
|
|
key="twitter:site"
|
|
property="twitter:site"
|
|
content="@UKGovWales"
|
|
/>
|
|
|
|
<meta
|
|
name="description"
|
|
content={t("common:service-description")}
|
|
/>
|
|
<meta
|
|
property="og:site_name"
|
|
content={t("common:gov-wales-label")}
|
|
/>
|
|
<meta
|
|
property="og:title"
|
|
content={t("myportal:page-title")}
|
|
/>
|
|
<meta
|
|
property="og:description"
|
|
content={t("common:service-description")}
|
|
/>
|
|
<meta property="og:type" content="website" />
|
|
<meta
|
|
property="og:url"
|
|
content={t("common:gov-wales-link")}
|
|
/>
|
|
<meta
|
|
property="og:image"
|
|
content="https://gov.wales/themes/custom/govwales/images/content/og-global-1200.png"
|
|
/>
|
|
<meta name="twitter:card" content="summary" />
|
|
<meta
|
|
name="twitter:title"
|
|
content={t("common:gov-wales-label")}
|
|
/>
|
|
<meta
|
|
name="twitter:url"
|
|
content={t("common:gov-wales-link") + router.asPath}
|
|
/>
|
|
<meta
|
|
name="twitter:image"
|
|
content="https://gov.wales/themes/custom/govwales/images/content/og-global-120.png"
|
|
/>
|
|
</>
|
|
</Head>
|
|
<div id="page_wrapper">
|
|
<CookieBanner />
|
|
<Header courseName={t("common:service-name")} />
|
|
<div className="govuk-width-container">
|
|
<Breadcrumbs slug={appealtypes} />
|
|
<MyPortal
|
|
myCases={myCases}
|
|
myRepresentations={myRepresentations}
|
|
watchedCases={watchedCases}
|
|
awaitingSubmission={awaitingSubmission}
|
|
accountDetails={accountDetails}
|
|
ggLogout={govGateway.config.end_session_endpoint}
|
|
showFileUpload={showFileUpload}
|
|
containerID={accountDetails.containerID}
|
|
/>
|
|
</div>
|
|
<Footer footerLinks={footerLinks} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) => async (ctx) => {
|
|
const { query, req, res } = ctx;
|
|
console.log("The query", query);
|
|
|
|
const { cookies } = req;
|
|
|
|
let loggedInUser = cookies.pinsUser;
|
|
|
|
let thisSession = await getSession(ctx);
|
|
|
|
console.log("nextAuth Session:", thisSession);
|
|
|
|
if (_.has(thisSession, "user") == false) {
|
|
return {
|
|
redirect: {
|
|
destination: "/error",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
//Create Storage container for logged in user
|
|
await createContainer(thisSession.user.id);
|
|
|
|
let providerConfig = await getProviderConfig();
|
|
|
|
store.dispatch(getGovGatewayConfig(providerConfig));
|
|
|
|
const [
|
|
accountDetails,
|
|
myCases,
|
|
myRepresentations,
|
|
watchedCases,
|
|
awaitingSubmission,
|
|
awaitingSubmissionFromBlob,
|
|
] = await Promise.all([
|
|
await getPersonalAccount(loggedInUser),
|
|
await getMyCases(loggedInUser),
|
|
await getMyRepresentations(loggedInUser),
|
|
await getWatchedCases(loggedInUser),
|
|
await getAwaitingSubmission(loggedInUser),
|
|
await getAwaitingSubmissionFromBlob(thisSession.user.id),
|
|
]);
|
|
|
|
// console.log(
|
|
// "/////////////////////////\n ",
|
|
// awaitingSubmissionFromBlob.value,
|
|
// awaitingSubmissionFromBlob.case
|
|
// );
|
|
|
|
if (_.has(accountDetails, "errorCode") != false) {
|
|
return {
|
|
redirect: {
|
|
destination: "/myportal/error",
|
|
permanent: false,
|
|
},
|
|
};
|
|
} else {
|
|
const [
|
|
myCasesDetails,
|
|
myRepresentationsDetails,
|
|
watchedCasesDetails,
|
|
awaitingSubmissionDetails,
|
|
] = await Promise.all([
|
|
await getDetails(myCases, "myCases"),
|
|
await getDetails(myRepresentations, "myRepresentations"),
|
|
await getDetails(watchedCases, "myWatchedCases"),
|
|
await getDetails(awaitingSubmission, "awaitingSubmission"),
|
|
]);
|
|
|
|
store.dispatch(setAccountDetails(accountDetails));
|
|
store.dispatch(setLoggedInUserId(loggedInUser));
|
|
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(
|
|
setAwaitingSubmissionFromBlob(awaitingSubmissionFromBlob)
|
|
);
|
|
|
|
store.dispatch(
|
|
setAwaitingSubmissionDetails(awaitingSubmissionFromBlob)
|
|
);
|
|
store.dispatch(setContainerID(thisSession.user.id));
|
|
|
|
return {
|
|
props: {
|
|
showFileUpload: process.env.SHOWFILEUPLOAD,
|
|
containerID: thisSession.user.id,
|
|
},
|
|
};
|
|
}
|
|
}
|
|
);
|
|
|
|
const getDetails = (resultsObj, detailsType) => {
|
|
let detailsArr = [];
|
|
resultsObj = resultsObj.value;
|
|
|
|
if (detailsType == "myRepresentations") {
|
|
const repsObj = resultsObj.map((searchDetail, index) => {
|
|
detailsArr.push(
|
|
getCase(searchDetail["_pinswg_case_value"]).then((data) => {
|
|
return getPortalModuleDetails(
|
|
getFormCollectionByID(data.pinswg_appealcasetype)
|
|
.LogicalCollectionName,
|
|
data.ticketnumber
|
|
);
|
|
})
|
|
);
|
|
});
|
|
}
|
|
|
|
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"
|
|
]
|
|
)
|
|
);
|
|
}
|
|
});
|
|
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,
|
|
govGateway: state.govGateway,
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps)(Home);
|