diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 620243440384f..8a2ef4a2b2f4e 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -256,6 +256,7 @@ function Expensify({ {shouldInit && ( <> diff --git a/src/components/DeeplinkWrapper/index.website.tsx b/src/components/DeeplinkWrapper/index.website.tsx index 649e66ccefa82..b395eb12c5fe0 100644 --- a/src/components/DeeplinkWrapper/index.website.tsx +++ b/src/components/DeeplinkWrapper/index.website.tsx @@ -5,6 +5,7 @@ import Navigation from '@libs/Navigation/Navigation'; import navigationRef from '@libs/Navigation/navigationRef'; import shouldPreventDeeplinkPrompt from '@libs/Navigation/shouldPreventDeeplinkPrompt'; import * as App from '@userActions/App'; +import * as Link from '@userActions/Link'; import * as Session from '@userActions/Session'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; @@ -15,7 +16,7 @@ function isMacOSWeb(): boolean { return !Browser.isMobile() && typeof navigator === 'object' && typeof navigator.userAgent === 'string' && /Mac/i.test(navigator.userAgent) && !/Electron/i.test(navigator.userAgent); } -function promptToOpenInDesktopApp() { +function promptToOpenInDesktopApp(initialUrl = '') { // If the current url path is /transition..., meaning it was opened from oldDot, during this transition period: // 1. The user session may not exist, because sign-in has not been completed yet. // 2. There may be non-idempotent operations (e.g. create a new workspace), which obviously should not be executed again in the desktop app. @@ -26,11 +27,11 @@ function promptToOpenInDesktopApp() { // Match any magic link (/v//<6 digit code>) const isMagicLink = CONST.REGEX.ROUTES.VALIDATE_LOGIN.test(window.location.pathname); - App.beginDeepLinkRedirect(!isMagicLink); + App.beginDeepLinkRedirect(!isMagicLink, Link.getInternalNewExpensifyPath(initialUrl)); } } -function DeeplinkWrapper({children, isAuthenticated, autoAuthState}: DeeplinkWrapperProps) { +function DeeplinkWrapper({children, isAuthenticated, autoAuthState, initialUrl}: DeeplinkWrapperProps) { const [currentScreen, setCurrentScreen] = useState(); const [hasShownPrompt, setHasShownPrompt] = useState(false); const removeListener = useRef<() => void>(); @@ -77,7 +78,7 @@ function DeeplinkWrapper({children, isAuthenticated, autoAuthState}: DeeplinkWra // Otherwise, we want to wait until the navigation state is set up // and we know the user is on a screen that supports deeplinks. if (isAuthenticated) { - promptToOpenInDesktopApp(); + promptToOpenInDesktopApp(initialUrl); setHasShownPrompt(true); } else { // Navigation state is not set up yet, we're unsure if we should show the deep link prompt or not @@ -93,7 +94,7 @@ function DeeplinkWrapper({children, isAuthenticated, autoAuthState}: DeeplinkWra promptToOpenInDesktopApp(); setHasShownPrompt(true); } - }, [currentScreen, hasShownPrompt, isAuthenticated, autoAuthState]); + }, [currentScreen, hasShownPrompt, isAuthenticated, autoAuthState, initialUrl]); return children; } diff --git a/src/components/DeeplinkWrapper/types.ts b/src/components/DeeplinkWrapper/types.ts index db61e5b01c24f..23e096d6a0939 100644 --- a/src/components/DeeplinkWrapper/types.ts +++ b/src/components/DeeplinkWrapper/types.ts @@ -6,6 +6,8 @@ type DeeplinkWrapperProps = ChildrenProps & { /** The auto authentication status */ autoAuthState?: string; + + initialUrl?: string; }; export default DeeplinkWrapperProps; diff --git a/src/libs/Browser/index.website.ts b/src/libs/Browser/index.website.ts index b89190dc7f785..2007f2c6cbc07 100644 --- a/src/libs/Browser/index.website.ts +++ b/src/libs/Browser/index.website.ts @@ -79,12 +79,12 @@ const isSafari: IsSafari = () => getBrowser() === 'safari' || isMobileSafari(); /** * The session information needs to be passed to the Desktop app, and the only way to do that is by using query params. There is no other way to transfer the data. */ -const openRouteInDesktopApp: OpenRouteInDesktopApp = (shortLivedAuthToken = '', email = '') => { +const openRouteInDesktopApp: OpenRouteInDesktopApp = (shortLivedAuthToken = '', email = '', initialRoute = '') => { const params = new URLSearchParams(); // If the user is opening the desktop app through a third party signin flow, we need to manually add the exitTo param // so that the desktop app redirects to the correct home route after signin is complete. const openingFromDesktopRedirect = window.location.pathname === `/${ROUTES.DESKTOP_SIGN_IN_REDIRECT}`; - params.set('exitTo', `${openingFromDesktopRedirect ? '/r' : window.location.pathname}${window.location.search}${window.location.hash}`); + params.set('exitTo', `${openingFromDesktopRedirect ? '/r' : initialRoute || window.location.pathname}${window.location.search}${window.location.hash}`); if (email && shortLivedAuthToken) { params.set('email', email); params.set('shortLivedAuthToken', shortLivedAuthToken); diff --git a/src/libs/Browser/types.ts b/src/libs/Browser/types.ts index cb242d3729aaa..ff0de91e7b78d 100644 --- a/src/libs/Browser/types.ts +++ b/src/libs/Browser/types.ts @@ -12,6 +12,6 @@ type IsChromeIOS = () => boolean; type IsSafari = () => boolean; -type OpenRouteInDesktopApp = (shortLivedAuthToken?: string, email?: string) => void; +type OpenRouteInDesktopApp = (shortLivedAuthToken?: string, email?: string, initialRoute?: string) => void; export type {GetBrowser, IsMobile, IsMobileSafari, IsMobileChrome, IsMobileWebKit, IsSafari, IsChromeIOS, OpenRouteInDesktopApp}; diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 7be767d73f48d..0c1a157f76f37 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -449,7 +449,7 @@ function redirectThirdPartyDesktopSignIn() { /** * @param shouldAuthenticateWithCurrentAccount Optional, indicates whether default authentication method (shortLivedAuthToken) should be used */ -function beginDeepLinkRedirect(shouldAuthenticateWithCurrentAccount = true) { +function beginDeepLinkRedirect(shouldAuthenticateWithCurrentAccount = true, initialRoute?: string) { // There's no support for anonymous users on desktop if (Session.isAnonymousUser()) { return; @@ -475,7 +475,7 @@ function beginDeepLinkRedirect(shouldAuthenticateWithCurrentAccount = true) { return; } - Browser.openRouteInDesktopApp(response.shortLivedAuthToken, currentUserEmail); + Browser.openRouteInDesktopApp(response.shortLivedAuthToken, currentUserEmail, initialRoute); }); }