Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent offline navigation on money request report deletion #34320

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 17 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3931,15 +3931,27 @@ function getAddWorkspaceRoomOrChatReportErrors(report: OnyxEntry<Report>): Recor
return report?.errorFields?.addWorkspaceRoom ?? report?.errorFields?.createChat;
}

function canUserPerformWriteAction(report: OnyxEntry<Report>) {
const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report);
// If the Money Request report is marked for deletion, let us prevent any further write action.
/**
* Return true if the Money Request report is marked for deletion.
*/
function isMoneyRequestReportPendingDeletion(report: OnyxEntry<Report>): boolean {
if (isMoneyRequestReport(report)) {
const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? '');
if (parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return false;
return true;
}
}
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's improve code readability :

function isMoneyRequestReportPendingDeletion(report: OnyxEntry<Report>): boolean {
    if(!isMoneyRequestReport(report)){
        return false;
    }
    
    const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? '');
    return parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

This comment was marked as outdated.

Copy link
Contributor Author

@rojiphil rojiphil Jan 13, 2024

Choose a reason for hiding this comment

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

I will make the changes and test this again.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering why I do not see Commit Suggestion for this code readability changes.

I couldn’t suggest the changes myself. It seems that option only works for the code that was changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn’t suggest the changes myself. It seems that option only works for the code that was changed.

Ah! That makes sense. Thanks


function canUserPerformWriteAction(report: OnyxEntry<Report>) {
const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report);

// If the Money Request report is marked for deletion, let us prevent any further write action.
if (isMoneyRequestReportPendingDeletion(report)) {
return false;
}

return !isArchivedRoom(report) && isEmptyObject(reportErrors) && report && isAllowedToComment(report) && !isAnonymousUser;
}

Expand Down Expand Up @@ -4489,6 +4501,7 @@ export {
getParentReport,
getRootParentReport,
getReportPreviewMessage,
isMoneyRequestReportPendingDeletion,
canUserPerformWriteAction,
getOriginalReportID,
canAccessReport,
Expand Down
5 changes: 5 additions & 0 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ function ReportScreen({
Navigation.goBack(ROUTES.HOME, false, true);
}
if (prevReport.parentReportID) {
// If Money Request report is pending for deletion, let us not navigate to Money Request Report
rojiphil marked this conversation as resolved.
Show resolved Hide resolved
const parentReport = ReportUtils.getReport(prevReport.parentReportID);
if (ReportUtils.isMoneyRequestReportPendingDeletion(parentReport)) {
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(prevReport.parentReportID));
return;
}
Expand Down
Loading