Skip to content

Commit

Permalink
Revert "Reset amount on reset button click"
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in authored Jul 12, 2024
1 parent 7e6375c commit 73c33c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
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

0 comments on commit 73c33c7

Please sign in to comment.