218 lines
7.5 KiB
JavaScript
218 lines
7.5 KiB
JavaScript
import _ from "lodash";
|
|
import useTranslation from "next-translate/useTranslation";
|
|
import Head from "next/head";
|
|
import { useRouter } from "next/router";
|
|
import { setCookie } from "nookies";
|
|
import { connect } from "react-redux";
|
|
import { getToken, hashString, getPortalLogin } from "../actions";
|
|
import CookieBanner from "../components/cookieBanner";
|
|
import Footer from "../components/footer";
|
|
import Header from "../components/header";
|
|
import Main from "../components/main";
|
|
import ServiceBanner from "../components/servicebanner";
|
|
import {
|
|
setAccountDetails,
|
|
setContainerID,
|
|
} from "../store/accountDetails/action";
|
|
import { setShowReps } from "../store/currentView/action";
|
|
import { wrapper } from "../store/store";
|
|
import { getSession, useSession, signIn, signOut } from "next-auth/react";
|
|
|
|
const Home = (props) => {
|
|
const {
|
|
footerLinks,
|
|
pages,
|
|
showLogin,
|
|
showMap,
|
|
loggedInUserId,
|
|
loginEmailStr,
|
|
loggedInUserEmail,
|
|
hasLoginCode,
|
|
} = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
|
|
let now = new Date();
|
|
let expDate = new Date(now);
|
|
expDate.setDate(now.getDate() + 1);
|
|
|
|
//console.log("hashed email str", loginEmailStr);
|
|
|
|
//const { data: session } = useSession();
|
|
|
|
//console.log("has session:", session);
|
|
//console.log("has LoginCode", hasLoginCode);
|
|
|
|
hasLoginCode == false
|
|
? "" //console.log("no session")
|
|
: _.has(loggedInUserId, "value")
|
|
? _.isEmpty(loggedInUserId.value)
|
|
? router.replace({
|
|
pathname:
|
|
router.locale == "cy"
|
|
? "/account/register"
|
|
: "/account/register",
|
|
query: {
|
|
id: encodeURI(loggedInUserEmail),
|
|
},
|
|
})
|
|
: (setCookie(null, "pinsUser", loggedInUserId.value[0].contactid, {
|
|
path: "/",
|
|
expires: expDate,
|
|
}),
|
|
router.replace({
|
|
pathname:
|
|
router.locale == "cy" ? "/cy/fymhorth" : "/myportal",
|
|
}))
|
|
: console.log("no value in user id");
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>{t("common:service-name")}</title>
|
|
{/* Language by default is EN, if multilingual site this will need updated */}
|
|
<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: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.pathname}
|
|
/>
|
|
<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="Appeals Casework Portal" />
|
|
<div className="govuk-width-container">
|
|
{hasLoginCode ? (
|
|
<div className="govuk-grid-row">
|
|
<div className="govuk-grid-column-two-thirds">
|
|
<h1>{t("home:logging-in-heading")}</h1>
|
|
<h2>{t("home:logging-in-paragraph")}</h2>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<>
|
|
<ServiceBanner />
|
|
<Main
|
|
pages={pages}
|
|
showLogin={showLogin}
|
|
showMap={showMap}
|
|
loggedInUserId={loggedInUserId}
|
|
/>
|
|
</>
|
|
)}
|
|
</div>
|
|
<Footer footerLinks={footerLinks} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) => async (ctx) => {
|
|
const { query, req, res } = ctx;
|
|
|
|
let thisSession = await getSession(ctx);
|
|
|
|
var relayToken = await getToken();
|
|
relayToken = relayToken.access_token;
|
|
|
|
console.log("\n////////////////////\nauth sess:", thisSession);
|
|
|
|
const showLoginCheck = process.env.SHOWLOGIN || false;
|
|
const showMapCheck = process.env.SHOWMAPS || false;
|
|
const showReps = process.env.SHOWREPRESENTATIONS || false;
|
|
store.dispatch(setShowReps(showReps, showLoginCheck));
|
|
|
|
console.log("server checks :", showReps, showLoginCheck);
|
|
let hasLoginCode = thisSession != null;
|
|
|
|
console.log("server side has session:", thisSession != null);
|
|
|
|
let ggLocale =
|
|
typeof query.ui_locales != "undefined" && query.ui_locales;
|
|
|
|
console.log("hasloginCode:", hasLoginCode + "\n////////////////////\n");
|
|
|
|
let ggToken = {};
|
|
let ggUserInfo = {};
|
|
let portalUserObj = {};
|
|
let loginEmailStr = "";
|
|
|
|
if (hasLoginCode == true) {
|
|
loginEmailStr = hashString(thisSession.user.email);
|
|
store.dispatch(setContainerID(thisSession.user.id));
|
|
|
|
portalUserObj = await getPortalLogin(thisSession.user.email);
|
|
} else {
|
|
console.log("///////////////\nempty session \n///////////////\n");
|
|
}
|
|
|
|
return {
|
|
props: {
|
|
showLogin: showLoginCheck,
|
|
showMap: showMapCheck,
|
|
hasSession: hasLoginCode,
|
|
loggedInUserId: portalUserObj,
|
|
loggedInUserEmail: loginEmailStr,
|
|
hasLoginCode: hasLoginCode,
|
|
},
|
|
};
|
|
}
|
|
);
|
|
|
|
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);
|