Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1838,8 +1838,9 @@ function getCurrentUserAccountID() {
* Leave a report by setting the state to submitted and closed
*
* @param {String} reportID
* @param {Boolean} shouldNavigate should navigate after leaving room or not
*/
function leaveRoom(reportID) {
function leaveRoom(reportID, shouldNavigate = true) {
const report = lodashGet(allReports, [reportID], {});
const reportKeys = _.keys(report);

Expand Down Expand Up @@ -1886,6 +1887,9 @@ function leaveRoom(reportID) {
},
);
Navigation.dismissModal();
if (!shouldNavigate) {
return;
}
Comment on lines +1890 to +1892
Copy link
Copy Markdown
Contributor

@fedirjh fedirjh Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this line above the modal dismissal .

Bug: User is navigated to concierge after leaving the thread

  1. Open report
  2. Navigate to thread
  3. Click back button
  4. User should go back to main report
  5. User is navigate to concierge
CleanShot.2023-09-26.at.16.07.37.mp4

Copy link
Copy Markdown
Contributor Author

@dukenv0307 dukenv0307 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fedirjh I see the problem, this PR changed the logic

so I don't think just moving that IF condition will work since when we call LeaveRoom, we set the optimistic data of that report statusNum to CLOSED

statusNum: CONST.REPORT.STATUS.CLOSED,

In ReportScreen, we have a logic to navigate to Concierge once statusNum is CLOSED

if (
// non-optimistic case
(!prevUserLeavingStatus && userLeavingStatus) ||
// optimistic case
(prevOnyxReportID && prevOnyxReportID === routeReportID && !onyxReportID && prevReport.statusNum === CONST.REPORT.STATUS.OPEN && report.statusNum === CONST.REPORT.STATUS.CLOSED)
) {
Navigation.goBack();
Report.navigateToConciergeChat();
return;
}

Working on this to find a solution

Copy link
Copy Markdown
Contributor

@fedirjh fedirjh Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one simple solution for this bug is that we add an optimistic prop let's say shouldNavigate and use it to prevent redirection inside ReportScreen.

optimisticData: [
    {
        onyxMethod: Onyx.METHOD.SET,
        key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
        value: {
            stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
            statusNum: CONST.REPORT.STATUS.CLOSED,                        
            shouldNavigate, // Add this prop
        },
    },
],

// Update the condition to 

if ( 
     // non-optimistic case 
     (!prevUserLeavingStatus && userLeavingStatus) || 
     // optimistic case 
     (... && report.shouldNavigate) 
 ) { 

if (Navigation.getTopmostReportId() === reportID) {
Navigation.goBack(ROUTES.HOME);
}
Expand Down
13 changes: 12 additions & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useRef, useState, useEffect, useMemo, useCallback} from 'react';
import {withOnyx} from 'react-native-onyx';
import {useFocusEffect} from '@react-navigation/native';
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import lodashGet from 'lodash/get';
Expand Down Expand Up @@ -153,6 +153,7 @@ function ReportScreen({
const reactionListRef = useRef();
const prevReport = usePrevious(report);
const prevUserLeavingStatus = usePrevious(userLeavingStatus);
const isFocused = useIsFocused();

const [skeletonViewContainerHeight, setSkeletonViewContainerHeight] = useState(0);
const [isBannerVisible, setIsBannerVisible] = useState(true);
Expand Down Expand Up @@ -180,6 +181,8 @@ function ReportScreen({
const didSubscribeToReportLeavingEvents = useRef(false);

const isDefaultReport = checkDefaultReport(report);
const isThread = ReportUtils.isThread(report);
const isNotificationPreferenceHidden = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;

let headerView = (
<HeaderView
Expand Down Expand Up @@ -350,6 +353,14 @@ function ReportScreen({
[report, isLoading, shouldHideReport, isDefaultReport, isOptimisticDelete, userLeavingStatus],
);

// When the report screen is unmounted or no longer in focus, and the user has no comments on that thread, call LeaveRoom
useEffect(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this hook runs when component unmounts ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will

if (isFocused || !isThread || !isNotificationPreferenceHidden) {
return;
}
Report.leaveRoom(reportID, false);
}, [isFocused, isThread, isNotificationPreferenceHidden, reportID]);

return (
<ReportScreenContext.Provider
value={{
Expand Down