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

Reset amount on reset button click #42897

Merged
merged 31 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
78f25f7
Reset amount on reset button click
kaushiktd May 31, 2024
5a4feba
Reset amount on reset button click
kaushiktd May 31, 2024
98c2c78
Reset amount on reset button click
kaushiktd May 31, 2024
37af19b
Reset amount on reset button click
kaushiktd May 31, 2024
4b30dd9
Reset amount on reset button click
kaushiktd May 31, 2024
4c4e872
Reset amount on reset button click
kaushiktd May 31, 2024
cde4e5f
Reset amount on reset button click
kaushiktd May 31, 2024
c805f32
Reset amount on reset button click
kaushiktd May 31, 2024
812ce37
Resolve Conflict
kaushiktd Jun 6, 2024
7cd56e9
Reset amount on reset button click
kaushiktd Jun 6, 2024
8f71b5d
Reset amount on reset button click
kaushiktd Jun 6, 2024
057afeb
Reset amount on reset button click
kaushiktd Jun 6, 2024
bc0b3b3
Reset amount on reset button click
kaushiktd Jun 6, 2024
96c4aca
Reset amount on reset button click
kaushiktd Jun 6, 2024
1f5660c
Reset amount on reset button click
kaushiktd Jun 6, 2024
6ea1723
Reset amount on reset button click
kaushiktd Jun 24, 2024
364708b
Reset amount on reset button click
kaushiktd Jun 24, 2024
b454ac2
Reset amount on reset button click
kaushiktd Jun 24, 2024
bc10692
Reset amount on reset button click
kaushiktd Jun 24, 2024
4db9a0a
Reset amount on reset button click
kaushiktd Jun 24, 2024
b3087ed
Reset amount on reset button click
kaushiktd Jun 24, 2024
d5df8f5
Merge branch 'Expensify:main' into reset-amount-keyboard-up
kaushiktd Jun 25, 2024
10d3696
Merge branch 'Expensify:main' into reset-amount-keyboard-up
kaushiktd Jun 27, 2024
1b40934
Reset amount on reset button click
kaushiktd Jun 27, 2024
5a81a36
Reset amount on reset button click
kaushiktd Jun 28, 2024
ff59531
Reset amount on reset button click
kaushiktd Jun 28, 2024
8042286
Reset amount on reset button click
kaushiktd Jun 28, 2024
5a2602c
Reset amount on reset button click
kaushiktd Jul 10, 2024
221b7a9
Reset amount on reset button click
kaushiktd Jul 10, 2024
bf86b78
Reset amount on reset button click
kaushiktd Jul 10, 2024
b1eda3e
Reset amount on reset button click
kaushiktd Jul 10, 2024
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
23 changes: 21 additions & 2 deletions src/components/MoneyRequestAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ type MoneyRequestAmountInputProps = {
* Autogrow input container length based on the entered text.
*/
autoGrow?: boolean;

shouldResetAmount?: boolean;

onResetAmount?: (resetValue: boolean) => void;
Copy link
Contributor

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?

};

type Selection = {
Expand Down Expand Up @@ -121,6 +125,8 @@ function MoneyRequestAmountInput(
hideFocusedState = true,
shouldKeepUserInput = false,
autoGrow = true,
shouldResetAmount,
onResetAmount,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
onResetAmount,
onResetAmount = () => {},

...props
}: MoneyRequestAmountInputProps,
forwardedRef: ForwardedRef<BaseTextInputRef>,
Expand Down Expand Up @@ -196,10 +202,23 @@ function MoneyRequestAmountInput(
}));

useEffect(() => {
if (!currency || typeof amount !== 'number' || (formatAmountOnBlur && textInput.current?.isFocused()) || shouldKeepUserInput) {
const shouldExitEarly = !currency || typeof amount !== 'number' || (formatAmountOnBlur && textInput.current?.isFocused()) || shouldKeepUserInput;
const frontendAmount = onFormatAmount(amount, currency);

if (shouldResetAmount) {
setCurrentAmount(frontendAmount);
setSelection({
start: frontendAmount.length,
end: frontendAmount.length,
});
onResetAmount?.(false);
return;
}
const frontendAmount = onFormatAmount(amount, currency);

if (shouldExitEarly) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (shouldExitEarly) {
if ((!currency || typeof amount !== 'number' || (formatAmountOnBlur && isTextInputFocused(textInput))) ?? shouldKeepUserInput) {

return;
}

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
Expand Down
5 changes: 5 additions & 0 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ function MoneyRequestConfirmationList({
const shouldDisplayMerchantError = isMerchantRequired && (shouldDisplayFieldError || formError === 'iou.error.invalidMerchant') && isMerchantEmpty;

const isCategoryRequired = !!policy?.requiresCategory;
const [shouldResetAmount, setShouldResetAmount] = useState(false);

useEffect(() => {
if (shouldDisplayFieldError && didConfirmSplit) {
Expand Down Expand Up @@ -519,6 +520,8 @@ function MoneyRequestConfirmationList({
onFormatAmount={CurrencyUtils.convertToDisplayStringWithoutCurrency}
onAmountChange={(value: string) => onSplitShareChange(participantOption.accountID ?? 0, Number(value))}
maxLength={formattedTotalAmount.length}
shouldResetAmount={shouldResetAmount}
onResetAmount={() => setShouldResetAmount(false)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we pass resetValue to onResetAmount if we don't use it here?

/>
),
}));
Expand All @@ -541,6 +544,7 @@ function MoneyRequestConfirmationList({
transaction?.comment?.splits,
transaction?.splitShares,
onSplitShareChange,
shouldResetAmount,
]);

const isSplitModified = useMemo(() => {
Expand All @@ -558,6 +562,7 @@ function MoneyRequestConfirmationList({
<PressableWithFeedback
onPress={() => {
IOU.resetSplitShares(transaction);
setShouldResetAmount(true);
}}
accessibilityLabel={CONST.ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
Expand Down
Loading