From 5d5c2657f82bf45c3d4072bfcb15d27e24c0c5ca Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Sat, 16 Nov 2024 15:22:16 +0530 Subject: [PATCH 1/4] fixes issue --- src/pages/Search/EmptySearchView.tsx | 71 ++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 19d00a06771e..33b67e9aae18 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -1,6 +1,7 @@ import React, {useMemo, useState} from 'react'; import {Linking, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; +import ConfirmModal from '@components/ConfirmModal'; import DotIndicatorMessage from '@components/DotIndicatorMessage'; import EmptyStateComponent from '@components/EmptyStateComponent'; import type {FeatureListItem} from '@components/FeatureList'; @@ -46,6 +47,15 @@ function EmptySearchView({type}: EmptySearchViewProps) { const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); const styles = useThemeStyles(); + 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); + }, [allPolicies]); const [ctaErrorMessage, setCtaErrorMessage] = useState(''); @@ -126,7 +136,14 @@ function EmptySearchView({type}: EmptySearchViewProps) { {buttonText: translate('emptySearchView.takeATour'), buttonAction: () => Link.openExternalLink(navatticURL)}, { buttonText: translate('iou.createExpense'), - buttonAction: () => interceptAnonymousUser(() => IOU.startMoneyRequest(CONST.IOU.TYPE.CREATE, ReportUtils.generateReportID())), + buttonAction: () => + interceptAnonymousUser(() => { + if (shouldRedirectToExpensifyClassic) { + setModalVisible(true); + return; + } + IOU.startMoneyRequest(CONST.IOU.TYPE.CREATE, ReportUtils.generateReportID()); + }), success: true, }, ], @@ -143,21 +160,47 @@ function EmptySearchView({type}: EmptySearchViewProps) { headerContentStyles: styles.emptyStateFolderWebStyles, }; } - }, [type, StyleUtils, translate, theme, styles, subtitleComponent, ctaErrorMessage, navatticURL]); + }, [ + type, + StyleUtils, + theme.travelBG, + theme.emptyFolderBG, + translate, + styles.textAlignLeft, + styles.emptyStateFolderWebStyles, + subtitleComponent, + ctaErrorMessage, + navatticURL, + shouldRedirectToExpensifyClassic, + ]); return ( - + <> + + { + setModalVisible(false); + Link.openOldDotLink(CONST.OLDDOT_URLS.INBOX); + }} + onCancel={() => setModalVisible(false)} + title={translate('sidebarScreen.redirectToExpensifyClassicModal.title')} + confirmText={translate('exitSurvey.goToExpensifyClassic')} + cancelText={translate('common.cancel')} + /> + ); } From bbb4ea2d3541a25c99f1f7a5f9a7b4e92587f37e Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Mon, 18 Nov 2024 23:04:36 +0530 Subject: [PATCH 2/4] fixes bad commit --- src/libs/ReportUtils.ts | 9 +++++++++ src/pages/Search/EmptySearchView.tsx | 8 +++----- .../FloatingActionButtonAndPopover.tsx | 19 ++++++++----------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 943361d31bc5..0d99d536b9e1 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8433,6 +8433,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, @@ -8760,6 +8768,7 @@ export { getAllReportErrors, getAllReportActionsErrorsAndReportActionThatRequiresAttention, hasInvoiceReports, + areAllGroupPoliciesExpenseChatDisabled, }; export type { diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 33b67e9aae18..82ecc3d010d4 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -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'; @@ -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 = { @@ -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) ?? {}); }, [allPolicies]); const [ctaErrorMessage, setCtaErrorMessage] = useState(''); diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 82985c38c2ae..5e02844957a2 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -178,7 +178,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions(); const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection, 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); @@ -191,11 +190,7 @@ 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) ?? {}); }, [allPolicies]); const shouldShowNewWorkspaceButton = Object.values(allPolicies ?? {}).every( @@ -203,7 +198,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl ); 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); } @@ -238,7 +233,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl }, [quickAction, translate, quickActionAvatars, quickActionReport]); const hideQABSubtitle = useMemo(() => { - if (!isValidReport) { + if (isEmptyObject(quickActionReport)) { return true; } if (quickActionAvatars.length === 0) { @@ -246,7 +241,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl } 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) => { @@ -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) { @@ -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. @@ -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); @@ -502,7 +499,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl quickActionReport, navigateToQuickAction, selectOption, - isValidReport, + reportNameValuePairs, ]); return ( From c9353bd3b27d7694cc4236796e5469be1dd51f39 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 19 Nov 2024 01:44:54 +0530 Subject: [PATCH 3/4] fix as per review --- src/libs/PolicyUtils.ts | 9 +++++++++ src/libs/ReportUtils.ts | 9 --------- src/pages/Search/EmptySearchView.tsx | 3 ++- .../FloatingActionButtonAndPopover.tsx | 15 +++++++-------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 4592500e9250..bdf760728576 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1108,6 +1108,14 @@ function isPolicyAccessible(policy: OnyxEntry): 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, @@ -1228,6 +1236,7 @@ export { getAllPoliciesLength, getActivePolicy, isPolicyAccessible, + areAllGroupPoliciesExpenseChatDisabled, }; export type {MemberEmailsToAccountIDs}; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0d99d536b9e1..943361d31bc5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -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, @@ -8768,7 +8760,6 @@ export { getAllReportErrors, getAllReportActionsErrorsAndReportActionThatRequiresAttention, hasInvoiceReports, - areAllGroupPoliciesExpenseChatDisabled, }; export type { diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 82ecc3d010d4..1726201c5aaf 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -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'; +import * as PolicyUtils from '@libs/PolicyUtils'; import {getNavatticURL} from '@libs/TourUtils'; import * as TripsResevationUtils from '@libs/TripReservationUtils'; import variables from '@styles/variables'; @@ -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) ?? {}); + return PolicyUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection) ?? {}); }, [allPolicies]); const [ctaErrorMessage, setCtaErrorMessage] = useState(''); diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 5e02844957a2..93d582c391c5 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -178,6 +178,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions(); const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection, 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); @@ -190,7 +191,7 @@ 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) ?? {}); + return PolicyUtils.areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection) ?? {}); }, [allPolicies]); const shouldShowNewWorkspaceButton = Object.values(allPolicies ?? {}).every( @@ -198,7 +199,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl ); 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); } @@ -233,7 +234,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl }, [quickAction, translate, quickActionAvatars, quickActionReport]); const hideQABSubtitle = useMemo(() => { - if (isEmptyObject(quickActionReport)) { + if (!isValidReport) { return true; } if (quickActionAvatars.length === 0) { @@ -241,7 +242,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl } 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) => { @@ -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) { @@ -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. @@ -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); @@ -499,7 +498,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl quickActionReport, navigateToQuickAction, selectOption, - reportNameValuePairs, + isValidReport, ]); return ( From 7da2510ccd45526cb5c54c5650403807e7a1a426 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 19 Nov 2024 01:47:30 +0530 Subject: [PATCH 4/4] fomating --- src/pages/Search/EmptySearchView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 1726201c5aaf..c26e8aeeb155 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -18,8 +18,8 @@ import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import interceptAnonymousUser from '@libs/interceptAnonymousUser'; -import * as ReportUtils from '@libs/ReportUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import {getNavatticURL} from '@libs/TourUtils'; import * as TripsResevationUtils from '@libs/TripReservationUtils'; import variables from '@styles/variables';