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
4 changes: 2 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {ValueOf} from 'type-fest';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsActions';
import useTheme from '@hooks/useTheme';
Expand All @@ -31,7 +32,6 @@ import {
hasOnlyHeldExpenses as hasOnlyHeldExpensesReportUtils,
hasUpdatedTotal,
isAllowedToApproveExpenseReport,
isArchivedReportWithID,
isExported as isExportedUtils,
isInvoiceReport,
isProcessingReport,
Expand Down Expand Up @@ -183,7 +183,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactionIDs, moneyRequestReport, policy, violations);
const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(moneyRequestReport?.reportID);
const isPayAtEndExpense = isPayAtEndExpenseTransactionUtils(transaction);
const isArchivedReport = isArchivedReportWithID(moneyRequestReport?.reportID);
const isArchivedReport = useReportIsArchived(moneyRequestReport?.reportID);
const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID}`, {selector: getArchiveReason, canBeMissing: true});

const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${moneyRequestReport?.reportID}`, {canBeMissing: true});
Expand Down
4 changes: 2 additions & 2 deletions src/components/MoneyReportHeaderOld.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {useOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsActions';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -33,7 +34,6 @@ import {
hasWarningTypeViolations,
isAllowedToApproveExpenseReport,
isAllowedToSubmitDraftExpenseReport,
isArchivedReportWithID,
isInvoiceReport,
isProcessingReport,
isReportApproved,
Expand Down Expand Up @@ -184,7 +184,7 @@ function MoneyReportHeaderOld({policy, report: moneyRequestReport, transactionTh
const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactionIDs, moneyRequestReport, policy, violations);
const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(moneyRequestReport?.reportID);
const isPayAtEndExpense = isPayAtEndExpenseTransactionUtils(transaction);
const isArchivedReport = isArchivedReportWithID(moneyRequestReport?.reportID);
const isArchivedReport = useReportIsArchived(moneyRequestReport?.reportID);
const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID}`, {selector: getArchiveReason, canBeMissing: true});

const getCanIOUBePaid = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useReportWithTransactionsAndViolations from '@hooks/useReportWithTransactionsAndViolations';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -60,7 +61,6 @@ import {
hasUpdatedTotal,
hasViolations,
hasWarningTypeViolations,
isArchivedReportWithID,
isInvoiceReport as isInvoiceReportUtils,
isInvoiceRoom as isInvoiceRoomReportUtils,
isPayAtEndExpenseReport,
Expand Down Expand Up @@ -250,7 +250,7 @@ function ReportPreview({
formattedMerchant = null;
}

const isArchived = isArchivedReportWithID(iouReport?.reportID);
const isArchived = useReportIsArchived(iouReport?.reportID);

// The submit button should be success green color only if the user is submitter and the policy does not have Scheduled Submit turned on
const isWaitingForSubmissionFromCurrentUser = useMemo(() => isWaitingForSubmissionFromCurrentUserReportUtils(chatReport, policy), [chatReport, policy]);
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/ReportPreviewOld.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useReportWithTransactionsAndViolations from '@hooks/useReportWithTransactionsAndViolations';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -63,7 +64,6 @@ import {
hasWarningTypeViolations,
isAllowedToApproveExpenseReport,
isAllowedToSubmitDraftExpenseReport,
isArchivedReportWithID,
isInvoiceReport as isInvoiceReportUtils,
isInvoiceRoom as isInvoiceRoomReportUtils,
isPayAtEndExpenseReport,
Expand Down Expand Up @@ -257,7 +257,7 @@ function ReportPreviewOld({
formattedMerchant = null;
}

const isArchived = isArchivedReportWithID(iouReport?.reportID);
const isArchived = useReportIsArchived(iouReport?.reportID);
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const filteredTransactions = transactions?.filter((transaction) => transaction) ?? [];
const shouldShowSubmitButton = canSubmitReport(iouReport, policy, filteredTransactions, violations);
Expand Down
9 changes: 7 additions & 2 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {Beta, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
import type {Comment} from '@src/types/onyx/Transaction';
import {getLinkedTransactionID} from './ReportActionsUtils';
import {getReasonAndReportActionThatRequiresAttention, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils';
import {getReasonAndReportActionThatRequiresAttention, getReportNameValuePairs, isArchivedReport, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils';
import SidebarUtils from './SidebarUtils';
import {getTransactionID as TransactionUtilsGetTransactionID} from './TransactionUtils';

Expand Down Expand Up @@ -1356,7 +1356,12 @@ type RBRReasonAndReportAction = {
* Gets the report action that is causing the RBR to show up in LHN
*/
function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: OnyxEntry<ReportActions>, hasViolations: boolean): RBRReasonAndReportAction | null {
const {reason, reportAction} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations) ?? {};
// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);

const {reason, reportAction} =
SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations, isArchivedReport(reportNameValuePairs)) ?? {};

if (reason) {
return {reason: `debug.reasonRBR.${reason}`, reportAction};
Expand Down
48 changes: 28 additions & 20 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,14 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa

// Filter out the system chat (Expensify chat) because the composer is disabled in it,
// and it prompts the user to use the Concierge chat instead.
reportsValues = reportsValues.filter((report) => !isSystemChat(report) && !isArchivedReportWithID(report?.reportID)) ?? [];
reportsValues =
reportsValues.filter((report) => {
// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);

return !isSystemChat(report) && !isArchivedReport(reportNameValuePairs);
}) ?? [];

// At least two reports remain: self DM and Concierge chat.
// Return the most recently visited report. Get the last read report from the report metadata.
Expand Down Expand Up @@ -1931,20 +1938,6 @@ function isArchivedNonExpenseReportWithID(report?: OnyxInputOrEntry<Report>, isR
return !(isExpenseReport(report) || isExpenseRequest(report)) && isReportArchived;
}

/**
* Whether the report with the provided reportID is an archived report
*/
function isArchivedReportWithID(reportOrID?: string | SearchReport) {
if (!reportOrID) {
return false;
}

// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
const reportNameValuePairs = typeof reportOrID === 'string' ? getReportNameValuePairs(reportOrID) : getReportNameValuePairs(reportOrID.reportID);
return isArchivedReport(reportNameValuePairs);
}

/**
* Whether the provided report is a closed report
*/
Expand Down Expand Up @@ -2295,7 +2288,11 @@ function getChildReportNotificationPreference(reportAction: OnyxInputOrEntry<Rep
}

function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry<Report>): boolean {
if (!isMoneyRequestReport(moneyRequestReport) || isArchivedReportWithID(moneyRequestReport?.reportID)) {
// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
const reportNameValuePairs = getReportNameValuePairs(moneyRequestReport?.reportID);

if (!isMoneyRequestReport(moneyRequestReport) || isArchivedReport(reportNameValuePairs)) {
return false;
}

Expand Down Expand Up @@ -7554,7 +7551,11 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(report: O
? undefined
: allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];

if (!isArchivedReportWithID(report?.reportID)) {
// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);

if (!isArchivedReport(reportNameValuePairs)) {
if (wasActionTakenByCurrentUser(parentReportAction) && isTransactionThread(parentReportAction)) {
const transactionID = isMoneyRequestAction(parentReportAction) ? getOriginalMessage(parentReportAction)?.IOUTransactionID : null;
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
Expand Down Expand Up @@ -7812,7 +7813,11 @@ function getChatByParticipants(
return Object.values(reports ?? {}).find((report) => {
const participantAccountIDs = Object.keys(report?.participants ?? {});

if (shouldExcludeClosedReports && isArchivedReportWithID(report?.reportID)) {
// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);

if (shouldExcludeClosedReports && isArchivedReport(reportNameValuePairs)) {
return false;
}

Expand Down Expand Up @@ -8124,8 +8129,12 @@ function isGroupChatAdmin(report: OnyxEntry<Report>, accountID: number) {
* as a participant of the report.
*/
function getMoneyRequestOptions(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, reportParticipants: number[], filterDeprecatedTypes = false): IOUType[] {
// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);

// In any thread, task report or trip room, we do not allow any new expenses
if (isChatThread(report) || isTaskReport(report) || isInvoiceReport(report) || isSystemChat(report) || isArchivedReportWithID(report?.reportID) || isTripRoom(report)) {
if (isChatThread(report) || isTaskReport(report) || isInvoiceReport(report) || isSystemChat(report) || isArchivedReport(reportNameValuePairs) || isTripRoom(report)) {
return [];
}

Expand Down Expand Up @@ -10633,7 +10642,6 @@ export {
isArchivedNonExpenseReport,
isArchivedReport,
isArchivedNonExpenseReportWithID,
isArchivedReportWithID,
isClosedReport,
isCanceledTaskReport,
isChatReport,
Expand Down
27 changes: 20 additions & 7 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
getPolicyName,
getReportDescription,
getReportName,
getReportNameValuePairs,
getReportNotificationPreference,
getReportParticipantsTitle,
getReportSubtitlePrefix,
Expand All @@ -86,7 +87,6 @@ import {
isAnnounceRoom,
isArchivedNonExpenseReport,
isArchivedReport,
isArchivedReportWithID,
isChatRoom,
isChatThread,
isConciergeChatReport,
Expand Down Expand Up @@ -241,7 +241,7 @@ function getOrderedReportIDs(
isSystemChat ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
report.isPinned ||
(!isInFocusMode && isArchivedReportWithID(report.reportID)) ||
(!isInFocusMode && isArchivedReport(reportNameValuePairs)) ||
requiresAttentionFromCurrentUser(report, parentReportAction);
if (isHidden && !shouldOverrideHidden) {
return;
Expand Down Expand Up @@ -345,12 +345,13 @@ function getReasonAndReportActionThatHasRedBrickRoad(
reportActions: OnyxEntry<ReportActions>,
hasViolations: boolean,
transactionViolations?: OnyxCollection<TransactionViolation[]>,
isReportArchived = false,
): ReasonAndReportActionThatHasRedBrickRoad | null {
const {reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions);
const errors = getAllReportErrors(report, reportActions);
const hasErrors = Object.keys(errors).length !== 0;

if (isArchivedReportWithID(report.reportID)) {
if (isReportArchived) {
return null;
}

Expand Down Expand Up @@ -394,8 +395,14 @@ function getReasonAndReportActionThatHasRedBrickRoad(
return null;
}

function shouldShowRedBrickRoad(report: Report, reportActions: OnyxEntry<ReportActions>, hasViolations: boolean, transactionViolations?: OnyxCollection<TransactionViolation[]>) {
return !!getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations);
function shouldShowRedBrickRoad(
report: Report,
reportActions: OnyxEntry<ReportActions>,
hasViolations: boolean,
transactionViolations?: OnyxCollection<TransactionViolation[]>,
isReportArchived = false,
) {
return !!getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations, isReportArchived);
}

/**
Expand Down Expand Up @@ -487,7 +494,9 @@ function getOptionData({
result.isMoneyRequestReport = isMoneyRequestReport(report);
result.shouldShowSubscript = shouldReportShowSubscript(report);
result.pendingAction = report.pendingFields?.addWorkspaceRoom ?? report.pendingFields?.createChat;
result.brickRoadIndicator = shouldShowRedBrickRoad(report, reportActions, hasViolations, transactionViolations) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
result.brickRoadIndicator = shouldShowRedBrickRoad(report, reportActions, hasViolations, transactionViolations, !!result.private_isArchived)
? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR
: '';
result.ownerAccountID = report.ownerAccountID;
result.managerID = report.managerID;
result.reportID = report.reportID;
Expand Down Expand Up @@ -782,7 +791,11 @@ function getRoomWelcomeMessage(report: OnyxEntry<Report>): WelcomeMessage {
return welcomeMessage;
}

if (isArchivedReportWithID(report?.reportID)) {
// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);

if (isArchivedReport(reportNameValuePairs)) {
welcomeMessage.phrase1 = translateLocal('reportActionsView.beginningOfArchivedRoomPartOne');
welcomeMessage.phrase2 = translateLocal('reportActionsView.beginningOfArchivedRoomPartTwo');
} else if (isDomainRoom(report)) {
Expand Down
9 changes: 7 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ import {
getOutstandingChildRequest,
getParsedComment,
getPersonalDetailsForAccountID,
getReportNameValuePairs,
getReportNotificationPreference,
getReportOrDraftReport,
getReportTransactions,
getTransactionDetails,
hasHeldExpenses as hasHeldExpensesReportUtils,
hasNonReimbursableTransactions as hasNonReimbursableTransactionsReportUtils,
isArchivedReport,
isArchivedReportWithID,
isClosedReport as isClosedReportUtil,
isDraftReport,
isExpenseReport,
Expand Down Expand Up @@ -8782,7 +8782,12 @@ function canSubmitReport(
) {
const currentUserAccountID = getCurrentUserAccountID();
const isOpenExpenseReport = isOpenExpenseReportReportUtils(report);
const isArchived = isArchivedReportWithID(report?.reportID);

// This will get removed as part of https://github.com/Expensify/App/issues/59961
// eslint-disable-next-line deprecation/deprecation
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);

const isArchived = isArchivedReport(reportNameValuePairs);
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
const transactionIDList = transactions.map((transaction) => transaction.transactionID);
const hasAllPendingRTERViolations = allHavePendingRTERViolation(transactionIDList, allViolations);
Expand Down
11 changes: 9 additions & 2 deletions src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Log from '@libs/Log';
import {isArchivedReportWithID, isThread} from '@libs/ReportUtils';
import {isArchivedReport, isThread} from '@libs/ReportUtils';
import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {OnyxInputOrEntry, ReportNameValuePairs} from '@src/types/onyx';

export default createOnyxDerivedValueConfig({
key: ONYXKEYS.DERIVED.CONCIERGE_CHAT_REPORT_ID,
Expand All @@ -13,8 +14,14 @@ export default createOnyxDerivedValueConfig({
}

const conciergeReport = Object.values(reports).find((report) => {
if (!report) {
return;
}

const reportNameValuePairs = (allReportNameValuePair[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`] ?? {}) as OnyxInputOrEntry<ReportNameValuePairs>;

// Merged accounts can have multiple conceirge chats, exclude archived chats.
if (!report?.participants || isThread(report) || isArchivedReportWithID(report?.reportID)) {
if (!report?.participants || isThread(report) || isArchivedReport(reportNameValuePairs)) {
return false;
}

Expand Down
Loading