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