frontend/pages/index.tsx (view raw)
1import {useRouter} from 'next/router';
2import {useTranslation} from 'react-i18next';
3import Layout from '../layouts/Centered';
4import CreateEvent from '../containers/CreateEvent';
5import LanguagesIcon from '../containers/Languages/Icon';
6import Paper from '../components/Paper';
7import Logo from '../components/Logo';
8import {useSession} from 'next-auth/react';
9import pageUtils from '../lib/pageUtils';
10import {useEffect} from 'react';
11import useRedirectUrlStore from '../stores/useRedirectUrl';
12
13const Home = () => {
14 const {t} = useTranslation();
15 const router = useRouter();
16 const session = useSession();
17 const isAuthenticated = session.status === 'authenticated';
18 const isReady = session.status !== 'loading';
19 const getRedirectUrl = useRedirectUrlStore(s => s.getRedirectUrl);
20
21 useEffect(() => {
22 const redirectUrl = getRedirectUrl();
23 if (redirectUrl) router.push(redirectUrl);
24 }, []);
25
26 const noUserMenuActions = [
27 {
28 label: t('menu.login'),
29 onClick: () => router.push('/auth/login'),
30 id: 'LoginTabs',
31 },
32 {
33 label: t('menu.register'),
34 onClick: () => router.push('/auth/register'),
35 id: 'RegisterTabs',
36 },
37 ];
38
39 const loggedMenuActions = [
40 {
41 label: t('menu.dashboard'),
42 onClick: () => router.push('/dashboard'),
43 id: 'SeeDashboardTabs',
44 },
45 {
46 label: t('menu.profile'),
47 onClick: () => router.push('/profile'),
48 id: 'ProfileTabs',
49 },
50 ];
51
52 const menuActions = isAuthenticated ? loggedMenuActions : noUserMenuActions;
53
54 if (!isReady) return null;
55
56 return (
57 <Layout
58 menuTitle={t('event.creation.title')}
59 menuActions={menuActions}
60 displayMenu={isAuthenticated}
61 >
62 <Paper>
63 <Logo />
64 <CreateEvent />
65 </Paper>
66 {!isAuthenticated && <LanguagesIcon displayMenu={false} />}
67 </Layout>
68 );
69};
70
71export const getServerSideProps = pageUtils.getServerSideProps();
72
73export default Home;