294 lines
9.9 KiB
JavaScript
294 lines
9.9 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 { getNotice, getToken, hashString } from "../actions";
|
|
import {
|
|
getGGToken,
|
|
getPortalLogin,
|
|
getProviderConfig,
|
|
getUserInfo,
|
|
} from "../actions/govgateway";
|
|
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 NoticeBanner from "../components/noticebanner";
|
|
import {
|
|
setAccountDetails,
|
|
setContainerID,
|
|
} from "../store/accountDetails/action";
|
|
import { getGovGatewayConfig } from "../store/govgateway/action";
|
|
import { wrapper } from "../store/store";
|
|
import { getSession, useSession, signIn, signOut } from "next-auth/react";
|
|
|
|
const Home = (props) => {
|
|
const {
|
|
footerLinks,
|
|
pages,
|
|
showLogin,
|
|
showMap,
|
|
loggedInUserId,
|
|
hasGGCode,
|
|
loginEmailStr,
|
|
loggedInUserEmail,
|
|
ggLocale,
|
|
hasLoginCode,
|
|
noticeContent,
|
|
} = 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" || ggLocale == "cy"
|
|
? "/cy/fymhorth"
|
|
: "/myportal",
|
|
}))
|
|
: console.log("no value in user id");
|
|
|
|
var noticeDateFrom = new Date(
|
|
noticeContent.value[0].dateFrom.split("/")[2],
|
|
noticeContent.value[0].dateFrom.split("/")[1] - 1,
|
|
noticeContent.value[0].dateFrom.split("/")[0]
|
|
);
|
|
|
|
var noticeDateTo = new Date(
|
|
noticeContent.value[0].dateTo.split("/")[2],
|
|
noticeContent.value[0].dateTo.split("/")[1] - 1,
|
|
noticeContent.value[0].dateTo.split("/")[0]
|
|
);
|
|
|
|
var today = new Date();
|
|
var day = today.getDate();
|
|
var month = today.getMonth();
|
|
var year = today.getFullYear();
|
|
|
|
today = new Date(year, month, day);
|
|
const displayNotice = today >= noticeDateFrom && today <= noticeDateTo;
|
|
|
|
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 ? (
|
|
<>
|
|
<h1>
|
|
{ggLocale == "cy"
|
|
? "Mewngofnodi"
|
|
: "Logging in"}
|
|
</h1>
|
|
<h2>
|
|
{ggLocale == "cy"
|
|
? "Arhoswch os gwelwch yn dda..."
|
|
: "Please wait..."}
|
|
</h2>
|
|
</>
|
|
) : (
|
|
<>
|
|
{displayNotice && (
|
|
<NoticeBanner noticeContent={noticeContent} />
|
|
)}
|
|
<ServiceBanner />
|
|
<Main
|
|
ggLocale={ggLocale}
|
|
pages={pages}
|
|
showLogin={showLogin}
|
|
showMap={showMap}
|
|
loggedInUserId={loggedInUserId}
|
|
// GG_REDIRECT_URI={props.GG_REDIRECT_URI}
|
|
// GG_CLIENT_ID={props.GG_CLIENT_ID}
|
|
/>
|
|
</>
|
|
)}
|
|
</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;
|
|
|
|
let hasLoginCode = thisSession != null;
|
|
|
|
console.log("server side has session:", thisSession != null);
|
|
|
|
// let providerConfig = await getProviderConfig();
|
|
let ggLocale =
|
|
typeof query.ui_locales != "undefined" && query.ui_locales;
|
|
|
|
console.log("hasloginCode:", hasLoginCode);
|
|
|
|
// store.dispatch(getGovGatewayConfig(providerConfig));
|
|
|
|
const noticeContent = await getNotice();
|
|
|
|
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,
|
|
relayToken
|
|
);
|
|
|
|
if (_.has(portalUserObj, "status") != false) {
|
|
if (portalUserObj.status == 400) {
|
|
return {
|
|
redirect: {
|
|
//destination: "/dns-not-found",
|
|
destination: "/error",
|
|
permanent: false,
|
|
},
|
|
};
|
|
} else {
|
|
console.log("loggin user stuff: ", portalUserObj);
|
|
store.dispatch(setAccountDetails(portalUserObj));
|
|
}
|
|
}
|
|
} else {
|
|
console.log("empty session");
|
|
}
|
|
console.log("///////////////\n");
|
|
if (ggToken.status == 400) {
|
|
return {
|
|
redirect: {
|
|
destination: "/myportal/error",
|
|
permanent: false,
|
|
},
|
|
};
|
|
} else {
|
|
return {
|
|
props: {
|
|
ggLocale: ggLocale,
|
|
showLogin: showLoginCheck,
|
|
showMap: showMapCheck,
|
|
hasSession: hasLoginCode,
|
|
loggedInUserId: portalUserObj,
|
|
loggedInUserEmail: loginEmailStr,
|
|
hasLoginCode: hasLoginCode,
|
|
noticeContent: noticeContent,
|
|
},
|
|
};
|
|
}
|
|
}
|
|
);
|
|
|
|
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,
|
|
govGateway: state.govGateway,
|
|
};
|
|
};
|
|
export default connect(mapStateToProps)(Home);
|