Skip to content
Open
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
17 changes: 14 additions & 3 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function MoneyRequestView({
const {personalCardsWithBrokenConnection} = useCardFeedErrors();
const connectionLink = getBrokenConnectionUrlToFixPersonalCard(personalCardsWithBrokenConnection, environmentURL);
const [originalTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transaction?.comment?.originalTransactionID)}`, {canBeMissing: true});
const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction);
const {isExpenseSplit, isBillSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction);
const [transactionReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`, {canBeMissing: true});
const isSplitAvailable =
moneyRequestReport &&
Expand All @@ -349,23 +349,30 @@ function MoneyRequestView({
const canEditAmount =
!isGPSDistanceRequest &&
isEditable &&
!isBillSplit &&
Copy link
Contributor

Choose a reason for hiding this comment

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

❌ CONSISTENCY-3 (docs)

The !isBillSplit && guard is duplicated across 5 separate canEdit* variables (canEditAmount, canEditMerchant, canEditDate, canEditDistance, canEditDistanceRate). This same condition could be centralized inside canEditFieldOfMoneyRequest in src/libs/ReportUtils.ts, which already receives the transaction via linkedTransaction. Scattering the guard at call sites means any new caller of canEditFieldOfMoneyRequest won't benefit from this restriction, and any new canEdit* variable in this file must remember to add the guard.

Consider adding the isBillSplit check inside canEditFieldOfMoneyRequest for the relevant restricted fields (amount, merchant, date, distance, distance_rate), so it is enforced centrally:

// Inside canEditFieldOfMoneyRequest, after getting the transaction:
const {isBillSplit} = getOriginalTransactionWithSplitInfo(transaction);
if (isBillSplit && restrictedFields.includes(fieldToEdit)) {
    return false;
}

This removes the need for 5 repeated !isBillSplit && checks at the call site and the redundant isBillSplit early return in the onPress handler.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

(canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.AMOUNT, undefined, isChatReportArchived) || (isExpenseSplit && isSplitAvailable));
const canEditMerchant =
isEditable && canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.MERCHANT, undefined, isChatReportArchived, undefined, transaction, moneyRequestReport, policy);
isEditable &&
!isBillSplit &&
canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.MERCHANT, undefined, isChatReportArchived, undefined, transaction, moneyRequestReport, policy);

const canEditDate =
isEditable && canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DATE, undefined, isChatReportArchived, undefined, transaction, moneyRequestReport, policy);
isEditable &&
!isBillSplit &&
canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DATE, undefined, isChatReportArchived, undefined, transaction, moneyRequestReport, policy);

const canEditDistanceOrRate = isPolicyAccessible(policy, currentUserEmailParam) || isP2PDistanceRequest;

const canEditDistance =
!isGPSDistanceRequest &&
isEditable &&
!isBillSplit &&
canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE, undefined, isChatReportArchived, undefined, transaction, moneyRequestReport, policy) &&
canEditDistanceOrRate;

const canEditDistanceRate =
isEditable &&
!isBillSplit &&
canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE_RATE, undefined, isChatReportArchived, undefined, transaction, moneyRequestReport, policy) &&
canEditDistanceOrRate;

Expand Down Expand Up @@ -866,6 +873,10 @@ function MoneyRequestView({
return;
}

if (isBillSplit) {
return;
}

if (isExpenseSplit && isSplitAvailable) {
initSplitExpense(allTransactions, allReports, transaction);
return;
Expand Down
Loading