-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Reset amount on reset button click #42897
Merged
youssef-lr
merged 31 commits into
Expensify:main
from
kaushiktd:reset-amount-keyboard-up
Jul 11, 2024
Merged
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
78f25f7
Reset amount on reset button click
kaushiktd 5a4feba
Reset amount on reset button click
kaushiktd 98c2c78
Reset amount on reset button click
kaushiktd 37af19b
Reset amount on reset button click
kaushiktd 4b30dd9
Reset amount on reset button click
kaushiktd 4c4e872
Reset amount on reset button click
kaushiktd cde4e5f
Reset amount on reset button click
kaushiktd c805f32
Reset amount on reset button click
kaushiktd 812ce37
Resolve Conflict
kaushiktd 7cd56e9
Reset amount on reset button click
kaushiktd 8f71b5d
Reset amount on reset button click
kaushiktd 057afeb
Reset amount on reset button click
kaushiktd bc0b3b3
Reset amount on reset button click
kaushiktd 96c4aca
Reset amount on reset button click
kaushiktd 1f5660c
Reset amount on reset button click
kaushiktd 6ea1723
Reset amount on reset button click
kaushiktd 364708b
Reset amount on reset button click
kaushiktd b454ac2
Reset amount on reset button click
kaushiktd bc10692
Reset amount on reset button click
kaushiktd 4db9a0a
Reset amount on reset button click
kaushiktd b3087ed
Reset amount on reset button click
kaushiktd d5df8f5
Merge branch 'Expensify:main' into reset-amount-keyboard-up
kaushiktd 10d3696
Merge branch 'Expensify:main' into reset-amount-keyboard-up
kaushiktd 1b40934
Reset amount on reset button click
kaushiktd 5a81a36
Reset amount on reset button click
kaushiktd ff59531
Reset amount on reset button click
kaushiktd 8042286
Reset amount on reset button click
kaushiktd 5a2602c
Reset amount on reset button click
kaushiktd 221b7a9
Reset amount on reset button click
kaushiktd bf86b78
Reset amount on reset button click
kaushiktd b1eda3e
Reset amount on reset button click
kaushiktd 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -88,6 +88,18 @@ type MoneyRequestAmountInputProps = { | |||||
* Autogrow input container length based on the entered text. | ||||||
*/ | ||||||
autoGrow?: boolean; | ||||||
|
||||||
/** | ||||||
* Determines whether the amount should be reset. | ||||||
*/ | ||||||
shouldResetAmount?: boolean; | ||||||
|
||||||
/** | ||||||
* Callback function triggered when the amount is reset. | ||||||
* | ||||||
* @param resetValue - A boolean indicating whether the amount should be reset. | ||||||
*/ | ||||||
onResetAmount?: (resetValue: boolean) => void; | ||||||
}; | ||||||
|
||||||
type Selection = { | ||||||
|
@@ -123,6 +135,8 @@ function MoneyRequestAmountInput( | |||||
hideFocusedState = true, | ||||||
shouldKeepUserInput = false, | ||||||
autoGrow = true, | ||||||
shouldResetAmount, | ||||||
onResetAmount, | ||||||
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.
Suggested change
|
||||||
...props | ||||||
}: MoneyRequestAmountInputProps, | ||||||
forwardedRef: ForwardedRef<BaseTextInputRef>, | ||||||
|
@@ -202,10 +216,21 @@ function MoneyRequestAmountInput( | |||||
})); | ||||||
|
||||||
useEffect(() => { | ||||||
const frontendAmount = onFormatAmount(amount, currency); | ||||||
setCurrentAmount(frontendAmount); | ||||||
if (shouldResetAmount) { | ||||||
setSelection({ | ||||||
start: frontendAmount.length, | ||||||
end: frontendAmount.length, | ||||||
}); | ||||||
onResetAmount?.(false); | ||||||
return; | ||||||
} | ||||||
|
||||||
if ((!currency || typeof amount !== 'number' || (formatAmountOnBlur && isTextInputFocused(textInput))) ?? shouldKeepUserInput) { | ||||||
return; | ||||||
} | ||||||
const frontendAmount = onFormatAmount(amount, currency); | ||||||
|
||||||
setCurrentAmount(frontendAmount); | ||||||
|
||||||
// Only update selection if the amount prop was changed from the outside and is not the same as the current amount we just computed | ||||||
|
@@ -219,7 +244,7 @@ function MoneyRequestAmountInput( | |||||
|
||||||
// we want to re-initialize the state only when the amount changes | ||||||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||||||
}, [amount, shouldKeepUserInput]); | ||||||
}, [amount, shouldKeepUserInput, shouldResetAmount]); | ||||||
|
||||||
// Modifies the amount to match the decimals for changed currency. | ||||||
useEffect(() => { | ||||||
|
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add comments to both of these props please?