-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add backup transaction again #39144
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
Merged
Merged
Add backup transaction again #39144
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6379d9d
add backup transaction again
DylanDylann d85d48c
add isDraft param
DylanDylann 752d578
lint fix
DylanDylann 298876e
merge main
DylanDylann 1e96d99
merge main
DylanDylann 3e5bca2
merge main
DylanDylann d7f3b45
add new field and get correct transactionID
DylanDylann f0fa143
merge main
DylanDylann db75ccd
update comment
DylanDylann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import variables from '@styles/variables'; | |
| import * as IOU from '@userActions/IOU'; | ||
| import * as MapboxToken from '@userActions/MapboxToken'; | ||
| import * as Transaction from '@userActions/Transaction'; | ||
| import * as TransactionEdit from '@userActions/TransactionEdit'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
|
|
@@ -84,6 +85,7 @@ function IOURequestStepDistance({ | |
| const duplicateWaypointsError = useMemo(() => nonEmptyWaypointsCount >= 2 && _.size(validatedWaypoints) !== nonEmptyWaypointsCount, [nonEmptyWaypointsCount, validatedWaypoints]); | ||
| const atLeastTwoDifferentWaypointsError = useMemo(() => _.size(validatedWaypoints) < 2, [validatedWaypoints]); | ||
| const isEditing = action === CONST.IOU.ACTION.EDIT; | ||
| const transactionWasSaved = useRef(false); | ||
| const isCreatingNewRequest = !(backTo || isEditing); | ||
|
|
||
| useEffect(() => { | ||
|
|
@@ -112,6 +114,29 @@ function IOURequestStepDistance({ | |
| setShouldShowAtLeastTwoDifferentWaypointsError(false); | ||
| }, [atLeastTwoDifferentWaypointsError, duplicateWaypointsError, hasRouteError, isLoading, isLoadingRoute, nonEmptyWaypointsCount, transaction]); | ||
|
|
||
| // This effect runs when the component is mounted and unmounted. It's purpose is to be able to properly | ||
| // discard changes if the user cancels out of making any changes. This is accomplished by backing up the | ||
| // original transaction, letting the user modify the current transaction, and then if the user ever | ||
| // cancels out of the modal without saving changes, the original transaction is restored from the backup. | ||
| useEffect(() => { | ||
| if (isCreatingNewRequest) { | ||
| return () => {}; | ||
| } | ||
|
|
||
| // On mount, create the backup transaction. | ||
| TransactionEdit.createBackupTransaction(transaction); | ||
|
|
||
| return () => { | ||
| // If the user cancels out of the modal without without saving changes, then the original transaction | ||
| // needs to be restored from the backup so that all changes are removed. | ||
| if (transactionWasSaved.current) { | ||
| return; | ||
| } | ||
| TransactionEdit.restoreOriginalTransactionFromBackup(lodashGet(transaction, 'transactionID', ''), action === CONST.IOU.ACTION.CREATE); | ||
| }; | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
|
|
||
| const navigateBack = () => { | ||
| Navigation.goBack(backTo); | ||
| }; | ||
|
|
@@ -191,6 +216,9 @@ function IOURequestStepDistance({ | |
| setShouldShowAtLeastTwoDifferentWaypointsError(true); | ||
| return; | ||
| } | ||
| if (!isCreatingNewRequest) { | ||
| transactionWasSaved.current = true; | ||
| } | ||
|
Comment on lines
+219
to
+221
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have checked if |
||
| if (isEditing) { | ||
| // If nothing was changed, simply go to transaction thread | ||
| // We compare only addresses because numbers are rounded while backup | ||
|
|
@@ -213,6 +241,7 @@ function IOURequestStepDistance({ | |
| hasRouteError, | ||
| isLoadingRoute, | ||
| isLoading, | ||
| isCreatingNewRequest, | ||
| isEditing, | ||
| navigateToNextStep, | ||
| transactionBackup, | ||
|
|
@@ -292,7 +321,10 @@ export default compose( | |
| withFullTransactionOrNotFound, | ||
| withOnyx({ | ||
| transactionBackup: { | ||
| key: (props) => `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${props.transactionID}`, | ||
| key: ({route}) => { | ||
| const transactionID = lodashGet(route, 'params.transactionID', 0); | ||
| return `${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transactionID}`; | ||
| }, | ||
| }, | ||
| }), | ||
| )(IOURequestStepDistance); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.