From d5cdc350020e984463a1d4d05cd1db1fca21457a Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 12 Mar 2024 13:49:42 +0100 Subject: [PATCH 1/6] implement openPolicyMoreFeaturesPage --- .../parameters/OpenPolicyMoreFeaturesPageParams.ts | 5 +++++ src/libs/API/parameters/index.ts | 1 + src/libs/API/types.ts | 2 ++ src/libs/actions/Policy.ts | 12 ++++++++++++ 4 files changed, 20 insertions(+) create mode 100644 src/libs/API/parameters/OpenPolicyMoreFeaturesPageParams.ts diff --git a/src/libs/API/parameters/OpenPolicyMoreFeaturesPageParams.ts b/src/libs/API/parameters/OpenPolicyMoreFeaturesPageParams.ts new file mode 100644 index 000000000000..30e8f1b36ca0 --- /dev/null +++ b/src/libs/API/parameters/OpenPolicyMoreFeaturesPageParams.ts @@ -0,0 +1,5 @@ +type OpenPolicyMoreFeaturesPageParams = { + policyID: string; +}; + +export default OpenPolicyMoreFeaturesPageParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 7e0e9b6e4a96..4df74b6c428d 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -170,3 +170,4 @@ export type {default as AcceptJoinRequestParams} from './AcceptJoinRequest'; export type {default as DeclineJoinRequestParams} from './DeclineJoinRequest'; export type {default as JoinPolicyInviteLinkParams} from './JoinPolicyInviteLink'; export type {default as OpenPolicyDistanceRatesPageParams} from './OpenPolicyDistanceRatesPageParams'; +export type {default as OpenPolicyMoreFeaturesPageParams} from './OpenPolicyMoreFeaturesPageParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index bf215e09e37d..9e3f2b14625d 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -371,6 +371,7 @@ const READ_COMMANDS = { OPEN_WORKSPACE_INVITE_PAGE: 'OpenWorkspaceInvitePage', OPEN_DRAFT_WORKSPACE_REQUEST: 'OpenDraftWorkspaceRequest', OPEN_POLICY_DISTANCE_RATES_PAGE: 'OpenPolicyDistanceRatesPage', + OPEN_POLICY_MORE_FEATURES_PAGE: 'OpenPolicyMoreFeaturesPage', } as const; type ReadCommand = ValueOf; @@ -408,6 +409,7 @@ type ReadCommandParameters = { [READ_COMMANDS.OPEN_WORKSPACE_INVITE_PAGE]: Parameters.OpenWorkspaceInvitePageParams; [READ_COMMANDS.OPEN_DRAFT_WORKSPACE_REQUEST]: Parameters.OpenDraftWorkspaceRequestParams; [READ_COMMANDS.OPEN_POLICY_DISTANCE_RATES_PAGE]: Parameters.OpenPolicyDistanceRatesPageParams; + [READ_COMMANDS.OPEN_POLICY_MORE_FEATURES_PAGE]: Parameters.OpenPolicyMoreFeaturesPageParams; }; const SIDE_EFFECT_REQUEST_COMMANDS = { diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 85572ebe04a7..83dfb98ef340 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -25,6 +25,7 @@ import type { OpenDraftWorkspaceRequestParams, OpenPolicyCategoriesPageParams, OpenPolicyDistanceRatesPageParams, + OpenPolicyMoreFeaturesPageParams, OpenPolicyTagsPageParams, OpenWorkspaceInvitePageParams, OpenWorkspaceMembersPageParams, @@ -3237,6 +3238,16 @@ function openPolicyDistanceRatesPage(policyID?: string) { API.read(READ_COMMANDS.OPEN_POLICY_DISTANCE_RATES_PAGE, params); } +function openPolicyMoreFeaturesPage(policyID?: string) { + if (!policyID) { + return; + } + + const params: OpenPolicyMoreFeaturesPageParams = {policyID}; + + API.read(READ_COMMANDS.OPEN_POLICY_MORE_FEATURES_PAGE, params); +} + export { removeMembers, updateWorkspaceMembersRole, @@ -3302,4 +3313,5 @@ export { enablePolicyTaxes, enablePolicyWorkflows, openPolicyDistanceRatesPage, + openPolicyMoreFeaturesPage, }; From d70955c3cc6fa286f46ac4d947352d4c99270263 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 12 Mar 2024 13:49:49 +0100 Subject: [PATCH 2/6] integrate openPolicyMoreFeaturesPage --- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 45a950e0fafb..d335c3f9c57b 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -1,5 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useCallback} from 'react'; +import React, {useCallback, useEffect} from 'react'; import {View} from 'react-native'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Illustrations from '@components/Icon/Illustrations'; @@ -141,6 +141,10 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro [isSmallScreenWidth, styles, renderItem, translate], ); + useEffect(() => { + Policy.openPolicyMoreFeaturesPage(route.params.policyID); + }, [route.params.policyID]); + return ( From 82cb80177f75e50a8518820790fd0c8af973b137 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 12 Mar 2024 14:22:27 +0100 Subject: [PATCH 3/6] policyID is not optional --- src/libs/actions/Policy.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 83dfb98ef340..ee3a9cf697f6 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -3238,11 +3238,7 @@ function openPolicyDistanceRatesPage(policyID?: string) { API.read(READ_COMMANDS.OPEN_POLICY_DISTANCE_RATES_PAGE, params); } -function openPolicyMoreFeaturesPage(policyID?: string) { - if (!policyID) { - return; - } - +function openPolicyMoreFeaturesPage(policyID: string) { const params: OpenPolicyMoreFeaturesPageParams = {policyID}; API.read(READ_COMMANDS.OPEN_POLICY_MORE_FEATURES_PAGE, params); From 4f4caa040701b1a243ef390e086d577b13f050f9 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 12 Mar 2024 14:23:41 +0100 Subject: [PATCH 4/6] rename areDistancesEnabled --- src/libs/actions/Policy.ts | 14 +++++++------- src/pages/workspace/WorkspaceInitialPage.tsx | 2 +- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 4 ++-- src/types/onyx/Policy.ts | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index ee3a9cf697f6..8d1fe3f65bb0 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1659,7 +1659,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName customUnits, areCategoriesEnabled: true, areTagsEnabled: false, - areDistanceRatesEnabled: false, + areDistancesEnabled: false, areWorkflowsEnabled: false, areReportFieldsEnabled: false, areConnectionsEnabled: false, @@ -2093,7 +2093,7 @@ function createWorkspaceFromIOUPayment(iouReport: Report | EmptyObject): string customUnits, areCategoriesEnabled: true, areTagsEnabled: false, - areDistanceRatesEnabled: false, + areDistancesEnabled: false, areWorkflowsEnabled: false, areReportFieldsEnabled: false, areConnectionsEnabled: false, @@ -2882,9 +2882,9 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - areDistanceRatesEnabled: enabled, + areDistancesEnabled: enabled, pendingFields: { - areDistanceRatesEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + areDistancesEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, }, }, @@ -2895,7 +2895,7 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { pendingFields: { - areDistanceRatesEnabled: null, + areDistancesEnabled: null, }, }, }, @@ -2905,9 +2905,9 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - areDistanceRatesEnabled: !enabled, + areDistancesEnabled: !enabled, pendingFields: { - areDistanceRatesEnabled: null, + areDistancesEnabled: null, }, }, }, diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 240a148110f7..6bf00b0a92ce 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -145,7 +145,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r const protectedCollectPolicyMenuItems: WorkspaceMenuItem[] = []; - if (policy?.areDistanceRatesEnabled) { + if (policy?.areDistancesEnabled) { protectedCollectPolicyMenuItems.push({ translationKey: 'workspace.common.distanceRates', icon: Expensicons.Car, diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index d335c3f9c57b..717b1799f1be 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -48,8 +48,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro icon: Illustrations.Car, titleTranslationKey: 'workspace.moreFeatures.distanceRates.title', subtitleTranslationKey: 'workspace.moreFeatures.distanceRates.subtitle', - isActive: policy?.areDistanceRatesEnabled ?? false, - pendingAction: policy?.pendingFields?.areDistanceRatesEnabled, + isActive: policy?.areDistancesEnabled ?? false, + pendingAction: policy?.pendingFields?.areDistancesEnabled, action: (isEnabled: boolean) => { Policy.enablePolicyDistanceRates(policy?.id ?? '', isEnabled); }, diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index cf959194be5f..5c17b3990ca0 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -337,7 +337,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< areTagsEnabled?: boolean; /** Whether the Distance Rates feature is enabled */ - areDistanceRatesEnabled?: boolean; + areDistancesEnabled?: boolean; /** Whether the workflows feature is enabled */ areWorkflowsEnabled?: boolean; From 2fa43551897b8b3dd1ab51867de47379ec89dd6d Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 12 Mar 2024 15:44:19 +0100 Subject: [PATCH 5/6] Revert "rename areDistancesEnabled" This reverts commit 4f4caa040701b1a243ef390e086d577b13f050f9. --- src/libs/actions/Policy.ts | 14 +++++++------- src/pages/workspace/WorkspaceInitialPage.tsx | 2 +- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 4 ++-- src/types/onyx/Policy.ts | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 8d1fe3f65bb0..ee3a9cf697f6 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1659,7 +1659,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName customUnits, areCategoriesEnabled: true, areTagsEnabled: false, - areDistancesEnabled: false, + areDistanceRatesEnabled: false, areWorkflowsEnabled: false, areReportFieldsEnabled: false, areConnectionsEnabled: false, @@ -2093,7 +2093,7 @@ function createWorkspaceFromIOUPayment(iouReport: Report | EmptyObject): string customUnits, areCategoriesEnabled: true, areTagsEnabled: false, - areDistancesEnabled: false, + areDistanceRatesEnabled: false, areWorkflowsEnabled: false, areReportFieldsEnabled: false, areConnectionsEnabled: false, @@ -2882,9 +2882,9 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - areDistancesEnabled: enabled, + areDistanceRatesEnabled: enabled, pendingFields: { - areDistancesEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + areDistanceRatesEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, }, }, @@ -2895,7 +2895,7 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) { key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { pendingFields: { - areDistancesEnabled: null, + areDistanceRatesEnabled: null, }, }, }, @@ -2905,9 +2905,9 @@ function enablePolicyDistanceRates(policyID: string, enabled: boolean) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - areDistancesEnabled: !enabled, + areDistanceRatesEnabled: !enabled, pendingFields: { - areDistancesEnabled: null, + areDistanceRatesEnabled: null, }, }, }, diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 6bf00b0a92ce..240a148110f7 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -145,7 +145,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r const protectedCollectPolicyMenuItems: WorkspaceMenuItem[] = []; - if (policy?.areDistancesEnabled) { + if (policy?.areDistanceRatesEnabled) { protectedCollectPolicyMenuItems.push({ translationKey: 'workspace.common.distanceRates', icon: Expensicons.Car, diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 717b1799f1be..d335c3f9c57b 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -48,8 +48,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro icon: Illustrations.Car, titleTranslationKey: 'workspace.moreFeatures.distanceRates.title', subtitleTranslationKey: 'workspace.moreFeatures.distanceRates.subtitle', - isActive: policy?.areDistancesEnabled ?? false, - pendingAction: policy?.pendingFields?.areDistancesEnabled, + isActive: policy?.areDistanceRatesEnabled ?? false, + pendingAction: policy?.pendingFields?.areDistanceRatesEnabled, action: (isEnabled: boolean) => { Policy.enablePolicyDistanceRates(policy?.id ?? '', isEnabled); }, diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 5c17b3990ca0..cf959194be5f 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -337,7 +337,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< areTagsEnabled?: boolean; /** Whether the Distance Rates feature is enabled */ - areDistancesEnabled?: boolean; + areDistanceRatesEnabled?: boolean; /** Whether the workflows feature is enabled */ areWorkflowsEnabled?: boolean; From 9d5fed69719033ba8ac932c66b0c68ae50609944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Wed, 13 Mar 2024 12:15:39 +0000 Subject: [PATCH 6/6] Address review comment --- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 91f172eaac63..457c96ac2fd7 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -7,6 +7,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import Section from '@components/Section'; import useLocalize from '@hooks/useLocalize'; +import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import type {WorkspacesCentralPaneNavigatorParamList} from '@libs/Navigation/types'; @@ -141,9 +142,16 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro [isSmallScreenWidth, styles, renderItem, translate], ); - useEffect(() => { + function fetchFeatures() { Policy.openPolicyMoreFeaturesPage(route.params.policyID); - }, [route.params.policyID]); + } + + useNetwork({onReconnect: fetchFeatures}); + + useEffect(() => { + fetchFeatures(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); return (