Skip to content

Commit

Permalink
Merge pull request Expensify#42901 from Expensify/vit-41914
Browse files Browse the repository at this point in the history
Add new read commands for the workspace profile and initial settings pages
  • Loading branch information
MonilBhavsar authored Jun 24, 2024
2 parents affb2c3 + 3925401 commit 2526e31
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/libs/API/parameters/OpenPolicyInitialPageParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type OpenPolicyInitialPageParams = {
policyID: string;
};

export default OpenPolicyInitialPageParams;
5 changes: 5 additions & 0 deletions src/libs/API/parameters/OpenPolicyProfilePageParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type OpenPolicyProfilePageParams = {
policyID: string;
};

export default OpenPolicyProfilePageParams;
2 changes: 2 additions & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 4 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import type {
EnablePolicyWorkflowsParams,
LeavePolicyParams,
OpenDraftWorkspaceRequestParams,
OpenPolicyInitialPageParams,
OpenPolicyMoreFeaturesPageParams,
OpenPolicyProfilePageParams,
OpenPolicyTaxesPageParams,
OpenPolicyWorkflowsPageParams,
OpenWorkspaceInvitePageParams,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2973,6 +2987,8 @@ export {
enablePolicyWorkflows,
enableDistanceRequestTax,
openPolicyMoreFeaturesPage,
openPolicyProfilePage,
openPolicyInitialPage,
generateCustomUnitID,
clearQBOErrorField,
clearXeroErrorField,
Expand Down
16 changes: 14 additions & 2 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
27 changes: 23 additions & 4 deletions src/pages/workspace/WorkspaceProfilePage.tsx
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';
Expand All @@ -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';
Expand All @@ -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<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({policy, currencyList = {}, route}: WorkspaceProfilePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
Expand Down Expand Up @@ -82,6 +87,20 @@ 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(() => {
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(
() => (
<Avatar
Expand Down Expand Up @@ -282,7 +301,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),
);
1 change: 1 addition & 0 deletions src/pages/workspace/withPolicy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2526e31

Please sign in to comment.