From 80e24739968a5dee138dbab180e80ea6ade36198 Mon Sep 17 00:00:00 2001 From: burczu Date: Fri, 8 Mar 2024 10:48:44 +0100 Subject: [PATCH 1/6] revert of the goBack functionality --- src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx | 4 +--- .../members/WorkspaceMemberDetailsRoleSelectionPage.tsx | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index 4199bb5f432d..c747d04edfa2 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -52,7 +52,6 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou const accountID = Number(route.params.accountID); const policyID = route.params.policyID; - const backTo = route.params.backTo ?? ('' as Route); const member = policyMembers?.[accountID]; const details = personalDetails?.[accountID] ?? ({} as PersonalDetails); @@ -87,7 +86,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou }, [accountID, backTo, policyID]); const navigateToProfile = useCallback(() => { - Navigation.navigate(ROUTES.PROFILE.getRoute(accountID, Navigation.getActiveRoute())); + Navigation.navigate(ROUTES.PROFILE.getRoute(accountID)); }, [accountID]); const openRoleSelectionModal = useCallback(() => { @@ -107,7 +106,6 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou Navigation.goBack(backTo)} /> diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx index 7958ae93b922..840b49b8e5cf 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx @@ -15,7 +15,6 @@ import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPol import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading'; import * as Policy from '@userActions/Policy'; import CONST from '@src/CONST'; -import type {Route} from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; type WorkspaceMemberDetailsPageProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps; @@ -33,7 +32,6 @@ function WorkspaceMemberDetailsRoleSelectionPage({policyMembers, route}: Workspa const accountID = Number(route.params.accountID) ?? 0; const policyID = route.params.policyID; - const backTo = route.params.backTo ?? ('' as Route); const member = policyMembers?.[accountID]; const items: ListItemType[] = [ @@ -57,7 +55,7 @@ function WorkspaceMemberDetailsRoleSelectionPage({policyMembers, route}: Workspa } Policy.updateWorkspaceMembersRole(route.params.policyID, [accountID], value); - Navigation.goBack(backTo); + Navigation.goBack(); }; return ( @@ -66,7 +64,6 @@ function WorkspaceMemberDetailsRoleSelectionPage({policyMembers, route}: Workspa Navigation.goBack(backTo)} /> Date: Fri, 15 Mar 2024 14:01:23 +0100 Subject: [PATCH 2/6] add members optimistic and success actions changed --- src/libs/actions/Policy.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 3c34e823ac9a..4de693525915 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1291,7 +1291,10 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount const optimisticMembersState: OnyxCollection = {}; const failureMembersState: OnyxCollection = {}; accountIDs.forEach((accountID) => { - optimisticMembersState[accountID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}; + optimisticMembersState[accountID] = { + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + role: CONST.POLICY.ROLE.USER, + }; failureMembersState[accountID] = { errors: ErrorUtils.getMicroSecondOnyxError('workspace.people.error.genericAdd'), }; @@ -1318,12 +1321,11 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount // Convert to object with each key clearing pendingAction, when it is an existing account. // Remove the object, when it is a newly created account. value: accountIDs.reduce((accountIDsWithClearedPendingAction, accountID) => { - let value = null; - const accountAlreadyExists = !isEmptyObject(allPersonalDetails?.[accountID]); - - if (accountAlreadyExists) { - value = {pendingAction: null, errors: null}; - } + const value = { + ...allPolicyMembers?.[accountID], + pendingAction: null, + errors: null + }; return {...accountIDsWithClearedPendingAction, [accountID]: value}; }, {}), From 7bdd6534a9cea282b8db0b187907bc915dd266df Mon Sep 17 00:00:00 2001 From: burczu Date: Wed, 3 Apr 2024 13:27:16 +0200 Subject: [PATCH 3/6] correct fallback added --- src/ROUTES.ts | 4 ++-- src/libs/Navigation/types.ts | 2 -- src/pages/workspace/WorkspaceMembersPage.tsx | 2 +- .../workspace/members/WorkspaceMemberDetailsPage.tsx | 8 ++++---- .../members/WorkspaceMemberDetailsRoleSelectionPage.tsx | 4 +++- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 8130c271a2db..cf757230cf3c 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -620,11 +620,11 @@ const ROUTES = { }, WORKSPACE_MEMBER_DETAILS: { route: 'settings/workspaces/:policyID/members/:accountID', - getRoute: (policyID: string, accountID: number, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/members/${accountID}`, backTo), + getRoute: (policyID: string, accountID: number) => `settings/workspaces/${policyID}/members/${accountID}` as const, }, WORKSPACE_MEMBER_ROLE_SELECTION: { route: 'settings/workspaces/:policyID/members/:accountID/role-selection', - getRoute: (policyID: string, accountID: number, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/members/${accountID}/role-selection`, backTo), + getRoute: (policyID: string, accountID: number) => `settings/workspaces/${policyID}/members/${accountID}/role-selection` as const, }, WORKSPACE_OWNER_CHANGE_SUCCESS: { route: 'settings/workspaces/:policyID/change-owner/:accountID/success', diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index b88c44b9aa70..35ebc08b49f3 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -220,12 +220,10 @@ type SettingsNavigatorParamList = { [SCREENS.WORKSPACE.MEMBER_DETAILS]: { policyID: string; accountID: string; - backTo: Routes; }; [SCREENS.WORKSPACE.MEMBER_DETAILS_ROLE_SELECTION]: { policyID: string; accountID: string; - backTo: Routes; }; [SCREENS.WORKSPACE.OWNER_CHANGE_SUCCESS]: { policyID: string; diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index 7b77f6b60ede..e68ee6606902 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -285,7 +285,7 @@ function WorkspaceMembersPage({ } Policy.clearWorkspaceOwnerChangeFlow(policyID); - Navigation.navigate(ROUTES.WORKSPACE_MEMBER_DETAILS.getRoute(route.params.policyID, item.accountID, Navigation.getActiveRoute())); + Navigation.navigate(ROUTES.WORKSPACE_MEMBER_DETAILS.getRoute(route.params.policyID, item.accountID)); }, [isPolicyAdmin, policy, policyID, route.params.policyID], ); diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index c747d04edfa2..561fb207477d 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -29,7 +29,6 @@ import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullsc import * as Policy from '@userActions/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {PersonalDetails, PersonalDetailsList} from '@src/types/onyx'; @@ -82,15 +81,15 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou const removeUser = useCallback(() => { Policy.removeMembers([accountID], policyID); setIsRemoveMemberConfirmModalVisible(false); - Navigation.goBack(backTo); - }, [accountID, backTo, policyID]); + Navigation.goBack(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID)); + }, [accountID, policyID]); const navigateToProfile = useCallback(() => { Navigation.navigate(ROUTES.PROFILE.getRoute(accountID)); }, [accountID]); const openRoleSelectionModal = useCallback(() => { - Navigation.navigate(ROUTES.WORKSPACE_MEMBER_ROLE_SELECTION.getRoute(policyID, accountID, Navigation.getActiveRoute())); + Navigation.navigate(ROUTES.WORKSPACE_MEMBER_ROLE_SELECTION.getRoute(policyID, accountID)); }, [accountID, policyID]); const startChangeOwnershipFlow = useCallback(() => { @@ -106,6 +105,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou Navigation.goBack(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID))} /> diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx index 840b49b8e5cf..38caf24c7ecb 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx @@ -16,6 +16,7 @@ import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullsc import * as Policy from '@userActions/Policy'; import CONST from '@src/CONST'; import type SCREENS from '@src/SCREENS'; +import ROUTES from "@src/ROUTES"; type WorkspaceMemberDetailsPageProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps; @@ -55,7 +56,7 @@ function WorkspaceMemberDetailsRoleSelectionPage({policyMembers, route}: Workspa } Policy.updateWorkspaceMembersRole(route.params.policyID, [accountID], value); - Navigation.goBack(); + Navigation.goBack(ROUTES.WORKSPACE_MEMBER_DETAILS.getRoute(policyID, accountID)); }; return ( @@ -64,6 +65,7 @@ function WorkspaceMemberDetailsRoleSelectionPage({policyMembers, route}: Workspa Navigation.goBack(ROUTES.WORKSPACE_MEMBER_DETAILS.getRoute(policyID, accountID))} /> Date: Wed, 3 Apr 2024 13:48:38 +0200 Subject: [PATCH 4/6] backTo for profile page setting reverted --- src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index 561fb207477d..a225974a0861 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -85,7 +85,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou }, [accountID, policyID]); const navigateToProfile = useCallback(() => { - Navigation.navigate(ROUTES.PROFILE.getRoute(accountID)); + Navigation.navigate(ROUTES.PROFILE.getRoute(accountID, Navigation.getActiveRoute())); }, [accountID]); const openRoleSelectionModal = useCallback(() => { From 9a6f3237afb3f8060c004e3369fdfacbab1601e6 Mon Sep 17 00:00:00 2001 From: burczu Date: Thu, 4 Apr 2024 10:15:58 +0200 Subject: [PATCH 5/6] role selection modal introduced --- src/SCREENS.ts | 1 - .../ModalStackNavigators/index.tsx | 1 - .../FULL_SCREEN_TO_RHP_MAPPING.ts | 1 - src/libs/Navigation/linkingConfig/config.ts | 3 - src/libs/Navigation/types.ts | 4 - src/libs/actions/Policy.ts | 2 +- .../members/WorkspaceMemberDetailsPage.tsx | 43 +++++++++- ...rkspaceMemberDetailsRoleSelectionModal.tsx | 68 +++++++++++++++ ...orkspaceMemberDetailsRoleSelectionPage.tsx | 86 ------------------- 9 files changed, 108 insertions(+), 101 deletions(-) create mode 100644 src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionModal.tsx delete mode 100644 src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx diff --git a/src/SCREENS.ts b/src/SCREENS.ts index cf864fd96b3e..baaf2dcf5b45 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -241,7 +241,6 @@ const SCREENS = { CATEGORIES_SETTINGS: 'Categories_Settings', MORE_FEATURES: 'Workspace_More_Features', MEMBER_DETAILS: 'Workspace_Member_Details', - MEMBER_DETAILS_ROLE_SELECTION: 'Workspace_Member_Details_Role_Selection', OWNER_CHANGE_CHECK: 'Workspace_Owner_Change_Check', OWNER_CHANGE_SUCCESS: 'Workspace_Owner_Change_Success', OWNER_CHANGE_ERROR: 'Workspace_Owner_Change_Error', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index 0d1b9b59a089..4db609297e39 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -233,7 +233,6 @@ const SettingsModalStackNavigator = createModalStackNavigator require('../../../../pages/workspace/categories/CategorySettingsPage').default as React.ComponentType, [SCREENS.WORKSPACE.CATEGORIES_SETTINGS]: () => require('../../../../pages/workspace/categories/WorkspaceCategoriesSettingsPage').default as React.ComponentType, [SCREENS.WORKSPACE.MEMBER_DETAILS]: () => require('../../../../pages/workspace/members/WorkspaceMemberDetailsPage').default as React.ComponentType, - [SCREENS.WORKSPACE.MEMBER_DETAILS_ROLE_SELECTION]: () => require('../../../../pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage').default as React.ComponentType, [SCREENS.WORKSPACE.OWNER_CHANGE_CHECK]: () => require('@pages/workspace/members/WorkspaceOwnerChangeWrapperPage').default as React.ComponentType, [SCREENS.WORKSPACE.OWNER_CHANGE_SUCCESS]: () => require('../../../../pages/workspace/members/WorkspaceOwnerChangeSuccessPage').default as React.ComponentType, [SCREENS.WORKSPACE.OWNER_CHANGE_ERROR]: () => require('../../../../pages/workspace/members/WorkspaceOwnerChangeErrorPage').default as React.ComponentType, diff --git a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts index 1247933701a8..984f2ef20bbd 100755 --- a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts +++ b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts @@ -8,7 +8,6 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial> = { SCREENS.WORKSPACE.INVITE, SCREENS.WORKSPACE.INVITE_MESSAGE, SCREENS.WORKSPACE.MEMBER_DETAILS, - SCREENS.WORKSPACE.MEMBER_DETAILS_ROLE_SELECTION, SCREENS.WORKSPACE.OWNER_CHANGE_CHECK, SCREENS.WORKSPACE.OWNER_CHANGE_SUCCESS, SCREENS.WORKSPACE.OWNER_CHANGE_ERROR, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 823b6514c42b..bd04d479261d 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -281,9 +281,6 @@ const config: LinkingOptions['config'] = { [SCREENS.WORKSPACE.MEMBER_DETAILS]: { path: ROUTES.WORKSPACE_MEMBER_DETAILS.route, }, - [SCREENS.WORKSPACE.MEMBER_DETAILS_ROLE_SELECTION]: { - path: ROUTES.WORKSPACE_MEMBER_ROLE_SELECTION.route, - }, [SCREENS.WORKSPACE.OWNER_CHANGE_SUCCESS]: { path: ROUTES.WORKSPACE_OWNER_CHANGE_SUCCESS.route, }, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 35ebc08b49f3..561cdb0b985b 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -221,10 +221,6 @@ type SettingsNavigatorParamList = { policyID: string; accountID: string; }; - [SCREENS.WORKSPACE.MEMBER_DETAILS_ROLE_SELECTION]: { - policyID: string; - accountID: string; - }; [SCREENS.WORKSPACE.OWNER_CHANGE_SUCCESS]: { policyID: string; accountID: number; diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 4de693525915..960bcf11d0f4 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1324,7 +1324,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount const value = { ...allPolicyMembers?.[accountID], pendingAction: null, - errors: null + errors: null, }; return {...accountIDsWithClearedPendingAction, [accountID]: value}; diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index a225974a0861..499a8fc52685 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -1,5 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useCallback, useEffect} from 'react'; +import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; @@ -32,6 +32,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {PersonalDetails, PersonalDetailsList} from '@src/types/onyx'; +import type {ListItemType} from './WorkspaceMemberDetailsRoleSelectionModal'; +import WorkspaceMemberDetailsRoleSelectionModal from './WorkspaceMemberDetailsRoleSelectionModal'; type WorkspacePolicyOnyxProps = { /** Personal details of all users */ @@ -47,7 +49,8 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou const StyleUtils = useStyleUtils(); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); - const [isRemoveMemberConfirmModalVisible, setIsRemoveMemberConfirmModalVisible] = React.useState(false); + const [isRemoveMemberConfirmModalVisible, setIsRemoveMemberConfirmModalVisible] = useState(false); + const [isRoleSelectionModalVisible, setIsRoleSelectionModalVisible] = useState(false); const accountID = Number(route.params.accountID); const policyID = route.params.policyID; @@ -62,6 +65,24 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou const isCurrentUserAdmin = policyMembers?.[currentUserPersonalDetails?.accountID]?.role === CONST.POLICY.ROLE.ADMIN; const isCurrentUserOwner = policy?.owner === currentUserPersonalDetails?.login; + const roleItems: ListItemType[] = useMemo( + () => [ + { + value: CONST.POLICY.ROLE.ADMIN, + text: translate('common.admin'), + isSelected: member?.role === CONST.POLICY.ROLE.ADMIN, + keyForList: CONST.POLICY.ROLE.ADMIN, + }, + { + value: CONST.POLICY.ROLE.USER, + text: translate('common.member'), + isSelected: member?.role === CONST.POLICY.ROLE.USER, + keyForList: CONST.POLICY.ROLE.USER, + }, + ], + [member?.role, translate], + ); + useEffect(() => { if (!policy?.errorFields?.changeOwner && policy?.isChangeOwnerSuccessful) { return; @@ -89,8 +110,16 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou }, [accountID]); const openRoleSelectionModal = useCallback(() => { - Navigation.navigate(ROUTES.WORKSPACE_MEMBER_ROLE_SELECTION.getRoute(policyID, accountID)); - }, [accountID, policyID]); + setIsRoleSelectionModalVisible(true); + }, []); + + const changeRole = useCallback( + ({value}: ListItemType) => { + setIsRoleSelectionModalVisible(false); + Policy.updateWorkspaceMembersRole(policyID, [accountID], value); + }, + [accountID, policyID], + ); const startChangeOwnershipFlow = useCallback(() => { Policy.clearWorkspaceOwnerChangeFlow(policyID); @@ -172,6 +201,12 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou onPress={navigateToProfile} shouldShowRightIcon /> + setIsRoleSelectionModalVisible(false)} + /> diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionModal.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionModal.tsx new file mode 100644 index 000000000000..9613a697013e --- /dev/null +++ b/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionModal.tsx @@ -0,0 +1,68 @@ +import React from 'react'; +import {View} from 'react-native'; +import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import Modal from '@components/Modal'; +import ScreenWrapper from '@components/ScreenWrapper'; +import SelectionList from '@components/SelectionList'; +import RadioListItem from '@components/SelectionList/RadioListItem'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import CONST from '@src/CONST'; + +type ListItemType = { + value: typeof CONST.POLICY.ROLE.ADMIN | typeof CONST.POLICY.ROLE.USER; + text: string; + isSelected: boolean; + keyForList: typeof CONST.POLICY.ROLE.ADMIN | typeof CONST.POLICY.ROLE.USER; +}; + +type WorkspaceMemberDetailsPageProps = { + /** Whether the modal is visible */ + isVisible: boolean; + + /** The list of items to render */ + items: ListItemType[]; + + /** Function to call when the user selects a role */ + onRoleChange: ({value}: ListItemType) => void; + + /** Function to call when the user closes the role selection modal */ + onClose: () => void; +}; + +function WorkspaceMemberDetailsRoleSelectionModal({isVisible, items, onRoleChange, onClose}: WorkspaceMemberDetailsPageProps) { + const {translate} = useLocalize(); + const styles = useThemeStyles(); + + return ( + onClose?.()} + onModalHide={onClose} + hideModalContentWhileAnimating + useNativeDriver + > + + + + item.isSelected)?.keyForList} + /> + + + + ); +} + +WorkspaceMemberDetailsRoleSelectionModal.displayName = 'WorkspaceMemberDetailsRoleSelectionModal'; + +export type {ListItemType}; + +export default WorkspaceMemberDetailsRoleSelectionModal; diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx deleted file mode 100644 index 38caf24c7ecb..000000000000 --- a/src/pages/workspace/members/WorkspaceMemberDetailsRoleSelectionPage.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import type {StackScreenProps} from '@react-navigation/stack'; -import React from 'react'; -import {View} from 'react-native'; -import HeaderWithBackButton from '@components/HeaderWithBackButton'; -import ScreenWrapper from '@components/ScreenWrapper'; -import SelectionList from '@components/SelectionList'; -import RadioListItem from '@components/SelectionList/RadioListItem'; -import useLocalize from '@hooks/useLocalize'; -import useThemeStyles from '@hooks/useThemeStyles'; -import Navigation from '@navigation/Navigation'; -import type {SettingsNavigatorParamList} from '@navigation/types'; -import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper'; -import PaidPolicyAccessOrNotFoundWrapper from '@pages/workspace/PaidPolicyAccessOrNotFoundWrapper'; -import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading'; -import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading'; -import * as Policy from '@userActions/Policy'; -import CONST from '@src/CONST'; -import type SCREENS from '@src/SCREENS'; -import ROUTES from "@src/ROUTES"; - -type WorkspaceMemberDetailsPageProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps; - -type ListItemType = { - value: typeof CONST.POLICY.ROLE.ADMIN | typeof CONST.POLICY.ROLE.USER; - text: string; - isSelected: boolean; - keyForList: typeof CONST.POLICY.ROLE.ADMIN | typeof CONST.POLICY.ROLE.USER; -}; - -function WorkspaceMemberDetailsRoleSelectionPage({policyMembers, route}: WorkspaceMemberDetailsPageProps) { - const {translate} = useLocalize(); - const styles = useThemeStyles(); - - const accountID = Number(route.params.accountID) ?? 0; - const policyID = route.params.policyID; - const member = policyMembers?.[accountID]; - - const items: ListItemType[] = [ - { - value: CONST.POLICY.ROLE.ADMIN, - text: translate('common.admin'), - isSelected: member?.role === CONST.POLICY.ROLE.ADMIN, - keyForList: CONST.POLICY.ROLE.ADMIN, - }, - { - value: CONST.POLICY.ROLE.USER, - text: translate('common.member'), - isSelected: member?.role === CONST.POLICY.ROLE.USER, - keyForList: CONST.POLICY.ROLE.USER, - }, - ]; - - const changeRole = ({value}: ListItemType) => { - if (!member) { - return; - } - - Policy.updateWorkspaceMembersRole(route.params.policyID, [accountID], value); - Navigation.goBack(ROUTES.WORKSPACE_MEMBER_DETAILS.getRoute(policyID, accountID)); - }; - - return ( - - - - Navigation.goBack(ROUTES.WORKSPACE_MEMBER_DETAILS.getRoute(policyID, accountID))} - /> - - item.isSelected)?.keyForList} - /> - - - - - ); -} - -WorkspaceMemberDetailsRoleSelectionPage.displayName = 'WorkspaceMemberDetailsRoleSelectionPage'; - -export default withPolicyAndFullscreenLoading(WorkspaceMemberDetailsRoleSelectionPage); From 23e68c675411b80ddc8aa1cc0af993c5a01662aa Mon Sep 17 00:00:00 2001 From: burczu Date: Thu, 4 Apr 2024 14:27:22 +0200 Subject: [PATCH 6/6] simple go back without fallback --- src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index 499a8fc52685..b78a1b890275 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -102,7 +102,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou const removeUser = useCallback(() => { Policy.removeMembers([accountID], policyID); setIsRemoveMemberConfirmModalVisible(false); - Navigation.goBack(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID)); + Navigation.goBack(); }, [accountID, policyID]); const navigateToProfile = useCallback(() => { @@ -134,7 +134,6 @@ function WorkspaceMemberDetailsPage({personalDetails, policyMembers, policy, rou Navigation.goBack(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID))} />