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

Revert "Reset amount on reset button click" #45328

Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 5 additions & 27 deletions src/components/MoneyRequestAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,6 @@ 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 = {
Expand Down Expand Up @@ -135,8 +123,6 @@ function MoneyRequestAmountInput(
hideFocusedState = true,
shouldKeepUserInput = false,
autoGrow = true,
shouldResetAmount,
onResetAmount,
...props
}: MoneyRequestAmountInputProps,
forwardedRef: ForwardedRef<BaseTextInputRef>,
Expand Down Expand Up @@ -216,21 +202,10 @@ 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
Expand All @@ -241,7 +216,10 @@ function MoneyRequestAmountInput(
end: frontendAmount.length,
});
}
}, [amount, currency, formatAmountOnBlur, shouldKeepUserInput, onFormatAmount, shouldResetAmount, onResetAmount, currentAmount]);

// we want to re-initialize the state only when the amount changes
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [amount, shouldKeepUserInput]);

// Modifies the amount to match the decimals for changed currency.
useEffect(() => {
Expand Down
6 changes: 1 addition & 5 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function MoneyRequestConfirmationList({
const isMerchantRequired = isPolicyExpenseChat && (!isScanRequest || isEditingSplitBill) && shouldShowMerchant;

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

useEffect(() => {
if (shouldDisplayFieldError && didConfirmSplit) {
setFormError('iou.error.genericSmartscanFailureMessage');
Expand Down Expand Up @@ -479,8 +479,6 @@ function MoneyRequestConfirmationList({
onFormatAmount={CurrencyUtils.convertToDisplayStringWithoutCurrency}
onAmountChange={(value: string) => onSplitShareChange(participantOption.accountID ?? -1, Number(value))}
maxLength={formattedTotalAmount.length}
shouldResetAmount={shouldResetAmount}
onResetAmount={(resetValue) => setShouldResetAmount(resetValue)}
/>
),
}));
Expand All @@ -503,7 +501,6 @@ function MoneyRequestConfirmationList({
transaction?.comment?.splits,
transaction?.splitShares,
onSplitShareChange,
shouldResetAmount,
]);

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