-
Notifications
You must be signed in to change notification settings - Fork 4k
[cp stag] Fix Not Here page when opening card spend rules on a Collect workspace #97704
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f64b14f
Fix Not Here page when opening card spend rules on a Collect workspace
Krishna2323 8139952
Guard the Collect upgrade redirect and extend it to the spend rule pi…
Krishna2323 363203b
fix eslint
Krishna2323 eddd714
remove disable lint comment.
Krishna2323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import {arePolicyRulesEnabled, isCollectPolicy, tryNavigateToControlPolicyUpgrade} from '@libs/PolicyUtils'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Route} from '@src/ROUTES'; | ||
| import ROUTES from '@src/ROUTES'; | ||
|
|
||
| import {useEffect, useRef} from 'react'; | ||
|
|
||
| import useOnyx from './useOnyx'; | ||
| import usePermissions from './usePermissions'; | ||
| import usePolicy from './usePolicy'; | ||
|
|
||
| /** | ||
| * Sends a Collect admin who lands on a Control-only Rules page to the Control upgrade page. | ||
| * | ||
| * The Rules page gates its own Control-only features on press, but these pages are also reachable in ways that | ||
| * skip it: direct deep links to the page and its child pickers, and Wallet > Expensify card > Edit spend rules. | ||
| * An `accessVariants` CONTROL check can't be used for that, because AccessOrNotFoundWrapper only ever renders | ||
| * Not Found, never an upgrade path. | ||
| * | ||
| * @param policyID - The policy the page belongs to. | ||
| * @param backTo - Where the upgrade page should return to. Defaults to the workspace Rules page. | ||
| */ | ||
| function useControlOnlyRuleUpgradeRedirect(policyID: string, backTo?: Route) { | ||
| const policy = usePolicy(policyID); | ||
| const {isBetaEnabled} = usePermissions(); | ||
| const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`); | ||
|
|
||
| const isCollect = isCollectPolicy(policy); | ||
| // Mirrors the feature check in AccessOrNotFoundWrapper. When Rules itself is disabled, that wrapper already | ||
| // redirects to More features, so redirecting to the upgrade page too would flash it on the way there. | ||
| const isRulesFeatureEnabled = arePolicyRulesEnabled(policy, policyCategories, isBetaEnabled(CONST.BETAS.RULES_REVAMP)); | ||
| const hasRedirectedToUpgrade = useRef(false); | ||
| const upgradeBackTo = backTo ?? ROUTES.WORKSPACE_RULES.getRoute(policyID); | ||
|
|
||
| useEffect(() => { | ||
| if (!isCollect || !isRulesFeatureEnabled || hasRedirectedToUpgrade.current) { | ||
| return; | ||
| } | ||
|
|
||
| // Replace rather than push: Back from the upgrade page must not land on a page Collect can't use. | ||
| hasRedirectedToUpgrade.current = tryNavigateToControlPolicyUpgrade(policy, CONST.UPGRADE_FEATURE_INTRO_MAPPING.rules.alias, upgradeBackTo, true); | ||
| }, [isCollect, isRulesFeatureEnabled, policy, upgradeBackTo]); | ||
| } | ||
|
|
||
| export default useControlOnlyRuleUpgradeRedirect; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.