frontend/containers/EventBar/useActions.ts (view raw)
1import {useRouter} from 'next/router';
2import {useTranslation} from 'react-i18next';
3import useProfile from '../../hooks/useProfile';
4import useRedirectUrlStore from '../../stores/useRedirectUrl';
5
6interface Props {
7 onAdd: (isAddToMyEvent: boolean) => void;
8 eventId?: string;
9}
10
11const useActions = (props: Props) => {
12 const {onAdd, eventId} = props;
13 const {t} = useTranslation();
14 const router = useRouter();
15 const {connected} = useProfile();
16 const setRedirectUrl = useRedirectUrlStore(s => s.setRedirectUrl);
17
18 const noUserMenuActions = [
19 {
20 label: t('event.actions.add_to_my_events'),
21 onClick: () => {
22 onAdd(true);
23 },
24 id: 'AddToMyEventsTab',
25 },
26 {divider: true},
27 {
28 label: t('menu.login'),
29 onClick: () => {
30 setRedirectUrl(window.location.href);
31 router.push('/auth/login');
32 },
33 id: 'SignInTab',
34 },
35 {
36 label: t('menu.register'),
37 onClick: () => {
38 setRedirectUrl(window.location.href);
39 router.push({
40 pathname: '/auth/register',
41 state: {event: eventId},
42 });
43 },
44 id: 'SignUpTab',
45 },
46 {divider: true},
47 ];
48
49 const loggedMenuActions = [
50 {
51 label: t('menu.dashboard'),
52 onClick: () => router.push('/dashboard'),
53 id: 'GoToDashboardTab',
54 },
55 {
56 label: t('menu.profile'),
57 onClick: () => router.push('/profile'),
58 id: 'ProfileTab',
59 },
60 {divider: true},
61 ];
62
63 return connected ? loggedMenuActions : noUserMenuActions;
64};
65
66export default useActions;