-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add new read commands for the workspace profile and initial settings pages - v2 #44902
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
+78
−12
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bfb59a4
[Chore]: Add openPolicyProfilePage and openPolicyInitialPage and API …
fedirjh 4450e8d
[Chore]: Add profile page to withPolicy HOC
fedirjh 7c06299
[Chore]: Use openPolicyInitialPage in WorkspaceInitialPage
fedirjh 3c7a6a1
[Chore]: use openPolicyProfilePage in WorkspaceProfilePage
fedirjh 7aedbf9
[Chore]: Fix prettier
fedirjh 30c5860
[Chore]: Fix prettier
fedirjh b99d555
[Fix]: use policyDraft in WorkspaceProfilePage
fedirjh 886eecc
[Chore]: Add comment
fedirjh 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,5 @@ | ||
| type OpenPolicyInitialPageParams = { | ||
| policyID: string; | ||
| }; | ||
|
|
||
| export default OpenPolicyInitialPageParams; |
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,5 @@ | ||
| type OpenPolicyProfilePageParams = { | ||
| policyID: string; | ||
| }; | ||
|
|
||
| export default OpenPolicyProfilePageParams; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import {useFocusEffect} from '@react-navigation/native'; | ||
| import type {StackScreenProps} from '@react-navigation/stack'; | ||
| import {ExpensiMark} from 'expensify-common'; | ||
| import React, {useCallback, useState} from 'react'; | ||
| import type {ImageStyle, StyleProp} from 'react-native'; | ||
|
|
@@ -15,12 +17,14 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback'; | |
| import Section from '@components/Section'; | ||
| import useActiveWorkspace from '@hooks/useActiveWorkspace'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useNetwork from '@hooks/useNetwork'; | ||
| import usePermissions from '@hooks/usePermissions'; | ||
| import useThemeIllustrations from '@hooks/useThemeIllustrations'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
| import * as ErrorUtils from '@libs/ErrorUtils'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import type {FullScreenNavigatorParamList} from '@libs/Navigation/types'; | ||
| import * as PolicyUtils from '@libs/PolicyUtils'; | ||
| import * as ReportUtils from '@libs/ReportUtils'; | ||
| import StringUtils from '@libs/StringUtils'; | ||
|
|
@@ -29,29 +33,31 @@ import * as Policy from '@userActions/Policy/Policy'; | |
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type SCREENS from '@src/SCREENS'; | ||
| import type * as OnyxTypes from '@src/types/onyx'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
| import withPolicy from './withPolicy'; | ||
| import type {WithPolicyProps} from './withPolicy'; | ||
| import WorkspacePageWithSections from './WorkspacePageWithSections'; | ||
|
|
||
| type WorkSpaceProfilePageOnyxProps = { | ||
| type WorkspaceProfilePageOnyxProps = { | ||
| /** Constant, list of available currencies */ | ||
| currencyList: OnyxEntry<OnyxTypes.CurrencyList>; | ||
| }; | ||
|
|
||
| type WorkSpaceProfilePageProps = WithPolicyProps & WorkSpaceProfilePageOnyxProps; | ||
|
|
||
| type WorkspaceProfilePageProps = WithPolicyProps & WorkspaceProfilePageOnyxProps & StackScreenProps<FullScreenNavigatorParamList, typeof SCREENS.WORKSPACE.PROFILE>; | ||
| const parser = new ExpensiMark(); | ||
|
|
||
| function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfilePageProps) { | ||
| function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = {}, route}: WorkspaceProfilePageProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const {isSmallScreenWidth} = useWindowDimensions(); | ||
| const illustrations = useThemeIllustrations(); | ||
| const {activeWorkspaceID, setActiveWorkspaceID} = useActiveWorkspace(); | ||
| const {canUseSpotnanaTravel} = usePermissions(); | ||
|
|
||
| // When we create a new workspace, the policy prop will be empty on the first render. Therefore, we have to use policyDraft until policy has been set in Onyx. | ||
| const policy = policyDraft?.id ? policyDraft : policyProp; | ||
| const outputCurrency = policy?.outputCurrency ?? ''; | ||
| const currencySymbol = currencyList?.[outputCurrency]?.symbol ?? ''; | ||
| const formattedCurrency = !isEmptyObject(policy) && !isEmptyObject(currencyList) ? `${outputCurrency} - ${currencySymbol}` : ''; | ||
|
|
@@ -82,6 +88,23 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi | |
| const imageStyle: StyleProp<ImageStyle> = isSmallScreenWidth ? [styles.mhv12, styles.mhn5, styles.mbn5] : [styles.mhv8, styles.mhn8, styles.mbn5]; | ||
| const shouldShowAddress = !readOnly || formattedAddress; | ||
|
|
||
| const fetchPolicyData = useCallback(() => { | ||
| if (policyDraft?.id) { | ||
| return; | ||
| } | ||
| Policy.openPolicyProfilePage(route.params.policyID); | ||
| }, [policyDraft?.id, route.params.policyID]); | ||
|
|
||
| useNetwork({onReconnect: fetchPolicyData}); | ||
|
|
||
| // We have the same focus effect in the WorkspaceInitialPage, this way we can get the policy data in narrow | ||
| // as well as in the wide layout when looking at policy settings. | ||
| useFocusEffect( | ||
| useCallback(() => { | ||
| fetchPolicyData(); | ||
| }, [fetchPolicyData]), | ||
| ); | ||
|
|
||
| const DefaultAvatar = useCallback( | ||
| () => ( | ||
| <Avatar | ||
|
|
@@ -116,11 +139,6 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi | |
| } | ||
| }, [policy?.id, policyName, activeWorkspaceID, setActiveWorkspaceID]); | ||
|
|
||
| // When we create a new workspaces, the policy prop will not be set on the first render. Therefore, we have to delay rendering until it has been set in Onyx. | ||
| if (policy === undefined) { | ||
| return null; | ||
| } | ||
|
|
||
|
Comment on lines
-119
to
-123
Contributor
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. Nice one! |
||
| return ( | ||
| <WorkspacePageWithSections | ||
| headerText={translate('workspace.common.profile')} | ||
|
|
@@ -282,7 +300,7 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi | |
| WorkspaceProfilePage.displayName = 'WorkspaceProfilePage'; | ||
|
|
||
| export default withPolicy( | ||
| withOnyx<WorkSpaceProfilePageProps, WorkSpaceProfilePageOnyxProps>({ | ||
| withOnyx<WorkspaceProfilePageProps, WorkspaceProfilePageOnyxProps>({ | ||
| currencyList: {key: ONYXKEYS.CURRENCY_LIST}, | ||
| })(WorkspaceProfilePage), | ||
| ); | ||
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.
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.
This hook will trigger when reconnecting, even when this screen is not focused. This accidentally introduced this bug #82769. During reconnect in Add Bank Account Flow,
openPolicyInitialPageAPI was called and wiped out thereimbursementAccount.More details:
#82769 (comment)