-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: negative amount in settlement button when the unheld expense comes from self #51209
Changes from 1 commit
f69e86b
702d6b5
02e1f41
c9b00c5
108c738
5e66d72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,7 @@ function ReportPreview({ | |
const [isPaidAnimationRunning, setIsPaidAnimationRunning] = useState(false); | ||
const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false); | ||
const [requestType, setRequestType] = useState<ActionHandledType>(); | ||
const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(iouReport, policy); | ||
const {nonHeldAmount, fullAmount, isNonHeldAmountNegative} = ReportUtils.getNonHeldAndFullAmount(iouReport, policy); | ||
const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(iouReport?.reportID ?? ''); | ||
const [paymentType, setPaymentType] = useState<PaymentMethodType>(); | ||
const [invoiceReceiverPolicy] = useOnyx( | ||
|
@@ -230,7 +230,7 @@ function ReportPreview({ | |
return ''; | ||
} | ||
|
||
if (ReportUtils.hasHeldExpenses(iouReport?.reportID) && canAllowSettlement) { | ||
if (ReportUtils.hasHeldExpenses(iouReport?.reportID) && canAllowSettlement && !isNonHeldAmountNegative) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's an example of something not clear. Why don't we return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Beamanator As the original issue states, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a great comment for this PR 🙏 Can you please add a comment like that here? & think about the other places you made similar changes - the point is so that other people can read the code & understand why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comments. |
||
return nonHeldAmount; | ||
} | ||
|
||
|
@@ -582,7 +582,7 @@ function ReportPreview({ | |
|
||
{isHoldMenuVisible && iouReport && requestType !== undefined && ( | ||
<ProcessMoneyReportHoldMenu | ||
nonHeldAmount={!hasOnlyHeldExpenses ? nonHeldAmount : undefined} | ||
nonHeldAmount={!hasOnlyHeldExpenses && !isNonHeldAmountNegative ? nonHeldAmount : undefined} | ||
requestType={requestType} | ||
fullAmount={fullAmount} | ||
onClose={() => setIsHoldMenuVisible(false)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -546,6 +546,12 @@ type ParsingDetails = { | |
policyID?: string; | ||
}; | ||
|
||
type NonHeldAndFullAmount = { | ||
nonHeldAmount: string; | ||
fullAmount: string; | ||
isNonHeldAmountNegative: boolean; | ||
}; | ||
|
||
type Thread = { | ||
parentReportID: string; | ||
parentReportActionID: string; | ||
|
@@ -7677,7 +7683,7 @@ function hasUpdatedTotal(report: OnyxInputOrEntry<Report>, policy: OnyxInputOrEn | |
/** | ||
* Return held and full amount formatted with used currency | ||
*/ | ||
function getNonHeldAndFullAmount(iouReport: OnyxEntry<Report>, policy: OnyxEntry<Policy>): string[] { | ||
function getNonHeldAndFullAmount(iouReport: OnyxEntry<Report>, policy: OnyxEntry<Policy>): NonHeldAndFullAmount { | ||
const reportTransactions = reportsTransactions[iouReport?.reportID ?? ''] ?? []; | ||
const hasPendingTransaction = reportTransactions.some((transaction) => !!transaction.pendingAction); | ||
|
||
|
@@ -7687,16 +7693,18 @@ function getNonHeldAndFullAmount(iouReport: OnyxEntry<Report>, policy: OnyxEntry | |
if (hasUpdatedTotal(iouReport, policy) && hasPendingTransaction) { | ||
const unheldTotal = reportTransactions.reduce((currentVal, transaction) => currentVal + (!TransactionUtils.isOnHold(transaction) ? transaction.amount : 0), 0); | ||
|
||
return [ | ||
CurrencyUtils.convertToDisplayString(unheldTotal * coefficient, iouReport?.currency), | ||
CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * coefficient, iouReport?.currency), | ||
]; | ||
return { | ||
nonHeldAmount: CurrencyUtils.convertToDisplayString(unheldTotal * coefficient, iouReport?.currency), | ||
fullAmount: CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * coefficient, iouReport?.currency), | ||
isNonHeldAmountNegative: unheldTotal * coefficient < 0, | ||
}; | ||
} | ||
|
||
return [ | ||
CurrencyUtils.convertToDisplayString((iouReport?.unheldTotal ?? 0) * coefficient, iouReport?.currency), | ||
CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * coefficient, iouReport?.currency), | ||
]; | ||
return { | ||
nonHeldAmount: CurrencyUtils.convertToDisplayString((iouReport?.unheldTotal ?? 0) * coefficient, iouReport?.currency), | ||
fullAmount: CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * coefficient, iouReport?.currency), | ||
isNonHeldAmountNegative: (iouReport?.unheldTotal ?? 0) * coefficient < 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
}; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkzie2 Please rename
isNonHeldAmountNegative
tohasValidNonHeldAmount
, as this makes more sense in the contexts where the boolean value is being checked.hasValidNonHeldAmount
should betrue
if thenonHeldAmount
value is not negative and is greater than0
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great suggestion. I updated.