Skip to content
Merged
65 changes: 54 additions & 11 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useTransactionViolations from '@hooks/useTransactionViolations';
import useViolations from '@hooks/useViolations';
import type {ViolationField} from '@hooks/useViolations';
import useViolations from '@hooks/useViolations';
import {getCompanyCardDescription} from '@libs/CardUtils';
import {isCategoryMissing} from '@libs/CategoryUtils';
import {convertToDisplayString} from '@libs/CurrencyUtils';
Expand All @@ -38,6 +38,7 @@
import {getLengthOfTag, getTagLists, hasDependentTags as hasDependentTagsPolicyUtils, isTaxTrackingEnabled} from '@libs/PolicyUtils';
import {getOriginalMessage, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {isSplitAction} from '@libs/ReportSecondaryActionUtils';
import type {TransactionDetails} from '@libs/ReportUtils';
import {
canEditFieldOfMoneyRequest,
canEditMoneyRequest,
Expand All @@ -54,7 +55,6 @@
isTrackExpenseReport,
shouldEnableNegative,
} from '@libs/ReportUtils';
import type {TransactionDetails} from '@libs/ReportUtils';
import {hasEnabledTags} from '@libs/TagsOptionsListUtils';
import {
getBillable,
Expand Down Expand Up @@ -437,6 +437,20 @@
],
);

const distanceCopyValue = !canEditDistance ? distanceToDisplay : undefined;
const distanceRateCopyValue = !canEditDistanceRate ? rateToDisplay : undefined;
const amountCopyValue = !canEditAmount ? amountTitle : undefined;
const descriptionCopyValue = !canEdit ? (updatedTransactionDescription ?? transactionDescription) : undefined;
const merchantCopyValue = !canEditMerchant ? updatedMerchantTitle : undefined;
const dateCopyValue = !canEditDate ? transactionDate : undefined;
const categoryValue = updatedTransaction?.category ?? categoryForDisplay;
const categoryCopyValue = !canEdit ? categoryValue : undefined;
const cardCopyValue = cardProgramName;
const taxRateValue = taxRateTitle ?? fallbackTaxRateTitle;
const taxRateCopyValue = !canEditTaxFields ? taxRateValue : undefined;
const taxAmountTitle = formattedTaxAmount ? formattedTaxAmount.toString() : '';
const taxAmountCopyValue = !canEditTaxFields ? taxAmountTitle : undefined;

const distanceRequestFields = (
<>
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints') ?? getPendingFieldAction('merchant')}>
Expand Down Expand Up @@ -467,7 +481,8 @@
ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction.transactionID, report.reportID, getReportRHPActiveRoute()),
);
}}
copyValue={!canEditDistance ? distanceToDisplay : undefined}
copyValue={distanceCopyValue}
copyable={!!distanceCopyValue}
/>
</OfflineWithFeedback>
<OfflineWithFeedback pendingAction={getPendingFieldAction('customUnitRateID')}>
Expand All @@ -493,7 +508,8 @@
}}
brickRoadIndicator={getErrorForField('customUnitRateID') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={getErrorForField('customUnitRateID')}
copyValue={!canEditDistanceRate ? rateToDisplay : undefined}
copyValue={distanceRateCopyValue}
copyable={!!distanceRateCopyValue}
/>
</OfflineWithFeedback>
</>
Expand All @@ -514,6 +530,11 @@
setCurrentTransactionTag(transactionTag);
}, [transactionTag, previousTransactionTag]);

const getAttendeesTitle = useMemo(() => {
return Array.isArray(actualAttendees) ? actualAttendees.map((item) => item?.displayName ?? item?.login).join(', ') : '';
}, [transactionAttendees]);

Check warning on line 535 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has a missing dependency: 'actualAttendees'. Either include it or remove the dependency array

Check warning on line 535 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has a missing dependency: 'actualAttendees'. Either include it or remove the dependency array
const attendeesCopyValue = !canEdit ? getAttendeesTitle : undefined;

const previousTagLength = getLengthOfTag(previousTag ?? '');
const currentTagLength = getLengthOfTag(currentTransactionTag ?? '');

Expand Down Expand Up @@ -544,6 +565,7 @@
hasDependentTags,
tagForDisplay,
);
const tagCopyValue = !canEdit ? tagForDisplay : undefined;

return (
<OfflineWithFeedback
Expand All @@ -570,13 +592,16 @@
errorText={tagError}
shouldShowBasicTitle
shouldShowDescriptionOnTop
copyValue={tagCopyValue}
copyable={!!tagCopyValue}
/>
</OfflineWithFeedback>
);
});

const actualParentReport = isFromMergeTransaction ? getReportOrDraftReport(getReportIDForExpense(updatedTransaction)) : parentReport;
const shouldShowReport = !!parentReportID || !!actualParentReport;
const reportCopyValue = !canEditReport ? getReportName(actualParentReport) || actualParentReport?.reportName : undefined;

// In this case we want to use this value. The shouldUseNarrowLayout will always be true as this case is handled when we display ReportScreen in RHP.
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
Expand Down Expand Up @@ -642,6 +667,8 @@
}}
brickRoadIndicator={getErrorForField('amount') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={getErrorForField('amount')}
copyValue={amountCopyValue}
copyable={!!amountCopyValue}
/>
</OfflineWithFeedback>
<OfflineWithFeedback pendingAction={getPendingFieldAction('comment')}>
Expand All @@ -661,6 +688,8 @@
brickRoadIndicator={getErrorForField('comment') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={getErrorForField('comment')}
numberOfLinesTitle={0}
copyValue={descriptionCopyValue}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coming from #72826, descriptionCopyValue should be converted from html to text

copyable={!!descriptionCopyValue}
/>
</OfflineWithFeedback>
{isManualDistanceRequest || (isMapDistanceRequest && transaction?.comment?.waypoints) ? (
Expand All @@ -682,7 +711,8 @@
brickRoadIndicator={getErrorForField('merchant') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={getErrorForField('merchant')}
numberOfLinesTitle={0}
copyValue={!canEditMerchant ? updatedMerchantTitle : undefined}
copyValue={merchantCopyValue}
copyable={!!merchantCopyValue}
/>
</OfflineWithFeedback>
)}
Expand All @@ -700,14 +730,15 @@
}}
brickRoadIndicator={getErrorForField('date') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={getErrorForField('date')}
copyValue={!canEditDate ? transactionDate : undefined}
copyValue={dateCopyValue}
copyable={!!dateCopyValue}
/>
</OfflineWithFeedback>
{!!shouldShowCategory && (
<OfflineWithFeedback pendingAction={getPendingFieldAction('category')}>
<MenuItemWithTopDescription
description={translate('common.category')}
title={updatedTransaction?.category ?? categoryForDisplay}
title={categoryValue}
numberOfLinesTitle={2}
interactive={canEdit}
shouldShowRightIcon={canEdit}
Expand All @@ -732,6 +763,8 @@
}}
brickRoadIndicator={getErrorForField('category') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={getErrorForField('category')}
copyValue={categoryCopyValue}
copyable={!!categoryCopyValue}
/>
</OfflineWithFeedback>
)}
Expand All @@ -740,16 +773,18 @@
<OfflineWithFeedback pendingAction={getPendingFieldAction('cardID')}>
<MenuItemWithTopDescription
description={translate('iou.card')}
title={cardProgramName}
title={cardCopyValue}
titleStyle={styles.flex1}
interactive={false}
copyValue={cardCopyValue}
copyable={!!cardCopyValue}
/>
</OfflineWithFeedback>
)}
{shouldShowTax && (
<OfflineWithFeedback pendingAction={getPendingFieldAction('taxCode')}>
<MenuItemWithTopDescription
title={taxRateTitle ?? fallbackTaxRateTitle}
title={taxRateValue}
description={taxRatesDescription}
interactive={canEditTaxFields}
shouldShowRightIcon={canEditTaxFields}
Expand All @@ -761,13 +796,15 @@
}}
brickRoadIndicator={getErrorForField('tax') ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={getErrorForField('tax')}
copyValue={taxRateCopyValue}
copyable={!!taxRateCopyValue}
/>
</OfflineWithFeedback>
)}
{shouldShowTax && (
<OfflineWithFeedback pendingAction={getPendingFieldAction('taxAmount')}>
<MenuItemWithTopDescription
title={formattedTaxAmount ? formattedTaxAmount.toString() : ''}
title={taxAmountTitle}
description={translate('iou.taxAmount')}
interactive={canEditTaxFields}
shouldShowRightIcon={canEditTaxFields}
Expand All @@ -777,14 +814,16 @@
ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction.transactionID, report.reportID, getReportRHPActiveRoute()),
);
}}
copyValue={taxAmountCopyValue}
copyable={!!taxAmountCopyValue}
/>
</OfflineWithFeedback>
)}
{shouldShowAttendees && (
<OfflineWithFeedback pendingAction={getPendingFieldAction('attendees')}>
<MenuItemWithTopDescription
key="attendees"
title={Array.isArray(actualAttendees) ? actualAttendees.map((item) => item?.displayName ?? item?.login).join(', ') : ''}
title={getAttendeesTitle}
description={`${translate('iou.attendees')} ${
Array.isArray(actualAttendees) && actualAttendees.length > 1 && formattedPerAttendeeAmount
? `${CONST.DOT_SEPARATOR} ${formattedPerAttendeeAmount} ${translate('common.perPerson')}`
Expand All @@ -798,6 +837,8 @@
interactive={canEdit}
shouldShowRightIcon={canEdit}
shouldRenderAsHTML
copyValue={attendeesCopyValue}
copyable={!!attendeesCopyValue}
/>
</OfflineWithFeedback>
)}
Expand Down Expand Up @@ -878,6 +919,8 @@
}}
interactive={canEditReport}
shouldRenderAsHTML
copyValue={reportCopyValue}
copyable={!!reportCopyValue}
/>
</OfflineWithFeedback>
)}
Expand Down
1 change: 1 addition & 0 deletions src/pages/workspace/WorkspaceOverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
wrapperStyle={styles.sectionMenuItemTopDescription}
onPress={onPressAddress}
copyValue={readOnly ? formattedAddress : undefined}
copyable={readOnly && !!formattedAddress}
/>
</View>
</OfflineWithFeedback>
Expand Down
Loading