From c666844aba20fb45c58c460c59de51e5ac6b246e Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Thu, 2 May 2024 16:50:36 -0700 Subject: [PATCH 1/4] Exclude guides from preferred exporter --- ...ooksPreferredExporterConfigurationPage.tsx | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx index a3eae0e19f24..fc139c4cdce4 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx @@ -5,9 +5,11 @@ import SelectionList from '@components/SelectionList'; import RadioListItem from '@components/SelectionList/RadioListItem'; import type {ListItem} from '@components/SelectionList/types'; import Text from '@components/Text'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import * as Connections from '@libs/actions/connections'; +import * as PolicyUtils from '@libs/PolicyUtils'; import {getAdminEmployees} from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; @@ -25,19 +27,32 @@ function QuickbooksPreferredExporterConfigurationPage({policy}: WithPolicyConnec const styles = useThemeStyles(); const {export: exportConfiguration} = policy?.connections?.quickbooksOnline?.config ?? {}; const exporters = getAdminEmployees(policy); + const {login: currentUserLogin} = useCurrentUserPersonalDetails(); const policyID = policy?.id ?? ''; const data: CardListItem[] = useMemo( () => exporters?.reduce((vendors, vendor) => { - if (vendor.email) { - vendors.push({ - value: vendor.email, - text: vendor.email, - keyForList: vendor.email, - isSelected: exportConfiguration?.exporter === vendor.email, - }); + if (!vendor.email) { + return vendors; } + + // Don't show guides if the current user is not a guide themselves or an Expensify employee + if ( + PolicyUtils.isExpensifyTeam(vendor.email) && + policy?.owner && + currentUserLogin && + !PolicyUtils.isExpensifyTeam(policy?.owner) && + !PolicyUtils.isExpensifyTeam(currentUserLogin) + ) { + return vendors; + } + vendors.push({ + value: vendor.email, + text: vendor.email, + keyForList: vendor.email, + isSelected: exportConfiguration?.exporter === vendor.email, + }); return vendors; }, []), [exportConfiguration, exporters], From f0395bfe66023195c2abdd4700af2952ff578282 Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Thu, 2 May 2024 16:55:17 -0700 Subject: [PATCH 2/4] Rename variables --- ...ooksPreferredExporterConfigurationPage.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx index fc139c4cdce4..0339679f21a4 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx @@ -32,28 +32,28 @@ function QuickbooksPreferredExporterConfigurationPage({policy}: WithPolicyConnec const policyID = policy?.id ?? ''; const data: CardListItem[] = useMemo( () => - exporters?.reduce((vendors, vendor) => { - if (!vendor.email) { - return vendors; + exporters?.reduce((options, exporter) => { + if (!exporter.email) { + return options; } // Don't show guides if the current user is not a guide themselves or an Expensify employee if ( - PolicyUtils.isExpensifyTeam(vendor.email) && + PolicyUtils.isExpensifyTeam(exporter.email) && policy?.owner && currentUserLogin && !PolicyUtils.isExpensifyTeam(policy?.owner) && !PolicyUtils.isExpensifyTeam(currentUserLogin) ) { - return vendors; + return options; } - vendors.push({ - value: vendor.email, - text: vendor.email, - keyForList: vendor.email, - isSelected: exportConfiguration?.exporter === vendor.email, + options.push({ + value: exporter.email, + text: exporter.email, + keyForList: exporter.email, + isSelected: exportConfiguration?.exporter === exporter.email, }); - return vendors; + return options; }, []), [exportConfiguration, exporters], ); From dfdcb7278a7155448d8146c85784c4ce145133e6 Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Thu, 2 May 2024 16:56:39 -0700 Subject: [PATCH 3/4] Simplify check --- .../QuickbooksPreferredExporterConfigurationPage.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx index 0339679f21a4..381a5850d7bd 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx @@ -38,13 +38,7 @@ function QuickbooksPreferredExporterConfigurationPage({policy}: WithPolicyConnec } // Don't show guides if the current user is not a guide themselves or an Expensify employee - if ( - PolicyUtils.isExpensifyTeam(exporter.email) && - policy?.owner && - currentUserLogin && - !PolicyUtils.isExpensifyTeam(policy?.owner) && - !PolicyUtils.isExpensifyTeam(currentUserLogin) - ) { + if (PolicyUtils.isExpensifyTeam(exporter.email) && !PolicyUtils.isExpensifyTeam(policy?.owner) && !PolicyUtils.isExpensifyTeam(currentUserLogin)) { return options; } options.push({ From 7fe7f61c917e64d2895feca31f9a8e24f9a09abc Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Thu, 2 May 2024 18:21:44 -0700 Subject: [PATCH 4/4] Add missing useMemo dependencies --- .../qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx index 381a5850d7bd..a55b293fc3a1 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksPreferredExporterConfigurationPage.tsx @@ -49,7 +49,7 @@ function QuickbooksPreferredExporterConfigurationPage({policy}: WithPolicyConnec }); return options; }, []), - [exportConfiguration, exporters], + [exportConfiguration, exporters, currentUserLogin, policy?.owner], ); const selectExporter = useCallback(