Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/libs/actions/IOU/Duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ function duplicateExpenseTransaction({
quickAction,
recentWaypoints,
betas,
draftTransactionIDs,
isSelfTourViewed,
};
return trackExpense(trackExpenseParams);
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/IOU/MoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ type MoneyRequestStepDistanceNavigationParams = {
introSelected?: IntroSelected;
activePolicyID?: string;
privateIsArchived?: string;
draftTransactionIDs: string[] | undefined;
selfDMReport: OnyxEntry<Report>;
gpsCoordinates?: string;
gpsDistance?: number;
Expand Down Expand Up @@ -232,6 +233,7 @@ function createTransaction({
introSelected,
activePolicyID,
quickAction,
draftTransactionIDs,
recentWaypoints,
betas,
isSelfTourViewed,
Expand Down Expand Up @@ -580,6 +582,7 @@ function handleMoneyRequestStepDistanceNavigation({
introSelected,
activePolicyID,
privateIsArchived,
draftTransactionIDs = [],
Copy link
Contributor

Choose a reason for hiding this comment

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

same above

selfDMReport,
gpsCoordinates,
gpsDistance,
Expand Down Expand Up @@ -673,6 +676,7 @@ function handleMoneyRequestStepDistanceNavigation({
introSelected,
activePolicyID,
quickAction,
draftTransactionIDs,
recentWaypoints,
betas,
isSelfTourViewed,
Expand Down
8 changes: 5 additions & 3 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
policyRecentlyUsedCurrencies: string[];
existingTransactionDraft: OnyxEntry<OnyxTypes.Transaction>;
draftTransactionIDs: string[];
draftTransactionIDs: string[] | undefined;
isSelfTourViewed: boolean;
betas: OnyxEntry<OnyxTypes.Beta[]>;
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
Expand Down Expand Up @@ -720,6 +720,7 @@
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
recentWaypoints: OnyxEntry<OnyxTypes.RecentWaypoint[]>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
draftTransactionIDs: string[] | undefined;
isSelfTourViewed: boolean;
};

Expand Down Expand Up @@ -770,7 +771,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 774 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -869,7 +870,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 873 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -883,7 +884,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 887 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -892,7 +893,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 896 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -906,7 +907,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 910 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -919,7 +920,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 923 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -928,7 +929,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 932 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -938,7 +939,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 942 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -947,7 +948,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 951 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand All @@ -955,7 +956,7 @@
});

let allReportActions: OnyxCollection<OnyxTypes.ReportActions>;
Onyx.connect({

Check warning on line 959 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -6203,7 +6204,7 @@
quickAction,
policyRecentlyUsedCurrencies,
existingTransactionDraft,
draftTransactionIDs,
draftTransactionIDs = [],
isSelfTourViewed,
betas,
personalDetails,
Expand Down Expand Up @@ -6486,6 +6487,7 @@
quickAction,
recentWaypoints = [],
betas,
draftTransactionIDs = [],
isSelfTourViewed,
} = params;
const {participant, payeeAccountID, payeeEmail} = participantParams;
Expand Down Expand Up @@ -6819,7 +6821,7 @@

if (shouldHandleNavigation) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => removeDraftTransactions());
InteractionManager.runAfterInteractions(() => removeDraftTransactionsByIDs(draftTransactionIDs));
}

if (!params.isRetry) {
Expand Down
1 change: 1 addition & 0 deletions src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function SubmitDetailsPage({
quickAction,
recentWaypoints,
betas,
draftTransactionIDs,
isSelfTourViewed,
});
} else {
Expand Down
1 change: 1 addition & 0 deletions src/pages/iou/request/step/IOURequestStepAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ function IOURequestStepAmount({
quickAction,
recentWaypoints,
betas,
draftTransactionIDs,
isSelfTourViewed,
});
return;
Expand Down
7 changes: 6 additions & 1 deletion src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {validTransactionDraftIDsSelector} from '@src/selectors/TransactionDraft';
import type {PolicyTagLists, RecentlyUsedCategories, Report} from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/IOU';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
Expand Down Expand Up @@ -217,6 +218,7 @@ function IOURequestStepConfirmation({
const [userLocation] = useOnyx(ONYXKEYS.USER_LOCATION);
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector});

const reportAttributesDerived = useReportAttributes();
const [recentlyUsedDestinations] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_DESTINATIONS}${policyID}`);
Expand Down Expand Up @@ -688,7 +690,7 @@ function IOURequestStepConfirmation({
policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [],
quickAction,
existingTransactionDraft,
draftTransactionIDs: transactionIDs,
draftTransactionIDs,

Choose a reason for hiding this comment

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

P2 Badge Keep draft cleanup scoped to submitted transactions

Passing draftTransactionIDs here now sends every ID from ONYXKEYS.COLLECTION.TRANSACTION_DRAFT into requestMoney, and requestMoney later calls removeDraftTransactionsByIDs(...) on that list. In flows where the user has unrelated draft expenses open (for example, another in-progress request in a different report), submitting from this confirmation page will now clear those unrelated drafts as well, which is unintended data loss compared with using the local transactionIDs set for the current submission.

Useful? React with 👍 / 👎.

Copy link
Contributor

Choose a reason for hiding this comment

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

@codex this looks intentional

cc @dukenv0307

Choose a reason for hiding this comment

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

isSelfTourViewed,
betas,
personalDetails,
Expand Down Expand Up @@ -733,6 +735,7 @@ function IOURequestStepConfirmation({
betas,
personalDetails,
isGPSDistanceRequest,
draftTransactionIDs,
],
);

Expand Down Expand Up @@ -897,6 +900,7 @@ function IOURequestStepConfirmation({
quickAction,
recentWaypoints,
betas,
draftTransactionIDs,
isSelfTourViewed,
});
}
Expand Down Expand Up @@ -926,6 +930,7 @@ function IOURequestStepConfirmation({
quickAction,
recentWaypoints,
betas,
draftTransactionIDs,
isSelfTourViewed,
],
);
Expand Down
4 changes: 4 additions & 0 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {hasSeenTourSelector} from '@src/selectors/Onboarding';
import {validTransactionDraftIDsSelector} from '@src/selectors/TransactionDraft';
import type {Participant} from '@src/types/onyx/IOU';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {Waypoint, WaypointCollection} from '@src/types/onyx/Transaction';
Expand Down Expand Up @@ -105,6 +106,7 @@ function IOURequestStepDistance({
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const {policyForMovingExpenses} = usePolicyForMovingExpenses();
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector});
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});

const isEditing = action === CONST.IOU.ACTION.EDIT;
Expand Down Expand Up @@ -343,6 +345,7 @@ function IOURequestStepDistance({
policyForMovingExpenses,
betas,
recentWaypoints,
draftTransactionIDs,
isSelfTourViewed: !!isSelfTourViewed,
amountOwed,
});
Expand Down Expand Up @@ -379,6 +382,7 @@ function IOURequestStepDistance({
selfDMReport,
betas,
recentWaypoints,
draftTransactionIDs,
isSelfTourViewed,
amountOwed,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import withWritableReportOrNotFound from '@pages/iou/request/step/withWritableRe
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {hasSeenTourSelector} from '@src/selectors/Onboarding';
import {validTransactionDraftIDsSelector} from '@src/selectors/TransactionDraft';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import DistanceCounter from './DistanceCounter';
import GPSButtons from './GPSButtons';
Expand Down Expand Up @@ -55,6 +56,7 @@ function IOURequestStepDistanceGPS({
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector});
const selfDMReport = useSelfDMReport();
const {policyForMovingExpenses} = usePolicyForMovingExpenses();
const [betas] = useOnyx(ONYXKEYS.BETAS);
Expand Down Expand Up @@ -126,6 +128,7 @@ function IOURequestStepDistanceGPS({
recentWaypoints,
unit,
personalOutputCurrency: personalPolicy?.outputCurrency,
draftTransactionIDs,
isSelfTourViewed: !!isSelfTourViewed,
amountOwed,
});
Expand Down
4 changes: 4 additions & 0 deletions src/pages/iou/request/step/IOURequestStepDistanceManual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import {hasSeenTourSelector} from '@src/selectors/Onboarding';
import {validTransactionDraftIDsSelector} from '@src/selectors/TransactionDraft';
import type Transaction from '@src/types/onyx/Transaction';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import StepScreenWrapper from './StepScreenWrapper';
Expand Down Expand Up @@ -93,6 +94,7 @@ function IOURequestStepDistanceManual({
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`);
const [parentReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${getNonEmptyStringOnyxID(report?.parentReportID)}`);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector});
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});

const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`);
Expand Down Expand Up @@ -240,6 +242,7 @@ function IOURequestStepDistanceManual({
recentWaypoints,
unit,
personalOutputCurrency: personalPolicy?.outputCurrency,
draftTransactionIDs,
isSelfTourViewed: !!isSelfTourViewed,
amountOwed,
});
Expand Down Expand Up @@ -286,6 +289,7 @@ function IOURequestStepDistanceManual({
selfDMReport,
betas,
personalPolicy?.outputCurrency,
draftTransactionIDs,
isSelfTourViewed,
amountOwed,
],
Expand Down
5 changes: 5 additions & 0 deletions src/pages/iou/request/step/IOURequestStepDistanceMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {hasSeenTourSelector} from '@src/selectors/Onboarding';
import {validTransactionDraftIDsSelector} from '@src/selectors/TransactionDraft';
import type {Participant} from '@src/types/onyx/IOU';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {Waypoint, WaypointCollection} from '@src/types/onyx/Transaction';
Expand Down Expand Up @@ -169,6 +170,8 @@ function IOURequestStepDistanceMap({
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector});

const currentUserAccountIDParam = currentUserPersonalDetails.accountID;
const currentUserEmailParam = currentUserPersonalDetails.login ?? '';

Expand Down Expand Up @@ -335,6 +338,7 @@ function IOURequestStepDistanceMap({
policyForMovingExpenses,
betas,
recentWaypoints,
draftTransactionIDs,
isSelfTourViewed: !!isSelfTourViewed,
amountOwed,
});
Expand Down Expand Up @@ -371,6 +375,7 @@ function IOURequestStepDistanceMap({
selfDMReport,
betas,
recentWaypoints,
draftTransactionIDs,
isSelfTourViewed,
amountOwed,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import {hasSeenTourSelector} from '@src/selectors/Onboarding';
import {validTransactionDraftIDsSelector} from '@src/selectors/TransactionDraft';
import type Transaction from '@src/types/onyx/Transaction';
import type {FileObject} from '@src/types/utils/Attachment';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
Expand Down Expand Up @@ -117,6 +118,7 @@ function IOURequestStepDistanceOdometer({
const {policyForMovingExpenses} = usePolicyForMovingExpenses();
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [selectedTab, selectedTabResult] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.DISTANCE_REQUEST_TYPE}`);
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector});
const isLoadingSelectedTab = isLoadingOnyxValue(selectedTabResult);

// isEditing: we're changing an already existing odometer expense; isEditingConfirmation: we navigated here by pressing 'Distance' field from the confirmation step during the creation of a new odometer expense to adjust the input before submitting
Expand Down Expand Up @@ -471,6 +473,7 @@ function IOURequestStepDistanceOdometer({
recentWaypoints,
unit,
personalOutputCurrency: personalPolicy?.outputCurrency,
draftTransactionIDs,
isSelfTourViewed: !!isSelfTourViewed,
amountOwed,
});
Expand Down
11 changes: 9 additions & 2 deletions src/selectors/TransactionDraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ const validTransactionDraftsSelector = (drafts: OnyxCollection<Transaction>): Re
return acc;
}, {});

// eslint-disable-next-line import/prefer-default-export
export {validTransactionDraftsSelector};
const validTransactionDraftIDsSelector = (drafts: OnyxCollection<Transaction>): string[] =>
Object.values(drafts ?? {}).reduce<string[]>((acc, draft) => {
if (draft) {
acc.push(draft.transactionID);
}
return acc;
}, []);

export {validTransactionDraftsSelector, validTransactionDraftIDsSelector};
Loading
Loading