From aee597815bbac60374830c468891d6a9c888cadf Mon Sep 17 00:00:00 2001 From: Rodrigo Muniz <32344098+rcmuniz1994@users.noreply.github.com> Date: Sun, 29 Oct 2023 14:39:11 -0300 Subject: [PATCH] Use call link as join link (#49) --------- Co-authored-by: Marcell Guilherme Costa da Silva Co-authored-by: mazuh --- src/components/participants/ParticipantsModal.test.tsx | 4 ++-- src/components/participants/ParticipantsModal.tsx | 5 ++--- src/hooks/useRedirectionRule.test.ts | 10 +++++++++- src/hooks/useRedirectionRule.ts | 8 +++++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/components/participants/ParticipantsModal.test.tsx b/src/components/participants/ParticipantsModal.test.tsx index 6c9a9a1..6bbee33 100644 --- a/src/components/participants/ParticipantsModal.test.tsx +++ b/src/components/participants/ParticipantsModal.test.tsx @@ -38,7 +38,7 @@ describe("ParticipantsModal", () => { preloadedState: { call }, }); expect( - screen.getByText(window.location.href + "join?callUid=" + call.uid) + screen.getByText(`${window.location.origin}${window.location.pathname}`) ).toBeVisible(); }); @@ -51,7 +51,7 @@ describe("ParticipantsModal", () => { await act(() => fireEvent.click(copyButton)); expect(navigator.clipboard.writeText).toHaveBeenCalledWith( - window.location.href + "join?callUid=" + call.uid + `${window.location.origin}${window.location.pathname}` ); const successSnackbar = await waitFor(() => screen.getByRole("alert")); diff --git a/src/components/participants/ParticipantsModal.tsx b/src/components/participants/ParticipantsModal.tsx index 8d30145..93a8661 100644 --- a/src/components/participants/ParticipantsModal.tsx +++ b/src/components/participants/ParticipantsModal.tsx @@ -18,7 +18,7 @@ import { selectPendingUsers, } from "../../state/call"; import DialogModal from "../basic/DialogModal"; -import { selectCallHostId, selectCallUid } from "../../state/call"; +import { selectCallHostId } from "../../state/call"; import { selectUserUid } from "../../state/user"; export interface ParticipantsModalProps { @@ -103,8 +103,7 @@ export default function ParticipantsModal({ } function CallLink() { - const callUid = useAppSelector(selectCallUid); - const link = `${window.location.origin}/join?callUid=${callUid}`; + const link = `${window.location.origin}${window.location.pathname}`; const handleCopyClick = async () => { await navigator.clipboard.writeText(link); diff --git a/src/hooks/useRedirectionRule.test.ts b/src/hooks/useRedirectionRule.test.ts index 968052a..a5c043d 100644 --- a/src/hooks/useRedirectionRule.test.ts +++ b/src/hooks/useRedirectionRule.test.ts @@ -213,12 +213,20 @@ describe("getRedirectionRule: /p2p-call", () => { expect(result).toBe("/create"); }); - it("when not authenticated, be forced to reset flow", () => { + it("when not authenticated and the url has call uuid, then go to join page", () => { // TODO: retrieve attempt call uid and convert into "/?joining=" flow const result = getRedirectionRule( { path: "/p2p-call/123-321", hasAuth: false, isSessionBlocked: false }, {} ); + expect(result).toBe("/join?callUid=123-321"); + }); + + it("when not authenticated and the url has not call uuid, be forced to reset flow", () => { + const result = getRedirectionRule( + { path: "/p2p-call/", hasAuth: false }, + {} + ); expect(result).toBe("/"); }); diff --git a/src/hooks/useRedirectionRule.ts b/src/hooks/useRedirectionRule.ts index 688231e..76e8785 100644 --- a/src/hooks/useRedirectionRule.ts +++ b/src/hooks/useRedirectionRule.ts @@ -35,7 +35,7 @@ export default function useRedirectionRule(): string { export interface RedirectionContext { path: string; hasAuth: boolean; - isSessionBlocked: boolean; + isSessionBlocked?: boolean; pendingCall?: string; ongoingCall?: string; } @@ -127,6 +127,8 @@ export function getRedirectionRule( } if (path.startsWith("/p2p-call")) { + const callUuid = path.replace("/p2p-call/", ""); + if (isSessionBlocked) { return "/blocked-session"; } @@ -136,6 +138,10 @@ export function getRedirectionRule( // return "/left"; } + if (!hasAuth && callUuid) { + return `/join?callUid=${callUuid}`; + } + if (!hasAuth) { return "/"; }