-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[CP Stg] Change tax on confirm page #73361
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -332,19 +332,14 @@ function MoneyRequestConfirmationList({ | |
|
|
||
| const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy, isDistanceRequest, isPerDiemRequest); | ||
|
|
||
| // Update the tax code when the default changes (for example, because the transaction currency changed) | ||
| const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? ''; | ||
|
blimpich marked this conversation as resolved.
blimpich marked this conversation as resolved.
roryabraham marked this conversation as resolved.
Contributor
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. ❌ PERF-6 (docs)The // Option 1: Move computation inside useEffect
useEffect(() => {
if (!transactionID) {
return;
}
const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? '';
setMoneyRequestTaxRate(transactionID, defaultTaxCode);
}, [policy, transaction, transactionID]);
// Option 2: Properly memoize the computation
const defaultTaxCode = useMemo(() => getDefaultTaxCode(policy, transaction) ?? '', [policy, transaction]); |
||
| useEffect(() => { | ||
| // Set the default tax code when conditions change | ||
| if (!shouldShowTax || !transaction || !transactionID) { | ||
|
Contributor
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. We removed the |
||
| if (!transactionID) { | ||
| return; | ||
| } | ||
| const defaultTaxCode = getDefaultTaxCode(policy, transaction); | ||
| const currentTaxCode = transaction.taxCode ?? ''; | ||
|
|
||
| // Update tax code if it's different from what should be the default | ||
| if (defaultTaxCode !== currentTaxCode) { | ||
| setMoneyRequestTaxRate(transactionID, defaultTaxCode ?? ''); | ||
| } | ||
| }, [customUnitRateID, policy, shouldShowTax, transaction, transactionID]); | ||
| setMoneyRequestTaxRate(transactionID, defaultTaxCode); | ||
|
blimpich marked this conversation as resolved.
|
||
| }, [defaultTaxCode, transactionID]); | ||
|
roryabraham marked this conversation as resolved.
roryabraham marked this conversation as resolved.
Contributor
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. ❌ PERF-6 (docs)The dependency array should specify individual object properties instead of entire objects. Currently, passing // Instead of relying on defaultTaxCode computed outside, specify the actual dependencies:
useEffect(() => {
if (!transactionID) {
return;
}
const defaultTaxCode = getDefaultTaxCode(policy, transaction) ?? '';
setMoneyRequestTaxRate(transactionID, defaultTaxCode);
}, [policy?.taxRates, policy?.defaultExternalID, transaction?.currency, transaction?.amount, transactionID]);This creates more granular dependency tracking and reduces unnecessary hook executions when unrelated policy or transaction properties change. |
||
|
|
||
| const isMovingTransactionFromTrackExpense = isMovingTransactionFromTrackExpenseUtil(action); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.