Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ function QuickCreationActionsBar() {
allBetas,
false,
shouldDismissEmptyReportsConfirmation,
undefined,
translate,
);
// Navigate to the Reports page first so getCreateReportRoute() resolves against
// the Search/Reports fullscreen context before opening the created report modal.
Expand All @@ -111,7 +113,7 @@ function QuickCreationActionsBar() {
Navigation.navigate(getCreateReportRoute({reportID: createdReportID}));
});
},
[currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, allBetas],
[currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, allBetas, translate],
);

const {openCreateReportConfirmation} = useCreateEmptyReportConfirmation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function SearchActionsBarCreateButton() {
allBetas,
false,
shouldDismissEmptyReportsConfirmation,
undefined,
translate,
);
Navigation.setNavigationActionToMicrotaskQueue(() => {
Navigation.navigate(
Expand All @@ -96,7 +98,7 @@ function SearchActionsBarCreateButton() {
);
});
},
[currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, allBetas],
[currentUserPersonalDetails, hasViolations, defaultChatEnabledPolicy, isASAPSubmitBetaEnabled, allBetas, translate],
);

const {openCreateReportConfirmation} = useCreateEmptyReportConfirmation({
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useCreateNewReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {accountIDSelector, emailSelector} from '@selectors/Session';
import {useCallback} from 'react';

import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import useLocalize from './useLocalize';
import useOnyx from './useOnyx';
import usePermissions from './usePermissions';

Expand All @@ -19,6 +20,7 @@ function useCreateNewReport() {
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const {isBetaEnabled} = usePermissions();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const {translate} = useLocalize();
const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector});
const [email] = useOnyx(ONYXKEYS.SESSION, {selector: emailSelector});
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
Expand All @@ -30,9 +32,9 @@ function useCreateNewReport() {
return useCallback(
(policyID: string, shouldDismissEmptyReportsConfirmation = false) => {
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
return createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policy, betas, false, shouldDismissEmptyReportsConfirmation);
return createNewReport(currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policy, betas, false, shouldDismissEmptyReportsConfirmation, undefined, translate);
},
[betas, currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policies],
[betas, currentUserPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policies, translate],
);
}

Expand Down
47 changes: 23 additions & 24 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5576,6 +5576,8 @@ type GetReportPreviewMessageBaseParams = {
isForListPreview?: boolean;
/** This can be either a report preview action or the IOU action. This will be the original report preview action in cases where `iouReportAction` was unwrapped from a report preview action. Otherwise, it will be the same as `iouReportAction`. */
originalReportAction?: OnyxInputOrEntry<ReportAction>;
// TODO: We'll remove the optional (?) modifier from the translate parameter once https://github.com/Expensify/App/issues/66430 is completed

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.

❌ CONSISTENCY-11 (docs)

This change adds a // TODO: comment describing deferred work (removing the optional ? modifier from the translate parameter once issue #66430 is completed). Per contributingGuides/philosophies/OVERENGINEERING.md, future work should be captured in the linked GitHub issue rather than left as an in-code TODO, which is invisible to planning and tends to rot in the codebase.

Remove the TODO comment and rely on the referenced GitHub issue (#66430) to track making the translate parameter required:

    /** ... */
    originalReportAction?: OnyxInputOrEntry<ReportAction>;
    translate?: LocalizedTranslate;
};

Reviewed at: 9bff627 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

translate?: LocalizedTranslate;
};

/**
Expand All @@ -5585,6 +5587,7 @@ function getReportPreviewMessage(params: GetReportPreviewMessageBaseParams & {is
function getReportPreviewMessage(params: GetReportPreviewMessageBaseParams & {isCopyAction: true; reportAttributes?: ReportAttributesDerivedValue['reports']}): string;
function getReportPreviewMessage(params: GetReportPreviewMessageBaseParams & {isCopyAction?: boolean; reportAttributes?: ReportAttributesDerivedValue['reports']}): string {
const {reportOrID, iouReportAction = null, shouldConsiderScanningReceiptOrPendingRoute = false, isPreviewMessageForParentChatReport = false, policy, isForListPreview = false} = params;
const translateFn = params.translate ?? translateLocal;
const originalReportAction = params.originalReportAction ?? iouReportAction;
const report = typeof reportOrID === 'string' ? getReport(reportOrID, deprecatedAllReports) : reportOrID;
const reportActionMessage = getReportActionHtml(iouReportAction);
Expand Down Expand Up @@ -5617,16 +5620,16 @@ function getReportPreviewMessage(params: GetReportPreviewMessageBaseParams & {is

if (!isEmptyObject(linkedTransaction)) {
if (isScanning(linkedTransaction)) {
return translateLocal('iou.receiptScanning', {count: 1});
return translateFn('iou.receiptScanning', {count: 1});
}

if (hasMissingSmartscanFieldsTransactionUtils(linkedTransaction, report)) {
return translateLocal('iou.receiptMissingDetails');
return translateFn('iou.receiptMissingDetails');
}

const amount = getTransactionAmount(linkedTransaction, !isEmptyObject(report) && isExpenseReport(report), linkedTransaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID) ?? 0;
const formattedAmount = convertToDisplayString(amount, getCurrency(linkedTransaction)) ?? '';
return translateLocal('iou.didSplitAmount', formattedAmount, getMerchantOrDescription(linkedTransaction));
return translateFn('iou.didSplitAmount', formattedAmount, getMerchantOrDescription(linkedTransaction));
}
}

Expand All @@ -5641,43 +5644,43 @@ function getReportPreviewMessage(params: GetReportPreviewMessageBaseParams & {is

if (amount && currency) {
const formattedAmount = convertToDisplayString(amount, currency);
return translateLocal('iou.trackedAmount', formattedAmount, comment);
return translateFn('iou.trackedAmount', formattedAmount, comment);
}

return reportActionMessage;
}

if (!isEmptyObject(linkedTransaction)) {
if (isScanning(linkedTransaction)) {
return translateLocal('iou.receiptScanning', {count: 1});
return translateFn('iou.receiptScanning', {count: 1});
}

if (hasMissingSmartscanFieldsTransactionUtils(linkedTransaction, report)) {
return translateLocal('iou.receiptMissingDetails');
return translateFn('iou.receiptMissingDetails');
}

const amount = getTransactionAmount(linkedTransaction, !isEmptyObject(report) && isExpenseReport(report), linkedTransaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID) ?? 0;
const formattedAmount = convertToDisplayString(amount, getCurrency(linkedTransaction)) ?? '';

const merchantOrComment = getMerchantOrDescription(linkedTransaction);

return translateLocal('iou.trackedAmount', formattedAmount, merchantOrComment);
return translateFn('iou.trackedAmount', formattedAmount, merchantOrComment);
}
}

const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID);
const {totalDisplaySpend: totalAmount} = getMoneyRequestSpendBreakdown(report);

const parentReport = getParentReport(report);
const policyName = getPolicyName({report: parentReport ?? report, policy});
const policyName = getPolicyName({report: parentReport ?? report, policy, unavailableTranslation: translateFn('workspace.common.unavailable')});
const payerName = isExpenseReport(report)
? policyName
: getDisplayNameForParticipant({accountID: report.managerID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber: formatPhoneNumberPhoneUtils});

const formattedAmount = convertToDisplayString(totalAmount, report.currency);

if (isReportApproved({report}) && isReportInGroupPolicy(report)) {
return translateLocal('iou.managerApprovedAmount', payerName ?? '', formattedAmount);
return translateFn('iou.managerApprovedAmount', payerName ?? '', formattedAmount);
}

const reportPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
Expand All @@ -5688,11 +5691,11 @@ function getReportPreviewMessage(params: GetReportPreviewMessageBaseParams & {is
}

if (!isEmptyObject(linkedTransaction) && isScanning(linkedTransaction)) {
return translateLocal('iou.receiptScanning', {count: numberOfScanningReceipts});
return translateFn('iou.receiptScanning', {count: numberOfScanningReceipts});
}

if (!isEmptyObject(linkedTransaction) && isFetchingWaypointsFromServer(linkedTransaction) && !getTransactionAmount(linkedTransaction)) {
return translateLocal('iou.fieldPending');
return translateFn('iou.fieldPending');
}

const originalMessage = !isEmptyObject(iouReportAction) && isMoneyRequestAction(iouReportAction) ? getOriginalMessage(iouReportAction) : undefined;
Expand Down Expand Up @@ -5721,7 +5724,7 @@ function getReportPreviewMessage(params: GetReportPreviewMessageBaseParams & {is
if (isFromInvoice) {
translatePhraseKey = originalMessage?.payAsBusiness ? 'iou.settleInvoiceBusiness' : 'iou.settleInvoicePersonal';
const currentBankAccount = getBankAccountFromID(originalMessage?.bankAccountID);
return translateLocal(translatePhraseKey, formattedAmount, currentBankAccount?.accountData?.accountNumber?.slice(-4) ?? '');
return translateFn(translatePhraseKey, formattedAmount, currentBankAccount?.accountData?.accountNumber?.slice(-4) ?? '');
}
}

Expand All @@ -5734,22 +5737,22 @@ function getReportPreviewMessage(params: GetReportPreviewMessageBaseParams & {is
actualPayerName = actualPayerName && isForListPreview && !isPreviewMessageForParentChatReport ? `${actualPayerName}:` : actualPayerName;
const payerDisplayName = isPreviewMessageForParentChatReport ? payerName : actualPayerName;
if (translatePhraseKey === 'iou.businessBankAccount') {
return translateLocal(translatePhraseKey, '', originalMessage?.accountNumber?.slice(-4) ?? reportPolicy?.achAccount?.accountNumber?.slice(-4) ?? '');
return translateFn(translatePhraseKey, '', originalMessage?.accountNumber?.slice(-4) ?? reportPolicy?.achAccount?.accountNumber?.slice(-4) ?? '');
}
if (translatePhraseKey === 'iou.automaticallyPaidWithExpensify' || translatePhraseKey === 'iou.paidWithExpensify') {
return translateLocal(translatePhraseKey, payerDisplayName ?? '');
return translateFn(translatePhraseKey, payerDisplayName ?? '');
}
if (translatePhraseKey === 'iou.paidElsewhere') {
return getElsewherePaymentReportActionMessage(translateLocal, originalMessage, payerDisplayName ?? undefined);
return getElsewherePaymentReportActionMessage(translateFn, originalMessage, payerDisplayName ?? undefined);
}
if (translatePhraseKey === 'iou.payerPaidAmount') {
return translateLocal(translatePhraseKey, formattedAmount, payerDisplayName ?? '');
return translateFn(translatePhraseKey, formattedAmount, payerDisplayName ?? '');
}
}

if (report.isWaitingOnBankAccount) {
const submitterDisplayName = getDisplayNameForParticipant({accountID: report.ownerAccountID, shouldUseShortForm: true, formatPhoneNumber: formatPhoneNumberPhoneUtils}) ?? '';
return translateLocal('iou.waitingOnBankAccount', submitterDisplayName);
return translateFn('iou.waitingOnBankAccount', submitterDisplayName);
}

const lastActorID = iouReportAction?.actorAccountID;
Expand Down Expand Up @@ -5779,17 +5782,13 @@ function getReportPreviewMessage(params: GetReportPreviewMessageBaseParams & {is
lastActorID && lastActorID !== deprecatedCurrentUserAccountID
? getDisplayNameForParticipant({accountID: lastActorID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber: formatPhoneNumberPhoneUtils})
: '';
return `${requestorName ? `${requestorName}: ` : ''}${translateLocal('iou.expenseAmount', amountToDisplay, comment)}`;
return `${requestorName ? `${requestorName}: ` : ''}${translateFn('iou.expenseAmount', amountToDisplay, comment)}`;
}

if (containsNonReimbursable) {
return translateLocal(
'iou.payerSpentAmount',
formattedAmount,
getDisplayNameForParticipant({accountID: report.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils}) ?? '',
);
return translateFn('iou.payerSpentAmount', formattedAmount, getDisplayNameForParticipant({accountID: report.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils}) ?? '');
}
return translateLocal('iou.payerOwesAmount', formattedAmount, payerName ?? '', comment);
return translateFn('iou.payerOwesAmount', formattedAmount, payerName ?? '', comment);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/libs/actions/IOU/Duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,17 @@ function duplicateReport({
}

const newReportName = translate('common.copyOfReportName', sourceReportName);
const {reportPreviewReportActionID, ...newReport} = createNewReport(ownerPersonalDetails, false, isASAPSubmitBetaEnabled, targetPolicy, betas, false, undefined, newReportName);
const {reportPreviewReportActionID, ...newReport} = createNewReport(
ownerPersonalDetails,
false,
isASAPSubmitBetaEnabled,
targetPolicy,
betas,
false,
undefined,
newReportName,
translate,
);

const isCrossWorkspace = !!sourceReport && sourceReport.policyID !== targetPolicy.id;

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4590,7 +4590,7 @@ function createWorkspaceFromIOUPayment(
message: [
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
text: ReportUtils.getReportPreviewMessage({reportOrID: expenseReport, policy: newWorkspace}),
text: ReportUtils.getReportPreviewMessage({reportOrID: expenseReport, policy: newWorkspace, translate: localeTranslate}),
},
],
created: DateUtils.getDBTime(),
Expand Down
5 changes: 4 additions & 1 deletion src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3995,6 +3995,7 @@ function buildNewReportOptimisticData(
isASAPSubmitBetaEnabled: boolean,
betas: OnyxEntry<Beta[]>,
reportName?: string,
translate?: LocalizedTranslate,
) {
const {accountID, login, email} = ownerPersonalDetails;
const timeOfCreation = DateUtils.getDBTime();
Expand Down Expand Up @@ -4033,7 +4034,7 @@ function buildNewReportOptimisticData(
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
};

const message = getReportPreviewMessage({reportOrID: optimisticReportData});
const message = getReportPreviewMessage({reportOrID: optimisticReportData, translate});
const createReportActionMessage = [
{
html: message,
Expand Down Expand Up @@ -4235,6 +4236,7 @@ function createNewReport(
shouldNotifyNewAction = false,
shouldDismissEmptyReportsConfirmation?: boolean,
reportName?: string,
translate?: LocalizedTranslate,
) {
const optimisticReportID = generateReportID();
const reportActionID = rand64();
Expand All @@ -4250,6 +4252,7 @@ function createNewReport(
isASAPSubmitBetaEnabled,
betas,
reportName,
translate,
);

if (shouldDismissEmptyReportsConfirmation) {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Search/EmptySearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ function EmptySearchViewContent({
betas,
false,
shouldDismissEmptyReportsConfirmation,
undefined,
translate,
);
Navigation.setNavigationActionToMicrotaskQueue(() => {
Navigation.navigate(
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Search/SearchTransactionsChangeReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {ListItem} from '@components/SelectionList/types';

import useConditionalCreateEmptyReportConfirmation from '@hooks/useConditionalCreateEmptyReportConfirmation';
import useHasPerDiemTransactions from '@hooks/useHasPerDiemTransactions';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses';
Expand Down Expand Up @@ -54,6 +55,7 @@ function SearchTransactionsChangeReport() {
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const {isBetaEnabled} = usePermissions();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const {translate} = useLocalize();
const session = useSession();
const personalDetails = usePersonalDetails();
const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '');
Expand Down Expand Up @@ -142,6 +144,8 @@ function SearchTransactionsChangeReport() {
betas,
false,
shouldDismissEmptyReportsConfirmation,
undefined,
translate,
);
const reportNextStep = allReportNextSteps?.[`${ONYXKEYS.COLLECTION.NEXT_STEP}${optimisticReport.reportID}`];
const policyTagList = policyForMovingExpenses?.id ? allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyForMovingExpenses.id}`] : {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ const ContextMenuActions: ContextMenuAction[] = [
iouReportAction: reportAction,
isCopyAction: true,
reportAttributes,
translate,
});
Clipboard.setString(displayMessage);
} else if (isTaskActionReportActionsUtils(reportAction)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,17 @@ function AttachmentPickerWithMenuItems({
policyID: report?.policyID,
policyName: policy?.name ?? '',
onConfirm: (shouldDismissEmptyReportsConfirmation) =>
selectOption(() => createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, betas, true, shouldDismissEmptyReportsConfirmation), true),
selectOption(
() => createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, betas, true, shouldDismissEmptyReportsConfirmation, undefined, translate),
true,
),
});

const handleCreateReport = () => {
if (shouldShowEmptyReportConfirmation) {
openCreateReportConfirmation();
} else {
createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, betas, true, false);
createNewReport(currentUserPersonalDetails, isASAPSubmitBetaEnabled, hasViolations, policy, betas, true, false, undefined, translate);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ function CreateReportMenuItem() {
allBetas,
false,
shouldDismissEmptyReportsConfirmation,
undefined,
translate,
);
// Navigate to the Reports page first so getCreateReportRoute() resolves against
// the Search/Reports fullscreen context before opening the created report modal.
Expand Down
Loading
Loading