fix Expense - Merchant can be made empty by using Expense as Merchant in expense rule - #81205
Conversation
|
@mkhutornyi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
| if (!isValid) { | ||
| (errors as Record<string, string>)[fieldID] = translate('common.error.characterLimitExceedCounter', byteLength, characterLimit); | ||
| } else if (fieldID === CONST.EXPENSE_RULES.FIELDS.RENAME_MERCHANT || fieldID === CONST.MERCHANT_RULES.FIELDS.MERCHANT) { | ||
| const isInvalidMerchant = trimmedValue === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT || trimmedValue === CONST.TRANSACTION.DEFAULT_MERCHANT; |
There was a problem hiding this comment.
❌ CONSISTENCY-3 (docs)
This pattern of checking if a merchant value equals CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT or CONST.TRANSACTION.DEFAULT_MERCHANT is duplicated throughout the codebase in at least 10+ locations:
src/libs/TransactionUtils/index.ts(lines 595, 598)src/libs/SearchUIUtils.ts(lines 893, 959, 2370-2371, 4266)src/pages/iou/request/step/IOURequestStepMerchant.tsx(lines 60, 94)src/components/ReportActionItem/MoneyRequestView.tsx(line 282)- And more...
Suggested fix: Create a reusable utility function in TransactionUtils or ValidationUtils:
/**
* Checks if a merchant string value is considered invalid/empty
*/
function isInvalidMerchantValue(merchant: string): boolean {
return merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT ||
merchant === CONST.TRANSACTION.DEFAULT_MERCHANT;
}Then use it here:
const isInvalidMerchant = isInvalidMerchantValue(trimmedValue);This consolidates the logic in one place, making it easier to maintain and update if invalid merchant criteria change in the future.
Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safariweb1.movweb2.mov |
|
@situchan conflicts |
|
🚀 Deployed to staging by https://github.com/luacmartins in version: 9.3.11-40 🚀
|
|
🚀 Deployed to production by https://github.com/Julesssss in version: 9.3.12-1 🚀
|
Explanation of Change
handle
(none),Expensemerchant namesFixed Issues
$ #81122
Tests
Case 1:
(none),Expense)Please enter a valid merchanterror showsCase 2:
Precondition: Rules is enabled in workspace
Offline tests
Same as Tests
QA Steps
Same as Tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-02-03.at.12.02.48.AM.mov