diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 7ad12cf3e1ed..cdfb186e504d 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -48,7 +48,6 @@ import DateUtils from '@libs/DateUtils'; import * as EmojiUtils from '@libs/EmojiUtils'; import * as Environment from '@libs/Environment/Environment'; import * as ErrorUtils from '@libs/ErrorUtils'; -import getPlatform from '@libs/getPlatform'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import LocalNotification from '@libs/Notification/LocalNotification'; @@ -56,6 +55,7 @@ import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; import * as PhoneNumber from '@libs/PhoneNumber'; import getPolicyMemberAccountIDs from '@libs/PolicyMembersUtils'; import {extractPolicyIDFromPath} from '@libs/PolicyUtils'; +import processReportIDDeeplink from '@libs/processReportIDDeeplink'; import * as Pusher from '@libs/Pusher/pusher'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -178,27 +178,7 @@ const typingWatchTimers: Record = {}; let reportIDDeeplinkedFromOldDot: string | undefined; Linking.getInitialURL().then((url) => { - const isWeb = ([CONST.PLATFORM.WEB] as unknown as string).includes(getPlatform()); - const currentParams = new URLSearchParams(url ?? ''); - const currentExitToRoute = currentParams.get('exitTo') ?? ''; - const {reportID: currentReportID} = ReportUtils.parseReportRouteParams(currentExitToRoute); - - if (!isWeb) { - reportIDDeeplinkedFromOldDot = currentReportID; - - return; - } - - const prevUrl = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.INITIAL_URL); - const prevParams = new URLSearchParams(prevUrl ?? ''); - const prevExitToRoute = prevParams.get('exitTo') ?? ''; - const {reportID: prevReportID} = ReportUtils.parseReportRouteParams(prevExitToRoute); - - reportIDDeeplinkedFromOldDot = currentReportID || prevReportID; - - if (currentReportID && url) { - sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.INITIAL_URL, url); - } + reportIDDeeplinkedFromOldDot = processReportIDDeeplink(url ?? ''); }); let lastVisitedPath: string | undefined; diff --git a/src/libs/processReportIDDeeplink/getReportIDFromUrl.ts b/src/libs/processReportIDDeeplink/getReportIDFromUrl.ts new file mode 100644 index 000000000000..6763b5a45085 --- /dev/null +++ b/src/libs/processReportIDDeeplink/getReportIDFromUrl.ts @@ -0,0 +1,9 @@ +import * as ReportUtils from '@libs/ReportUtils'; + +export default function getReportIDFromUrl(url: string): string { + const currentParams = new URLSearchParams(url); + const currentExitToRoute = currentParams.get('exitTo') ?? ''; + const {reportID} = ReportUtils.parseReportRouteParams(currentExitToRoute); + + return reportID; +} diff --git a/src/libs/processReportIDDeeplink/index.ts b/src/libs/processReportIDDeeplink/index.ts new file mode 100644 index 000000000000..7970556735b8 --- /dev/null +++ b/src/libs/processReportIDDeeplink/index.ts @@ -0,0 +1,5 @@ +import getReportIDFromUrl from './getReportIDFromUrl'; + +export default function processReportIDDeeplink(url: string): string { + return getReportIDFromUrl(url); +} diff --git a/src/libs/processReportIDDeeplink/index.website.ts b/src/libs/processReportIDDeeplink/index.website.ts new file mode 100644 index 000000000000..02fcfe75f968 --- /dev/null +++ b/src/libs/processReportIDDeeplink/index.website.ts @@ -0,0 +1,14 @@ +import CONST from '@src/CONST'; +import getReportIDFromUrl from './getReportIDFromUrl'; + +export default function processReportIDDeeplink(url: string): string { + const prevUrl = sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.INITIAL_URL); + const prevReportID = getReportIDFromUrl(prevUrl ?? ''); + const currentReportID = getReportIDFromUrl(url); + + if (currentReportID && url) { + sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.INITIAL_URL, url); + } + + return currentReportID || prevReportID; +}