MCPcopy Create free account
hub / github.com/dailydotdev/apps / useSquadNavigation

Function useSquadNavigation

packages/shared/src/hooks/useSquadNavigation.ts:22–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22export const useSquadNavigation = (): UseSquadNavigation => {
23 const { user, showLogin } = useAuthContext();
24 const router = useRouter();
25 const { openModal } = useLazyModal();
26
27 const newSquadUrl = `${webappUrl}squads/new`;
28
29 const openNewSquad = useCallback(
30 (props?: OpenNewSquadProps) => {
31 if (!user) {
32 props?.event?.preventDefault();
33 showLogin({ trigger: AuthTriggers.CreateSquad });
34 return;
35 }
36
37 props?.event?.preventDefault();
38
39 if (props?.pageRedirect) {
40 router.push(`${newSquadUrl}?origin=${props.origin}`);
41 return;
42 }
43
44 openModal({ type: LazyModal.NewSquad });
45 },
46 [user, openModal, showLogin, router, newSquadUrl],
47 );
48
49 const editSquad = useCallback(
50 ({ handle }: EditSquadProps) => {
51 router.push(`${webappUrl}squads/${handle}/edit`);
52 },
53 [router],
54 );
55
56 useEffect(() => {
57 const search = new URLSearchParams(window.location.search);
58 const query = Object.fromEntries(search);
59 if (!query?.squad) {
60 return;
61 }
62
63 const { origin, pathname } = window.location;
64 openNewSquad({ origin: Origin.Notification });
65 router.replace(origin + pathname);
66 // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
67 // eslint-disable-next-line react-hooks/exhaustive-deps
68 }, [router.pathname]);
69
70 return { openNewSquad, editSquad, newSquadUrl };
71};

Callers 6

NewSquadModalFunction · 0.90
SquadHeaderMenuFunction · 0.90
SquadsToShareFunction · 0.90
NewSquadButtonFunction · 0.90
SidebarDesktopV2Function · 0.90
NetworkSectionFunction · 0.90

Calls 5

useAuthContextFunction · 0.90
useLazyModalFunction · 0.90
pushMethod · 0.80
replaceMethod · 0.80
useRouterFunction · 0.50

Tested by

no test coverage detected