Skip to content

Commit

Permalink
Merge pull request #37700 from Expensify/cmartins-makeMembersPageRead…
Browse files Browse the repository at this point in the history
…Only

Make members page read only
  • Loading branch information
chiragsalian authored Mar 6, 2024
2 parents 91c2b49 + bf9cc2f commit 042bdcc
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 58 deletions.
21 changes: 7 additions & 14 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_TRAVEL.getRoute(policyID)))),
routeName: SCREENS.WORKSPACE.TRAVEL,
},
{
translationKey: 'workspace.common.members',
icon: Expensicons.Users,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID)))),
brickRoadIndicator: hasMembersError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
routeName: SCREENS.WORKSPACE.MEMBERS,
},
{
translationKey: 'workspace.common.bankAccount',
icon: Expensicons.Bank,
Expand All @@ -156,13 +149,6 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS.getRoute(policyID)))),
routeName: SCREENS.WORKSPACE.WORKFLOWS,
},
{
translationKey: 'workspace.common.members',
icon: Expensicons.Users,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID)))),
brickRoadIndicator: hasMembersError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
routeName: SCREENS.WORKSPACE.MEMBERS,
},
{
translationKey: 'workspace.common.categories',
icon: Expensicons.Folder,
Expand All @@ -185,6 +171,13 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
brickRoadIndicator: hasGeneralSettingsError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
routeName: SCREENS.WORKSPACE.PROFILE,
},
{
translationKey: 'workspace.common.members',
icon: Expensicons.Users,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID)))),
brickRoadIndicator: hasMembersError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
routeName: SCREENS.WORKSPACE.MEMBERS,
},
...(isPaidGroupPolicy && shouldShowProtectedItems ? protectedCollectPolicyMenuItems : []),
...(isFreeGroupPolicy && shouldShowProtectedItems ? protectedFreePolicyMenuItems : []),
];
Expand Down
110 changes: 66 additions & 44 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
const {translate, formatPhoneNumber, preferredLocale} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
const dropdownButtonRef = useRef(null);
const isPolicyAdmin = PolicyUtils.isPolicyAdmin(policy);

/**
* Get filtered personalDetails list with current policyMembers
Expand Down Expand Up @@ -306,7 +307,7 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
const isSelected = selectedEmployees.includes(accountID);

const isOwner = policy?.owner === details.login;
const isAdmin = session?.email === details.login || policyMember.role === CONST.POLICY.ROLE.ADMIN;
const isAdmin = policyMember.role === CONST.POLICY.ROLE.ADMIN;

let roleBadge = null;
if (isOwner || isAdmin) {
Expand All @@ -324,10 +325,11 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
accountID,
isSelected,
isDisabled:
accountID === session?.accountID ||
accountID === policy?.ownerAccountID ||
policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ||
!isEmptyObject(policyMember.errors),
isPolicyAdmin &&
(accountID === session?.accountID ||
accountID === policy?.ownerAccountID ||
policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ||
!isEmptyObject(policyMember.errors)),
text: formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)),
alternateText: formatPhoneNumber(details?.login ?? ''),
rightElement: roleBadge,
Expand Down Expand Up @@ -375,16 +377,24 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
</>
);

const getCustomListHeader = () => (
<View style={[styles.flex1, styles.flexRow, styles.justifyContentBetween]}>
<View>
<Text style={[styles.searchInputStyle, styles.ml3]}>{translate('common.member')}</Text>
</View>
<View style={[StyleUtils.getMinimumWidth(60)]}>
<Text style={[styles.searchInputStyle, styles.textAlignCenter]}>{translate('common.role')}</Text>
const getCustomListHeader = () => {
const header = (
<View style={[styles.flex1, styles.flexRow, styles.justifyContentBetween]}>
<View>
<Text style={[styles.searchInputStyle, isPolicyAdmin ? styles.ml3 : styles.ml0]}>{translate('common.member')}</Text>
</View>
<View style={[StyleUtils.getMinimumWidth(60)]}>
<Text style={[styles.searchInputStyle, styles.textAlignCenter]}>{translate('common.role')}</Text>
</View>
</View>
</View>
);
);

if (isPolicyAdmin) {
return header;
}

return <View style={[styles.peopleRow, styles.userSelectNone, styles.ph9, styles.pv3, styles.pb5]}>{header}</View>;
};

const changeUserRole = (role: typeof CONST.POLICY.ROLE.ADMIN | typeof CONST.POLICY.ROLE.USER) => {
if (!isEmptyObject(errors)) {
Expand Down Expand Up @@ -428,33 +438,39 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
return options;
};

const getHeaderButtons = () => (
<View style={styles.w100}>
{selectedEmployees.length > 0 ? (
<ButtonWithDropdownMenu<WorkspaceMemberBulkActionType>
shouldAlwaysShowDropdownMenu
pressOnEnter
customText={translate('workspace.people.selected', {selectedNumber: selectedEmployees.length})}
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.MEDIUM}
onPress={() => null}
options={getBulkActionsButtonOptions()}
buttonRef={dropdownButtonRef}
style={[isSmallScreenWidth && styles.flexGrow1]}
/>
) : (
<Button
medium
success
onPress={inviteUser}
text={translate('workspace.invite.member')}
icon={Expensicons.Plus}
iconStyles={{transform: [{scale: 0.6}]}}
innerStyles={[isSmallScreenWidth && styles.alignItemsCenter]}
style={[isSmallScreenWidth && styles.flexGrow1]}
/>
)}
</View>
);
const getHeaderButtons = () => {
if (!isPolicyAdmin) {
return null;
}

return (
<View style={styles.w100}>
{selectedEmployees.length > 0 ? (
<ButtonWithDropdownMenu<WorkspaceMemberBulkActionType>
shouldAlwaysShowDropdownMenu
pressOnEnter
customText={translate('workspace.people.selected', {selectedNumber: selectedEmployees.length})}
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.MEDIUM}
onPress={() => null}
options={getBulkActionsButtonOptions()}
buttonRef={dropdownButtonRef}
style={[isSmallScreenWidth && styles.flexGrow1]}
/>
) : (
<Button
medium
success
onPress={inviteUser}
text={translate('workspace.invite.member')}
icon={Expensicons.Plus}
iconStyles={{transform: [{scale: 0.6}]}}
innerStyles={[isSmallScreenWidth && styles.alignItemsCenter]}
style={[isSmallScreenWidth && styles.flexGrow1]}
/>
)}
</View>
);
};

return (
<ScreenWrapper
Expand All @@ -464,7 +480,7 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
shouldShowOfflineIndicatorInWideScreen
>
<FullPageNotFoundView
shouldShow={(isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)}
shouldShow={(isEmptyObject(policy) && !isLoadingReportData) || PolicyUtils.isPendingDeletePolicy(policy)}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
Expand Down Expand Up @@ -501,13 +517,19 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se
/>
<View style={[styles.w100, styles.flex1]}>
<SelectionList
canSelectMultiple
canSelectMultiple={isPolicyAdmin}
sections={[{data, indexOffset: 0, isDisabled: false}]}
ListItem={TableListItem}
disableKeyboardShortcuts={removeMembersConfirmModalVisible}
headerMessage={getHeaderMessage()}
headerContent={getHeaderContent()}
onSelectRow={(item) => toggleUser(item.accountID)}
onSelectRow={(item) => {
if (!isPolicyAdmin) {
Navigation.navigate(ROUTES.PROFILE.getRoute(item.accountID));
return;
}
toggleUser(item.accountID);
}}
onSelectAll={() => toggleAllUsers(data)}
onDismissError={dismissError}
showLoadingPlaceholder={!isOfflineAndNoMemberDataAvailable && (!OptionsListUtils.isPersonalDetailsReady(personalDetails) || isEmptyObject(policyMembers))}
Expand Down

0 comments on commit 042bdcc

Please sign in to comment.