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