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

[CP Staging] Uneven splits follow up #41717

Merged
merged 5 commits into from
May 7, 2024
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
6 changes: 5 additions & 1 deletion src/components/AmountTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type AmountTextInputProps = {

/** Style for the TextInput container */
containerStyle?: StyleProp<ViewStyle>;

/** Hide the focus styles on TextInput */
hideFocusedState?: boolean;
} & Pick<BaseTextInputProps, 'autoFocus'>;

function AmountTextInput(
Expand All @@ -50,14 +53,15 @@ function AmountTextInput(
onKeyPress,
containerStyle,
disableKeyboard = true,
hideFocusedState = true,
...rest
}: AmountTextInputProps,
ref: ForwardedRef<BaseTextInputRef>,
) {
return (
<TextInput
autoGrow
hideFocusedState
hideFocusedState={hideFocusedState}
shouldInterceptSwipe
disableKeyboard={disableKeyboard}
inputStyle={style}
Expand Down
6 changes: 6 additions & 0 deletions src/components/MoneyRequestAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ type MoneyRequestAmountInputProps = {
/** Whether we want to format the display amount on blur */
formatAmountOnBlur?: boolean;

/** Max length for the amount input */
maxLength?: number;

/** Hide the focus styles on TextInput */
hideFocusedState?: boolean;
};

type Selection = {
Expand Down Expand Up @@ -99,6 +103,7 @@ function MoneyRequestAmountInput(
disableKeyboard = true,
formatAmountOnBlur,
maxLength,
hideFocusedState = true,
...props
}: MoneyRequestAmountInputProps,
forwardedRef: ForwardedRef<BaseTextInputRef>,
Expand Down Expand Up @@ -279,6 +284,7 @@ function MoneyRequestAmountInput(
prefixContainerStyle={props.prefixContainerStyle}
touchableInputWrapperStyle={props.touchableInputWrapperStyle}
maxLength={maxLength}
hideFocusedState={hideFocusedState}
youssef-lr marked this conversation as resolved.
Show resolved Hide resolved
/>
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,8 @@ function MoneyRequestConfirmationList({
let amount: number | undefined = 0;
if (iouAmount > 0) {
amount =
isPolicyExpenseChat || !transaction?.comment?.splits
? IOUUtils.calculateAmount(selectedParticipants.length, iouAmount, iouCurrencyCode ?? '', isPayer)
: transaction.comment.splits.find((split) => split.accountID === participantOption.accountID)?.amount;
transaction?.comment?.splits?.find((split) => split.accountID === participantOption.accountID)?.amount ??
IOUUtils.calculateAmount(selectedParticipants.length, iouAmount, iouCurrencyCode ?? '', isPayer);
}
return {
...participantOption,
Expand All @@ -500,7 +499,7 @@ function MoneyRequestConfirmationList({
onAmountChange: (value: string) => onSplitShareChange(participantOption.accountID ?? 0, Number(value)),
},
}));
}, [transaction, iouCurrencyCode, isPolicyExpenseChat, onSplitShareChange, payeePersonalDetails, selectedParticipants, currencyList, iouAmount, shouldShowReadOnlySplits, StyleUtils]);
}, [transaction, iouCurrencyCode, onSplitShareChange, payeePersonalDetails, selectedParticipants, currencyList, iouAmount, shouldShowReadOnlySplits, StyleUtils]);

const isSplitModified = useMemo(() => {
if (!transaction?.splitShares) {
Expand Down Expand Up @@ -1090,6 +1089,7 @@ function MoneyRequestConfirmationList({
onConfirmSelection={confirm}
selectedOptions={selectedOptions}
disableArrowKeysActions
disableFocusOptions
boldStyle
showTitleTooltip
shouldTextInputAppearBelowOptions
Expand Down
4 changes: 2 additions & 2 deletions src/components/OptionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,16 @@ function OptionRow({
prefixCharacter={option.amountInputProps.prefixCharacter}
disableKeyboard={false}
isCurrencyPressable={false}
hideFocusedState={false}
hideCurrencySymbol
formatAmountOnBlur
touchableInputWrapperStyle={[styles.optionRowAmountInputWrapper, option.amountInputProps.containerStyle]}
prefixContainerStyle={[styles.pv0]}
containerStyle={[styles.textInputContainer]}
inputStyle={[
styles.optionRowAmountInput,
StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(option.amountInputProps.prefixCharacter ?? '') + styles.pl1.paddingLeft) as TextStyle,
option.amountInputProps.inputStyle,
]}
containerStyle={styles.iouAmountTextInputContainer}
onAmountChange={option.amountInputProps.onAmountChange}
maxLength={option.amountInputProps.maxLength}
/>
Expand Down
4 changes: 4 additions & 0 deletions src/components/TextInputWithCurrencySymbol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ type TextInputWithCurrencySymbolProps = {
/** Customizes the touchable wrapper of the TextInput component */
touchableInputWrapperStyle?: StyleProp<ViewStyle>;

/** Max length for the amount input */
maxLength?: number;

/** Hide the focus styles on TextInput */
hideFocusedState?: boolean;
} & Pick<BaseTextInputProps, 'autoFocus'>;

export default TextInputWithCurrencySymbolProps;
5 changes: 2 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6423,9 +6423,8 @@ function setSplitShares(transaction: OnyxEntry<OnyxTypes.Transaction>, amount: n
}

const isPayer = accountID === userAccountID;

// This function expects the length of participants without current user
const splitAmount = IOUUtils.calculateAmount(accountIDs.length - 1, amount, currency, isPayer);
const participantsLength = newAccountIDs.includes(userAccountID) ? newAccountIDs.length - 1 : newAccountIDs.length;
Copy link
Contributor Author

@youssef-lr youssef-lr May 7, 2024

Choose a reason for hiding this comment

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

Context: newAccountIDs may or may not contain the current user accountID depending on where this is called from. If we're splitting from within an existing group, it will have the user's accountID. If from Global Create, it won't. We need to send the participants length - 1 to calculateAmount

const splitAmount = IOUUtils.calculateAmount(participantsLength, amount, currency, isPayer);
return {
...result,
[accountID]: {
Expand Down
5 changes: 0 additions & 5 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,11 +1137,6 @@ const styles = (theme: ThemeColors) =>
borderColor: theme.border,
},

optionRowAmountInputWrapper: {
borderColor: theme.border,
borderBottomWidth: 2,
},

optionRowAmountInput: {
textAlign: 'right',
},
Expand Down
Loading