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('event.actions.share'),
29 onClick: () => {
30 onAdd(true);
31 },
32 id: 'ShareEvent',
33 },
34 {divider: true},
35 {
36 label: t('menu.login'),
37 onClick: () => {
38 setRedirectUrl(window.location.href);
39 router.push('/auth/login');
40 },
41 id: 'SignInTab',
42 },
43 {
44 label: t('menu.register'),
45 onClick: () => {
46 setRedirectUrl(window.location.href);
47 router.push({
48 pathname: '/auth/register',
49 state: {event: eventId},
50 });
51 },
52 id: 'SignUpTab',
53 },
54 {divider: true},
55 ];
56
57 const loggedMenuActions = [
58 {
59 label: t('menu.profile'),
60 onClick: () => router.push('/profile'),
61 id: 'ProfileTab',
62 },
63 {
64 label: t('menu.dashboard'),
65 onClick: () => (window.location.href = '/dashboard'),
66 id: 'GoToDashboardTab',
67 },
68 {
69 label: t('event.actions.share'),
70 onClick: () => {
71 onAdd(true);
72 },
73 id: 'ShareEvent',
74 },
75 {divider: true},
76 ];
77
78 return connected ? loggedMenuActions : noUserMenuActions;
79};
80
81export default useActions;