Skip to content

Commit

Permalink
fix as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
ishpaul777 committed Nov 18, 2024
1 parent bbb4ea2 commit c9353bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
9 changes: 9 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,14 @@ function isPolicyAccessible(policy: OnyxEntry<Policy>): boolean {
return !isEmptyObject(policy) && (Object.keys(policy).length !== 1 || isEmptyObject(policy.errors)) && !!policy?.id;
}

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

export {
canEditTaxRate,
extractPolicyIDFromPath,
Expand Down Expand Up @@ -1228,6 +1236,7 @@ export {
getAllPoliciesLength,
getActivePolicy,
isPolicyAccessible,
areAllGroupPoliciesExpenseChatDisabled,
};

export type {MemberEmailsToAccountIDs};
9 changes: 0 additions & 9 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8433,14 +8433,6 @@ 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 @@ -8768,7 +8760,6 @@ export {
getAllReportErrors,
getAllReportActionsErrorsAndReportActionThatRequiresAttention,
hasInvoiceReports,
areAllGroupPoliciesExpenseChatDisabled,
};

export type {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Search/EmptySearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import * as ReportUtils from '@libs/ReportUtils';

Check failure on line 21 in src/pages/Search/EmptySearchView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `ReportUtils·from·'@libs/Report` with `PolicyUtils·from·'@libs/Policy`
import * as PolicyUtils from '@libs/PolicyUtils';

Check failure on line 22 in src/pages/Search/EmptySearchView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `PolicyUtils·from·'@libs/Policy` with `ReportUtils·from·'@libs/Report`
import {getNavatticURL} from '@libs/TourUtils';
import * as TripsResevationUtils from '@libs/TripReservationUtils';
import variables from '@styles/variables';
Expand Down Expand Up @@ -52,7 +53,7 @@ function EmptySearchView({type}: EmptySearchViewProps) {
const [modalVisible, setModalVisible] = useState(false);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const shouldRedirectToExpensifyClassic = useMemo(() => {
return ReportUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<OnyxTypes.Policy>) ?? {});
return PolicyUtils.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,6 +178,7 @@ 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 @@ -190,15 +191,15 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
* 2. none of the group policies they are a member of have isPolicyExpenseChatEnabled=true
*/
const shouldRedirectToExpensifyClassic = useMemo(() => {
return ReportUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<OnyxTypes.Policy>) ?? {});
return PolicyUtils.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 (quickActionReport) {
if (isValidReport) {
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 @@ -233,15 +234,15 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
}, [quickAction, translate, quickActionAvatars, quickActionReport]);

const hideQABSubtitle = useMemo(() => {
if (isEmptyObject(quickActionReport)) {
if (!isValidReport) {
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;
}, [personalDetails, quickActionReport, quickAction?.action, quickActionAvatars]);
}, [isValidReport, quickActionAvatars, personalDetails, quickAction?.action]);

const selectOption = useCallback(
(onSelected: () => void, shouldRestrictAction: boolean) => {
Expand All @@ -255,7 +256,6 @@ 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 @@ -284,7 +284,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
break;
default:
}
}, [quickAction, quickActionReport, reportNameValuePairs, selectOption]);
}, [isValidReport, quickAction?.action, quickAction?.targetAccountID, quickActionReport?.reportID, selectOption]);

/**
* Check if LHN status changed from active to inactive.
Expand Down Expand Up @@ -472,7 +472,6 @@ 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 @@ -499,7 +498,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
quickActionReport,
navigateToQuickAction,
selectOption,
reportNameValuePairs,
isValidReport,
]);

return (
Expand Down

0 comments on commit c9353bd

Please sign in to comment.