-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not here error appears briefly when enabling features #40650
Changes from 10 commits
0da9f7f
3f893fd
0744c28
224c9ea
b72180c
578b27e
cf28c35
6a16d6d
bd426b3
dd18fab
29269b7
7752289
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback'; | |
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import ScrollView from '@components/ScrollView'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useNetwork from '@hooks/useNetwork'; | ||
import usePermissions from '@hooks/usePermissions'; | ||
import usePrevious from '@hooks/usePrevious'; | ||
import useSingleExecution from '@hooks/useSingleExecution'; | ||
|
@@ -33,6 +34,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; | |
import ROUTES from '@src/ROUTES'; | ||
import SCREENS from '@src/SCREENS'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
import type {PolicyFeatureName} from '@src/types/onyx/Policy'; | ||
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
import type IconAsset from '@src/types/utils/IconAsset'; | ||
import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading'; | ||
|
@@ -71,6 +73,8 @@ type WorkspaceInitialPageOnyxProps = { | |
|
||
type WorkspaceInitialPageProps = WithPolicyAndFullscreenLoadingProps & WorkspaceInitialPageOnyxProps & StackScreenProps<FullScreenNavigatorParamList, typeof SCREENS.WORKSPACE.INITIAL>; | ||
|
||
type PolicyFeatureStates = Record<PolicyFeatureName, boolean>; | ||
|
||
function dismissError(policyID: string) { | ||
PolicyUtils.goBackFromInvalidPolicy(); | ||
Policy.removeWorkspace(policyID); | ||
|
@@ -86,6 +90,20 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc | |
const activeRoute = useNavigationState(getTopmostWorkspacesCentralPaneName); | ||
const {translate} = useLocalize(); | ||
const {canUseAccountingIntegrations} = usePermissions(); | ||
const {isOffline} = useNetwork(); | ||
|
||
const prevPendingFields = usePrevious(policy?.pendingFields); | ||
const policyFeatureStates = useMemo( | ||
() => ({ | ||
[CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED]: policy?.areDistanceRatesEnabled, | ||
[CONST.POLICY.MORE_FEATURES.ARE_WORKFLOWS_ENABLED]: policy?.areWorkflowsEnabled, | ||
[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], | ||
) as PolicyFeatureStates; | ||
Comment on lines
+96
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sorry, my fault |
||
|
||
const policyID = policy?.id ?? ''; | ||
const policyName = policy?.name ?? ''; | ||
|
@@ -122,6 +140,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc | |
const shouldShowProtectedItems = PolicyUtils.isPolicyAdmin(policy); | ||
const isPaidGroupPolicy = PolicyUtils.isPaidGroupPolicy(policy); | ||
const isFreeGroupPolicy = PolicyUtils.isFreeGroupPolicy(policy); | ||
const [featureStates, setFeatureStates] = useState(policyFeatureStates); | ||
|
||
const protectedFreePolicyMenuItems: WorkspaceMenuItem[] = [ | ||
{ | ||
|
@@ -167,7 +186,23 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc | |
|
||
const protectedCollectPolicyMenuItems: WorkspaceMenuItem[] = []; | ||
|
||
if (policy?.areDistanceRatesEnabled) { | ||
// If features are pending, we should not update feature states | ||
useEffect(() => { | ||
ZhenjaHorbach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setFeatureStates((currentFeatureStates) => { | ||
const newFeatureStates = {} as PolicyFeatureStates; | ||
(Object.keys(policy?.pendingFields ?? {}) as PolicyFeatureName[]).forEach((key) => { | ||
Comment on lines
+193
to
+194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should always avoid casting ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in this case it make sense |
||
const isFeatureEnabled = PolicyUtils.isPolicyFeatureEnabled(policy, key); | ||
newFeatureStates[key] = | ||
prevPendingFields?.[key] !== policy?.pendingFields?.[key] || isOffline || !policy?.pendingFields?.[key] ? isFeatureEnabled : currentFeatureStates[key]; | ||
}); | ||
return { | ||
...policyFeatureStates, | ||
...newFeatureStates, | ||
}; | ||
}); | ||
}, [policy, isOffline, policyFeatureStates, prevPendingFields]); | ||
|
||
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED]) { | ||
protectedCollectPolicyMenuItems.push({ | ||
translationKey: 'workspace.common.distanceRates', | ||
icon: Expensicons.Car, | ||
|
@@ -176,7 +211,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc | |
}); | ||
} | ||
|
||
if (policy?.areWorkflowsEnabled) { | ||
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_WORKFLOWS_ENABLED]) { | ||
protectedCollectPolicyMenuItems.push({ | ||
translationKey: 'workspace.common.workflows', | ||
icon: Expensicons.Workflows, | ||
|
@@ -186,7 +221,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc | |
}); | ||
} | ||
|
||
if (policy?.areCategoriesEnabled) { | ||
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED]) { | ||
protectedCollectPolicyMenuItems.push({ | ||
translationKey: 'workspace.common.categories', | ||
icon: Expensicons.Folder, | ||
|
@@ -196,7 +231,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc | |
}); | ||
} | ||
|
||
if (policy?.areTagsEnabled) { | ||
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED]) { | ||
protectedCollectPolicyMenuItems.push({ | ||
translationKey: 'workspace.common.tags', | ||
icon: Expensicons.Tag, | ||
|
@@ -205,7 +240,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc | |
}); | ||
} | ||
|
||
if (policy?.tax?.trackingEnabled) { | ||
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED]) { | ||
protectedCollectPolicyMenuItems.push({ | ||
translationKey: 'workspace.common.taxes', | ||
icon: Expensicons.Tax, | ||
|
@@ -215,7 +250,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc | |
}); | ||
} | ||
|
||
if (policy?.areConnectionsEnabled && canUseAccountingIntegrations) { | ||
if (featureStates?.[CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED] && canUseAccountingIntegrations) { | ||
protectedCollectPolicyMenuItems.push({ | ||
translationKey: 'workspace.common.accounting', | ||
icon: Expensicons.Sync, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming from issue #54767, The problem was that
InteractionManager.runAfterInteractions
caused the toggle to become unresponsive when a Lottie animation was present in the background.We resolved the issue by replacing
InteractionManager.runAfterInteractions
withrequestAnimationFrame
.Proposal: #54767 (comment)
PR: #55442