Skip to content
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
7 changes: 4 additions & 3 deletions src/components/ReportActionItem/MoneyRequestReceiptView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import ReceiptStorage from '@libs/ReceiptStorage';
import retryReceiptUpload, {canRetryReceiptUpload} from '@libs/ReceiptUploadRetryHandler';
import type {ReceiptRetryContext} from '@libs/ReceiptUploadRetryHandler/types';
import {getThumbnailAndImageURIs} from '@libs/ReceiptUtils';
import {getOriginalMessage, isMoneyRequestAction, wasActionTakenByCurrentUser} from '@libs/ReportActionsUtils';
import {getOriginalMessage, resolveTransactionThreadReport, isMoneyRequestAction, wasActionTakenByCurrentUser} from '@libs/ReportActionsUtils';
import {isMarkAsCashActionForTransaction} from '@libs/ReportPrimaryActionUtils';
import {
canCurrentUserEditExpense,
Expand Down Expand Up @@ -191,6 +191,7 @@ function MoneyRequestReceiptView({
selector: transactionThreadReportIDSelector(transaction?.transactionID),
});
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(transactionThreadReportID)}`);
const resolvedTransactionThreadReport = resolveTransactionThreadReport(transaction, transactionThreadReport, report, parentReportAction);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport?.policyID}`);
const [policyVendors] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_VENDORS}${moneyRequestReport?.policyID}`);
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST);
Expand Down Expand Up @@ -457,7 +458,7 @@ function MoneyRequestReceiptView({
formatPhoneNumber,
getCurrencyDecimals,
transactionReport,
transactionThreadReport,
transactionThreadReport: resolvedTransactionThreadReport,
transactionViolations: rawTransactionViolations,
currentUserPersonalDetails: currentUserPersonalDetail,
}
Expand Down Expand Up @@ -651,7 +652,7 @@ function MoneyRequestReceiptView({
transactionReport,
delegateAccountID,
currentUserPersonalDetails: currentUserPersonalDetail,
transactionThreadReport,
transactionThreadReport: resolvedTransactionThreadReport,
});
};

Expand Down
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: 'Die Gesamtsumme wird aktualisiert, sobald du wieder online bist',
changedTheExpense: 'hat die Ausgabe geändert',
addedReceipt: 'hat einen Beleg hinzugefügt',
removedReceipt: 'hat einen Beleg entfernt',
setTheRequest: (valueName: string, newValueToDisplay: string) => `den Wert ${valueName} auf ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`lege ${translatedChangedField} auf ${newMerchant} fest, wodurch der Betrag auf ${newAmountToDisplay} gesetzt wurde`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: 'Το σύνολο θα ενημερωθεί όταν είστε ξανά συνδεδεμένοι στο διαδίκτυο',
changedTheExpense: 'τροποποίησε την δαπάνη',
addedReceipt: 'πρόσθεσε μια απόδειξη',
removedReceipt: 'αφαίρεσε μια απόδειξη',
setTheRequest: (valueName: string, newValueToDisplay: string) => `η τιμή ${valueName} σε ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`ορίστηκε το ${translatedChangedField} σε ${newMerchant}, το οποίο όρισε το ποσό σε ${newAmountToDisplay}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,7 @@ const translations = {
pendingConversionMessage: "Total will update when you're back online",
changedTheExpense: 'changed the expense',
addedReceipt: 'added a receipt',
removedReceipt: 'removed a receipt',
setTheRequest: (valueName: string, newValueToDisplay: string) => `the ${valueName} to ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`set the ${translatedChangedField} to ${newMerchant}, which set the amount to ${newAmountToDisplay}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: 'El total se actualizará cuando estés online',
changedTheExpense: 'cambió el gasto',
addedReceipt: 'añadió un recibo',
removedReceipt: 'eliminó un recibo',
setTheRequest: (valueName, newValueToDisplay) =>
`${valueName === 'comerciante' || valueName === 'importe' || valueName === 'gasto' ? 'el' : 'la'} ${valueName} a ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField, newMerchant, newAmountToDisplay) =>
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: 'Le total sera mis à jour quand vous serez de nouveau en ligne',
changedTheExpense: 'a modifié la dépense',
addedReceipt: 'a ajouté un reçu',
removedReceipt: 'a supprimé un reçu',
setTheRequest: (valueName: string, newValueToDisplay: string) => `le ${valueName} sur ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`défini le ${translatedChangedField} sur ${newMerchant}, ce qui a défini le montant sur ${newAmountToDisplay}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: 'Il totale verrà aggiornato quando torni online',
changedTheExpense: 'ha modificato la spesa',
addedReceipt: 'ha aggiunto una ricevuta',
removedReceipt: 'ha rimosso una ricevuta',
setTheRequest: (valueName: string, newValueToDisplay: string) => `${valueName} a ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`imposta ${translatedChangedField} su ${newMerchant}, che ha impostato l’importo su ${newAmountToDisplay}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: 'オンラインに戻ると合計が更新されます',
changedTheExpense: '経費を変更しました',
addedReceipt: '領収書を追加しました',
removedReceipt: '領収書を削除しました',
setTheRequest: (valueName: string, newValueToDisplay: string) => `${valueName} を ${newValueToDisplay} に`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`${translatedChangedField} を ${newMerchant} に設定し、その結果金額が ${newAmountToDisplay} に設定されました`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: 'Totaal wordt bijgewerkt zodra je weer online bent',
changedTheExpense: 'heeft de uitgave gewijzigd',
addedReceipt: 'heeft een bon toegevoegd',
removedReceipt: 'heeft een bon verwijderd',
setTheRequest: (valueName: string, newValueToDisplay: string) => `de ${valueName} naar ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`stel ${translatedChangedField} in op ${newMerchant}, waarmee het bedrag is ingesteld op ${newAmountToDisplay}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: 'Suma zaktualizuje się, gdy wrócisz do trybu online',
changedTheExpense: 'zmienił(a) wydatek',
addedReceipt: 'dodał(a) paragon',
removedReceipt: 'usunął(-ęła) paragon',
setTheRequest: (valueName: string, newValueToDisplay: string) => `${valueName} na ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`ustawiono ${translatedChangedField} na ${newMerchant}, co ustawiło kwotę na ${newAmountToDisplay}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: 'O total será atualizado quando você voltar a ficar online',
changedTheExpense: 'alterou a despesa',
addedReceipt: 'adicionou um recibo',
removedReceipt: 'removeu um recibo',
setTheRequest: (valueName: string, newValueToDisplay: string) => `o(a) ${valueName} para ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`definiu ${translatedChangedField} como ${newMerchant}, o que definiu o valor como ${newAmountToDisplay}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,7 @@ const translations: TranslationDeepObject<typeof en> = {
pendingConversionMessage: '当你重新联网时,总金额会更新',
changedTheExpense: '更改了报销单',
addedReceipt: '添加了收据',
removedReceipt: '删除了收据',
setTheRequest: (valueName: string, newValueToDisplay: string) => `将 ${valueName} 更改为 ${newValueToDisplay}`,
setTheDistanceMerchant: (translatedChangedField: string, newMerchant: string, newAmountToDisplay: string) =>
`将 ${translatedChangedField} 设置为 ${newMerchant},这会将金额设置为 ${newAmountToDisplay}`,
Expand Down
1 change: 1 addition & 0 deletions src/libs/API/parameters/DetachReceiptParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type DetachReceiptParams = {
transactionID: string;
reportActionID: string;
receiptRemovedReportActionID?: string;
};

export default DetachReceiptParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/ReplaceReceiptParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type ReplaceReceiptParams = {
receiptState?: ValueOf<typeof CONST.IOU.RECEIPT_STATE>;
isSameReceipt?: boolean;
reportActionID?: string;
receiptRemovedReportActionID?: string;
};

export default ReplaceReceiptParams;
4 changes: 4 additions & 0 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ function getForReportAction({
return translate('iou.addedReceipt');
}

if (isReportActionOriginalMessageAnObject && reportActionOriginalMessage.receiptRemoved) {
return translate('iou.removedReceipt');
}

// oldCurrency isn't required here: confirming a failed-scan placeholder amount (e.g. re-entering 0 to clear the
// scan error) has no real previous value, so neither the optimistic message nor the server's confirmed action
// include oldAmount/oldCurrency for it. Falling through to hasModifiedAmount=false would otherwise hide the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {ReceiptRetryContext} from './types';

import isRetrySupported from './isRetrySupported';

type StoredReplaceReceiptRetryParams = Pick<ReplaceReceiptRetryParams, 'transactionID' | 'state' | 'isSameReceipt' | 'receiptAddedReportActionID'>;
type StoredReplaceReceiptRetryParams = Pick<ReplaceReceiptRetryParams, 'transactionID' | 'state' | 'isSameReceipt' | 'receiptAddedReportActionID' | 'receiptRemovedReportActionID'>;

const RECEIPT_STATES = new Set<unknown>(Object.values(CONST.IOU.RECEIPT_STATE));

Expand Down Expand Up @@ -47,6 +47,7 @@ function getReplaceReceiptRetryParams(receiptError: ReceiptError): StoredReplace
state: 'state' in parsed && isReceiptState(parsed.state) ? parsed.state : undefined,
isSameReceipt: 'isSameReceipt' in parsed && parsed.isSameReceipt === true ? true : undefined,
receiptAddedReportActionID: 'receiptAddedReportActionID' in parsed && typeof parsed.receiptAddedReportActionID === 'string' ? parsed.receiptAddedReportActionID : undefined,
receiptRemovedReportActionID: 'receiptRemovedReportActionID' in parsed && typeof parsed.receiptRemovedReportActionID === 'string' ? parsed.receiptRemovedReportActionID : undefined,
};
}

Expand Down Expand Up @@ -85,6 +86,7 @@ function buildReplaceReceiptRetryPayload(context: ReceiptRetryContext, receiptFi
state: retryParams.state,
isSameReceipt: retryParams.isSameReceipt,
receiptAddedReportActionID: retryParams.receiptAddedReportActionID,
receiptRemovedReportActionID: retryParams.receiptRemovedReportActionID,
transactionPolicy: policyParams.policy,
transactionPolicyCategories: policyParams.policyCategories,
transactionPolicyTagList: policyParams.policyTagList,
Expand Down
23 changes: 23 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
PrivatePersonalDetails,
ReportMetadata,
ReportNameValuePairs,
Transaction,
VisibleReportActionsDerivedValue,
} from '@src/types/onyx';
import type {
Expand Down Expand Up @@ -2253,6 +2254,27 @@ function getLinkedTransactionID(reportAction: OnyxEntry<ReportAction> | undefine
return getOriginalMessage(reportAction)?.IOUTransactionID;
}

/**
* The expense's thread, or the open report when that report is the thread.
* Self DM expenses are unreported, so their thread is the report already on screen.
*/
function resolveTransactionThreadReport(
transaction: OnyxEntry<Transaction> | undefined,
transactionThreadReport: OnyxEntry<Report> | undefined,
report: OnyxEntry<Report> | undefined,
parentReportAction: OnyxEntry<ReportAction> | undefined,
): OnyxEntry<Report> | undefined {
if (transactionThreadReport?.reportID || !transaction?.transactionID) {
return transactionThreadReport;
}

if (getLinkedTransactionID(parentReportAction) === transaction.transactionID) {
return report;
}

return transactionThreadReport;
}

function getReportAction(reportID: string | undefined, reportActionID: string | undefined): ReportAction | undefined {
if (!reportID || !reportActionID) {
return undefined;
Expand Down Expand Up @@ -5780,6 +5802,7 @@ export {
getLastVisibleMessage,
getLatestReportActionFromOnyxData,
getLinkedTransactionID,
resolveTransactionThreadReport,
getCrossBorderReimbursedMessage,
getElsewherePaymentReportActionMessage,
getMarkedReimbursedMessage,
Expand Down
99 changes: 59 additions & 40 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8996,70 +8996,89 @@ function buildOptimisticModifiedExpenseReportAction(
}

/**
* Builds an optimistic DETACH_RECEIPT report action with a randomly generated reportActionID.
* Builds an optimistic "added a receipt" action that shares its ID with the server action.
*
* @param created Shared clock sample so a replacement can order the removal first.
* @param reportActionID Pre-generated so a retry updates this action instead of posting another.
*/
function buildOptimisticDetachReceipt(reportID: string | undefined, transactionID: string, merchant: string = CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT) {
return {
actionName: CONST.REPORT.ACTIONS.TYPE.MANAGER_DETACH_RECEIPT,
actorAccountID: deprecatedCurrentUserAccountID,
automatic: false,
avatar: getCurrentUserAvatar(),
created: DateUtils.getDBTime(),
isAttachmentOnly: false,
originalMessage: {
transactionID,
merchant: `${merchant}`,
},
message: [
{
type: 'COMMENT',
html: `detached a receipt from expense '${merchant}'`,
text: `detached a receipt from expense '${merchant}'`,
whisperedTo: [],
},
],
person: [
{
style: 'strong',
text: getPersonalDetail(deprecatedCurrentUserAccountID)?.displayName ?? String(deprecatedCurrentUserAccountID),
type: 'TEXT',
},
],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
reportActionID: rand64(),
function buildOptimisticReceiptAddedAction(
reportID: string | undefined,
transactionID: string,
currentUserAccountID: number,
currentUserDisplayName: string | undefined,
currentUserAvatar: AvatarSource | undefined,
delegateAccountID: number | undefined,
created?: string,
reportActionID: string = rand64(),
): OptimisticModifiedExpenseReportAction {
return buildOptimisticReceiptAuditAction(
reportID,
shouldShow: true,
};
transactionID,
currentUserAccountID,
currentUserDisplayName,
currentUserAvatar,
delegateAccountID,
'receiptAdded',
created,
reportActionID,
);
}

/**
* Builds an optimistic "added a receipt" action for the transaction thread.
* It shares a reportActionID with the server action so the two reconcile.
* Builds an optimistic "removed a receipt" action that shares its ID with the server action.
*
* @param created Set slightly earlier so a replacement shows the removal first.
* @param reportActionID Pre-generated so a retry updates this action instead of posting another.
*/
function buildOptimisticReceiptAddedAction(
function buildOptimisticReceiptRemovedAction(
reportID: string | undefined,
transactionID: string,
currentUserAccountID: number,
currentUserDisplayName: string | undefined,
currentUserAvatar: AvatarSource | undefined,
delegateAccountID: number | undefined,
created?: string,
reportActionID: string = rand64(),
) {
): OptimisticModifiedExpenseReportAction {
return buildOptimisticReceiptAuditAction(
reportID,
transactionID,
currentUserAccountID,
currentUserDisplayName,
currentUserAvatar,
delegateAccountID,
'receiptRemoved',
created,
reportActionID,
);
}

function buildOptimisticReceiptAuditAction(
reportID: string | undefined,
transactionID: string,
currentUserAccountID: number,
currentUserDisplayName: string | undefined,
currentUserAvatar: AvatarSource | undefined,
delegateAccountID: number | undefined,
changeKey: 'receiptAdded' | 'receiptRemoved',
created: string = DateUtils.getDBTime(),
reportActionID: string = rand64(),
): OptimisticModifiedExpenseReportAction {
return {
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE,
actorAccountID: currentUserAccountID,
automatic: false,
avatar: currentUserAvatar,
created: DateUtils.getDBTime(),
created,
isAttachmentOnly: false,
originalMessage: {
transactionID,
receiptAdded: true,
[changeKey]: true,
},
message: [
{
// The App builds the text from originalMessage, so this text is only used by OldDot.
text: 'You added a receipt',
text: changeKey === 'receiptAdded' ? 'You added a receipt' : 'You removed a receipt',
style: 'strong',
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
},
Expand Down Expand Up @@ -15084,8 +15103,8 @@ export {
buildOptimisticAnnounceChat,
buildOptimisticWorkspaceChats,
buildOptimisticCardAssignedReportAction,
buildOptimisticDetachReceipt,
buildOptimisticReceiptAddedAction,
buildOptimisticReceiptRemovedAction,
buildOptimisticRejectReportAction,
buildOptimisticRejectReportActionComment,
buildOptimisticReportLevelRejectAction,
Expand Down
Loading
Loading