From e0fc8d8c6f0e9395fc372fc5615faacb29782420 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Thu, 18 Jul 2024 12:30:51 +0700 Subject: [PATCH 1/9] fix: accounting not enable connection made from od --- src/libs/PolicyUtils.ts | 3 +++ src/pages/workspace/WorkspaceInitialPage.tsx | 2 +- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 4 ++-- src/pages/workspace/withPolicyConnections.tsx | 7 ++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index fe53a7bcd5ce..a1ad356ae27e 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -413,6 +413,9 @@ function isPolicyFeatureEnabled(policy: OnyxEntry, featureName: PolicyFe if (featureName === CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED) { return !!policy?.tax?.trackingEnabled; } + if (featureName === CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED) { + return policy?.[featureName] ? !!policy?.[featureName] : !!policy?.connections; + } return !!policy?.[featureName]; } diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 267a3ac38850..6d433b3f474c 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -106,7 +106,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc [CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED]: policy?.areCategoriesEnabled, [CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED]: policy?.areTagsEnabled, [CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED]: policy?.tax?.trackingEnabled, - [CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED]: policy?.areConnectionsEnabled, + [CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED]: policy?.areConnectionsEnabled ? policy?.areConnectionsEnabled : !isEmptyObject(policy?.connections), [CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED]: policy?.areExpensifyCardsEnabled, [CONST.POLICY.MORE_FEATURES.ARE_REPORT_FIELDS_ENABLED]: policy?.areReportFieldsEnabled, }), diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 46d897bd0a0f..e8a0b5420ab3 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -85,7 +85,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro const {isSmallScreenWidth} = useWindowDimensions(); const {translate} = useLocalize(); const {canUseReportFieldsFeature, canUseWorkspaceFeeds} = usePermissions(); - const hasAccountingConnection = !!policy?.areConnectionsEnabled && !isEmptyObject(policy?.connections); + const hasAccountingConnection = policy?.areConnectionsEnabled ? policy?.areConnectionsEnabled : !isEmptyObject(policy?.connections); const isSyncTaxEnabled = !!policy?.connections?.quickbooksOnline?.config?.syncTax || !!policy?.connections?.xero?.config?.importTaxRates || @@ -225,7 +225,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro icon: Illustrations.Accounting, titleTranslationKey: 'workspace.moreFeatures.connections.title', subtitleTranslationKey: 'workspace.moreFeatures.connections.subtitle', - isActive: !!policy?.areConnectionsEnabled, + isActive: policy?.areConnectionsEnabled ? policy?.areConnectionsEnabled : !isEmptyObject(policy?.connections), pendingAction: policy?.pendingFields?.areConnectionsEnabled, action: (isEnabled: boolean) => { if (hasAccountingConnection) { diff --git a/src/pages/workspace/withPolicyConnections.tsx b/src/pages/workspace/withPolicyConnections.tsx index 874aa4728c0d..7ed2f974412d 100644 --- a/src/pages/workspace/withPolicyConnections.tsx +++ b/src/pages/workspace/withPolicyConnections.tsx @@ -5,6 +5,7 @@ import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import useNetwork from '@hooks/useNetwork'; import {openPolicyAccountingPage} from '@libs/actions/PolicyConnections'; import ONYXKEYS from '@src/ONYXKEYS'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; import withPolicy from './withPolicy'; import type {WithPolicyProps} from './withPolicy'; @@ -28,7 +29,11 @@ function withPolicyConnections(Wrappe const [hasConnectionsDataBeenFetched] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${props.policy?.id ?? '-1'}`, { initWithStoredValues: false, }); - const isConnectionDataFetchNeeded = !isOffline && props.policy && props.policy.areConnectionsEnabled && !props.policy.connections && !hasConnectionsDataBeenFetched; + const isConnectionDataFetchNeeded = + !isOffline && + props.policy && + (props.policy.areConnectionsEnabled ? !!props.policy.areConnectionsEnabled : !isEmptyObject(props.policy.connections)) && + !hasConnectionsDataBeenFetched; useEffect(() => { // When the accounting feature is not enabled, or if the connections data already exists, From c470b8012644abf83907d8efa2ae1475af3f6c49 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Fri, 19 Jul 2024 15:55:00 +0700 Subject: [PATCH 2/9] fix infinite rendering --- src/pages/workspace/WorkspaceInitialPage.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 6d433b3f474c..8dcd680f703d 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -333,6 +333,11 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc const prevPolicy = usePrevious(policy); const prevProtectedMenuItems = usePrevious(protectedCollectPolicyMenuItems); const enabledItem = protectedCollectPolicyMenuItems.find((curItem) => !prevProtectedMenuItems.some((prevItem) => curItem.routeName === prevItem.routeName)); + const [enabledItemState, setEnabledItemState] = useState(enabledItem); + + useEffect(() => { + setEnabledItemState(enabledItem); + }, [enabledItem]); // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundPage = @@ -403,7 +408,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc onPress={item.action} brickRoadIndicator={item.brickRoadIndicator} wrapperStyle={styles.sectionMenuItem} - highlighted={enabledItem?.routeName === item.routeName} + highlighted={enabledItemState?.routeName === item.routeName} focused={!!(item.routeName && activeRoute?.startsWith(item.routeName))} hoverAndPressStyle={styles.hoveredComponentBG} isPaneMenu From 237a3ea9a1cf12d344339f27dc9df861fd9a6032 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Fri, 19 Jul 2024 18:12:50 +0700 Subject: [PATCH 3/9] fix animate --- src/pages/workspace/WorkspaceInitialPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 8dcd680f703d..e7f6fea2807a 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -408,7 +408,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc onPress={item.action} brickRoadIndicator={item.brickRoadIndicator} wrapperStyle={styles.sectionMenuItem} - highlighted={enabledItemState?.routeName === item.routeName} + highlighted={enabledItem?.routeName === item.routeName} focused={!!(item.routeName && activeRoute?.startsWith(item.routeName))} hoverAndPressStyle={styles.hoveredComponentBG} isPaneMenu From 8d607188c1e3994d20a9b89f7bdb966f2f180833 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Fri, 19 Jul 2024 19:31:47 +0700 Subject: [PATCH 4/9] improve code --- src/pages/workspace/WorkspaceInitialPage.tsx | 2 +- src/pages/workspace/withPolicyConnections.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index e7f6fea2807a..8f4868c18d1f 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -333,7 +333,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc const prevPolicy = usePrevious(policy); const prevProtectedMenuItems = usePrevious(protectedCollectPolicyMenuItems); const enabledItem = protectedCollectPolicyMenuItems.find((curItem) => !prevProtectedMenuItems.some((prevItem) => curItem.routeName === prevItem.routeName)); - const [enabledItemState, setEnabledItemState] = useState(enabledItem); + const [, setEnabledItemState] = useState(enabledItem); useEffect(() => { setEnabledItemState(enabledItem); diff --git a/src/pages/workspace/withPolicyConnections.tsx b/src/pages/workspace/withPolicyConnections.tsx index 7ed2f974412d..b3a31998c420 100644 --- a/src/pages/workspace/withPolicyConnections.tsx +++ b/src/pages/workspace/withPolicyConnections.tsx @@ -32,7 +32,7 @@ function withPolicyConnections(Wrappe const isConnectionDataFetchNeeded = !isOffline && props.policy && - (props.policy.areConnectionsEnabled ? !!props.policy.areConnectionsEnabled : !isEmptyObject(props.policy.connections)) && + (props.policy.areConnectionsEnabled ? props.policy.areConnectionsEnabled : !isEmptyObject(props.policy.connections)) && !hasConnectionsDataBeenFetched; useEffect(() => { From c8fdc55dd673c493cf9a435d3ae9d0e9ffa183f8 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Mon, 22 Jul 2024 12:06:06 +0700 Subject: [PATCH 5/9] fix requested changes --- src/libs/PolicyUtils.ts | 2 +- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 4 ++-- src/pages/workspace/withPolicyConnections.tsx | 5 +---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index a1ad356ae27e..3cd8d552b393 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -414,7 +414,7 @@ function isPolicyFeatureEnabled(policy: OnyxEntry, featureName: PolicyFe return !!policy?.tax?.trackingEnabled; } if (featureName === CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED) { - return policy?.[featureName] ? !!policy?.[featureName] : !!policy?.connections; + return policy?.[featureName] ? !!policy?.[featureName] : !isEmptyObject(policy?.connections); } return !!policy?.[featureName]; diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index e8a0b5420ab3..a8c8c17731c8 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -85,7 +85,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro const {isSmallScreenWidth} = useWindowDimensions(); const {translate} = useLocalize(); const {canUseReportFieldsFeature, canUseWorkspaceFeeds} = usePermissions(); - const hasAccountingConnection = policy?.areConnectionsEnabled ? policy?.areConnectionsEnabled : !isEmptyObject(policy?.connections); + const hasAccountingConnection = !!policy?.areConnectionsEnabled || !isEmptyObject(policy?.connections); const isSyncTaxEnabled = !!policy?.connections?.quickbooksOnline?.config?.syncTax || !!policy?.connections?.xero?.config?.importTaxRates || @@ -225,7 +225,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro icon: Illustrations.Accounting, titleTranslationKey: 'workspace.moreFeatures.connections.title', subtitleTranslationKey: 'workspace.moreFeatures.connections.subtitle', - isActive: policy?.areConnectionsEnabled ? policy?.areConnectionsEnabled : !isEmptyObject(policy?.connections), + isActive: hasAccountingConnection, pendingAction: policy?.pendingFields?.areConnectionsEnabled, action: (isEnabled: boolean) => { if (hasAccountingConnection) { diff --git a/src/pages/workspace/withPolicyConnections.tsx b/src/pages/workspace/withPolicyConnections.tsx index b3a31998c420..dc228b65d1c4 100644 --- a/src/pages/workspace/withPolicyConnections.tsx +++ b/src/pages/workspace/withPolicyConnections.tsx @@ -30,10 +30,7 @@ function withPolicyConnections(Wrappe initWithStoredValues: false, }); const isConnectionDataFetchNeeded = - !isOffline && - props.policy && - (props.policy.areConnectionsEnabled ? props.policy.areConnectionsEnabled : !isEmptyObject(props.policy.connections)) && - !hasConnectionsDataBeenFetched; + !isOffline && props.policy && (!!props.policy.areConnectionsEnabled || !isEmptyObject(props.policy.connections)) && !hasConnectionsDataBeenFetched; useEffect(() => { // When the accounting feature is not enabled, or if the connections data already exists, From b11c5a678a8c9683eded3479c5f5eedc89bbd6da Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Mon, 22 Jul 2024 14:44:14 +0700 Subject: [PATCH 6/9] fix accounting disabled when there is no connection --- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index a8c8c17731c8..9c3000d3cccf 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -85,7 +85,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro const {isSmallScreenWidth} = useWindowDimensions(); const {translate} = useLocalize(); const {canUseReportFieldsFeature, canUseWorkspaceFeeds} = usePermissions(); - const hasAccountingConnection = !!policy?.areConnectionsEnabled || !isEmptyObject(policy?.connections); + const hasAccountingConnection = !!policy?.areConnectionsEnabled && !isEmptyObject(policy?.connections); + const isAccountingEnabled = !!policy?.areConnectionsEnabled || !isEmptyObject(policy?.connections); const isSyncTaxEnabled = !!policy?.connections?.quickbooksOnline?.config?.syncTax || !!policy?.connections?.xero?.config?.importTaxRates || @@ -225,7 +226,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro icon: Illustrations.Accounting, titleTranslationKey: 'workspace.moreFeatures.connections.title', subtitleTranslationKey: 'workspace.moreFeatures.connections.subtitle', - isActive: hasAccountingConnection, + isActive: isAccountingEnabled, pendingAction: policy?.pendingFields?.areConnectionsEnabled, action: (isEnabled: boolean) => { if (hasAccountingConnection) { From 723024b51e5cf900572d749cdec24c078beda924 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Mon, 22 Jul 2024 14:50:15 +0700 Subject: [PATCH 7/9] fix ternary operator --- src/pages/workspace/WorkspaceInitialPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 8f4868c18d1f..a321dca0d73a 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -106,7 +106,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc [CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED]: policy?.areCategoriesEnabled, [CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED]: policy?.areTagsEnabled, [CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED]: policy?.tax?.trackingEnabled, - [CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED]: policy?.areConnectionsEnabled ? policy?.areConnectionsEnabled : !isEmptyObject(policy?.connections), + [CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED]: !!policy?.areConnectionsEnabled || !isEmptyObject(policy?.connections), [CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED]: policy?.areExpensifyCardsEnabled, [CONST.POLICY.MORE_FEATURES.ARE_REPORT_FIELDS_ENABLED]: policy?.areReportFieldsEnabled, }), From d12061b3e96f35ced7a97ac7e67257d7e7450535 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Mon, 22 Jul 2024 14:53:33 +0700 Subject: [PATCH 8/9] fix hasAccountingConnection --- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 9c3000d3cccf..08f369be05d7 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -85,7 +85,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro const {isSmallScreenWidth} = useWindowDimensions(); const {translate} = useLocalize(); const {canUseReportFieldsFeature, canUseWorkspaceFeeds} = usePermissions(); - const hasAccountingConnection = !!policy?.areConnectionsEnabled && !isEmptyObject(policy?.connections); + const hasAccountingConnection = !isEmptyObject(policy?.connections); const isAccountingEnabled = !!policy?.areConnectionsEnabled || !isEmptyObject(policy?.connections); const isSyncTaxEnabled = !!policy?.connections?.quickbooksOnline?.config?.syncTax || From b1b27f1306fae5b4dcf9da56787c40d05d59e0b6 Mon Sep 17 00:00:00 2001 From: NJ-2020 Date: Wed, 24 Jul 2024 10:35:50 +0700 Subject: [PATCH 9/9] remove setEnabledItemState and useEffect --- src/pages/workspace/WorkspaceInitialPage.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index a321dca0d73a..3fe3c08a9ac5 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -333,11 +333,6 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc const prevPolicy = usePrevious(policy); const prevProtectedMenuItems = usePrevious(protectedCollectPolicyMenuItems); const enabledItem = protectedCollectPolicyMenuItems.find((curItem) => !prevProtectedMenuItems.some((prevItem) => curItem.routeName === prevItem.routeName)); - const [, setEnabledItemState] = useState(enabledItem); - - useEffect(() => { - setEnabledItemState(enabledItem); - }, [enabledItem]); // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundPage =