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 8 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
24 changes: 21 additions & 3 deletions src/components/MoneyRequestAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ type MoneyRequestAmountInputProps = {
* Autogrow input container length based on the entered text.
*/
autoGrow?: boolean;

/** Flag indicating if the reset button was clicked to reset the amount */
resetClicked?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should improve the naming to be more self-explanatory
Perhaps shouldResetAmount would work?

};

type Selection = {
Expand Down Expand Up @@ -116,6 +119,7 @@ function MoneyRequestAmountInput(
maxLength,
hideFocusedState = true,
autoGrow = true,
resetClicked = false,
...props
}: MoneyRequestAmountInputProps,
forwardedRef: ForwardedRef<BaseTextInputRef>,
Expand All @@ -135,6 +139,7 @@ function MoneyRequestAmountInput(
});

const forwardDeletePressedRef = useRef(false);
const resetFlag = useRef(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's call this the same as the new prop (resetClicked/shouldResetAmount/or whichever it ends up being called)


/**
* Sets the selection and the amount accordingly to the value passed to the input
Expand Down Expand Up @@ -165,11 +170,14 @@ function MoneyRequestAmountInput(
hasSelectionBeenSet = true;
setSelection((prevSelection) => getNewSelection(prevSelection, isForwardDelete ? strippedAmount.length : prevAmount.length, strippedAmount.length));
}
onAmountChange?.(strippedAmount);
return strippedAmount;
const resultAmount = resetFlag.current ? selectedAmountAsString : strippedAmount;
onAmountChange?.(resultAmount);

resetFlag.current = false; // Reset the flag after handling
return resultAmount;
});
},
[decimals, onAmountChange],
[decimals, onAmountChange, selectedAmountAsString],
);

useImperativeHandle(moneyRequestAmountInputRef, () => ({
Expand Down Expand Up @@ -258,6 +266,16 @@ function MoneyRequestAmountInput(

const formattedAmount = MoneyRequestUtils.replaceAllDigits(currentAmount, toLocaleDigit);

useEffect(() => {
if (!resetClicked) {
return;
}

resetFlag.current = true;
setNewAmount(selectedAmountAsString);
setSelection({start: formattedAmount.length, end: formattedAmount.length}); // Move cursor to the end
}, [resetClicked, selectedAmountAsString, setNewAmount, formattedAmount]);

return (
<TextInputWithCurrencySymbol
autoGrow={autoGrow}
Expand Down
4 changes: 4 additions & 0 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ function MoneyRequestConfirmationList({
const shouldDisplayMerchantError = isMerchantRequired && (shouldDisplayFieldError || formError === 'iou.error.invalidMerchant') && isMerchantEmpty;

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

useEffect(() => {
if (shouldDisplayFieldError && hasSmartScanFailed) {
Expand Down Expand Up @@ -513,6 +514,7 @@ function MoneyRequestConfirmationList({
onFormatAmount={CurrencyUtils.convertToDisplayStringWithoutCurrency}
onAmountChange={(value: string) => onSplitShareChange(participantOption.accountID ?? 0, Number(value))}
maxLength={formattedTotalAmount.length}
resetClicked={resetClicked}
/>
),
}));
Expand All @@ -535,6 +537,7 @@ function MoneyRequestConfirmationList({
transaction?.comment?.splits,
transaction?.splitShares,
onSplitShareChange,
resetClicked,
]);

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