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, getSession} from 'next-auth/react';
7import pageUtils from '../lib/pageUtils';
8import useProfile from '../hooks/useProfile';
9
10const ProfilePage = () => {
11 const router = useRouter();
12 const {t} = useTranslation();
13 const session = useSession();
14 const {profile} = useProfile();
15
16 const menuActions = [
17 {
18 label: t('menu.new_event'),
19 onClick: () => router.push('/'),
20 id: 'AddEventTabs',
21 },
22 {
23 label: t('menu.dashboard'),
24 onClick: () => router.push('/dashboard'),
25 id: 'DashboardTabs',
26 },
27 ];
28
29 if (session.status === 'loading') return <Loading />;
30
31 return (
32 <Layout menuTitle={t('profile.title')} menuActions={menuActions} goBack>
33 {profile && <Profile profile={profile} logout={signOut} />}
34 </Layout>
35 );
36};
37
38export const getServerSideProps = async (context: any) => {
39 const session = await getSession(context);
40
41 if (!session)
42 return {
43 redirect: {
44 destination: '/',
45 permanent: false,
46 },
47 };
48 else return pageUtils.getServerSideProps()(context);
49};
50
51export default ProfilePage;