Skip to content

Commit

Permalink
Merge pull request #44142 from dominictb/fix/42950-clean-dist-req-error
Browse files Browse the repository at this point in the history
fix: delete money request if failed to create chat
  • Loading branch information
neil-marcellini authored Jul 17, 2024
2 parents 5377e04 + d71f595 commit 0c8e2cc
Show file tree
Hide file tree
Showing 3 changed files with 279 additions and 78 deletions.
8 changes: 8 additions & 0 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ function MoneyRequestView({
if (!transaction?.transactionID) {
return;
}

const isCreateChatErrored = !!report?.errorFields?.createChat;
if ((isCreateChatErrored || !!report.isOptimisticReport) && parentReportAction) {
const urlToNavigateBack = IOU.cleanUpMoneyRequest(transaction.transactionID, parentReportAction, true);
Navigation.goBack(urlToNavigateBack);
return;
}

if (transaction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
if (chatReport?.reportID && ReportUtils.getAddWorkspaceRoomOrChatReportErrors(chatReport)) {
Report.navigateToConciergeChatAndDeleteReport(chatReport.reportID, true, true);
Expand Down
100 changes: 51 additions & 49 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {fastMerge} from 'expensify-common';
import _ from 'lodash';
import lodashFindLast from 'lodash/findLast';
import type {OnyxCollection, OnyxCollectionInputValue, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
Expand All @@ -10,8 +10,8 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {OnyxInputOrEntry} from '@src/types/onyx';
import type {JoinWorkspaceResolution, OriginalMessageExportIntegration} from '@src/types/onyx/OriginalMessage';
import type Report from '@src/types/onyx/Report';
import type {Message, OldDotReportAction, OriginalMessage, ReportActions} from '@src/types/onyx/ReportAction';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {Message, OldDotReportAction, OriginalMessage, ReportActions} from '@src/types/onyx/ReportAction';
import type ReportActionName from '@src/types/onyx/ReportActionName';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import DateUtils from './DateUtils';
Expand Down Expand Up @@ -715,10 +715,12 @@ function replaceBaseURLInPolicyChangeLogAction(reportAction: ReportAction): Repo
return updatedReportAction;
}

function getLastVisibleAction(reportID: string, actionsToMerge: OnyxCollection<ReportAction> | OnyxCollectionInputValue<ReportAction> = {}): OnyxEntry<ReportAction> {
function getLastVisibleAction(reportID: string, actionsToMerge: Record<string, NullishDeep<ReportAction> | null> = {}): OnyxEntry<ReportAction> {
let reportActions: Array<ReportAction | null | undefined> = [];
if (!_.isEmpty(actionsToMerge)) {
reportActions = Object.values(fastMerge(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {}, actionsToMerge ?? {}, true));
reportActions = Object.values(fastMerge(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {}, actionsToMerge ?? {}, true)) as Array<
ReportAction | null | undefined
>;
} else {
reportActions = Object.values(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {});
}
Expand All @@ -732,7 +734,7 @@ function getLastVisibleAction(reportID: string, actionsToMerge: OnyxCollection<R

function getLastVisibleMessage(
reportID: string,
actionsToMerge: OnyxCollection<ReportAction> | OnyxCollectionInputValue<ReportAction> = {},
actionsToMerge: Record<string, NullishDeep<ReportAction> | null> = {},
reportAction: OnyxInputOrEntry<ReportAction> | undefined = undefined,
): LastVisibleMessage {
const lastVisibleAction = reportAction ?? getLastVisibleAction(reportID, actionsToMerge);
Expand Down Expand Up @@ -1534,92 +1536,92 @@ function getExportIntegrationActionFragments(reportAction: OnyxEntry<ReportActio
}

export {
doesReportHaveVisibleActions,
extractLinksFromMessageHtml,
getActionableMentionWhisperMessage,
getAllReportActions,
getCombinedReportActions,
getDismissedViolationMessageText,
getOneTransactionThreadReportID,
getFilteredForOneTransactionView,
getFirstVisibleReportActionID,
getIOUActionForReportID,
getIOUReportIDFromReportActionPreview,
getLastClosedReportAction,
getLastVisibleAction,
getLastVisibleMessage,
getLatestReportActionFromOnyxData,
getLinkedTransactionID,
getMemberChangeMessageFragment,
getMemberChangeMessagePlainText,
getMessageOfOldDotReportAction,
getMostRecentIOURequestActionID,
getMostRecentReportActionLastModified,
getNumberOfMoneyRequests,
getOneTransactionThreadReportID,
getOriginalMessage,
getParentReportAction,
getReportAction,
getReportActionHtml,
getReportActionMessage,
getReportActionMessageText,
getWhisperedTo,
isApprovedOrSubmittedReportAction,
getReportActionText,
getReportPreviewAction,
getSortedReportActions,
getCombinedReportActions,
getSortedReportActionsForDisplay,
getTextFromHtml,
getTrackExpenseActionableWhisper,
getWhisperedTo,
hasRequestFromCurrentAccount,
isActionOfType,
isActionableJoinRequest,
isActionableJoinRequestPending,
isActionableMentionWhisper,
isActionableReportMentionWhisper,
isActionableTrackExpense,
isAddCommentAction,
isApprovedOrSubmittedReportAction,
isChronosOOOListAction,
isClosedAction,
isConsecutiveActionMadeByPreviousActor,
isCreatedAction,
isCreatedTaskReportAction,
isCurrentActionUnread,
isDeletedAction,
isDeletedParentAction,
isLinkedTransactionHeld,
isMemberChangeAction,
isExportIntegrationAction,
isMessageDeleted,
isModifiedExpenseAction,
isMoneyRequestAction,
isNotifiableReportAction,
isOldDotReportAction,
isPayAction,
isPendingRemove,
isReversedTransaction,
isPolicyChangeLogAction,
isReimbursementDeQueuedAction,
isReimbursementQueuedAction,
isRenamedAction,
isReportActionAttachment,
isReportActionDeprecated,
isReportPreviewAction,
isResolvedActionTrackExpense,
isReversedTransaction,
isRoomChangeLogAction,
isSentMoneyReportAction,
isSplitBillAction,
isTrackExpenseAction,
isPayAction,
isTaskAction,
doesReportHaveVisibleActions,
isThreadParentMessage,
isTrackExpenseAction,
isTransactionThread,
isTripPreview,
isWhisperAction,
isWhisperActionTargetedToOthers,
isReimbursementQueuedAction,
shouldReportActionBeVisible,
shouldHideNewMarker,
shouldReportActionBeVisible,
shouldReportActionBeVisibleAsLastAction,
hasRequestFromCurrentAccount,
getFirstVisibleReportActionID,
isMemberChangeAction,
getMemberChangeMessageFragment,
isOldDotReportAction,
getTrackExpenseActionableWhisper,
getMessageOfOldDotReportAction,
getMemberChangeMessagePlainText,
isReimbursementDeQueuedAction,
isActionableMentionWhisper,
isActionableReportMentionWhisper,
getActionableMentionWhisperMessage,
isCurrentActionUnread,
isActionableJoinRequest,
isActionableJoinRequestPending,
getReportActionText,
getReportActionHtml,
getReportActionMessage,
getOriginalMessage,
isActionOfType,
isActionableTrackExpense,
getAllReportActions,
isLinkedTransactionHeld,
wasActionTakenByCurrentUser,
isResolvedActionTrackExpense,
isClosedAction,
isRenamedAction,
isRoomChangeLogAction,
isInviteOrRemovedAction,
isChronosOOOListAction,
isAddCommentAction,
isPolicyChangeLogAction,
getTextFromHtml,
isTripPreview,
getIOUActionForReportID,
getFilteredForOneTransactionView,
isActionableAddPaymentCard,
getExportIntegrationActionFragments,
getExportIntegrationLastMessageText,
Expand Down
Loading

0 comments on commit 0c8e2cc

Please sign in to comment.