all repos — caroster @ 64425eee42c3bbb4a10591bf227f141cc690b8c0

[Octree] Group carpool to your event https://caroster.io

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.profile'),
52      onClick: () => router.push('/profile'),
53      id: 'ProfileTab',
54    },
55    {divider: true},
56    {
57      label: t('menu.dashboard'),
58      onClick: () => (window.location.href = '/dashboard'),
59      id: 'GoToDashboardTab',
60    },
61    {divider: true},
62  ];
63
64  return connected ? loggedMenuActions : noUserMenuActions;
65};
66
67export default useActions;