import { useState, useEffect } from 'react' import { Link, routes, navigate } from '@redwoodjs/router' import { useAuth } from '@redwoodjs/auth' import { Toaster, toast } from '@redwoodjs/web/toast' import { Popover } from '@headlessui/react' import { getActiveClasses } from 'get-active-classes' import Footer from 'src/components/Footer' import { useLocation } from '@redwoodjs/router' import LoginModal from 'src/components/LoginModal' import NavPlusButton from 'src/components/NavPlusButton' import ReactGA from 'react-ga' import { isBrowser } from '@redwoodjs/prerender/browserUtils' import { ImageFallback } from 'src/components/ImageUploader' import useUser from 'src/helpers/hooks/useUser' import './MainLayout.css' import RecentProjectsCell from 'src/components/RecentProjectsCell' import LogoType from 'src/components/LogoType' let previousSubmission = '' const MainLayout = ({ children, shouldRemoveFooterInIde }) => { const { logOut, isAuthenticated, currentUser, client } = useAuth() const { user, loading } = useUser() const [isLoginModalOpen, setIsLoginModalOpen] = useState(false) const recordedLogin = () => { ReactGA.event({ category: 'login', action: 'navbar login', }) setIsLoginModalOpen(true) } const { pathname, params } = useLocation() useEffect(() => { const newSubmission = `${pathname || ''}${params || ''}` // not the "React" way of doing think, but otherwise it will submit twice // it's because the old page submits it and when the new page loads it happens again if (previousSubmission !== newSubmission) { ReactGA.pageview(newSubmission) previousSubmission = newSubmission } }, [pathname, params]) let hash if (isBrowser) { hash = window.location.hash } useEffect(() => { const [key, token] = hash.slice(1).split('=') if (key === 'confirmation_token') { client .confirm(token, true) .then(() => { toast.success('Email confirmed') }) .catch(() => { toast.error('Problem confirming email') }) } else if (key === 'recovery_token') { client .recover(token, true) .then(() => { navigate(routes.updatePassword()) }) .catch(() => { toast.error('Problem recovering account') }) } }, [hash, client]) return (