all repos — caroster @ main

[Octree] Group carpool to your event https://caroster.io

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      label: t('menu.register'),
31      onClick: () => router.push('/auth/register'),
32      id: 'RegisterTabs',
33    },
34  ];
35
36  const loggedMenuActions = [
37    {
38      label: t('menu.profile'),
39      onClick: () => router.push('/profile'),
40      id: 'ProfileTabs',
41    },
42    {divider: true},
43    {
44      label: t('menu.dashboard'),
45      onClick: () => router.push('/dashboard'),
46      id: 'SeeDashboardTabs',
47    },
48  ];
49
50  const menuActions = isAuthenticated ? loggedMenuActions : noUserMenuActions;
51
52  if (!isReady) return null;
53
54  return (
55    <Layout
56      menuTitle={t('event.creation.title')}
57      menuActions={menuActions}
58      displayMenu={isAuthenticated}
59      {...props}
60    >
61      <Paper
62        sx={{
63          padding: theme.spacing(2),
64          width: '480px',
65          maxWidth: '100%',
66          display: 'block',
67          margin: '0 auto',
68        }}
69      >
70        <Logo />
71        <CreateEvent />
72      </Paper>
73      {!isAuthenticated && <LanguagesIcon displayMenu={false} />}
74    </Layout>
75  );
76};
77
78export const getServerSideProps = pageUtils.getServerSideProps();
79
80export default Home;