From b9d5cffd1b10ab088a5b4813711b57f57a1e460c Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 5 Mar 2024 15:17:47 +0100 Subject: [PATCH 1/4] implement processReportIDDeeplink --- .../processReportIDDeeplink/getReportIDfromUrl.ts | 9 +++++++++ src/libs/processReportIDDeeplink/index.ts | 5 +++++ src/libs/processReportIDDeeplink/index.website.ts | 14 ++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/libs/processReportIDDeeplink/getReportIDfromUrl.ts create mode 100644 src/libs/processReportIDDeeplink/index.ts create mode 100644 src/libs/processReportIDDeeplink/index.website.ts diff --git a/src/libs/processReportIDDeeplink/getReportIDfromUrl.ts b/src/libs/processReportIDDeeplink/getReportIDfromUrl.ts new file mode 100644 index 000000000000..96334f5615fb --- /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..72f017367c5e --- /dev/null +++ b/src/libs/processReportIDDeeplink/index.ts @@ -0,0 +1,5 @@ +import getReportIDfromUrl from './getReportIDfromUrl'; + +export default function processReportIDDeeplink(url: 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..ad03ca759cbb --- /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) { + 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; +} From da072b51117e2ee63fc20af0290fdfc8d8d83f58 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 5 Mar 2024 15:28:23 +0100 Subject: [PATCH 2/4] integrate processReportIDDeeplink --- src/libs/actions/Report.ts | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) 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; From 88b215a3fb82f5df46f620369973cce09eea1c66 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 5 Mar 2024 15:57:11 +0100 Subject: [PATCH 3/4] add return types --- src/libs/processReportIDDeeplink/index.ts | 2 +- src/libs/processReportIDDeeplink/index.website.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/processReportIDDeeplink/index.ts b/src/libs/processReportIDDeeplink/index.ts index 72f017367c5e..228b4f28e864 100644 --- a/src/libs/processReportIDDeeplink/index.ts +++ b/src/libs/processReportIDDeeplink/index.ts @@ -1,5 +1,5 @@ import getReportIDfromUrl from './getReportIDfromUrl'; -export default function processReportIDDeeplink(url: string) { +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 index ad03ca759cbb..1fa3cd58d39b 100644 --- a/src/libs/processReportIDDeeplink/index.website.ts +++ b/src/libs/processReportIDDeeplink/index.website.ts @@ -1,7 +1,7 @@ import CONST from '@src/CONST'; import getReportIDfromUrl from './getReportIDfromUrl'; -export default function processReportIDDeeplink(url: string) { +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); From 1310235410228389887a0dfa8cf60d0016687b61 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 5 Mar 2024 16:01:17 +0100 Subject: [PATCH 4/4] rename a file --- .../{getReportIDfromUrl.ts => getReportIDFromUrl.ts} | 2 +- src/libs/processReportIDDeeplink/index.ts | 4 ++-- src/libs/processReportIDDeeplink/index.website.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) rename src/libs/processReportIDDeeplink/{getReportIDfromUrl.ts => getReportIDFromUrl.ts} (81%) diff --git a/src/libs/processReportIDDeeplink/getReportIDfromUrl.ts b/src/libs/processReportIDDeeplink/getReportIDFromUrl.ts similarity index 81% rename from src/libs/processReportIDDeeplink/getReportIDfromUrl.ts rename to src/libs/processReportIDDeeplink/getReportIDFromUrl.ts index 96334f5615fb..6763b5a45085 100644 --- a/src/libs/processReportIDDeeplink/getReportIDfromUrl.ts +++ b/src/libs/processReportIDDeeplink/getReportIDFromUrl.ts @@ -1,6 +1,6 @@ import * as ReportUtils from '@libs/ReportUtils'; -export default function getReportIDfromUrl(url: string): string { +export default function getReportIDFromUrl(url: string): string { const currentParams = new URLSearchParams(url); const currentExitToRoute = currentParams.get('exitTo') ?? ''; const {reportID} = ReportUtils.parseReportRouteParams(currentExitToRoute); diff --git a/src/libs/processReportIDDeeplink/index.ts b/src/libs/processReportIDDeeplink/index.ts index 228b4f28e864..7970556735b8 100644 --- a/src/libs/processReportIDDeeplink/index.ts +++ b/src/libs/processReportIDDeeplink/index.ts @@ -1,5 +1,5 @@ -import getReportIDfromUrl from './getReportIDfromUrl'; +import getReportIDFromUrl from './getReportIDFromUrl'; export default function processReportIDDeeplink(url: string): string { - return getReportIDfromUrl(url); + return getReportIDFromUrl(url); } diff --git a/src/libs/processReportIDDeeplink/index.website.ts b/src/libs/processReportIDDeeplink/index.website.ts index 1fa3cd58d39b..02fcfe75f968 100644 --- a/src/libs/processReportIDDeeplink/index.website.ts +++ b/src/libs/processReportIDDeeplink/index.website.ts @@ -1,10 +1,10 @@ import CONST from '@src/CONST'; -import getReportIDfromUrl from './getReportIDfromUrl'; +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); + const prevReportID = getReportIDFromUrl(prevUrl ?? ''); + const currentReportID = getReportIDFromUrl(url); if (currentReportID && url) { sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.INITIAL_URL, url);