Skip to content

Commit

Permalink
Merge pull request #39903 from nkdengineer/fix/39462
Browse files Browse the repository at this point in the history
Fix request preview isn't crossed out when deleting in offline
  • Loading branch information
NikkiWines authored Apr 17, 2024
2 parents 314f2d3 + 450f9fd commit 5bace84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function isTransactionThread(parentReportAction: OnyxEntry<ReportAction> | Empty
/**
* Returns the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions with a childReportID. Returns a reportID if there is exactly one transaction thread for the report, and null otherwise.
*/
function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry<ReportActions> | ReportAction[]): string | null {
function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry<ReportActions> | ReportAction[], isOffline: boolean | undefined = undefined): string | null {
// If the report is not an IOU or Expense report, it shouldn't be treated as one-transaction report.
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE) {
Expand All @@ -250,7 +250,7 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn
action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
(iouRequestTypes.includes(action.originalMessage.type) ?? []) &&
action.childReportID &&
action.originalMessage.IOUTransactionID,
(Boolean(action.originalMessage.IOUTransactionID) || (action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && (isOffline ?? isNetworkOffline))),
);

// If we don't have any IOU request actions, or we have more than one IOU request actions, this isn't a oneTransaction report
Expand Down
7 changes: 6 additions & 1 deletion src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {CurrentReportIDContextValue} from '@components/withCurrentReportID'
import withCurrentReportID from '@components/withCurrentReportID';
import useAppFocusEvent from '@hooks/useAppFocusEvent';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import useViewportOffsetTop from '@hooks/useViewportOffsetTop';
Expand Down Expand Up @@ -157,6 +158,7 @@ function ReportScreen({
const firstRenderRef = useRef(true);
const flatListRef = useRef<FlatList>(null);
const reactionListRef = useRef<ReactionListRef>(null);
const {isOffline} = useNetwork();
/**
* Create a lightweight Report so as to keep the re-rendering as light as possible by
* passing in only the required props.
Expand Down Expand Up @@ -334,7 +336,10 @@ function ReportScreen({
);
}

const transactionThreadReportID = useMemo(() => ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, reportActions ?? []), [report.reportID, reportActions]);
const transactionThreadReportID = useMemo(
() => ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, reportActions ?? [], isOffline),
[report.reportID, reportActions, isOffline],
);

useEffect(() => {
if (!transactionThreadReportID || !route.params.reportActionID) {
Expand Down

0 comments on commit 5bace84

Please sign in to comment.