diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c5490faf7a6e..913e44bd560e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2511,8 +2511,8 @@ function isIOURequest(report: OnyxInputOrEntry): boolean { } /** - * A Track Expense Report is a thread where the parent the parentReportAction is a transaction, and - * parentReportAction has type of track. + * @deprecated Use isTrackExpenseReportNew function instead + * */ function isTrackExpenseReport(report: OnyxInputOrEntry): boolean { if (isThread(report)) { @@ -2523,6 +2523,17 @@ function isTrackExpenseReport(report: OnyxInputOrEntry): boolean { return false; } +/** + * A Track Expense Report is a thread where the parent the parentReportAction is a transaction, and + * parentReportAction has type of track. + */ +function isTrackExpenseReportNew(report: OnyxInputOrEntry, parentReport: OnyxInputOrEntry, parentReportAction: OnyxInputOrEntry): boolean { + if (isThread(report)) { + return !isEmptyObject(parentReportAction) && isSelfDM(parentReport) && isTrackExpenseAction(parentReportAction); + } + return false; +} + /** * Checks if a report is an IOU or expense request. */ @@ -2631,6 +2642,7 @@ function isOneTransactionThread(report: OnyxEntry, parentReport: OnyxEnt * Checks if given report is a transaction thread */ function isReportTransactionThread(report: OnyxEntry) { + // eslint-disable-next-line @typescript-eslint/no-deprecated return isMoneyRequest(report) || isTrackExpenseReport(report); } @@ -4889,6 +4901,7 @@ function canEditReportAction(reportAction: OnyxInputOrEntry): bool } function canModifyHoldStatus(report: Report, reportAction: ReportAction): boolean { + // eslint-disable-next-line @typescript-eslint/no-deprecated if (!isMoneyRequestReport(report) || isTrackExpenseReport(report)) { return false; } @@ -4918,6 +4931,7 @@ function canHoldUnholdReportAction( const isApproved = isReportApproved({report}); const isRequestIOU = isIOUReport(report); const isHoldActionCreator = isActionCreator(holdReportAction); + // eslint-disable-next-line @typescript-eslint/no-deprecated const isTrackExpenseMoneyReport = isTrackExpenseReport(report); const isActionOwner = isActionCreator(reportAction); const isApprover = isMoneyRequestReport(report) && report.managerID !== null && currentUserPersonalDetails?.accountID === report?.managerID; @@ -11119,7 +11133,13 @@ function isAdminOwnerApproverOrReportOwner(report: OnyxEntry, policy: On /** * Whether the user can join a report */ -function canJoinChat(report: OnyxEntry, parentReportAction: OnyxInputOrEntry, policy: OnyxEntry, isReportArchived = false): boolean { +function canJoinChat( + report: OnyxEntry, + parentReportAction: OnyxInputOrEntry, + policy: OnyxEntry, + parentReport: OnyxEntry, + isReportArchived = false, +): boolean { // We disabled thread functions for whisper action // So we should not show join option for existing thread on whisper message that has already been left, or manually leave it if (isWhisperAction(parentReportAction)) { @@ -11131,7 +11151,7 @@ function canJoinChat(report: OnyxEntry, parentReportAction: OnyxInputOrE return false; } - const isExpenseChat = isMoneyRequestReport(report) || isMoneyRequest(report) || isInvoiceReport(report) || isTrackExpenseReport(report); + const isExpenseChat = isMoneyRequestReport(report) || isMoneyRequest(report) || isInvoiceReport(report) || isTrackExpenseReportNew(report, parentReport, parentReportAction); // Anyone viewing these chat types is already a participant and therefore cannot join if (isRootGroupChat(report, isReportArchived) || isSelfDM(report) || isInvoiceRoom(report) || isSystemChat(report) || isExpenseChat) { return false; @@ -13262,6 +13282,7 @@ export { isSystemChat, isTaskReport, isThread, + // eslint-disable-next-line @typescript-eslint/no-deprecated isTrackExpenseReport, isUnread, isUnreadWithMention, @@ -13403,6 +13424,7 @@ export { shouldBlockSubmitDueToStrictPolicyRules, isWorkspaceChat, isOneTransactionReport, + isTrackExpenseReportNew, shouldHideSingleReportField, }; diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index bc5dd4d3280a..884f5b8c5d43 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -92,7 +92,7 @@ import { isSystemChat as isSystemChatUtil, isTaskReport as isTaskReportUtil, isThread as isThreadUtil, - isTrackExpenseReport as isTrackExpenseReportUtil, + isTrackExpenseReportNew as isTrackExpenseReportUtil, isUserCreatedPolicyRoom as isUserCreatedPolicyRoomUtil, isWorkspaceChat as isWorkspaceChatUtil, isWorkspaceMemberLeavingWorkspaceRoom as isWorkspaceMemberLeavingWorkspaceRoomUtil, @@ -198,7 +198,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail const isInvoiceRoom = useMemo(() => isInvoiceRoomUtil(report), [report]); const isTaskReport = useMemo(() => isTaskReportUtil(report), [report]); const isSelfDM = useMemo(() => isSelfDMUtil(report), [report]); - const isTrackExpenseReport = useMemo(() => isTrackExpenseReportUtil(report), [report]); + const isTrackExpenseReport = useMemo(() => isTrackExpenseReportUtil(report, parentReport, parentReportAction), [report, parentReport, parentReportAction]); const isCanceledTaskReport = isCanceledTaskReportUtil(report, parentReportAction); const isParentReportArchived = useReportIsArchived(parentReport?.reportID); const isTaskModifiable = canModifyTask(report, currentUserPersonalDetails?.accountID, isParentReportArchived); @@ -669,7 +669,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail expensifyIcons.Camera, ]); - const canJoin = canJoinChat(report, parentReportAction, policy, !!reportNameValuePairs?.private_isArchived); + const canJoin = canJoinChat(report, parentReportAction, policy, parentReport, !!reportNameValuePairs?.private_isArchived); const promotedActions = useMemo(() => { const result: PromotedAction[] = []; diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index 0e5aa6525958..58a35d1fbdd3 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -187,7 +187,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked, const join = callFunctionIfActionIsAllowed(() => joinRoom(report)); - const canJoin = canJoinChat(report, parentReportAction, policy, isReportArchived); + const canJoin = canJoinChat(report, parentReportAction, policy, parentReport, isReportArchived); const joinButton = (