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

Function useSquadNavigation

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

Source from the content-addressed store, hash-verified

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

Callers 4

NewSquadModalFunction · 0.90
SquadsToShareFunction · 0.90
SquadDirectoryLayoutFunction · 0.90
NetworkSectionFunction · 0.90

Calls 7

useAuthContextFunction · 0.90
useLazyModalFunction · 0.90
getSquadManageUrlFunction · 0.90
openModalFunction · 0.85
pushMethod · 0.80
replaceMethod · 0.80
useRouterFunction · 0.50

Tested by

no test coverage detected