all repos — caroster @ v8.0

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

frontend/containers/EventBar/useActions.ts (view raw)

 1import {useRouter} from 'next/router';
 2import {useTranslation} from 'next-i18next';
 3import useProfile from '../../hooks/useProfile';
 4import useShare from '../../hooks/useShare';
 5import useEventStore from '../../stores/useEventStore';
 6
 7interface Props {
 8  onAdd: (isAddToMyEvent: boolean) => void;
 9  eventId?: string;
10}
11
12const useActions = (props: Props) => {
13  const {onAdd, eventId} = props;
14  const {t} = useTranslation();
15  const router = useRouter();
16  const {connected} = useProfile();
17  const {share} = useShare();
18  const event = useEventStore(s => s.event);
19
20  const noUserMenuActions = [
21    {
22      label: t('event.actions.add_to_my_events'),
23      onClick: () => {
24        onAdd(true);
25      },
26      id: 'AddToMyEventsTab',
27      icon: 'library_add',
28    },
29    {
30      label: t('event.actions.share'),
31      onClick: () =>
32        share({
33          title: `Caroster ${event.name}`,
34        }),
35      id: 'ShareEvent',
36      icon: 'share',
37    },
38    {
39      label: t('menu.login'),
40      onClick: () => {
41        router.push(`/auth/login?redirectPath=${router.asPath}`);
42      },
43      id: 'SignInTab',
44      icon: 'login',
45    },
46  ];
47
48  const loggedMenuActions = [
49    {
50      label: t('menu.profile'),
51      onClick: () => router.push('/profile'),
52      id: 'ProfileTab',
53      icon: 'account_circle',
54    },
55    {
56      label: t('menu.dashboard'),
57      onClick: () => (window.location.href = '/dashboard'),
58      id: 'GoToDashboardTab',
59      icon: 'space_dashboard',
60    },
61    {
62      label: t('event.actions.share'),
63      onClick: () =>
64        share({
65          title: `Caroster ${event.name}`,
66        }),
67      id: 'ShareEvent',
68      icon: 'share',
69    },
70  ];
71
72  return connected ? loggedMenuActions : noUserMenuActions;
73};
74
75export default useActions;