Skip to content

Track Expense - Polish #60067

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

Merged
merged 16 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,18 @@ function MoneyRequestConfirmationList({

const hasRoute = hasRouteUtil(transaction, isDistanceRequest);
const isDistanceRequestWithPendingRoute = isDistanceRequest && (!hasRoute || !rate) && !isMovingTransactionFromTrackExpense;

const distanceRequestAmount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES, rate ?? 0);
const formattedAmount = isDistanceRequestWithPendingRoute
? ''
: convertToDisplayString(shouldCalculateDistanceAmount ? distanceRequestAmount : iouAmount, isDistanceRequest ? currency : iouCurrencyCode);
const formattedAmountPerAttendee = isDistanceRequestWithPendingRoute
? ''
: convertToDisplayString(
(shouldCalculateDistanceAmount ? distanceRequestAmount : iouAmount) / (iouAttendees?.length && iouAttendees.length > 0 ? iouAttendees.length : 1),
isDistanceRequest ? currency : iouCurrencyCode,
);
const formattedAmountPerAttendee =
isDistanceRequestWithPendingRoute || isScanRequest
? ''
: convertToDisplayString(
(shouldCalculateDistanceAmount ? distanceRequestAmount : iouAmount) / (iouAttendees?.length && iouAttendees.length > 0 ? iouAttendees.length : 1),
isDistanceRequest ? currency : iouCurrencyCode,
);
const isFocused = useIsFocused();
const [formError, debouncedFormError, setFormError] = useDebouncedState<TranslationPaths | ''>('');

Expand Down
2 changes: 1 addition & 1 deletion src/components/MoneyRequestConfirmationListFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ function MoneyRequestConfirmationListFooter({
shouldShowRightIcon
title={iouAttendees?.map((item) => item?.displayName ?? item?.login).join(', ')}
description={`${translate('iou.attendees')} ${
iouAttendees?.length && iouAttendees.length > 1 ? `\u00B7 ${formattedAmountPerAttendee} ${translate('common.perPerson')}` : ''
iouAttendees?.length && iouAttendees.length > 1 && formattedAmountPerAttendee ? `\u00B7 ${formattedAmountPerAttendee} ${translate('common.perPerson')}` : ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we removed \u00B7? Was that by purpose? It caused #61429

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question. I don't recall. @allroundexperts do you recall?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't remember that. I think this was removed by mistake.

}`}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
Expand Down
26 changes: 20 additions & 6 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,16 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
const isEmptyMerchant = transactionMerchant === '' || transactionMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT;
const isDistanceRequest = isDistanceRequestTransactionUtils(transaction);
const isPerDiemRequest = isPerDiemRequestTransactionUtils(transaction);
const hasReceipt = hasReceiptTransactionUtils(updatedTransaction ?? transaction);
const isReceiptBeingScanned = hasReceipt && isReceiptBeingScannedTransactionUtils(updatedTransaction ?? transaction);
const didReceiptScanSucceed = hasReceipt && didReceiptScanSucceedTransactionUtils(transaction);
const hasRoute = hasRouteTransactionUtils(transactionBackup ?? transaction, isDistanceRequest);
const shouldDisplayTransactionAmount = ((isDistanceRequest && hasRoute) || !!transactionAmount) && transactionAmount !== undefined;
const formattedTransactionAmount = shouldDisplayTransactionAmount ? convertToDisplayString(transactionAmount, transactionCurrency) : '';
const formattedPerAttendeeAmount = shouldDisplayTransactionAmount ? convertToDisplayString(transactionAmount / (transactionAttendees?.length ?? 1), transactionCurrency) : '';
const formattedPerAttendeeAmount =
shouldDisplayTransactionAmount && !isReceiptBeingScanned && didReceiptScanSucceed
? convertToDisplayString(transactionAmount / (transactionAttendees?.length ?? 1), transactionCurrency)
: '';
const formattedOriginalAmount = transactionOriginalAmount && transactionOriginalCurrency && convertToDisplayString(transactionOriginalAmount, transactionOriginalCurrency);
const isCardTransaction = isCardTransactionTransactionUtils(transaction);
const cardProgramName = getCardName(transaction);
Expand Down Expand Up @@ -194,9 +200,6 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
const canEditMerchant = canUserPerformWriteAction && canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.MERCHANT);
const canEditDate = canUserPerformWriteAction && canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DATE);
const canEditReceipt = canUserPerformWriteAction && canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.RECEIPT);
const hasReceipt = hasReceiptTransactionUtils(updatedTransaction ?? transaction);
const isReceiptBeingScanned = hasReceipt && isReceiptBeingScannedTransactionUtils(updatedTransaction ?? transaction);
const didReceiptScanSucceed = hasReceipt && didReceiptScanSucceedTransactionUtils(transaction);
const canEditDistance = canUserPerformWriteAction && canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE);
const canEditDistanceRate = canUserPerformWriteAction && canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE_RATE);
const canEditReport = canUserPerformWriteAction && canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.REPORT);
Expand All @@ -207,7 +210,16 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals

const policyTagLists = useMemo(() => getTagLists(policyTagList), [policyTagList]);

const iouType = isTrackExpense ? CONST.IOU.TYPE.TRACK : CONST.IOU.TYPE.SUBMIT;
const iouType = useMemo(() => {
if (isTrackExpense) {
return CONST.IOU.TYPE.TRACK;
}
if (isInvoice) {
return CONST.IOU.TYPE.INVOICE;
}

return CONST.IOU.TYPE.SUBMIT;
}, [isTrackExpense, isInvoice]);

// Flags for showing categories and tags
// transactionCategory can be an empty string
Expand Down Expand Up @@ -749,7 +761,9 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
shouldShowRightIcon
title={Array.isArray(transactionAttendees) ? transactionAttendees.map((item) => item?.displayName ?? item?.login).join(', ') : ''}
description={`${translate('iou.attendees')} ${
Array.isArray(transactionAttendees) && transactionAttendees.length > 1 ? `${formattedPerAttendeeAmount} ${translate('common.perPerson')}` : ''
Array.isArray(transactionAttendees) && transactionAttendees.length > 1 && formattedPerAttendeeAmount
? `${formattedPerAttendeeAmount} ${translate('common.perPerson')}`
: ''
}`}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
Expand Down
4 changes: 2 additions & 2 deletions src/components/SelectionList/InviteMemberListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ function InviteMemberListItem<TItem extends ListItem>({
const theme = useTheme();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const {renderProductTrainingTooltip, shouldShowProductTrainingTooltip} = useProductTrainingContext(
CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.SCAN_TEST_TOOLTIP_MANAGER,
!getIsUserSubmittedExpenseOrScannedReceipt() && Permissions.canUseManagerMcTest(betas) && isSelectedManagerMcTest(item.login),
!getIsUserSubmittedExpenseOrScannedReceipt() && Permissions.canUseManagerMcTest(betas) && isSelectedManagerMcTest(item.login) && !item.isSelected,
);

const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type CategorizeTrackedExpenseParams = {
guidedSetupData?: string;
engagementChoice?: string;
description?: string;
attendees?: string;
};

export default CategorizeTrackedExpenseParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/CreateDistanceRequestParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type CreateDistanceRequestParams = {
splits?: string;
chatType?: string;
description?: string;
attendees?: string;
};

export default CreateDistanceRequestParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/CreatePerDiemRequestParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type CreatePerDiemRequestParams = {
transactionThreadReportID: string;
createdReportActionIDForThread: string | undefined;
billable?: boolean;
attendees?: string;
};

export default CreatePerDiemRequestParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/ShareTrackedExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ShareTrackedExpenseParams = {
description?: string;
accountantEmail: string;
policyName?: string;
attendees?: string;
};

export default ShareTrackedExpenseParams;
22 changes: 18 additions & 4 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/* eslint-disable no-continue */
import {Str} from 'expensify-common';
import keyBy from 'lodash/keyBy';
import lodashOrderBy from 'lodash/orderBy';
import Onyx from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
Expand Down Expand Up @@ -42,7 +43,7 @@ import Navigation from './Navigation/Navigation';
import Parser from './Parser';
import Performance from './Performance';
import Permissions from './Permissions';
import {getDisplayNameOrDefault, getPersonalDetailsByIDs} from './PersonalDetailsUtils';
import {getDisplayNameOrDefault, getPersonalDetailByEmail, getPersonalDetailsByIDs} from './PersonalDetailsUtils';
import {addSMSDomainIfPhoneNumber, parsePhoneNumber} from './PhoneNumber';
import {canSendInvoiceFromWorkspace, getSubmitToAccountID, isUserInvitedToWorkspace} from './PolicyUtils';
import {
Expand Down Expand Up @@ -222,7 +223,7 @@ type GetOptionsConfig = {
excludeLogins?: Record<string, boolean>;
includeRecentReports?: boolean;
includeSelectedOptions?: boolean;
recentAttendees?: Attendee[];
recentAttendees?: Option[];
excludeHiddenThreads?: boolean;
excludeHiddenChatRoom?: boolean;
canShowManagerMcTest?: boolean;
Expand Down Expand Up @@ -1876,11 +1877,24 @@ function getAttendeeOptions(
includeInvoiceRooms = false,
action: IOUAction | undefined = undefined,
) {
const personalDetailList = keyBy(
personalDetails.map(({item}) => item),
'accountID',
);
const filteredRecentAttendees = recentAttendees
.filter((attendee) => !attendees.find(({email, displayName}) => (attendee.email ? email === attendee.email : displayName === attendee.displayName)))
.map((attendee) => ({
...attendee,
login: attendee.email ?? attendee.displayName,
...getPersonalDetailByEmail(attendee.email),
}))
.map((attendee) => getParticipantsOption(attendee, personalDetailList as never));

return getValidOptions(
{reports, personalDetails},
{
betas,
selectedOptions: attendees,
selectedOptions: attendees.map((attendee) => ({...attendee, login: attendee.email})),
excludeLogins: CONST.EXPENSIFY_EMAILS_OBJECT,
includeOwnedWorkspaceChats,
includeRecentReports: false,
Expand All @@ -1889,7 +1903,7 @@ function getAttendeeOptions(
includeSelfDM: false,
includeInvoiceRooms,
action,
recentAttendees,
recentAttendees: filteredRecentAttendees,
},
);
}
Expand Down
1 change: 0 additions & 1 deletion src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ function isMerchantMissing(transaction: OnyxEntry<Transaction>) {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function shouldShowAttendees(iouType: IOUType, policy: OnyxEntry<Policy>): boolean {
return false;
// To be renabled once feature is complete: https://github.com/Expensify/App/issues/44725
// Keep this disabled for per diem expense
return iouType === CONST.IOU.TYPE.SUBMIT && !!policy?.id && (policy?.type === CONST.POLICY.TYPE.CORPORATE || policy?.type === CONST.POLICY.TYPE.TEAM);
Expand Down
Loading