frontend/pages/profile.tsx (view raw)
1import {useRouter} from 'next/router';
2import {useTranslation} from 'react-i18next';
3import Loading from '../containers/Loading';
4import Profile from '../containers/Profile';
5import Layout from '../layouts/Centered';
6import {useSession, signOut} from 'next-auth/react';
7import pageUtils from '../lib/pageUtils';
8import useProfile from '../hooks/useProfile';
9import {useEffect} from 'react';
10
11const ProfilePage = () => {
12 const router = useRouter();
13 const {t} = useTranslation();
14 const session = useSession();
15 const isAuthenticated = session.status === 'authenticated';
16 const {profile} = useProfile();
17
18 useEffect(() => {
19 if (!isAuthenticated) router.push('/');
20 }, [isAuthenticated]);
21
22 const menuActions = [
23 {
24 label: t('menu.new_event'),
25 onClick: () => router.push('/'),
26 id: 'AddEventTabs',
27 },
28 {
29 label: t('menu.dashboard'),
30 onClick: () => router.push('/dashboard'),
31 id: 'DashboardTabs',
32 },
33 ];
34
35 if (session.status === 'loading') return <Loading />;
36 else if (!isAuthenticated) return null;
37
38 return (
39 <Layout menuTitle={t('profile.title')} menuActions={menuActions} goBack>
40 {profile && <Profile profile={profile} logout={signOut} />}
41 </Layout>
42 );
43};
44
45export const getServerSideProps = pageUtils.getServerSideProps();
46
47export default ProfilePage;