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

fix: do not refresh draft txn after redirect #44363

Merged
merged 15 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,20 @@ function initMoneyRequest(reportID: string, policy: OnyxEntry<OnyxTypes.Policy>,
});
}

/**
*
* @param transactionID
* @param reportID
*/
dominictb marked this conversation as resolved.
Show resolved Hide resolved
function resetMoneyRequest(transactionID: string, reportID: string, isFromGlobalCreate: boolean) {
dominictb marked this conversation as resolved.
Show resolved Hide resolved
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {
reportID,
participants: [],
participantsAutoAssigned: false,
isFromGlobalCreate,
});
}

function createDraftTransaction(transaction: OnyxTypes.Transaction) {
if (!transaction) {
return;
Expand Down Expand Up @@ -6998,6 +7012,7 @@ export {
detachReceipt,
editMoneyRequest,
initMoneyRequest,
resetMoneyRequest,
navigateToStartStepIfScanFileCannotBeRead,
payMoneyRequest,
payInvoice,
Expand Down
10 changes: 9 additions & 1 deletion src/pages/iou/request/IOURequestStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ function IOURequestStartPage({
if (transaction?.reportID === reportID) {
return;
}
// if transaction is from global create, reset the reportID & participant
dominictb marked this conversation as resolved.
Show resolved Hide resolved
if (transaction?.isFromGlobalCreate && transaction.transactionID) {
IOU.resetMoneyRequest(transaction.transactionID, reportID, isFromGlobalCreate);
return;
}
IOU.initMoneyRequest(reportID, policy, isFromGlobalCreate, transactionRequestType.current);
}, [transaction, policy, reportID, iouType, isFromGlobalCreate]);

Expand All @@ -109,9 +114,12 @@ function IOURequestStartPage({

const resetIOUTypeIfChanged = useCallback(
(newIOUType: IOURequestType) => {
if (transaction?.iouRequestType === newIOUType) {
return;
}
IOU.initMoneyRequest(reportID, policy, isFromGlobalCreate, newIOUType);
},
[policy, reportID, isFromGlobalCreate],
[policy, reportID, isFromGlobalCreate, transaction?.iouRequestType],
);

if (!transaction?.transactionID) {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ function IOURequestStepConfirmation({
// If there is not a report attached to the IOU with a reportID, then the participants were manually selected and the user needs taken
// back to the participants step
if (!transaction?.participantsAutoAssigned) {
Navigation.goBack(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, reportID, undefined, action));
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Navigation.goBack(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, transaction?.reportID || reportID, undefined, action));
return;
}
IOUUtils.navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID, action);
Expand Down
Loading