Skip to content

Commit

Permalink
Merge pull request Expensify#31353 from Expensify/georgia-editCardTra…
Browse files Browse the repository at this point in the history
…nsactions

Allow editing card transactions (not amount)
  • Loading branch information
luacmartins authored Nov 24, 2023
2 parents 54df73c + 9b11ea3 commit 792376e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor
formattedTransactionAmount = translate('common.tbd');
}
const formattedOriginalAmount = transactionOriginalAmount && transactionOriginalCurrency && CurrencyUtils.convertToDisplayString(transactionOriginalAmount, transactionOriginalCurrency);
const isExpensifyCardTransaction = TransactionUtils.isExpensifyCardTransaction(transaction);
const cardProgramName = isExpensifyCardTransaction ? CardUtils.getCardDescription(transactionCardID) : '';
const isCardTransaction = TransactionUtils.isCardTransaction(transaction);
const cardProgramName = isCardTransaction ? CardUtils.getCardDescription(transactionCardID) : '';

// Flags for allowing or disallowing editing a money request
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
const canEdit = ReportUtils.canEditMoneyRequest(parentReportAction) && !isExpensifyCardTransaction;
const canEdit = ReportUtils.canEditMoneyRequest(parentReportAction);
const canEditAmount = canEdit && !isSettled && !isCardTransaction;

// A flag for verifying that the current report is a sub-report of a workspace chat
const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)), [report]);
Expand All @@ -125,7 +126,7 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor

let amountDescription = `${translate('iou.amount')}`;

if (isExpensifyCardTransaction) {
if (isCardTransaction) {
if (formattedOriginalAmount) {
amountDescription += ` • ${translate('iou.original')} ${formattedOriginalAmount}`;
}
Expand Down Expand Up @@ -190,8 +191,8 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor
titleIcon={Expensicons.Checkmark}
description={amountDescription}
titleStyle={styles.newKansasLarge}
interactive={canEdit && !isSettled}
shouldShowRightIcon={canEdit && !isSettled}
interactive={canEditAmount}
shouldShowRightIcon={canEditAmount}
onPress={() => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.AMOUNT))}
brickRoadIndicator={hasErrors && transactionAmount === 0 ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''}
error={hasErrors && transactionAmount === 0 ? translate('common.error.enterAmount') : ''}
Expand Down Expand Up @@ -271,13 +272,12 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor
/>
</OfflineWithFeedback>
)}
{isExpensifyCardTransaction && (
{isCardTransaction && (
<OfflineWithFeedback pendingAction={getPendingFieldAction('pendingFields.cardID')}>
<MenuItemWithTopDescription
description={translate('iou.card')}
title={cardProgramName}
titleStyle={styles.flex1}
interactive={canEdit}
/>
</OfflineWithFeedback>
)}
Expand Down
8 changes: 8 additions & 0 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ function isExpensifyCardTransaction(transaction: Transaction): boolean {
return isExpensifyCard(transaction.cardID);
}

/**
* Determine whether a transaction is made with a card.
*/
function isCardTransaction(transaction: Transaction): boolean {
return (transaction?.cardID ?? 0) > 0;
}

/**
* Check if the transaction status is set to Pending.
*/
Expand Down Expand Up @@ -475,6 +482,7 @@ export {
getValidWaypoints,
isDistanceRequest,
isExpensifyCardTransaction,
isCardTransaction,
isPending,
isPosted,
getWaypoints,
Expand Down

0 comments on commit 792376e

Please sign in to comment.