Skip to content

Commit

Permalink
changes as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
ishpaul777 committed Nov 18, 2024
1 parent 79bf01c commit 704446b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 59 deletions.
66 changes: 23 additions & 43 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,6 @@ type OptionData = {
isConciergeChat?: boolean;
isBold?: boolean;
lastIOUCreationDate?: string;
isChatRoom?: boolean;
participantsList?: PersonalDetails[];
icons?: Icon[];
iouReportAmount?: number;
displayName?: string;
Expand Down Expand Up @@ -6352,7 +6350,7 @@ function shouldDisplayViolationsRBRInLHN(report: OnyxEntry<Report>, transactionV
// - Belong to the same workspace
// And if any have a violation, then it should have a RBR
const allReports = Object.values(ReportConnection.getAllReports() ?? {}) as Report[];
const potentialReports = allReports.filter((r) => r?.ownerAccountID === currentUserAccountID && (r?.stateNum ?? 0) <= 1 && r?.policyID === report.policyID);
const potentialReports = allReports.filter((r) => r.ownerAccountID === currentUserAccountID && (r.stateNum ?? 0) <= 1 && r.policyID === report.policyID);
return potentialReports.some(
(potentialReport) => hasViolations(potentialReport.reportID, transactionViolations) || hasWarningTypeViolations(potentialReport.reportID, transactionViolations),
);
Expand Down Expand Up @@ -6425,23 +6423,21 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(report: O
? undefined
: allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID ?? '-1'}`]?.[report.parentReportActionID ?? '-1'];

if (!isArchivedRoom(report)) {
if (ReportActionsUtils.wasActionTakenByCurrentUser(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) {
const transactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID : null;
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
if (TransactionUtils.hasMissingSmartscanFields(transaction ?? null) && !isSettled(transaction?.reportID)) {
reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage');
reportAction = undefined;
}
} else if ((isIOUReport(report) || isExpenseReport(report)) && report?.ownerAccountID === currentUserAccountID) {
if (shouldShowRBRForMissingSmartscanFields(report?.reportID ?? '-1') && !isSettled(report?.reportID)) {
reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage');
reportAction = getReportActionWithMissingSmartscanFields(report?.reportID ?? '-1');
}
} else if (hasSmartscanError(reportActionsArray)) {
if (ReportActionsUtils.wasActionTakenByCurrentUser(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) {
const transactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID : null;
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
if (TransactionUtils.hasMissingSmartscanFields(transaction ?? null) && !isSettled(transaction?.reportID)) {
reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage');
reportAction = undefined;
}
} else if ((isIOUReport(report) || isExpenseReport(report)) && report?.ownerAccountID === currentUserAccountID) {
if (shouldShowRBRForMissingSmartscanFields(report?.reportID ?? '-1') && !isSettled(report?.reportID)) {
reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage');
reportAction = getReportActionWithSmartscanError(reportActionsArray);
reportAction = getReportActionWithMissingSmartscanFields(report?.reportID ?? '-1');
}
} else if (hasSmartscanError(reportActionsArray)) {
reportActionErrors.smartscan = ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericSmartscanFailureMessage');
reportAction = getReportActionWithSmartscanError(reportActionsArray);
}

return {
Expand Down Expand Up @@ -7944,30 +7940,6 @@ function getOptimisticDataForParentReportAction(reportID: string, lastVisibleAct
});
}

function getQuickActionDetails(
quickActionReport: Report,
personalDetails: PersonalDetailsList | undefined,
policyChatForActivePolicy: Report | undefined,
reportNameValuePairs: ReportNameValuePairs,
): {quickActionAvatars: Icon[]; hideQABSubtitle: boolean} {
const isValidQuickActionReport = !(isEmptyObject(quickActionReport) || isArchivedRoom(quickActionReport, reportNameValuePairs));
let hideQABSubtitle = false;
let quickActionAvatars: Icon[] = [];
if (isValidQuickActionReport) {
const avatars = getIcons(quickActionReport, personalDetails);
quickActionAvatars = avatars.length <= 1 || isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== currentUserAccountID);
} else {
hideQABSubtitle = true;
}
if (!isEmptyObject(policyChatForActivePolicy)) {
quickActionAvatars = getIcons(policyChatForActivePolicy, personalDetails);
}
return {
quickActionAvatars,
hideQABSubtitle,
};
}

function canBeAutoReimbursed(report: OnyxInputOrEntry<Report>, policy: OnyxInputOrEntry<Policy>): boolean {
if (isEmptyObject(policy)) {
return false;
Expand Down Expand Up @@ -8433,6 +8405,14 @@ function hasInvoiceReports() {
return allReports.some((report) => isInvoiceReport(report));
}

function areAllGroupPoliciesExpenseChatDisabled(policies = allPolicies) {
const groupPolicies = Object.values(policies ?? {}).filter((policy) => isGroupPolicy(policy?.type ?? ''));
if (groupPolicies.length === 0) {
return false;
}
return !groupPolicies.some((policy) => !!policy?.isPolicyExpenseChatEnabled);
}

export {
addDomainToShortMention,
completeShortMention,
Expand Down Expand Up @@ -8590,7 +8570,6 @@ export {
getInvoicePayerName,
getInvoicesChatName,
getPayeeName,
getQuickActionDetails,
hasActionsWithErrors,
hasAutomatedExpensifyAccountIDs,
hasExpensifyGuidesEmails,
Expand Down Expand Up @@ -8760,6 +8739,7 @@ export {
getAllReportErrors,
getAllReportActionsErrorsAndReportActionThatRequiresAttention,
hasInvoiceReports,
areAllGroupPoliciesExpenseChatDisabled
};

export type {
Expand Down
8 changes: 3 additions & 5 deletions src/pages/Search/EmptySearchView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useMemo, useState} from 'react';
import {Linking, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import ConfirmModal from '@components/ConfirmModal';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import EmptyStateComponent from '@components/EmptyStateComponent';
Expand All @@ -25,6 +26,7 @@ import * as IOU from '@userActions/IOU';
import * as Link from '@userActions/Link';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';

type EmptySearchViewProps = {
Expand All @@ -50,11 +52,7 @@ function EmptySearchView({type}: EmptySearchViewProps) {
const [modalVisible, setModalVisible] = useState(false);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const shouldRedirectToExpensifyClassic = useMemo(() => {
const groupPolicies = Object.values(allPolicies ?? {}).filter((policy) => ReportUtils.isGroupPolicy(policy?.type ?? ''));
if (groupPolicies.length === 0) {
return false;
}
return !groupPolicies.some((policy) => !!policy?.isPolicyExpenseChatEnabled);
return ReportUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<OnyxTypes.Policy>) ?? {});
}, [allPolicies]);

const [ctaErrorMessage, setCtaErrorMessage] = useState('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl

const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions();
const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection<OnyxTypes.Policy>, session?.email), [allPolicies, session?.email]);
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const {environment} = useEnvironment();
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const navatticURL = getNavatticURL(environment, introSelected?.choice);
Expand All @@ -191,19 +190,15 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
* 2. none of the group policies they are a member of have isPolicyExpenseChatEnabled=true
*/
const shouldRedirectToExpensifyClassic = useMemo(() => {
const groupPolicies = Object.values(allPolicies ?? {}).filter((policy) => ReportUtils.isGroupPolicy(policy?.type ?? ''));
if (groupPolicies.length === 0) {
return false;
}
return !groupPolicies.some((policy) => !!policy?.isPolicyExpenseChatEnabled);
return ReportUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<OnyxTypes.Policy>) ?? {});
}, [allPolicies]);

const shouldShowNewWorkspaceButton = Object.values(allPolicies ?? {}).every(
(policy) => !PolicyUtils.shouldShowPolicy(policy as OnyxEntry<OnyxTypes.Policy>, !!isOffline, session?.email),
);

const quickActionAvatars = useMemo(() => {
if (isValidReport) {
if (quickActionReport) {
const avatars = ReportUtils.getIcons(quickActionReport, personalDetails);
return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID);
}
Expand Down Expand Up @@ -238,15 +233,15 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
}, [quickAction, translate, quickActionAvatars, quickActionReport]);

const hideQABSubtitle = useMemo(() => {
if (!isValidReport) {
if (isEmptyObject(quickActionReport)) {
return true;
}
if (quickActionAvatars.length === 0) {
return false;
}
const displayName = personalDetails?.[quickActionAvatars.at(0)?.id ?? -1]?.firstName ?? '';
return quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && displayName.length === 0;
}, [isValidReport, quickActionAvatars, personalDetails, quickAction?.action]);
}, [personalDetails, quickActionReport, quickAction?.action, quickActionAvatars]);

const selectOption = useCallback(
(onSelected: () => void, shouldRestrictAction: boolean) => {
Expand All @@ -260,6 +255,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
);

const navigateToQuickAction = useCallback(() => {
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const quickActionReportID = isValidReport ? quickActionReport?.reportID ?? '-1' : ReportUtils.generateReportID();

switch (quickAction?.action) {
Expand Down Expand Up @@ -288,7 +284,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
break;
default:
}
}, [isValidReport, quickAction?.action, quickAction?.targetAccountID, quickActionReport?.reportID, selectOption]);
}, [quickAction, quickActionReport, reportNameValuePairs, selectOption]);

/**
* Check if LHN status changed from active to inactive.
Expand Down Expand Up @@ -476,6 +472,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
onSelected: () =>
interceptAnonymousUser(() => {
selectOption(() => {
const isValidReport = !(isEmptyObject(policyChatForActivePolicy) || ReportUtils.isArchivedRoom(policyChatForActivePolicy, reportNameValuePairs));
const quickActionReportID = isValidReport ? policyChatForActivePolicy?.reportID ?? '-1' : ReportUtils.generateReportID();
IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID ?? '-1', CONST.IOU.REQUEST_TYPE.SCAN, true);
}, true);
Expand All @@ -502,7 +499,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
quickActionReport,
navigateToQuickAction,
selectOption,
isValidReport,
reportNameValuePairs,
]);

return (
Expand Down

0 comments on commit 704446b

Please sign in to comment.