Skip to content
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

Add report action for deleting expenses #54175

Merged
merged 11 commits into from
Jan 27, 2025
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ const CONST = {
CREATED: 'CREATED',
DELEGATE_SUBMIT: 'DELEGATESUBMIT', // OldDot Action
DELETED_ACCOUNT: 'DELETEDACCOUNT', // Deprecated OldDot Action
DELETED_TRANSACTION: 'DELETEDTRANSACTION',
DISMISSED_VIOLATION: 'DISMISSEDVIOLATION',
DONATION: 'DONATION', // Deprecated OldDot Action
EXPORTED_TO_CSV: 'EXPORTCSV', // OldDot Action
Expand Down Expand Up @@ -1071,6 +1072,7 @@ const CONST = {
ADD_CUSTOM_UNIT: 'POLICYCHANGELOG_ADD_CUSTOM_UNIT',
ADD_CUSTOM_UNIT_RATE: 'POLICYCHANGELOG_ADD_CUSTOM_UNIT_RATE',
ADD_EMPLOYEE: 'POLICYCHANGELOG_ADD_EMPLOYEE',
DELETED_TRANSACTION: 'POLICYCHANGELOG_DELETED_TRANSACTION',
ADD_INTEGRATION: 'POLICYCHANGELOG_ADD_INTEGRATION',
ADD_REPORT_FIELD: 'POLICYCHANGELOG_ADD_REPORT_FIELD',
ADD_TAG: 'POLICYCHANGELOG_ADD_TAG',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import type {
DelegatorParams,
DeleteActionParams,
DeleteConfirmationParams,
DeleteTransactionParams,
DidSplitAmountMessageParams,
EditActionParams,
EditDestinationSubtitleParams,
Expand Down Expand Up @@ -879,6 +880,7 @@ const translations = {
canceled: 'Canceled',
posted: 'Posted',
deleteReceipt: 'Delete receipt',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `deleted an expense on this report, ${merchant} - ${amount}`,
pendingMatchWithCreditCard: 'Receipt pending match with card transaction',
pendingMatchWithCreditCardDescription: 'Receipt pending match with card transaction. Mark as cash to cancel.',
markAsCash: 'Mark as cash',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import type {
DelegatorParams,
DeleteActionParams,
DeleteConfirmationParams,
DeleteTransactionParams,
DidSplitAmountMessageParams,
EditActionParams,
EditDestinationSubtitleParams,
Expand Down Expand Up @@ -878,6 +879,7 @@ const translations = {
pendingMatchWithCreditCardDescription: 'Recibo pendiente de adjuntar con la transacción de la tarjeta. Márcalo como efectivo para cancelar.',
markAsCash: 'Marcar como efectivo',
routePending: 'Ruta pendiente...',
deletedTransaction: ({amount, merchant}: DeleteTransactionParams) => `eliminó un gasto de este informe, ${merchant} - ${amount}`,
receiptIssuesFound: () => ({
one: 'Problema encontrado',
other: 'Problemas encontrados',
Expand Down
6 changes: 6 additions & 0 deletions src/languages/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ type RequestCountParams = {
pendingReceipts: number;
};

type DeleteTransactionParams = {
amount: string;
merchant: string;
};

type SettleExpensifyCardParams = {
formattedAmount: string;
};
Expand Down Expand Up @@ -728,6 +733,7 @@ export type {
ReportArchiveReasonsRemovedFromPolicyParams,
RequestAmountParams,
RequestCountParams,
DeleteTransactionParams,
RequestedAmountMessageParams,
ResolutionConstraintsParams,
RoomNameReservedErrorParams,
Expand Down
12 changes: 12 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4960,6 +4960,17 @@ function getWorkspaceNameUpdatedMessage(action: ReportAction) {
return message;
}

function getDeletedTransactionMessage(action: ReportAction) {
const deletedTransactionOriginalMessage = ReportActionsUtils.getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.DELETED_TRANSACTION>) ?? {};
const amount = Math.abs(deletedTransactionOriginalMessage.amount ?? 0);
const currency = CurrencyUtils.getCurrencySymbol(deletedTransactionOriginalMessage.currency ?? '');
const message = Localize.translateLocal('iou.deletedTransaction', {
amount: `${currency}${amount}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

You have used wrong format for displaying amount, which caused #55837

merchant: deletedTransactionOriginalMessage.merchant ?? '',
});
return message;
}

/**
* @param iouReportID - the report ID of the IOU report the action belongs to
* @param type - IOUReportAction type. Can be oneOf(create, decline, cancel, pay, split)
Expand Down Expand Up @@ -8790,6 +8801,7 @@ export {
getIOUForwardedMessage,
getRejectedReportMessage,
getWorkspaceNameUpdatedMessage,
getDeletedTransactionMessage,
getReportAutomaticallySubmittedMessage,
getIOUSubmittedMessage,
getIcons,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,8 +1363,8 @@ function readNewestAction(reportID: string | undefined, shouldResetUnreadMarker
/**
* Sets the last read time on a report
*/
function markCommentAsUnread(reportID: string, reportActionCreated: string) {
if (reportID === '-1') {
function markCommentAsUnread(reportID?: string, reportActionCreated?: string) {
if (reportID === '-1' || !reportID || !reportActionCreated) {
Log.warn('7339cd6c-3263-4f89-98e5-730f0be15784 Invalid report passed to MarkCommentAsUnread. Not calling the API because it wil fail.');
return;
}
Expand Down
14 changes: 8 additions & 6 deletions src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ const ContextMenuActions: ContextMenuAction[] = [
// is false, so we need to pass true here to override this condition.
ReportActionComposeFocusManager.focus(true);
});
Report.navigateToAndOpenChildReport(reportAction?.childReportID ?? '-1', reportAction, originalReportID);
Report.navigateToAndOpenChildReport(reportAction?.childReportID, reportAction, originalReportID);
});
return;
}
Report.navigateToAndOpenChildReport(reportAction?.childReportID ?? '-1', reportAction, originalReportID);
Report.navigateToAndOpenChildReport(reportAction?.childReportID, reportAction, originalReportID);
},
getDescription: () => {},
},
Expand All @@ -208,7 +208,7 @@ const ContextMenuActions: ContextMenuAction[] = [
successIcon: Expensicons.Checkmark,
shouldShow: ({type, isUnreadChat}) => type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION || (type === CONST.CONTEXT_MENU_TYPES.REPORT && !isUnreadChat),
onPress: (closePopover, {reportAction, reportID}) => {
const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction) ?? '-1';
const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction);
Report.markCommentAsUnread(originalReportID, reportAction?.created);
if (closePopover) {
hideContextMenu(true, ReportActionComposeFocusManager.focus);
Expand Down Expand Up @@ -239,7 +239,7 @@ const ContextMenuActions: ContextMenuAction[] = [
onPress: (closePopover, {reportID, reportAction, draftMessage}) => {
if (ReportActionsUtils.isMoneyRequestAction(reportAction)) {
hideContextMenu(false);
const childReportID = reportAction?.childReportID ?? '-1';
const childReportID = `${reportAction?.childReportID ?? CONST.DEFAULT_NUMBER_ID}`;
Report.openReport(childReportID);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(childReportID));
return;
Expand Down Expand Up @@ -324,13 +324,13 @@ const ContextMenuActions: ContextMenuAction[] = [
if (closePopover) {
hideContextMenu(false, () => {
ReportActionComposeFocusManager.focus();
Report.toggleSubscribeToChildReport(reportAction?.childReportID ?? '-1', reportAction, originalReportID, childReportNotificationPreference);
Report.toggleSubscribeToChildReport(reportAction?.childReportID, reportAction, originalReportID, childReportNotificationPreference);
});
return;
}

ReportActionComposeFocusManager.focus();
Report.toggleSubscribeToChildReport(reportAction?.childReportID ?? '-1', reportAction, originalReportID, childReportNotificationPreference);
Report.toggleSubscribeToChildReport(reportAction?.childReportID, reportAction, originalReportID, childReportNotificationPreference);
},
getDescription: () => {},
},
Expand Down Expand Up @@ -473,6 +473,8 @@ const ContextMenuActions: ContextMenuAction[] = [
setClipboardMessage(ReportActionsUtils.getPolicyChangeLogChangeRoleMessage(reportAction));
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_EMPLOYEE) {
setClipboardMessage(ReportActionsUtils.getPolicyChangeLogDeleteMemberMessage(reportAction));
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETED_TRANSACTION) {
setClipboardMessage(ReportUtils.getDeletedTransactionMessage(reportAction));
} else if (ReportActionsUtils.isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.INTEGRATION_SYNC_FAILED)) {
const {label, errorMessage} = ReportActionsUtils.getOriginalMessage(reportAction) ?? {label: '', errorMessage: ''};
setClipboardMessage(Localize.translateLocal('report.actions.type.integrationSyncFailed', {label, errorMessage}));
Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,8 @@ function PureReportActionItem({
children = <ReportActionItemBasicMessage message={ReportActionsUtils.getReportActionText(action)} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.UNHOLD) {
children = <ReportActionItemBasicMessage message={translate('iou.unheldExpense')} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.DELETED_TRANSACTION) {
children = <ReportActionItemBasicMessage message={ReportUtils.getDeletedTransactionMessage(action)} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MERGED_WITH_CASH_TRANSACTION) {
children = <ReportActionItemBasicMessage message={translate('systemMessage.mergedWithCashTransaction')} />;
} else if (ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.DISMISSED_VIOLATION)) {
Expand Down
13 changes: 13 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@ type OriginalMessageModifiedExpense = {
attendees?: string;
};

/** Model of the `deleted transaction` report action */
type OriginalMessageDeletedTransaction = {
/** The merchant of the transaction */
merchant?: string;

/** The amount of the transaction */
amount?: number;

/** The currency of the transaction */
currency?: string;
};

/** Model of `reimbursement queued` report action */
type OriginalMessageReimbursementQueued = {
/** How is the payment getting reimbursed */
Expand Down Expand Up @@ -637,6 +649,7 @@ type OriginalMessageMap = {
[CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL]: OriginalMessageCard;
[CONST.REPORT.ACTIONS.TYPE.CARD_ASSIGNED]: OriginalMessageCard;
[CONST.REPORT.ACTIONS.TYPE.INTEGRATION_SYNC_FAILED]: OriginalMessageIntegrationSyncFailed;
[CONST.REPORT.ACTIONS.TYPE.DELETED_TRANSACTION]: OriginalMessageDeletedTransaction;
} & OldDotOriginalMessageMap & {
[T in ValueOf<typeof CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG>]: OriginalMessageChangeLog;
} & {
Expand Down
Loading