From f985b84069a548c113b1e2ad68b968737f055fee Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Tue, 20 Aug 2024 16:05:42 +0200 Subject: [PATCH 1/8] Fix navigation --- src/libs/Navigation/Navigation.ts | 5 +++-- src/libs/Navigation/linkTo/index.ts | 4 ++-- src/libs/Navigation/types.ts | 7 ++++++- src/libs/Permissions.ts | 2 +- .../workflows/approvals/ApprovalWorkflowEditor.tsx | 9 ++++++--- .../WorkspaceWorkflowsApprovalsApproverPage.tsx | 3 +-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 4bd86503fd2b..b8a3f5987cac 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -2,6 +2,7 @@ import {findFocusedRoute} from '@react-navigation/core'; import type {EventArg, NavigationContainerEventMap} from '@react-navigation/native'; import {CommonActions, getPathFromState, StackActions} from '@react-navigation/native'; import type {OnyxEntry} from 'react-native-onyx'; +import type {ValueOf} from 'type-fest'; import Log from '@libs/Log'; import {isCentralPaneName, removePolicyIDParamFromState} from '@libs/NavigationUtils'; import * as ReportConnection from '@libs/ReportConnection'; @@ -26,7 +27,7 @@ import linkTo from './linkTo'; import navigationRef from './navigationRef'; import setNavigationActionToMicrotaskQueue from './setNavigationActionToMicrotaskQueue'; import switchPolicyID from './switchPolicyID'; -import type {NavigationStateRoute, RootStackParamList, State, StateOrRoute, SwitchPolicyIDParams} from './types'; +import type {NavigationActionType, NavigationStateRoute, NavigationType, RootStackParamList, State, StateOrRoute, SwitchPolicyIDParams} from './types'; let resolveNavigationIsReadyPromise: () => void; const navigationIsReadyPromise = new Promise((resolve) => { @@ -174,7 +175,7 @@ function isActiveRoute(routePath: Route): boolean { * Main navigation method for redirecting to a route. * @param [type] - Type of action to perform. Currently UP is supported. */ -function navigate(route: Route = ROUTES.HOME, type?: string) { +function navigate(route: Route = ROUTES.HOME, type?: NavigationActionType | NavigationType) { if (!canNavigate('navigate', {route})) { // Store intended route if the navigator is not yet available, // we will try again after the NavigationContainer is ready diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/linkTo/index.ts index 45178ef1adaf..058d2491a65e 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/linkTo/index.ts @@ -23,7 +23,7 @@ import getAdaptedStateFromPath from '@navigation/linkingConfig/getAdaptedStateFr import getMatchingBottomTabRouteForState from '@navigation/linkingConfig/getMatchingBottomTabRouteForState'; import getMatchingCentralPaneRouteForState from '@navigation/linkingConfig/getMatchingCentralPaneRouteForState'; import replacePathInNestedState from '@navigation/linkingConfig/replacePathInNestedState'; -import type {NavigationRoot, RootStackParamList, StackNavigationAction, State} from '@navigation/types'; +import type {NavigationActionType, NavigationRoot, NavigationType, RootStackParamList, StackNavigationAction, State} from '@navigation/types'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import type {Route} from '@src/ROUTES'; @@ -32,7 +32,7 @@ import getActionForBottomTabNavigator from './getActionForBottomTabNavigator'; import getMinimalAction from './getMinimalAction'; import type {ActionPayloadParams} from './types'; -export default function linkTo(navigation: NavigationContainerRef | null, path: Route, type?: string, isActiveRoute?: boolean) { +export default function linkTo(navigation: NavigationContainerRef | null, path: Route, type?: NavigationActionType | NavigationType, isActiveRoute?: boolean) { if (!navigation) { throw new Error("Couldn't find a navigation object. Is your component inside a screen in a navigator?"); } diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index b689f36d8a35..e6d946571b0f 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -29,8 +29,11 @@ type GoBackAction = Extract; type ResetAction = Extract; type SetParamsAction = Extract; +type NavigationActionType = ValueOf; +type NavigationType = ValueOf; + type ActionNavigate = { - type: ValueOf; + type: NavigationActionType; payload: { name?: string; key?: string; @@ -1331,6 +1334,8 @@ type SwitchPolicyIDParams = { }; export type { + NavigationActionType, + NavigationType, AddPersonalBankAccountNavigatorParamList, AuthScreensParamList, CentralPaneScreensParamList, diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 15c15e113c8c..5d4cce7b7807 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -4,7 +4,7 @@ import type {IOUType} from '@src/CONST'; import type Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return !!betas?.includes(CONST.BETAS.ALL); + return !!betas?.includes(CONST.BETAS.ALL) || true; } function canUseDefaultRooms(betas: OnyxEntry): boolean { diff --git a/src/pages/workspace/workflows/approvals/ApprovalWorkflowEditor.tsx b/src/pages/workspace/workflows/approvals/ApprovalWorkflowEditor.tsx index 9864241a8e84..086c997dddc9 100644 --- a/src/pages/workspace/workflows/approvals/ApprovalWorkflowEditor.tsx +++ b/src/pages/workspace/workflows/approvals/ApprovalWorkflowEditor.tsx @@ -84,13 +84,13 @@ function ApprovalWorkflowEditor({approvalWorkflow, removeApprovalWorkflow, polic const editMembers = useCallback(() => { const backTo = approvalWorkflow.action === CONST.APPROVAL_WORKFLOW.ACTION.CREATE ? ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID) : undefined; - Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(policyID, backTo)); + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(policyID, backTo), CONST.NAVIGATION.ACTION_TYPE.PUSH); }, [approvalWorkflow.action, policyID]); const editApprover = useCallback( (approverIndex: number) => { const backTo = approvalWorkflow.action === CONST.APPROVAL_WORKFLOW.ACTION.CREATE ? ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID) : undefined; - Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approverIndex, backTo)); + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approverIndex, backTo), CONST.NAVIGATION.ACTION_TYPE.PUSH); }, [approvalWorkflow.action, policyID], ); @@ -101,7 +101,10 @@ function ApprovalWorkflowEditor({approvalWorkflow, removeApprovalWorkflow, polic Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.approvals.alias, Navigation.getActiveRoute())); return; } - Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approvalWorkflow.approvers.length, ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID))); + Navigation.navigate( + ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approvalWorkflow.approvers.length, ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID)), + CONST.NAVIGATION.ACTION_TYPE.PUSH, + ); }, [approvalWorkflow.approvers.length, policy, policyID]); return ( diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx index 545c09f75313..1b26c82e3044 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage.tsx @@ -184,8 +184,7 @@ function WorkspaceWorkflowsApprovalsApproverPageBeta({policy, personalDetails, i } if (approvalWorkflow?.action === CONST.APPROVAL_WORKFLOW.ACTION.CREATE) { - Navigation.goBack(); - Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(route.params.policyID), CONST.NAVIGATION.TYPE.UP); + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(route.params.policyID)); } else { const firstApprover = approvalWorkflow?.approvers?.[0]?.email ?? ''; Navigation.goBack(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EDIT.getRoute(route.params.policyID, firstApprover)); From 02177b5348c13fc9b35bec7a743518477497ba3e Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Thu, 22 Aug 2024 10:42:24 +0200 Subject: [PATCH 2/8] Use dimissModal function to go back to workflows screen --- .../approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx | 3 +-- .../approvals/WorkspaceWorkflowsApprovalsEditPage.tsx | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx index b5750e9e768f..dc0f067f60df 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsCreatePage.tsx @@ -19,7 +19,6 @@ import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPol import * as Workflow from '@userActions/Workflow'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import ApprovalWorkflowEditor from './ApprovalWorkflowEditor'; @@ -45,7 +44,7 @@ function WorkspaceWorkflowsApprovalsCreatePage({policy, isLoadingReportData = tr } Workflow.createApprovalWorkflow(route.params.policyID, approvalWorkflow); - Navigation.goBack(ROUTES.WORKSPACE_WORKFLOWS.getRoute(route.params.policyID)); + Navigation.dismissModal(); }, [approvalWorkflow, route.params.policyID]); return ( diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx index 41a8d5c6a4ee..3b782794923c 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx @@ -51,7 +51,7 @@ function WorkspaceWorkflowsApprovalsEditPage({policy, isLoadingReportData = true const membersToRemove = initialApprovalWorkflow.members.filter((initialMember) => !approvalWorkflow.members.some((member) => member.email === initialMember.email)); Workflow.updateApprovalWorkflow(route.params.policyID, approvalWorkflow, membersToRemove); - Navigation.goBack(); + Navigation.dismissModal(); }, [approvalWorkflow, initialApprovalWorkflow, route.params.policyID]); const removeApprovalWorkflow = useCallback(() => { @@ -61,7 +61,7 @@ function WorkspaceWorkflowsApprovalsEditPage({policy, isLoadingReportData = true // Remove the approval workflow using the initial data as it could be already edited Workflow.removeApprovalWorkflow(route.params.policyID, initialApprovalWorkflow); - Navigation.goBack(); + Navigation.dismissModal(); }, [initialApprovalWorkflow, route.params.policyID]); // Set the initial approval workflow when the page is loaded From 9879c449339708eed84cf773d8c60881648c5670 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Thu, 22 Aug 2024 10:43:27 +0200 Subject: [PATCH 3/8] Remove true from caUseAllBetas --- src/libs/Permissions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 5d4cce7b7807..15c15e113c8c 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -4,7 +4,7 @@ import type {IOUType} from '@src/CONST'; import type Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return !!betas?.includes(CONST.BETAS.ALL) || true; + return !!betas?.includes(CONST.BETAS.ALL); } function canUseDefaultRooms(betas: OnyxEntry): boolean { From 57cb537309d38c0a7a111ad7f61407f8513dae21 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Thu, 22 Aug 2024 12:03:02 +0200 Subject: [PATCH 4/8] Fix typecheck and lint --- src/libs/Navigation/Navigation.ts | 1 - src/libs/actions/Report.ts | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index b8a3f5987cac..06ae654386c9 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -2,7 +2,6 @@ import {findFocusedRoute} from '@react-navigation/core'; import type {EventArg, NavigationContainerEventMap} from '@react-navigation/native'; import {CommonActions, getPathFromState, StackActions} from '@react-navigation/native'; import type {OnyxEntry} from 'react-native-onyx'; -import type {ValueOf} from 'type-fest'; import Log from '@libs/Log'; import {isCentralPaneName, removePolicyIDParamFromState} from '@libs/NavigationUtils'; import * as ReportConnection from '@libs/ReportConnection'; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 7eb7e01d6edd..7692bf5e33d3 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -65,6 +65,7 @@ import * as Localize from '@libs/Localize'; import Log from '@libs/Log'; import {registerPaginationConfig} from '@libs/Middleware/Pagination'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; +import type {NavigationActionType, NavigationType} from '@libs/Navigation/types'; import {isOnboardingFlowName} from '@libs/NavigationUtils'; import type {NetworkStatus} from '@libs/NetworkConnection'; import LocalNotification from '@libs/Notification/LocalNotification'; @@ -985,7 +986,7 @@ function openReport( function navigateToAndOpenReport( userLogins: string[], shouldDismissModal = true, - actionType?: string, + actionType?: NavigationActionType | NavigationType, reportName?: string, avatarUri?: string, avatarFile?: File | CustomRNImageManipulatorResult | undefined, @@ -2147,7 +2148,7 @@ function updateWriteCapabilityAndNavigate(report: Report, newValue: WriteCapabil /** * Navigates to the 1:1 report with Concierge */ -function navigateToConciergeChat(shouldDismissModal = false, checkIfCurrentPageActive = () => true, actionType?: string) { +function navigateToConciergeChat(shouldDismissModal = false, checkIfCurrentPageActive = () => true, actionType?: NavigationActionType | NavigationType) { // If conciergeChatReportID contains a concierge report ID, we navigate to the concierge chat using the stored report ID. // Otherwise, we would find the concierge chat and navigate to it. if (!conciergeChatReportID) { From a08536cbab85926026897e5b8d9a2c881fc4571c Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Thu, 22 Aug 2024 12:07:16 +0200 Subject: [PATCH 5/8] Revert navigation type changes --- src/libs/Navigation/Navigation.ts | 4 ++-- src/libs/Navigation/linkTo/index.ts | 4 ++-- src/libs/Navigation/types.ts | 7 +------ src/libs/actions/Report.ts | 5 ++--- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 06ae654386c9..4bd86503fd2b 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -26,7 +26,7 @@ import linkTo from './linkTo'; import navigationRef from './navigationRef'; import setNavigationActionToMicrotaskQueue from './setNavigationActionToMicrotaskQueue'; import switchPolicyID from './switchPolicyID'; -import type {NavigationActionType, NavigationStateRoute, NavigationType, RootStackParamList, State, StateOrRoute, SwitchPolicyIDParams} from './types'; +import type {NavigationStateRoute, RootStackParamList, State, StateOrRoute, SwitchPolicyIDParams} from './types'; let resolveNavigationIsReadyPromise: () => void; const navigationIsReadyPromise = new Promise((resolve) => { @@ -174,7 +174,7 @@ function isActiveRoute(routePath: Route): boolean { * Main navigation method for redirecting to a route. * @param [type] - Type of action to perform. Currently UP is supported. */ -function navigate(route: Route = ROUTES.HOME, type?: NavigationActionType | NavigationType) { +function navigate(route: Route = ROUTES.HOME, type?: string) { if (!canNavigate('navigate', {route})) { // Store intended route if the navigator is not yet available, // we will try again after the NavigationContainer is ready diff --git a/src/libs/Navigation/linkTo/index.ts b/src/libs/Navigation/linkTo/index.ts index 058d2491a65e..45178ef1adaf 100644 --- a/src/libs/Navigation/linkTo/index.ts +++ b/src/libs/Navigation/linkTo/index.ts @@ -23,7 +23,7 @@ import getAdaptedStateFromPath from '@navigation/linkingConfig/getAdaptedStateFr import getMatchingBottomTabRouteForState from '@navigation/linkingConfig/getMatchingBottomTabRouteForState'; import getMatchingCentralPaneRouteForState from '@navigation/linkingConfig/getMatchingCentralPaneRouteForState'; import replacePathInNestedState from '@navigation/linkingConfig/replacePathInNestedState'; -import type {NavigationActionType, NavigationRoot, NavigationType, RootStackParamList, StackNavigationAction, State} from '@navigation/types'; +import type {NavigationRoot, RootStackParamList, StackNavigationAction, State} from '@navigation/types'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import type {Route} from '@src/ROUTES'; @@ -32,7 +32,7 @@ import getActionForBottomTabNavigator from './getActionForBottomTabNavigator'; import getMinimalAction from './getMinimalAction'; import type {ActionPayloadParams} from './types'; -export default function linkTo(navigation: NavigationContainerRef | null, path: Route, type?: NavigationActionType | NavigationType, isActiveRoute?: boolean) { +export default function linkTo(navigation: NavigationContainerRef | null, path: Route, type?: string, isActiveRoute?: boolean) { if (!navigation) { throw new Error("Couldn't find a navigation object. Is your component inside a screen in a navigator?"); } diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index e6d946571b0f..f2efbcb5fae9 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -29,11 +29,8 @@ type GoBackAction = Extract; type ResetAction = Extract; type SetParamsAction = Extract; -type NavigationActionType = ValueOf; -type NavigationType = ValueOf; - type ActionNavigate = { - type: NavigationActionType; + type: string; payload: { name?: string; key?: string; @@ -1334,8 +1331,6 @@ type SwitchPolicyIDParams = { }; export type { - NavigationActionType, - NavigationType, AddPersonalBankAccountNavigatorParamList, AuthScreensParamList, CentralPaneScreensParamList, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 7692bf5e33d3..7eb7e01d6edd 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -65,7 +65,6 @@ import * as Localize from '@libs/Localize'; import Log from '@libs/Log'; import {registerPaginationConfig} from '@libs/Middleware/Pagination'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; -import type {NavigationActionType, NavigationType} from '@libs/Navigation/types'; import {isOnboardingFlowName} from '@libs/NavigationUtils'; import type {NetworkStatus} from '@libs/NetworkConnection'; import LocalNotification from '@libs/Notification/LocalNotification'; @@ -986,7 +985,7 @@ function openReport( function navigateToAndOpenReport( userLogins: string[], shouldDismissModal = true, - actionType?: NavigationActionType | NavigationType, + actionType?: string, reportName?: string, avatarUri?: string, avatarFile?: File | CustomRNImageManipulatorResult | undefined, @@ -2148,7 +2147,7 @@ function updateWriteCapabilityAndNavigate(report: Report, newValue: WriteCapabil /** * Navigates to the 1:1 report with Concierge */ -function navigateToConciergeChat(shouldDismissModal = false, checkIfCurrentPageActive = () => true, actionType?: NavigationActionType | NavigationType) { +function navigateToConciergeChat(shouldDismissModal = false, checkIfCurrentPageActive = () => true, actionType?: string) { // If conciergeChatReportID contains a concierge report ID, we navigate to the concierge chat using the stored report ID. // Otherwise, we would find the concierge chat and navigate to it. if (!conciergeChatReportID) { From 37aa36f8caf244df10172695e6ad950715b19483 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Thu, 22 Aug 2024 12:08:18 +0200 Subject: [PATCH 6/8] Revert navigation type changes v2 --- src/libs/Navigation/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index f2efbcb5fae9..b689f36d8a35 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -30,7 +30,7 @@ type ResetAction = Extract; type SetParamsAction = Extract; type ActionNavigate = { - type: string; + type: ValueOf; payload: { name?: string; key?: string; From e1c591c43ec66ca9074853685af5c3a8460ede4d Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 26 Aug 2024 16:36:18 +0200 Subject: [PATCH 7/8] Fix notfoundview that is displayed for a brief second --- .../WorkspaceWorkflowsApprovalsEditPage.tsx | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx index 3b782794923c..fc23bb89b1d8 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx @@ -1,5 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useCallback, useEffect, useRef, useState} from 'react'; +import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; // eslint-disable-next-line no-restricted-imports import type {ScrollView} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -37,9 +37,6 @@ function WorkspaceWorkflowsApprovalsEditPage({policy, isLoadingReportData = true const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false); const formRef = useRef(null); - // eslint-disable-next-line rulesdir/no-negated-variables - const shouldShowNotFoundView = (isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy) || !approvalWorkflow; - const updateApprovalWorkflow = useCallback(() => { if (!approvalWorkflow || !initialApprovalWorkflow) { return; @@ -64,19 +61,33 @@ function WorkspaceWorkflowsApprovalsEditPage({policy, isLoadingReportData = true Navigation.dismissModal(); }, [initialApprovalWorkflow, route.params.policyID]); - // Set the initial approval workflow when the page is loaded - useEffect(() => { - if (!!initialApprovalWorkflow || !policy || !personalDetails) { - return; + const {currentApprovalWorkflow, defaultWorkflowMembers} = useMemo(() => { + if (!policy || !personalDetails) { + return {}; } const defaultApprover = policy?.approver ?? policy.owner; - const workflows = convertPolicyEmployeesToApprovalWorkflows({ + const allApprovalWorkflows = convertPolicyEmployeesToApprovalWorkflows({ employees: policy.employeeList ?? {}, defaultApprover, personalDetails, }); - const currentApprovalWorkflow = workflows.find((workflow) => workflow.approvers.at(0)?.email === route.params.firstApproverEmail); + + return { + defaultWorkflowMembers: allApprovalWorkflows.at(0)?.members ?? [], + currentApprovalWorkflow: allApprovalWorkflows.find((workflow) => workflow.approvers.at(0)?.email === route.params.firstApproverEmail), + }; + }, [personalDetails, policy, route.params.firstApproverEmail]); + + // eslint-disable-next-line rulesdir/no-negated-variables + const shouldShowNotFoundView = + (isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy) || !currentApprovalWorkflow; + + // Set the initial approval workflow when the page is loaded + useEffect(() => { + if (initialApprovalWorkflow) { + return; + } if (!currentApprovalWorkflow) { return Workflow.clearApprovalWorkflow(); @@ -84,13 +95,13 @@ function WorkspaceWorkflowsApprovalsEditPage({policy, isLoadingReportData = true Workflow.setApprovalWorkflow({ ...currentApprovalWorkflow, - availableMembers: [...currentApprovalWorkflow.members, ...(workflows.at(0)?.members ?? [])], + availableMembers: [...currentApprovalWorkflow.members, ...defaultWorkflowMembers], action: CONST.APPROVAL_WORKFLOW.ACTION.EDIT, isLoading: false, errors: null, }); setInitialApprovalWorkflow(currentApprovalWorkflow); - }, [initialApprovalWorkflow, personalDetails, policy, route.params.firstApproverEmail, route.params.policyID]); + }, [currentApprovalWorkflow, defaultWorkflowMembers, initialApprovalWorkflow]); return ( Date: Mon, 26 Aug 2024 16:37:27 +0200 Subject: [PATCH 8/8] Hide delete modal on removal --- .../workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx index fc23bb89b1d8..3b8b1c3b02b7 100644 --- a/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx +++ b/src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsEditPage.tsx @@ -58,6 +58,7 @@ function WorkspaceWorkflowsApprovalsEditPage({policy, isLoadingReportData = true // Remove the approval workflow using the initial data as it could be already edited Workflow.removeApprovalWorkflow(route.params.policyID, initialApprovalWorkflow); + setIsDeleteModalVisible(false); Navigation.dismissModal(); }, [initialApprovalWorkflow, route.params.policyID]);