()
| 24 | } |
| 25 | |
| 26 | export 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 | }; |
no test coverage detected