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';
10
11const Home = () => {
12 const {t} = useTranslation();
13 const router = useRouter();
14 const session = useSession();
15 const isAuthenticated = session.status === 'authenticated';
16 const isReady = session.status !== 'loading';
17
18 const noUserMenuActions = [
19 {
20 label: t('menu.login'),
21 onClick: () => router.push('/auth/login'),
22 id: 'LoginTabs',
23 },
24 {
25 label: t('menu.register'),
26 onClick: () => router.push('/auth/register'),
27 id: 'RegisterTabs',
28 },
29 ];
30
31 const loggedMenuActions = [
32 {
33 label: t('menu.dashboard'),
34 onClick: () => router.push('/dashboard'),
35 id: 'SeeDashboardTabs',
36 },
37 {
38 label: t('menu.profile'),
39 onClick: () => router.push('/profile'),
40 id: 'ProfileTabs',
41 },
42 ];
43
44 const menuActions = isAuthenticated ? loggedMenuActions : noUserMenuActions;
45
46 if (!isReady) return null;
47
48 return (
49 <Layout
50 menuTitle={t('event.creation.title')}
51 menuActions={menuActions}
52 displayMenu={isAuthenticated}
53 >
54 <Paper>
55 <Logo />
56 <CreateEvent />
57 </Paper>
58 {!isAuthenticated && <LanguagesIcon displayMenu={false} />}
59 </Layout>
60 );
61};
62
63export const getServerSideProps = pageUtils.getServerSideProps();
64
65export default Home;