diff --git a/src/libs/API/parameters/OpenPolicyInitialPageParams.ts b/src/libs/API/parameters/OpenPolicyInitialPageParams.ts new file mode 100644 index 000000000000..764abe9a6a77 --- /dev/null +++ b/src/libs/API/parameters/OpenPolicyInitialPageParams.ts @@ -0,0 +1,5 @@ +type OpenPolicyInitialPageParams = { + policyID: string; +}; + +export default OpenPolicyInitialPageParams; diff --git a/src/libs/API/parameters/OpenPolicyProfilePageParams.ts b/src/libs/API/parameters/OpenPolicyProfilePageParams.ts new file mode 100644 index 000000000000..55dce33a3dac --- /dev/null +++ b/src/libs/API/parameters/OpenPolicyProfilePageParams.ts @@ -0,0 +1,5 @@ +type OpenPolicyProfilePageParams = { + policyID: string; +}; + +export default OpenPolicyProfilePageParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 0eb9ae30336b..269821318889 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -191,6 +191,8 @@ export type {default as OpenPolicyDistanceRatesPageParams} from './OpenPolicyDis export type {default as OpenPolicyTaxesPageParams} from './OpenPolicyTaxesPageParams'; export type {default as EnablePolicyTaxesParams} from './EnablePolicyTaxesParams'; export type {default as OpenPolicyMoreFeaturesPageParams} from './OpenPolicyMoreFeaturesPageParams'; +export type {default as OpenPolicyProfilePageParams} from './OpenPolicyProfilePageParams'; +export type {default as OpenPolicyInitialPageParams} from './OpenPolicyInitialPageParams'; export type {default as CreatePolicyDistanceRateParams} from './CreatePolicyDistanceRateParams'; export type {default as SetPolicyDistanceRatesUnitParams} from './SetPolicyDistanceRatesUnitParams'; export type {default as SetPolicyDistanceRatesDefaultCategoryParams} from './SetPolicyDistanceRatesDefaultCategoryParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 92b6d7679418..c5057d5c8d7c 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -498,6 +498,8 @@ const READ_COMMANDS = { OPEN_POLICY_WORKFLOWS_PAGE: 'OpenPolicyWorkflowsPage', OPEN_POLICY_DISTANCE_RATES_PAGE: 'OpenPolicyDistanceRatesPage', OPEN_POLICY_MORE_FEATURES_PAGE: 'OpenPolicyMoreFeaturesPage', + OPEN_POLICY_PROFILE_PAGE: 'OpenPolicyProfilePage', + OPEN_POLICY_INITIAL_PAGE: 'OpenPolicyInitialPage', OPEN_POLICY_ACCOUNTING_PAGE: 'OpenPolicyAccountingPage', SEARCH: 'Search', OPEN_SUBSCRIPTION_PAGE: 'OpenSubscriptionPage', @@ -546,6 +548,8 @@ type ReadCommandParameters = { [READ_COMMANDS.OPEN_POLICY_WORKFLOWS_PAGE]: Parameters.OpenPolicyWorkflowsPageParams; [READ_COMMANDS.OPEN_POLICY_DISTANCE_RATES_PAGE]: Parameters.OpenPolicyDistanceRatesPageParams; [READ_COMMANDS.OPEN_POLICY_MORE_FEATURES_PAGE]: Parameters.OpenPolicyMoreFeaturesPageParams; + [READ_COMMANDS.OPEN_POLICY_PROFILE_PAGE]: Parameters.OpenPolicyProfilePageParams; + [READ_COMMANDS.OPEN_POLICY_INITIAL_PAGE]: Parameters.OpenPolicyInitialPageParams; [READ_COMMANDS.OPEN_POLICY_ACCOUNTING_PAGE]: Parameters.OpenPolicyAccountingPageParams; [READ_COMMANDS.SEARCH]: Parameters.SearchParams; [READ_COMMANDS.OPEN_SUBSCRIPTION_PAGE]: null; diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 9e5cb78ae16b..5feb860de247 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -17,7 +17,9 @@ import type { EnablePolicyWorkflowsParams, LeavePolicyParams, OpenDraftWorkspaceRequestParams, + OpenPolicyInitialPageParams, OpenPolicyMoreFeaturesPageParams, + OpenPolicyProfilePageParams, OpenPolicyTaxesPageParams, OpenPolicyWorkflowsPageParams, OpenWorkspaceInvitePageParams, @@ -2770,6 +2772,18 @@ function openPolicyMoreFeaturesPage(policyID: string) { API.read(READ_COMMANDS.OPEN_POLICY_MORE_FEATURES_PAGE, params); } +function openPolicyProfilePage(policyID: string) { + const params: OpenPolicyProfilePageParams = {policyID}; + + API.read(READ_COMMANDS.OPEN_POLICY_PROFILE_PAGE, params); +} + +function openPolicyInitialPage(policyID: string) { + const params: OpenPolicyInitialPageParams = {policyID}; + + API.read(READ_COMMANDS.OPEN_POLICY_INITIAL_PAGE, params); +} + function setPolicyCustomTaxName(policyID: string, customTaxName: string) { const policy = getPolicy(policyID); const originalCustomTaxName = policy?.taxRates?.name; @@ -2973,6 +2987,8 @@ export { enablePolicyWorkflows, enableDistanceRequestTax, openPolicyMoreFeaturesPage, + openPolicyProfilePage, + openPolicyInitialPage, generateCustomUnitID, clearQBOErrorField, clearXeroErrorField, diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 07dfdeb7c0d7..6715bf21c911 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -1,4 +1,4 @@ -import {useNavigationState} from '@react-navigation/native'; +import {useFocusEffect, useNavigationState} from '@react-navigation/native'; import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; @@ -86,7 +86,7 @@ function dismissError(policyID: string, pendingAction: PendingAction | undefined } } -function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAccount, policyCategories}: WorkspaceInitialPageProps) { +function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAccount, policyCategories, route}: WorkspaceInitialPageProps) { const styles = useThemeStyles(); const policy = policyDraft?.id ? policyDraft : policyProp; const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false); @@ -133,6 +133,18 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc setIsCurrencyModalOpen(false); }, [policy?.outputCurrency, isCurrencyModalOpen]); + const fetchPolicyData = useCallback(() => { + Policy.openPolicyInitialPage(route.params.policyID); + }, [route.params.policyID]); + + useNetwork({onReconnect: fetchPolicyData}); + + useFocusEffect( + useCallback(() => { + fetchPolicyData(); + }, [fetchPolicyData]), + ); + /** Call update workspace currency and hide the modal */ const confirmCurrencyChangeAndHideModal = useCallback(() => { Policy.updateGeneralSettings(policyID, policyName, CONST.CURRENCY.USD); diff --git a/src/pages/workspace/WorkspaceProfilePage.tsx b/src/pages/workspace/WorkspaceProfilePage.tsx index 6a86a83b5d11..6f2097688b5c 100644 --- a/src/pages/workspace/WorkspaceProfilePage.tsx +++ b/src/pages/workspace/WorkspaceProfilePage.tsx @@ -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,22 +33,23 @@ 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; }; -type WorkSpaceProfilePageProps = WithPolicyProps & WorkSpaceProfilePageOnyxProps; +type WorkspaceProfilePageProps = WithPolicyProps & WorkspaceProfilePageOnyxProps & StackScreenProps; const parser = new ExpensiMark(); -function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfilePageProps) { +function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkspaceProfilePageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const {isSmallScreenWidth} = useWindowDimensions(); @@ -82,6 +87,20 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi const imageStyle: StyleProp = isSmallScreenWidth ? [styles.mhv12, styles.mhn5, styles.mbn5] : [styles.mhv8, styles.mhn8, styles.mbn5]; const shouldShowAddress = !readOnly || formattedAddress; + const fetchPolicyData = useCallback(() => { + Policy.openPolicyProfilePage(route.params.policyID); + }, [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( () => ( ({ + withOnyx({ currencyList: {key: ONYXKEYS.CURRENCY_LIST}, })(WorkspaceProfilePage), ); diff --git a/src/pages/workspace/withPolicy.tsx b/src/pages/workspace/withPolicy.tsx index ccc5fe2c5a25..1b8f35e4d483 100644 --- a/src/pages/workspace/withPolicy.tsx +++ b/src/pages/workspace/withPolicy.tsx @@ -22,6 +22,7 @@ type PolicyRoute = RouteProp< NavigatorsParamList, | typeof SCREENS.REIMBURSEMENT_ACCOUNT_ROOT | typeof SCREENS.WORKSPACE.INITIAL + | typeof SCREENS.WORKSPACE.PROFILE | typeof SCREENS.WORKSPACE.BILLS | typeof SCREENS.WORKSPACE.MORE_FEATURES | typeof SCREENS.WORKSPACE.MEMBERS