From 480c4b4f43f25d90df58cd9fd5c5ffc286c75645 Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Tue, 15 Oct 2024 15:58:00 +0700 Subject: [PATCH 1/4] Resolve not found page briefly appeared when remove leave the group --- src/libs/actions/Report.ts | 35 ++++++++++++++++++++++++++++++--- src/pages/home/ReportScreen.tsx | 27 +++++++++++++++++-------- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 13b14d380758..27a7fb089d52 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2772,10 +2772,20 @@ function leaveGroupChat(reportID: string) { const optimisticData: OnyxUpdate[] = [ { - onyxMethod: Onyx.METHOD.SET, + onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: null, + value: { + reportID: null, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.CLOSED, + participants: { + [currentUserAccountID]: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + }, + }, }, + ]; // Clean up any quick actions for the report we're leaving from if (quickAction?.chatReportID?.toString() === reportID) { @@ -2786,8 +2796,27 @@ function leaveGroupChat(reportID: string) { }); } + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: Object.keys(report).reduce>((acc, key) => { + acc[key] = null; + return acc; + }, {}), + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: report, + }, + ]; + navigateToMostRecentReport(report); - API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData}); + API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData, successData, failureData}); } /** Leave a report by setting the state to submitted and closed */ diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index b45b3bcea4a4..72e8a0d48bdf 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -375,28 +375,39 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundPage = useMemo((): boolean => { if (shouldShowNotFoundLinkedAction) { + console.log('[wildebug] shouldShowNotFoundLinkedAction:', shouldShowNotFoundLinkedAction); return true; } - - // Wait until we're sure the app is done loading (needs to be a strict equality check since it's undefined initially) + if (isLoadingApp !== false) { + console.log('[wildebug] isLoadingApp:', isLoadingApp); return false; } - - // If we just finished loading the app, we still need to try fetching the report. Wait until that's done before - // showing the Not Found page + if (finishedLoadingApp) { + console.log('[wildebug] finishedLoadingApp:', finishedLoadingApp); return false; } - + if (!wasReportAccessibleRef.current && !firstRenderRef.current && !reportID && !isOptimisticDelete && !reportMetadata?.isLoadingInitialReportActions && !userLeavingStatus) { + console.log('[wildebug] wasReportAccessibleRef.current:', wasReportAccessibleRef.current); + console.log('[wildebug] firstRenderRef.current:', firstRenderRef.current); + console.log('[wildebug] reportID:', reportID); + console.log('[wildebug] isOptimisticDelete:', isOptimisticDelete); + console.log('[wildebug] reportMetadata?.isLoadingInitialReportActions:', reportMetadata?.isLoadingInitialReportActions); + console.log('[wildebug] userLeavingStatus:', userLeavingStatus); return true; } - + if (shouldHideReport) { + console.log('[wildebug] shouldHideReport:', shouldHideReport); return true; } - return !!currentReportIDFormRoute && !ReportUtils.isValidReportIDFromPath(currentReportIDFormRoute); + + const isValidReportID = !!currentReportIDFormRoute && !ReportUtils.isValidReportIDFromPath(currentReportIDFormRoute); + console.log('[wildebug] currentReportIDFormRoute:', currentReportIDFormRoute); + console.log('[wildebug] isValidReportID:', isValidReportID); + return isValidReportID; }, [ shouldShowNotFoundLinkedAction, isLoadingApp, From 63b49be0763a18fce449c344ba0bb034df18d46c Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Wed, 16 Oct 2024 09:16:29 +0700 Subject: [PATCH 2/4] revert unnecessary changes --- src/pages/home/ReportScreen.tsx | 34 +++++++++++---------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 3708a6d57e5e..b45b3bcea4a4 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -359,11 +359,9 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro !isCurrentReportLoadedFromOnyx || isLoading; - const isLinkedActionBecomesDeleted = prevIsLinkedActionDeleted !== undefined && !prevIsLinkedActionDeleted && isLinkedActionDeleted; - // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundLinkedAction = - (!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !isLinkedActionBecomesDeleted) || + (!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !!prevIsLinkedActionDeleted) || (shouldShowSkeleton && !reportMetadata.isLoadingInitialReportActions && !!reportActionIDFromRoute && @@ -377,39 +375,28 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundPage = useMemo((): boolean => { if (shouldShowNotFoundLinkedAction) { - console.log('[wildebug] shouldShowNotFoundLinkedAction:', shouldShowNotFoundLinkedAction); return true; } - + + // Wait until we're sure the app is done loading (needs to be a strict equality check since it's undefined initially) if (isLoadingApp !== false) { - console.log('[wildebug] isLoadingApp:', isLoadingApp); return false; } - + + // If we just finished loading the app, we still need to try fetching the report. Wait until that's done before + // showing the Not Found page if (finishedLoadingApp) { - console.log('[wildebug] finishedLoadingApp:', finishedLoadingApp); return false; } - + if (!wasReportAccessibleRef.current && !firstRenderRef.current && !reportID && !isOptimisticDelete && !reportMetadata?.isLoadingInitialReportActions && !userLeavingStatus) { - console.log('[wildebug] wasReportAccessibleRef.current:', wasReportAccessibleRef.current); - console.log('[wildebug] firstRenderRef.current:', firstRenderRef.current); - console.log('[wildebug] reportID:', reportID); - console.log('[wildebug] isOptimisticDelete:', isOptimisticDelete); - console.log('[wildebug] reportMetadata?.isLoadingInitialReportActions:', reportMetadata?.isLoadingInitialReportActions); - console.log('[wildebug] userLeavingStatus:', userLeavingStatus); return true; } - + if (shouldHideReport) { - console.log('[wildebug] shouldHideReport:', shouldHideReport); return true; } - - const isValidReportID = !!currentReportIDFormRoute && !ReportUtils.isValidReportIDFromPath(currentReportIDFormRoute); - console.log('[wildebug] currentReportIDFormRoute:', currentReportIDFormRoute); - console.log('[wildebug] isValidReportID:', isValidReportID); - return isValidReportID; + return !!currentReportIDFormRoute && !ReportUtils.isValidReportIDFromPath(currentReportIDFormRoute); }, [ shouldShowNotFoundLinkedAction, isLoadingApp, @@ -674,11 +661,12 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro useEffect(() => { // If the linked action is previously available but now deleted, // remove the reportActionID from the params to not link to the deleted action. + const isLinkedActionBecomesDeleted = prevIsLinkedActionDeleted !== undefined && !prevIsLinkedActionDeleted && isLinkedActionDeleted; if (!isLinkedActionBecomesDeleted) { return; } Navigation.setParams({reportActionID: ''}); - }, [isLinkedActionBecomesDeleted]); + }, [prevIsLinkedActionDeleted, isLinkedActionDeleted]); // If user redirects to an inaccessible whisper via a deeplink, on a report they have access to, // then we set reportActionID as empty string, so we display them the report and not the "Not found page". From 6eb346a5f0ba52a87f69d39dbec16aeb13f10ca6 Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Wed, 16 Oct 2024 09:24:17 +0700 Subject: [PATCH 3/4] Add comment --- src/libs/actions/Report.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 82cc1f684d56..b22eb4fd1e6e 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2759,6 +2759,8 @@ function leaveGroupChat(reportID: string) { return; } + // Use merge instead of set to avoid deleting the report too quickly, which could cause a brief "not found" page to appear. + // The remaining parts of the report object will be removed after the API call is successful. const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -2774,7 +2776,6 @@ function leaveGroupChat(reportID: string) { }, }, }, - ]; // Clean up any quick actions for the report we're leaving from if (quickAction?.chatReportID?.toString() === reportID) { @@ -2790,9 +2791,9 @@ function leaveGroupChat(reportID: string) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: Object.keys(report).reduce>((acc, key) => { - acc[key] = null; - return acc; - }, {}), + acc[key] = null; + return acc; + }, {}), }, ]; From 1f52c2903cf66525f454444e97e74a08f315c16b Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Wed, 16 Oct 2024 09:26:27 +0700 Subject: [PATCH 4/4] Revert unnecessary change --- src/pages/home/ReportScreen.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index b45b3bcea4a4..4a87d51e3c82 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -359,9 +359,11 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro !isCurrentReportLoadedFromOnyx || isLoading; + const isLinkedActionBecomesDeleted = prevIsLinkedActionDeleted !== undefined && !prevIsLinkedActionDeleted && isLinkedActionDeleted; + // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundLinkedAction = - (!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !!prevIsLinkedActionDeleted) || + (!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !isLinkedActionBecomesDeleted) || (shouldShowSkeleton && !reportMetadata.isLoadingInitialReportActions && !!reportActionIDFromRoute && @@ -661,12 +663,11 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro useEffect(() => { // If the linked action is previously available but now deleted, // remove the reportActionID from the params to not link to the deleted action. - const isLinkedActionBecomesDeleted = prevIsLinkedActionDeleted !== undefined && !prevIsLinkedActionDeleted && isLinkedActionDeleted; if (!isLinkedActionBecomesDeleted) { return; } Navigation.setParams({reportActionID: ''}); - }, [prevIsLinkedActionDeleted, isLinkedActionDeleted]); + }, [isLinkedActionBecomesDeleted]); // If user redirects to an inaccessible whisper via a deeplink, on a report they have access to, // then we set reportActionID as empty string, so we display them the report and not the "Not found page".