-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
fix: redirect to proper place after upgrade #46617
Changes from all commits
fd56509
6c2712d
7278e03
73dd174
409a1f2
e84cdb2
3037407
612f6d1
9fecc9d
c4420be
97dbd8b
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import {useNavigation} from '@react-navigation/native'; | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
import React from 'react'; | ||
import React, {useCallback, useEffect} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
|
@@ -8,6 +9,7 @@ import useNetwork from '@hooks/useNetwork'; | |
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; | ||
import {isControlPolicy} from '@libs/PolicyUtils'; | ||
import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; | ||
import CONST from '@src/CONST'; | ||
import * as Policy from '@src/libs/actions/Policy/Policy'; | ||
|
@@ -19,22 +21,51 @@ import UpgradeIntro from './UpgradeIntro'; | |
type WorkspaceUpgradePageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.UPGRADE>; | ||
|
||
function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { | ||
const navigation = useNavigation(); | ||
const styles = useThemeStyles(); | ||
const policyID = route.params.policyID; | ||
const feature = Object.values(CONST.UPGRADE_FEATURE_INTRO_MAPPING).find((f) => f.alias === route.params.featureName); | ||
const {translate} = useLocalize(); | ||
const [policy] = useOnyx(`policy_${policyID}`); | ||
const {isOffline} = useNetwork(); | ||
|
||
if (!feature || !policy) { | ||
return <NotFoundPage />; | ||
} | ||
const isUpgraded = React.useMemo(() => isControlPolicy(policy), [policy]); | ||
|
||
const upgradeToCorporate = () => { | ||
Policy.upgradeToCorporate(policy.id, feature.id); | ||
if (!policy || !feature) { | ||
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. Do we not have a way in the UI to upgrade without having to click on a feature first? 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 did this just to keep typescript happy since feature or policy could be |
||
return; | ||
} | ||
|
||
Policy.upgradeToCorporate(policy.id, feature.name); | ||
}; | ||
|
||
const isUpgraded = policy.type === CONST.POLICY.TYPE.CORPORATE; | ||
const confirmUpgrade = useCallback(() => { | ||
if (!feature) { | ||
return; | ||
} | ||
switch (feature.id) { | ||
case CONST.UPGRADE_FEATURE_INTRO_MAPPING.reportFields.id: | ||
Policy.enablePolicyReportFields(policyID, true, true); | ||
return Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID)); | ||
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. FYI, This caused this issue: #47683. More info in this proposal: #47683 (comment) |
||
default: | ||
return route.params.backTo ? Navigation.navigate(route.params.backTo) : Navigation.goBack(); | ||
} | ||
}, [feature, policyID, route.params.backTo]); | ||
|
||
useEffect(() => { | ||
const unsubscribeListener = navigation.addListener('blur', () => { | ||
if (!isUpgraded) { | ||
return; | ||
} | ||
confirmUpgrade(); | ||
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. @allroundexperts Hi, why do we need to listen blur event here? Could we call confirmUpgrade() right after licking "Got it, thanks" on onConfirmUpgrade callback? 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. We need to call the confirmation function if the user doesn't event click on the |
||
}); | ||
|
||
return unsubscribeListener; | ||
}, [isUpgraded, confirmUpgrade, navigation]); | ||
|
||
if (!feature || !policy) { | ||
return <NotFoundPage />; | ||
} | ||
Comment on lines
+66
to
+68
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. Coming from #47904 |
||
|
||
return ( | ||
<ScreenWrapper | ||
|
@@ -44,11 +75,11 @@ function WorkspaceUpgradePage({route}: WorkspaceUpgradePageProps) { | |
> | ||
<HeaderWithBackButton | ||
title={translate('common.upgrade')} | ||
onBackButtonPress={() => Navigation.goBack(route.params.backTo ?? ROUTES.WORKSPACE_PROFILE.getRoute(policyID))} | ||
onBackButtonPress={() => (isUpgraded ? Navigation.dismissModal() : Navigation.goBack())} | ||
/> | ||
{isUpgraded && ( | ||
<UpgradeConfirmation | ||
policyID={policy.id} | ||
onConfirmUpgrade={() => Navigation.dismissModal()} | ||
policyName={policy.name} | ||
/> | ||
)} | ||
|
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.
I suppose this PR related with this issue
We upgraded navigation event for editGLCode
But not for onBackButtonPress