diff --git a/pages/auth/login.tsx b/pages/auth/login.tsx index 7f58a62f..8b9d5e83 100644 --- a/pages/auth/login.tsx +++ b/pages/auth/login.tsx @@ -1,58 +1,22 @@ -import { - Box, - Card, - CardContent, - Container, - Typography, - useMediaQuery, - useTheme, -} from '@mui/material'; -import type { NextPage } from 'next'; +import { Box, Card, CardContent, Container, Typography, useMediaQuery, useTheme } from '@mui/material'; +import { NextPage } from 'next'; import { GetStaticPropsContext } from 'next'; import { useTranslations } from 'next-intl'; import Head from 'next/head'; -import Image from 'next/legacy/image'; +import Image from 'next/image'; import { useRouter } from 'next/router'; import { useEffect } from 'react'; import Link from '../../components/common/Link'; import LoginForm from '../../components/forms/LoginForm'; import PartnerHeader from '../../components/layout/PartnerHeader'; -import { - GET_STARTED_WITH_BLOOM_CLICKED, - RESET_PASSWORD_HERE_CLICKED, - generateGetStartedPartnerEvent, -} from '../../constants/events'; +import { GET_STARTED_WITH_BLOOM_CLICKED, RESET_PASSWORD_HERE_CLICKED, generateGetStartedPartnerEvent } from '../../constants/events'; import { getAllPartnersContent } from '../../constants/partners'; import { useTypedSelector } from '../../hooks/store'; +import welcomeToBloom from '../../public/welcome_to_bloom.svg'; import illustrationBloomHeadYellow from '../../public/illustration_bloom_head_yellow.svg'; import illustrationLeafMix from '../../public/illustration_leaf_mix.svg'; -import welcomeToBloom from '../../public/welcome_to_bloom.svg'; -import { rowStyle } from '../../styles/common'; import logEvent, { getEventUserData } from '../../utils/logEvent'; -const containerStyle = { - ...rowStyle, - backgroundColor: 'primary.light', -} as const; - -const textContainerStyle = { - maxWidth: 600, - width: { xs: '100%', md: '45%' }, -} as const; - -const formCardStyle = { - width: { xs: '100%', sm: '70%', md: '45%' }, - alignSelf: 'flex-start', -} as const; - -const imageContainerStyle = { - position: 'relative', - width: { xs: 120, md: 160 }, - height: { xs: 70, md: 80 }, - marginBottom: 3, - marginTop: { xs: 0, md: 2 }, -} as const; - const Login: NextPage = () => { const t = useTranslations('Auth'); const tS = useTranslations('Shared'); @@ -60,27 +24,13 @@ const Login: NextPage = () => { const router = useRouter(); const isSmallScreen = useMediaQuery(theme.breakpoints.down('md')); - const userToken = useTypedSelector((state) => state.user.token); - const userId = useTypedSelector((state) => state.user.id); - const userCreatedAt = useTypedSelector((state) => state.user.createdAt); - const partnerAccesses = useTypedSelector((state) => state.partnerAccesses); - const partnerAdmin = useTypedSelector((state) => state.partnerAdmin); - const eventUserData = getEventUserData(userCreatedAt, partnerAccesses, partnerAdmin); - - const headerProps = { - partnerLogoSrc: welcomeToBloom, - partnerLogoAlt: 'alt.welcomeToBloom', - imageSrc: illustrationBloomHeadYellow, - imageAlt: 'alt.bloomHead', - }; + const { token: userToken, id: userId, createdAt: userCreatedAt } = useTypedSelector(state => state.user); + const { partnerAccesses, partnerAdmin } = useTypedSelector(state => state); - const allPartnersContent = getAllPartnersContent(); + const eventUserData = getEventUserData(userCreatedAt, partnerAccesses, partnerAdmin); useEffect(() => { - // Redirect if the user is on the login page but is already logged in and their data has been retrieved from the backend if (!userId) return; - // Checking if the query type is a string to keep typescript happy - // because a query value can be an array const returnUrl = typeof router.query.return_url === 'string' ? router.query.return_url : null; if (!!partnerAdmin?.id) { @@ -92,79 +42,44 @@ const Login: NextPage = () => { } }, [userId, partnerAdmin?.id, router]); - const ExtraContent = () => { - return ( - <> - - {tS('alt.leafMix')} - - - {t('login.newUserTitle')} - - - { - logEvent(GET_STARTED_WITH_BLOOM_CLICKED, eventUserData); - }} - href="/" - > - {t('getStartedBloom')} + const ExtraContent = () => ( + <> + + {tS('alt.leafMix')} + + {t('login.newUserTitle')} + + logEvent(GET_STARTED_WITH_BLOOM_CLICKED, eventUserData)} href="/">{t('getStartedBloom')} + + {getAllPartnersContent()?.map(partner => ( + + logEvent(generateGetStartedPartnerEvent(partner.name), eventUserData)}> + {t.rich('getStartedWith', { partnerName: partner.name })} - - {allPartnersContent?.map((partner) => ( - - { - logEvent(generateGetStartedPartnerEvent(partner.name), eventUserData); - }} - > - {t.rich('getStartedWith', { partnerName: partner.name })} - - - ))} - - ); - }; + ))} + + ); return ( {t('login.title')} - - - - - {t('introduction')} - + + + + {t('introduction')} {!isSmallScreen && } - + - - {t('login.title')} - - + {t('login.title')} {t.rich('login.resetPasswordLink', { - resetLink: (children) => ( - { - logEvent(RESET_PASSWORD_HERE_CLICKED, eventUserData); - }} - href="/auth/reset-password" - > - {children} - + resetLink: children => ( + logEvent(RESET_PASSWORD_HERE_CLICKED, eventUserData)} href="/auth/reset-password">{children} ), })}