Skip to content

Commit

Permalink
Merge pull request #52428 from FitseTLT/fix-split-button-text-switchi…
Browse files Browse the repository at this point in the history
…ng-briefly

Fix - Distance - After tapping split expense with amount button, briefly "split expense" button shown
  • Loading branch information
Julesssss authored Nov 14, 2024
2 parents 458980d + b54c0fb commit d5a7b49
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {format} from 'date-fns';
import {fastMerge, Str} from 'expensify-common';
import {InteractionManager} from 'react-native';
import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxInputValue, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {PartialDeep, SetRequired, ValueOf} from 'type-fest';
Expand Down Expand Up @@ -74,6 +75,7 @@ import * as Policy from './Policy/Policy';
import * as Tag from './Policy/Tag';
import * as Report from './Report';
import {getRecentWaypoints, sanitizeRecentWaypoints} from './Transaction';
import * as TransactionEdit from './TransactionEdit';

type IOURequestType = ValueOf<typeof CONST.IOU.REQUEST_TYPE>;

Expand Down Expand Up @@ -624,12 +626,6 @@ function buildOnyxDataForMoneyRequest(
pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD},
},
},
// Remove the temporary transaction used during the creation flow
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`,
value: null,
},
);

if (!isEmptyObject(transactionThreadCreatedReportAction)) {
Expand Down Expand Up @@ -1004,12 +1000,6 @@ function buildOnyxDataForInvoice(
[transactionThreadCreatedReportAction?.reportActionID ?? '-1']: transactionThreadCreatedReportAction,
},
},
// Remove the temporary transaction used during the creation flow
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`,
value: null,
},
];
const successData: OnyxUpdate[] = [];

Expand Down Expand Up @@ -1451,12 +1441,6 @@ function buildOnyxDataForTrackExpense(
pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD},
},
},
// Remove the temporary transaction used during the creation flow
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`,
value: null,
},
);

if (!isEmptyObject(transactionThreadCreatedReportAction)) {
Expand Down Expand Up @@ -3680,6 +3664,7 @@ function requestMoney(
}
}

InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID);
if (activeReportID) {
Report.notifyNewAction(activeReportID, payeeAccountID);
Expand Down Expand Up @@ -3736,6 +3721,7 @@ function sendInvoice(
};

API.write(WRITE_COMMANDS.SEND_INVOICE, parameters, onyxData);
InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));

if (isSearchTopmostCentralPane()) {
Navigation.dismissModal();
Expand Down Expand Up @@ -3931,6 +3917,7 @@ function trackExpense(
API.write(WRITE_COMMANDS.TRACK_EXPENSE, parameters, onyxData);
}
}
InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID);

if (action === CONST.IOU.ACTION.SHARE) {
Expand Down Expand Up @@ -4118,11 +4105,6 @@ function createSplitsAndOnyxData(
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${splitTransaction.transactionID}`,
value: splitTransaction,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`,
value: null,
},
];
const successData: OnyxUpdate[] = [
{
Expand Down Expand Up @@ -4501,6 +4483,7 @@ function splitBill({
};

API.write(WRITE_COMMANDS.SPLIT_BILL, parameters, onyxData);
InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));

Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : existingSplitChatReportID);
Report.notifyNewAction(splitData.chatReportID, currentUserAccountID);
Expand Down Expand Up @@ -4568,6 +4551,7 @@ function splitBillAndOpenReport({
};

API.write(WRITE_COMMANDS.SPLIT_BILL_AND_OPEN_REPORT, parameters, onyxData);
InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));

Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : splitData.chatReportID);
Report.notifyNewAction(splitData.chatReportID, currentUserAccountID);
Expand Down Expand Up @@ -5138,6 +5122,7 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA
};

API.write(WRITE_COMMANDS.COMPLETE_SPLIT_BILL, parameters, {optimisticData, successData, failureData});
InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : chatReportID);
Report.notifyNewAction(chatReportID, sessionAccountID);
}
Expand Down Expand Up @@ -5315,6 +5300,7 @@ function createDistanceRequest(
});

API.write(WRITE_COMMANDS.CREATE_DISTANCE_REQUEST, parameters, onyxData);
InteractionManager.runAfterInteractions(() => TransactionEdit.removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID));
const activeReportID = isMoneyRequestReport ? report?.reportID ?? '-1' : parameters.chatReportID;
Navigation.dismissModal(isSearchTopmostCentralPane() ? undefined : activeReportID);
Report.notifyNewAction(activeReportID, userAccountID);
Expand Down

0 comments on commit d5a7b49

Please sign in to comment.