Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Expensify/App
Browse files Browse the repository at this point in the history
  • Loading branch information
perunt committed Jun 21, 2024
2 parents 3734b75 + a240ce8 commit 82b38df
Show file tree
Hide file tree
Showing 58 changed files with 1,100 additions and 1,006 deletions.
2 changes: 1 addition & 1 deletion src/components/ArchivedReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function ArchivedReportFooter({report, reportClosedAction, personalDetails = {}}
const styles = useThemeStyles();
const {translate} = useLocalize();

const originalMessage = reportClosedAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED ? reportClosedAction.originalMessage : null;
const originalMessage = ReportActionsUtils.isClosedAction(reportClosedAction) ? ReportActionsUtils.getOriginalMessage(reportClosedAction) : null;
const archiveReason = originalMessage?.reason ?? CONST.REPORT.ARCHIVE_REASON.DEFAULT;
const actorPersonalDetails = personalDetails?.[reportClosedAction?.actorAccountID ?? -1];
let displayName = PersonalDetailsUtils.getDisplayNameOrDefault(actorPersonalDetails);
Expand Down
2 changes: 1 addition & 1 deletion src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ export default withOnyx<AttachmentModalProps, AttachmentModalOnyxProps>({
transaction: {
key: ({report}) => {
const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1');
const transactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction?.originalMessage.IOUTransactionID ?? '-1' : '-1';
const transactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID ?? '-1' : '-1';
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`;
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ function extractAttachments(
return;
}

const decision = action?.message?.[0]?.moderationDecision?.decision;
const decision = ReportActionsUtils.getReportActionMessage(action)?.moderationDecision?.decision;
const hasBeenFlagged = decision === CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE || decision === CONST.MODERATION.MODERATOR_DECISION_HIDDEN;
const html = (action?.message?.[0]?.html ?? '').replace('/>', `data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"/>`);
const html = ReportActionsUtils.getReportActionHtml(action).replace('/>', `data-flagged="${hasBeenFlagged}" data-id="${action.reportActionID}"/>`);
htmlParser.write(html);
});
htmlParser.end();
Expand Down
8 changes: 5 additions & 3 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
const itemParentReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport?.parentReportID}`];
const itemParentReportAction = itemParentReportActions?.[itemFullReport?.parentReportActionID ?? '-1'];
const itemPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport?.policyID}`];
const transactionID = itemParentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? itemParentReportAction.originalMessage.IOUTransactionID ?? '-1' : '-1';
const transactionID = ReportActionsUtils.isMoneyRequestAction(itemParentReportAction)
? ReportActionsUtils.getOriginalMessage(itemParentReportAction)?.IOUTransactionID ?? '-1'
: '-1';
const itemTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
const hasDraftComment = DraftCommentUtils.isValidDraftComment(draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`]);
const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(itemReportActions);
Expand All @@ -128,8 +130,8 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
// Get the transaction for the last report action
let lastReportActionTransactionID = '';

if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) {
lastReportActionTransactionID = lastReportAction.originalMessage?.IOUTransactionID ?? '-1';
if (ReportActionsUtils.isMoneyRequestAction(lastReportAction)) {
lastReportActionTransactionID = ReportActionsUtils.getOriginalMessage(lastReportAction)?.IOUTransactionID ?? '-1';
}
const lastReportActionTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${lastReportActionTransactionID}`] ?? {};

Expand Down
1 change: 1 addition & 0 deletions src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ function MenuItem(
...(Array.isArray(wrapperStyle) ? wrapperStyle : [wrapperStyle]),
!focused && (isHovered || pressed) && hoverAndPressStyle,
shouldGreyOutWhenDisabled && disabled && styles.buttonOpacityDisabled,
isHovered && !pressed && styles.hoveredComponentBG,
] as StyleProp<ViewStyle>
}
disabledStyle={shouldUseDefaultCursorWhenDisabled && [styles.cursorDefault]}
Expand Down
12 changes: 8 additions & 4 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
if (!reportActions || !transactionThreadReport?.parentReportActionID) {
return null;
}
return reportActions.find((action) => action.reportActionID === transactionThreadReport.parentReportActionID);
return reportActions.find((action): action is OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> => action.reportActionID === transactionThreadReport.parentReportActionID);
}, [reportActions, transactionThreadReport?.parentReportActionID]);
const isDeletedParentAction = ReportActionsUtils.isDeletedAction(requestParentReportAction as OnyxTypes.ReportAction);
const isDeletedParentAction = !!requestParentReportAction && ReportActionsUtils.isDeletedAction(requestParentReportAction);

// Only the requestor can delete the request, admins can only edit it.
const isActionOwner =
Expand Down Expand Up @@ -151,7 +151,9 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea

const deleteTransaction = useCallback(() => {
if (requestParentReportAction) {
const iouTransactionID = requestParentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? requestParentReportAction.originalMessage?.IOUTransactionID ?? '-1' : '-1';
const iouTransactionID = ReportActionsUtils.isMoneyRequestAction(requestParentReportAction)
? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID ?? '-1'
: '-1';
if (ReportActionsUtils.isTrackExpenseAction(requestParentReportAction)) {
navigateBackToAfterDelete.current = IOU.deleteTrackExpense(moneyRequestReport?.reportID ?? '-1', iouTransactionID, requestParentReportAction, true);
} else {
Expand All @@ -166,7 +168,9 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
if (!requestParentReportAction) {
return;
}
const iouTransactionID = requestParentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? requestParentReportAction.originalMessage?.IOUTransactionID ?? '-1' : '-1';
const iouTransactionID = ReportActionsUtils.isMoneyRequestAction(requestParentReportAction)
? ReportActionsUtils.getOriginalMessage(requestParentReportAction)?.IOUTransactionID ?? '-1'
: '-1';
const reportID = transactionThreadReport?.reportID ?? '-1';

TransactionActions.markAsCash(iouTransactionID, reportID);
Expand Down
11 changes: 7 additions & 4 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import type {Policy, Report, ReportAction} from '@src/types/onyx';
import type {OriginalMessageIOU} from '@src/types/onyx/OriginalMessage';
import type IconAsset from '@src/types/utils/IconAsset';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import Button from './Button';
Expand Down Expand Up @@ -51,7 +50,11 @@ type MoneyRequestHeaderProps = {

function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrowLayout = false, onBackButtonPress}: MoneyRequestHeaderProps) {
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${(parentReportAction as ReportAction & OriginalMessageIOU)?.originalMessage?.IOUTransactionID ?? -1}`);
const [transaction] = useOnyx(
`${ONYXKEYS.COLLECTION.TRANSACTION}${
ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID ?? -1 : -1
}`,
);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {initialValue: true});
Expand Down Expand Up @@ -80,7 +83,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow

const deleteTransaction = useCallback(() => {
if (parentReportAction) {
const iouTransactionID = parentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage?.IOUTransactionID ?? '-1' : '-1';
const iouTransactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID ?? '-1' : '-1';
if (ReportActionsUtils.isTrackExpenseAction(parentReportAction)) {
navigateBackToAfterDelete.current = IOU.deleteTrackExpense(parentReport?.reportID ?? '-1', iouTransactionID, parentReportAction, true);
} else {
Expand All @@ -104,7 +107,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
const canDeleteRequest = isActionOwner && (ReportUtils.canAddOrDeleteTransactions(moneyRequestReport) || ReportUtils.isTrackExpenseReport(report)) && !isDeletedParentAction;

const changeMoneyRequestStatus = () => {
const iouTransactionID = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage?.IOUTransactionID ?? '-1' : '-1';
const iouTransactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID ?? '-1' : '-1';

if (isOnHold) {
IOU.unholdRequest(iouTransactionID, report?.reportID);
Expand Down
9 changes: 5 additions & 4 deletions src/components/ReportActionItem/ChronosOOOListActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import DateUtils from '@libs/DateUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as Chronos from '@userActions/Chronos';
import type {OriginalMessageChronosOOOList} from '@src/types/onyx/OriginalMessage';
import type {ReportActionBase} from '@src/types/onyx/ReportAction';
import type CONST from '@src/CONST';
import type ReportAction from '@src/types/onyx/ReportAction';

type ChronosOOOListActionsProps = {
/** The ID of the report */
reportID: string;

/** All the data of the action */
action: ReportActionBase & OriginalMessageChronosOOOList;
action: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.CHRONOS_OOO_LIST>;
};

function ChronosOOOListActions({reportID, action}: ChronosOOOListActionsProps) {
const styles = useThemeStyles();

const {translate, preferredLocale} = useLocalize();

const events = action.originalMessage?.events ?? [];
const events = ReportActionsUtils.getOriginalMessage(action)?.events ?? [];

if (!events.length) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import variables from '@styles/variables';
import * as PaymentMethods from '@userActions/PaymentMethods';
import * as Report from '@userActions/Report';
import CONST from '@src/CONST';
import type {IOUMessage} from '@src/types/onyx/OriginalMessage';
import type {OriginalMessageIOU} from '@src/types/onyx/OriginalMessage';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type {MoneyRequestPreviewProps, PendingMessageProps} from './types';
Expand Down Expand Up @@ -74,7 +74,8 @@ function MoneyRequestPreviewContent({
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(chatReport);
const {canUseViolations} = usePermissions();

const participantAccountIDs = action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && isBillSplit ? action.originalMessage.participantAccountIDs ?? [] : [managerID, ownerAccountID];
const participantAccountIDs =
ReportActionsUtils.isMoneyRequestAction(action) && isBillSplit ? ReportActionsUtils.getOriginalMessage(action)?.participantAccountIDs ?? [] : [managerID, ownerAccountID];
const participantAvatars = OptionsListUtils.getAvatarsForAccountIDs(participantAccountIDs, personalDetails ?? {});
const sortedParticipantAvatars = lodashSortBy(participantAvatars, (avatar) => avatar.id);
if (isPolicyExpenseChat && isBillSplit) {
Expand Down Expand Up @@ -225,7 +226,7 @@ function MoneyRequestPreviewContent({
};

const getDisplayDeleteAmountText = (): string => {
const iouOriginalMessage: IOUMessage | EmptyObject = action?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? action.originalMessage : {};
const iouOriginalMessage: OriginalMessageIOU | EmptyObject = ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action) ?? {} : {};
const {amount = 0, currency = CONST.CURRENCY.USD} = iouOriginalMessage;

return CurrencyUtils.convertToDisplayString(amount, currency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default withOnyx<MoneyRequestPreviewProps, MoneyRequestPreviewOnyxProps>(
transaction: {
key: ({action}) => {
const isMoneyRequestAction = ReportActionsUtils.isMoneyRequestAction(action);
const transactionID = isMoneyRequestAction ? action?.originalMessage?.IOUTransactionID : 0;
const transactionID = isMoneyRequestAction ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID : 0;
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`;
},
},
Expand Down
8 changes: 5 additions & 3 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function MoneyRequestView({
const isCancelled = moneyRequestReport && moneyRequestReport.isCancelledIOU;

// Used for non-restricted fields such as: description, category, tag, billable, etc.
const canEdit = ReportUtils.canEditMoneyRequest(parentReportAction);
const canEdit = ReportActionsUtils.isMoneyRequestAction(parentReportAction) && ReportUtils.canEditMoneyRequest(parentReportAction);
const canEditTaxFields = canEdit && !isDistanceRequest;

const canEditAmount = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.AMOUNT);
Expand Down Expand Up @@ -614,15 +614,17 @@ export default withOnyx<MoneyRequestViewPropsWithoutTransaction, MoneyRequestVie
transaction: {
key: ({report, parentReportActions}) => {
const parentReportAction = parentReportActions?.[report.parentReportActionID ?? '-1'];
const originalMessage = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage : undefined;
const originalMessage =
parentReportAction && ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction) : undefined;
const transactionID = originalMessage?.IOUTransactionID ?? -1;
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`;
},
},
transactionViolations: {
key: ({report, parentReportActions}) => {
const parentReportAction = parentReportActions?.[report.parentReportActionID ?? '-1'];
const originalMessage = parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage : undefined;
const originalMessage =
parentReportAction && ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction) : undefined;
const transactionID = originalMessage?.IOUTransactionID ?? -1;
return `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`;
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/RenameAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalD
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import type {ReportAction} from '@src/types/onyx';

type RenameActionProps = WithCurrentUserPersonalDetailsProps & {
Expand All @@ -20,7 +20,7 @@ function RenameAction({currentUserPersonalDetails, action}: RenameActionProps) {
const userDisplayName = action.person?.[0]?.text;
const actorAccountID = action.actorAccountID ?? '-1';
const displayName = actorAccountID === currentUserAccountID ? `${translate('common.you')}` : `${userDisplayName}`;
const originalMessage = action.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED ? action.originalMessage : null;
const originalMessage = ReportActionsUtils.isRenamedAction(action) ? ReportActionsUtils.getOriginalMessage(action) : null;
const oldName = originalMessage?.oldName ?? '';
const newName = originalMessage?.newName ?? '';

Expand Down
3 changes: 2 additions & 1 deletion src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import Navigation from '@libs/Navigation/Navigation';
import * as ReceiptUtils from '@libs/ReceiptUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import StringUtils from '@libs/StringUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
Expand Down Expand Up @@ -214,7 +215,7 @@ function ReportPreview({

// If iouReport is not available, get amount from the action message (Ex: "Domain20821's Workspace owes $33.00" or "paid ₫60" or "paid -₫60 elsewhere")
let displayAmount = '';
const actionMessage = action.message?.[0]?.text ?? '';
const actionMessage = ReportActionsUtils.getReportActionText(action);
const splits = actionMessage.split(' ');

splits.forEach((split) => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/ReportActionItem/TripRoomPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as CurrencyUtils from '@libs/CurrencyUtils';
import DateUtils from '@libs/DateUtils';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import Navigation from '@libs/Navigation/Navigation';
import {getReportActionText} from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TripReservationUtils from '@libs/TripReservationUtils';
import type {ContextMenuAnchor} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
Expand Down Expand Up @@ -123,7 +124,7 @@ function TripRoomPreview({action, chatReportID, containerStyles, contextMenuAnch

// If iouReport is not available, get amount from the action message (Ex: "Domain20821's Workspace owes $33.00" or "paid ₫60" or "paid -₫60 elsewhere")
let displayAmountValue = '';
const actionMessage = action.message?.[0]?.text ?? '';
const actionMessage = getReportActionText(action) ?? '';
const splits = actionMessage.split(' ');

splits.forEach((split) => {
Expand All @@ -135,7 +136,7 @@ function TripRoomPreview({action, chatReportID, containerStyles, contextMenuAnch
});

return displayAmountValue;
}, [action.message, iouReport?.currency, totalDisplaySpend]);
}, [action, iouReport?.currency, totalDisplaySpend]);

return (
<OfflineWithFeedback
Expand Down
Loading

0 comments on commit 82b38df

Please sign in to comment.