From 7802474d250bcea8b2b37fd1ff6329577ab84ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Wed, 1 May 2024 11:49:11 +0200 Subject: [PATCH 1/7] add beta for xero --- src/CONST.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CONST.ts b/src/CONST.ts index e33ba5a1b7b8..3308d59d9c91 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -358,6 +358,7 @@ const CONST = { P2P_DISTANCE_REQUESTS: 'p2pDistanceRequests', WORKFLOWS_DELAYED_SUBMISSION: 'workflowsDelayedSubmission', ACCOUNTING_ON_NEW_EXPENSIFY: 'accountingOnNewExpensify', + XERO_ON_NEW_EXPENSIFY: 'xeroOnNewExpensify', }, BUTTON_STATES: { DEFAULT: 'default', From 2a23d55d5b8a9ad007c1ea9bed716ec522bb02d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Wed, 1 May 2024 11:49:23 +0200 Subject: [PATCH 2/7] handle beta logic for xero --- src/libs/Permissions.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index c79e9011386f..6ef30cd35835 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -40,6 +40,10 @@ function canUseAccountingIntegrations(betas: OnyxEntry): boolean { return !!betas?.includes(CONST.BETAS.ACCOUNTING_ON_NEW_EXPENSIFY) || canUseAllBetas(betas); } +function canUseXeroIntegration(betas: OnyxEntry): boolean { + return !!betas?.includes(CONST.BETAS.XERO_ON_NEW_EXPENSIFY) || canUseAllBetas(betas); +} + /** * Link previews are temporarily disabled. */ @@ -57,4 +61,5 @@ export default { canUseP2PDistanceRequests, canUseWorkflowsDelayedSubmission, canUseAccountingIntegrations, + canUseXeroIntegration, }; From 433fa5c2fcb061bd28e26e851e186bd0f72aabfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Wed, 1 May 2024 15:19:27 +0200 Subject: [PATCH 3/7] hide xero if not on beta --- .../workspace/accounting/PolicyAccountingPage.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 48888c054813..c4804d4f7d43 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -36,6 +36,7 @@ import type {Policy, PolicyConnectionSyncProgress} from '@src/types/onyx'; import type {PolicyConnectionName, Tenant} from '@src/types/onyx/Policy'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type IconAsset from '@src/types/utils/IconAsset'; +import usePermissions from '@hooks/usePermissions'; type PolicyAccountingPageOnyxProps = { connectionSyncProgress: OnyxEntry; @@ -63,6 +64,7 @@ function accountingIntegrationData( translate: LocaleContextProps['translate'], isConnectedToIntegration?: boolean, integrationToDisconnect?: PolicyConnectionName, + canUseXeroIntegration?: boolean, ): AccountingIntegration | undefined { switch (connectionName) { case CONST.POLICY.CONNECTIONS.NAME.QBO: @@ -81,6 +83,10 @@ function accountingIntegrationData( onAdvancedPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ADVANCED.getRoute(policyID)), }; case CONST.POLICY.CONNECTIONS.NAME.XERO: + if (!canUseXeroIntegration) { + return undefined; + } + return { title: translate('workspace.accounting.xero'), icon: Expensicons.XeroSquare, @@ -105,6 +111,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting const styles = useThemeStyles(); const {translate} = useLocalize(); const {isOffline} = useNetwork(); + const {canUseXeroIntegration} = usePermissions(); const {isSmallScreenWidth, windowWidth} = useWindowDimensions(); const [threeDotsMenuPosition, setThreeDotsMenuPosition] = useState({horizontal: 0, vertical: 0}); const [isDisconnectModalOpen, setIsDisconnectModalOpen] = useState(false); @@ -146,7 +153,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting const connectionsMenuItems: MenuItemProps[] = useMemo(() => { if (isEmptyObject(policy?.connections) && !isSyncInProgress) { return accountingIntegrations.map((integration) => { - const integrationData = accountingIntegrationData(integration, policyID, translate); + const integrationData = accountingIntegrationData(integration, policyID, translate, false, connectedIntegration, canUseXeroIntegration); const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {}; return { ...iconProps, @@ -162,7 +169,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting if (!connectedIntegration) { return []; } - const integrationData = accountingIntegrationData(connectedIntegration, policyID, translate); + const integrationData = accountingIntegrationData(connectedIntegration, policyID, translate, true, connectedIntegration, canUseXeroIntegration); const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {}; return [ { @@ -258,6 +265,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting theme.spinner, threeDotsMenuPosition, translate, + canUseXeroIntegration, ]); const otherIntegrationsItems = useMemo(() => { From d7d662c742af261d1217bb377a41fa0a611e2d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Wed, 1 May 2024 17:31:39 +0200 Subject: [PATCH 4/7] fix xero unnecessary padding when hidden --- .../accounting/PolicyAccountingPage.tsx | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index c4804d4f7d43..1b4af7cb10f2 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -19,6 +19,7 @@ import ThreeDotsMenu from '@components/ThreeDotsMenu'; import type ThreeDotsMenuProps from '@components/ThreeDotsMenu/types'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; +import usePermissions from '@hooks/usePermissions'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; @@ -36,7 +37,6 @@ import type {Policy, PolicyConnectionSyncProgress} from '@src/types/onyx'; import type {PolicyConnectionName, Tenant} from '@src/types/onyx/Policy'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type IconAsset from '@src/types/utils/IconAsset'; -import usePermissions from '@hooks/usePermissions'; type PolicyAccountingPageOnyxProps = { connectionSyncProgress: OnyxEntry; @@ -48,8 +48,6 @@ type PolicyAccountingPageProps = WithPolicyProps & policy: Policy; }; -const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME); - type AccountingIntegration = { title: string; icon: IconAsset; @@ -64,7 +62,6 @@ function accountingIntegrationData( translate: LocaleContextProps['translate'], isConnectedToIntegration?: boolean, integrationToDisconnect?: PolicyConnectionName, - canUseXeroIntegration?: boolean, ): AccountingIntegration | undefined { switch (connectionName) { case CONST.POLICY.CONNECTIONS.NAME.QBO: @@ -83,10 +80,6 @@ function accountingIntegrationData( onAdvancedPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ADVANCED.getRoute(policyID)), }; case CONST.POLICY.CONNECTIONS.NAME.XERO: - if (!canUseXeroIntegration) { - return undefined; - } - return { title: translate('workspace.accounting.xero'), icon: Expensicons.XeroSquare, @@ -118,6 +111,14 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting const threeDotsMenuContainerRef = useRef(null); const isSyncInProgress = !!connectionSyncProgress?.stageInProgress && connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE; + + const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME).filter((name) => { + if (name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration) { + return false; + } + + return true; + }); const connectedIntegration = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]) ?? connectionSyncProgress?.connectionName; const policyID = policy?.id ?? ''; @@ -153,7 +154,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting const connectionsMenuItems: MenuItemProps[] = useMemo(() => { if (isEmptyObject(policy?.connections) && !isSyncInProgress) { return accountingIntegrations.map((integration) => { - const integrationData = accountingIntegrationData(integration, policyID, translate, false, connectedIntegration, canUseXeroIntegration); + const integrationData = accountingIntegrationData(integration, policyID, translate); const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {}; return { ...iconProps, @@ -169,7 +170,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting if (!connectedIntegration) { return []; } - const integrationData = accountingIntegrationData(connectedIntegration, policyID, translate, true, connectedIntegration, canUseXeroIntegration); + const integrationData = accountingIntegrationData(connectedIntegration, policyID, translate); const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {}; return [ { @@ -265,7 +266,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting theme.spinner, threeDotsMenuPosition, translate, - canUseXeroIntegration, + accountingIntegrations, ]); const otherIntegrationsItems = useMemo(() => { @@ -287,7 +288,16 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting wrapperStyle: styles.sectionMenuItemTopDescription, }; }); - }, [connectedIntegration, connectionSyncProgress?.connectionName, isSyncInProgress, policy?.connections, policyID, styles.sectionMenuItemTopDescription, translate]); + }, [ + connectedIntegration, + connectionSyncProgress?.connectionName, + isSyncInProgress, + policy?.connections, + policyID, + styles.sectionMenuItemTopDescription, + translate, + accountingIntegrations, + ]); const headerThreeDotsMenuItems: ThreeDotsMenuProps['menuItems'] = [ { From fe3f3e2f9fe785573b0be7d42d7bc65db498ad6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 2 May 2024 07:12:51 +0200 Subject: [PATCH 5/7] simplify condition --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 1b4af7cb10f2..8c75eeb61bc1 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -113,11 +113,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting const isSyncInProgress = !!connectionSyncProgress?.stageInProgress && connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE; const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME).filter((name) => { - if (name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration) { - return false; - } - - return true; + return !(name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration); }); const connectedIntegration = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]) ?? connectionSyncProgress?.connectionName; const policyID = policy?.id ?? ''; From 3abe5b9d4c8a80bd156df53d82bd3d7eccfe392a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 2 May 2024 12:40:41 +0200 Subject: [PATCH 6/7] fix lint --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 8c75eeb61bc1..8a53c5946fc5 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -112,9 +112,9 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting const isSyncInProgress = !!connectionSyncProgress?.stageInProgress && connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE; - const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME).filter((name) => { - return !(name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration); - }); + const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME).filter(name => + !(name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration) + ); const connectedIntegration = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]) ?? connectionSyncProgress?.connectionName; const policyID = policy?.id ?? ''; From 0a183687fac5f4b7049a7b11679eb9bb297a1e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Thu, 2 May 2024 14:24:05 +0200 Subject: [PATCH 7/7] fix prettier --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 8a53c5946fc5..1ecab8547b12 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -112,9 +112,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting const isSyncInProgress = !!connectionSyncProgress?.stageInProgress && connectionSyncProgress.stageInProgress !== CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE; - const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME).filter(name => - !(name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration) - ); + const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME).filter((name) => !(name === CONST.POLICY.CONNECTIONS.NAME.XERO && !canUseXeroIntegration)); const connectedIntegration = accountingIntegrations.find((integration) => !!policy?.connections?.[integration]) ?? connectionSyncProgress?.connectionName; const policyID = policy?.id ?? '';