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, 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 NoticeBanner from "../components/noticebanner"; import { setAccountDetails, setContainerID, } from "../store/accountDetails/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, 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" ? "/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 (