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