Skip to content

fix: migrate workspace invite role to a new page #60626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ const ONYXKEYS = {
POLICY_CONNECTION_SYNC_PROGRESS: 'policyConnectionSyncProgress_',
WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_',
WORKSPACE_INVITE_MESSAGE_DRAFT: 'workspaceInviteMessageDraft_',
WORKSPACE_INVITE_ROLE_DRAFT: 'workspaceInviteRoleDraft_',
REPORT: 'report_',
REPORT_NAME_VALUE_PAIRS: 'reportNameValuePairs_',
REPORT_DRAFT: 'reportDraft_',
Expand Down Expand Up @@ -932,6 +933,7 @@ type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST]: OnyxTypes.PolicyEmployeeList;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT]: OnyxTypes.InvitedEmailsToAccountIDs;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT]: string;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_ROLE_DRAFT]: string;
[ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report;
[ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS]: OnyxTypes.ReportNameValuePairs;
[ONYXKEYS.COLLECTION.REPORT_DRAFT]: OnyxTypes.Report;
Expand Down
4 changes: 4 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ const ROUTES = {
route: 'settings/workspaces/:policyID/invite-message',
getRoute: (policyID: string, backTo?: string) => `${getUrlWithBackToParam(`settings/workspaces/${policyID}/invite-message`, backTo)}` as const,
},
WORKSPACE_INVITE_MESSAGE_ROLE: {
route: 'settings/workspaces/:policyID/invite-message/role',
getRoute: (policyID: string, backTo?: string) => `${getUrlWithBackToParam(`settings/workspaces/${policyID}/invite-message/role`, backTo)}` as const,
},
WORKSPACE_OVERVIEW: {
route: 'settings/workspaces/:policyID/overview',
getRoute: (policyID: string | undefined, backTo?: string) => {
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ const SCREENS = {
MEMBERS_IMPORTED: 'Members_Imported',
INVITE: 'Workspace_Invite',
INVITE_MESSAGE: 'Workspace_Invite_Message',
INVITE_MESSAGE_ROLE: 'Workspace_Invite_Message_Role',
CATEGORIES: 'Workspace_Categories',
TAGS: 'Workspace_Tags',
TAGS_SETTINGS: 'Tags_Settings',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
require<ReactComponentModule>('../../../../pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsExpensesFromPage').default,
[SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_APPROVER]: () => require<ReactComponentModule>('../../../../pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApproverPage').default,
[SCREENS.WORKSPACE.INVITE_MESSAGE]: () => require<ReactComponentModule>('../../../../pages/workspace/WorkspaceInviteMessagePage').default,
[SCREENS.WORKSPACE.INVITE_MESSAGE_ROLE]: () => require<ReactComponentModule>('../../../../pages/workspace/WorkspaceInviteMessageRolePage').default,
[SCREENS.WORKSPACE.WORKFLOWS_PAYER]: () => require<ReactComponentModule>('../../../../pages/workspace/workflows/WorkspaceWorkflowsPayerPage').default,
[SCREENS.WORKSPACE.NAME]: () => require<ReactComponentModule>('../../../../pages/workspace/WorkspaceNamePage').default,
[SCREENS.WORKSPACE.DESCRIPTION]: () => require<ReactComponentModule>('../../../../pages/workspace/WorkspaceOverviewDescriptionPage').default,
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
[SCREENS.WORKSPACE.INVITE_MESSAGE]: {
path: ROUTES.WORKSPACE_INVITE_MESSAGE.route,
},
[SCREENS.WORKSPACE.INVITE_MESSAGE_ROLE]: {
path: ROUTES.WORKSPACE_INVITE_MESSAGE_ROLE.route,
},
[SCREENS.WORKSPACE.CATEGORY_SETTINGS]: {
path: ROUTES.WORKSPACE_CATEGORY_SETTINGS.route,
parse: {
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ type SettingsNavigatorParamList = {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.INVITE_MESSAGE_ROLE]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.CATEGORY_CREATE]: {
policyID: string;
backTo?: Routes;
Expand Down
10 changes: 10 additions & 0 deletions src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,14 @@ function setWorkspaceInviteMembersDraft(policyID: string, invitedEmailsToAccount
Onyx.set(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${policyID}`, invitedEmailsToAccountIDs);
}

function setWorkspaceInviteRoleDraft(policyID: string, role: ValueOf<typeof CONST.POLICY.ROLE>) {
Onyx.set(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_ROLE_DRAFT}${policyID}`, role);
}

function clearWorkspaceInviteRoleDraft(policyID: string) {
Onyx.set(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_ROLE_DRAFT}${policyID}`, null);
}

/**
* Accept user join request to a workspace
*/
Expand Down Expand Up @@ -1269,4 +1277,6 @@ export {
clearInviteDraft,
buildRoomMembersOnyxData,
openPolicyMemberProfilePage,
setWorkspaceInviteRoleDraft,
clearWorkspaceInviteRoleDraft,
};
68 changes: 13 additions & 55 deletions src/pages/workspace/WorkspaceInviteMessagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {InteractionManager, Keyboard, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {GestureResponderEvent} from 'react-native/Libraries/Types/CoreEventTypes';
import type {ValueOf} from 'type-fest';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors} from '@components/Form/types';
Expand All @@ -22,7 +21,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useViewportOffsetTop from '@hooks/useViewportOffsetTop';
import {clearDraftValues} from '@libs/actions/FormActions';
import {openExternalLink} from '@libs/actions/Link';
import {addMembersToWorkspace} from '@libs/actions/Policy/Member';
import {addMembersToWorkspace, clearWorkspaceInviteRoleDraft} from '@libs/actions/Policy/Member';
import {setWorkspaceInviteMessageDraft} from '@libs/actions/Policy/Policy';
import getIsNarrowLayout from '@libs/getIsNarrowLayout';
import Navigation from '@libs/Navigation/Navigation';
Expand All @@ -39,12 +38,9 @@ import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/WorkspaceInviteMessageForm';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import KeyboardUtils from '@src/utils/keyboard';
import AccessOrNotFoundWrapper from './AccessOrNotFoundWrapper';
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading';
import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading';
import WorkspaceMemberDetailsRoleSelectionModal from './WorkspaceMemberRoleSelectionModal';
import type {ListItemType} from './WorkspaceMemberRoleSelectionModal';

type WorkspaceInviteMessagePageProps = WithPolicyAndFullscreenLoadingProps &
WithCurrentUserPersonalDetailsProps &
Expand All @@ -54,7 +50,6 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
const styles = useThemeStyles();
const {translate} = useLocalize();
const [formData, formDataResult] = useOnyx(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM_DRAFT, {canBeMissing: true});
const [role, setRole] = useState<ValueOf<typeof CONST.POLICY.ROLE>>(CONST.POLICY.ROLE.USER);

const viewportOffsetTop = useViewportOffsetTop();
const [welcomeNote, setWelcomeNote] = useState<string>();
Expand All @@ -67,22 +62,15 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
const [workspaceInviteMessageDraft, workspaceInviteMessageDraftResult] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT}${route.params.policyID.toString()}`, {
canBeMissing: true,
});
const [allPersonalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: true});
const [workspaceInviteRoleDraft = CONST.POLICY.ROLE.USER] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_ROLE_DRAFT}${route.params.policyID.toString()}`, {canBeMissing: true});
const [allPersonalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false});
const isOnyxLoading = isLoadingOnyxValue(workspaceInviteMessageDraftResult, invitedEmailsToAccountIDsDraftResult, formDataResult);

const [isRoleSelectionModalVisible, setIsRoleSelectionModalVisible] = useState(false);

const welcomeNoteSubject = useMemo(
() => `# ${currentUserPersonalDetails?.displayName ?? ''} invited you to ${policy?.name ?? 'a workspace'}`,
[policy?.name, currentUserPersonalDetails?.displayName],
);

const openRoleSelectionModal = useCallback(() => {
KeyboardUtils.dismiss().then(() => {
setIsRoleSelectionModalVisible(true);
});
}, []);

const getDefaultWelcomeNote = useCallback(() => {
return (
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down Expand Up @@ -113,7 +101,7 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
Keyboard.dismiss();
const policyMemberAccountIDs = Object.values(getMemberAccountIDsForWorkspace(policy?.employeeList, false, false));
// Please see https://github.com/Expensify/App/blob/main/README.md#Security for more details
addMembersToWorkspace(invitedEmailsToAccountIDsDraft ?? {}, `${welcomeNoteSubject}\n\n${welcomeNote}`, route.params.policyID, policyMemberAccountIDs, role);
addMembersToWorkspace(invitedEmailsToAccountIDsDraft ?? {}, `${welcomeNoteSubject}\n\n${welcomeNote}`, route.params.policyID, policyMemberAccountIDs, workspaceInviteRoleDraft);
setWorkspaceInviteMessageDraft(route.params.policyID, welcomeNote ?? null);
clearDraftValues(ONYXKEYS.FORMS.WORKSPACE_INVITE_MESSAGE_FORM);
if ((route.params?.backTo as string)?.endsWith('members')) {
Expand Down Expand Up @@ -150,37 +138,11 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:

const policyName = policy?.name;

const roleItems: ListItemType[] = useMemo(
() => [
{
value: CONST.POLICY.ROLE.ADMIN,
text: translate('common.admin'),
alternateText: translate('workspace.common.adminAlternateText'),
isSelected: role === CONST.POLICY.ROLE.ADMIN,
keyForList: CONST.POLICY.ROLE.ADMIN,
},
{
value: CONST.POLICY.ROLE.AUDITOR,
text: translate('common.auditor'),
alternateText: translate('workspace.common.auditorAlternateText'),
isSelected: role === CONST.POLICY.ROLE.AUDITOR,
keyForList: CONST.POLICY.ROLE.AUDITOR,
},
{
value: CONST.POLICY.ROLE.USER,
text: translate('common.member'),
alternateText: translate('workspace.common.memberAlternateText'),
isSelected: role === CONST.POLICY.ROLE.USER,
keyForList: CONST.POLICY.ROLE.USER,
},
],
[role, translate],
);

const changeRole = useCallback(({value}: ListItemType) => {
setIsRoleSelectionModalVisible(false);
setRole(value);
}, []);
useEffect(() => {
return () => {
clearWorkspaceInviteRoleDraft(route.params.policyID);
};
}, [route.params.policyID]);

return (
<AccessOrNotFoundWrapper
Expand Down Expand Up @@ -239,16 +201,12 @@ function WorkspaceInviteMessagePage({policy, route, currentUserPersonalDetails}:
<View style={[styles.mb3]}>
<View style={[styles.mhn5, styles.mb3]}>
<MenuItemWithTopDescription
title={translate(`workspace.common.roleName`, {role})}
title={translate(`workspace.common.roleName`, {role: workspaceInviteRoleDraft})}
description={translate('common.role')}
shouldShowRightIcon
onPress={openRoleSelectionModal}
/>
<WorkspaceMemberDetailsRoleSelectionModal
isVisible={isRoleSelectionModalVisible}
items={roleItems}
onRoleChange={changeRole}
onClose={() => setIsRoleSelectionModalVisible(false)}
onPress={() => {
Navigation.navigate(ROUTES.WORKSPACE_INVITE_MESSAGE_ROLE.getRoute(route.params.policyID, Navigation.getActiveRoute()));
}}
/>
</View>
<InputWrapper
Expand Down
112 changes: 112 additions & 0 deletions src/pages/workspace/WorkspaceInviteMessageRolePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import React, {useMemo} from 'react';
import {View} from 'react-native';
import type {ValueOf} from 'type-fest';
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 useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import useViewportOffsetTop from '@hooks/useViewportOffsetTop';
import {setWorkspaceInviteRoleDraft} from '@libs/actions/Policy/Member';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import {goBackFromInvalidPolicy} from '@libs/PolicyUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import AccessOrNotFoundWrapper from './AccessOrNotFoundWrapper';
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading';
import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscreenLoading';

type ListItemType = {
value: ValueOf<typeof CONST.POLICY.ROLE>;
text: string;
alternateText: string;
isSelected: boolean;
keyForList: ValueOf<typeof CONST.POLICY.ROLE>;
};

type WorkspaceInviteMessageRolePageProps = WithPolicyAndFullscreenLoadingProps & PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.INVITE_MESSAGE_ROLE>;

function WorkspaceInviteMessageRolePage({policy, route}: WorkspaceInviteMessageRolePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [role = CONST.POLICY.ROLE.USER, roleResult] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_ROLE_DRAFT}${route.params.policyID}`, {
canBeMissing: true,
});
const viewportOffsetTop = useViewportOffsetTop();
const isOnyxLoading = isLoadingOnyxValue(roleResult);

const roleItems: ListItemType[] = useMemo(
() => [
{
value: CONST.POLICY.ROLE.ADMIN,
text: translate('common.admin'),
alternateText: translate('workspace.common.adminAlternateText'),
isSelected: role === CONST.POLICY.ROLE.ADMIN,
keyForList: CONST.POLICY.ROLE.ADMIN,
},
{
value: CONST.POLICY.ROLE.AUDITOR,
text: translate('common.auditor'),
alternateText: translate('workspace.common.auditorAlternateText'),
isSelected: role === CONST.POLICY.ROLE.AUDITOR,
keyForList: CONST.POLICY.ROLE.AUDITOR,
},
{
value: CONST.POLICY.ROLE.USER,
text: translate('common.member'),
alternateText: translate('workspace.common.memberAlternateText'),
isSelected: role === CONST.POLICY.ROLE.USER,
keyForList: CONST.POLICY.ROLE.USER,
},
],
[role, translate],
);

return (
<AccessOrNotFoundWrapper
policyID={route.params.policyID}
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
fullPageNotFoundViewProps={{subtitleKey: isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized', onLinkPress: goBackFromInvalidPolicy}}
>
<ScreenWrapper
testID={WorkspaceInviteMessageRolePage.displayName}
enableEdgeToEdgeBottomSafeAreaPadding
shouldEnableMaxHeight
style={{marginTop: viewportOffsetTop}}
>
<HeaderWithBackButton
title={translate('common.role')}
onBackButtonPress={() => Navigation.goBack(route.params.backTo)}
/>
{!isOnyxLoading && (
<View style={[styles.containerWithSpaceBetween, styles.pointerEventsBoxNone]}>
<SelectionList
sections={[{data: roleItems}]}
ListItem={RadioListItem}
onSelectRow={({value}: ListItemType) => {
setWorkspaceInviteRoleDraft(route.params.policyID, value);
Navigation.setNavigationActionToMicrotaskQueue(() => {
Navigation.goBack(route.params.backTo);
});
}}
isAlternateTextMultilineSupported
shouldSingleExecuteRowSelect
initiallyFocusedOptionKey={roleItems.find((item) => item.isSelected)?.keyForList}
addBottomSafeAreaPadding
/>
</View>
)}
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
}

WorkspaceInviteMessageRolePage.displayName = 'WorkspaceInviteMessageRolePage';
export default withPolicyAndFullscreenLoading(WorkspaceInviteMessageRolePage);
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 PolicyRouteName =
| typeof SCREENS.WORKSPACE.COMPANY_CARDS
| typeof SCREENS.WORKSPACE.INVITE
| typeof SCREENS.WORKSPACE.INVITE_MESSAGE
| typeof SCREENS.WORKSPACE.INVITE_MESSAGE_ROLE
| typeof SCREENS.WORKSPACE.WORKFLOWS_PAYER
| typeof SCREENS.WORKSPACE.WORKFLOWS
| typeof SCREENS.WORKSPACE.WORKFLOWS_APPROVALS_NEW
Expand Down