Skip to content
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

Going to workspace from details page #19064

Merged
merged 14 commits into from
May 19, 2023
10 changes: 9 additions & 1 deletion src/libs/PolicyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,12 @@ function isExpensifyTeam(email) {
return emailDomain === CONST.EXPENSIFY_PARTNER_NAME || emailDomain === CONST.EMAIL.GUIDES_DOMAIN;
}

export {hasPolicyMemberError, hasPolicyError, hasPolicyErrorFields, hasCustomUnitsError, getPolicyBrickRoadIndicatorStatus, shouldShowPolicy, isExpensifyTeam};
/**
* Checks if the current user is an admin of the policy.
*
* @param {Object} policy
* @returns {Boolean}
*/
const isPolicyAdmin = (policy) => policy.role === CONST.POLICY.ROLE.ADMIN;
alitoshmatov marked this conversation as resolved.
Show resolved Hide resolved

export {hasPolicyMemberError, hasPolicyError, hasPolicyErrorFields, hasCustomUnitsError, getPolicyBrickRoadIndicatorStatus, shouldShowPolicy, isExpensifyTeam, isPolicyAdmin};
35 changes: 27 additions & 8 deletions src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import {View, ScrollView} from 'react-native';
import {View, ScrollView, Pressable} from 'react-native';
import lodashGet from 'lodash/get';
import RoomHeaderAvatars from '../components/RoomHeaderAvatars';
import compose from '../libs/compose';
Expand All @@ -15,6 +15,7 @@ import styles from '../styles/styles';
import DisplayNames from '../components/DisplayNames';
import * as OptionsListUtils from '../libs/OptionsListUtils';
import * as ReportUtils from '../libs/ReportUtils';
import * as PolicyUtils from '../libs/PolicyUtils';
import * as Report from '../libs/actions/Report';
import participantPropTypes from '../components/participantPropTypes';
import * as Expensicons from '../components/Icon/Expensicons';
Expand Down Expand Up @@ -56,6 +57,10 @@ const defaultProps = {
};

class ReportDetailsPage extends Component {
getPolicy() {
return this.props.policies[`${ONYXKEYS.COLLECTION.POLICY}${this.props.report.policyID}`];
}

getMenuItems() {
const menuItems = [
{
Expand Down Expand Up @@ -93,7 +98,7 @@ class ReportDetailsPage extends Component {
});
}

const policy = this.props.policies[`${ONYXKEYS.COLLECTION.POLICY}${this.props.report.policyID}`];
const policy = this.getPolicy();
const isThread = ReportUtils.isThread(this.props.report);
if (ReportUtils.isUserCreatedPolicyRoom(this.props.report) || ReportUtils.canLeaveRoom(this.props.report, !_.isEmpty(policy)) || isThread) {
menuItems.push({
Expand All @@ -119,6 +124,15 @@ class ReportDetailsPage extends Component {
isMultipleParticipant,
);
const menuItems = this.getMenuItems();
const isPolicyAdmin = PolicyUtils.isPolicyAdmin(this.getPolicy());
const chatRoomSubtitleText = (
<Text
style={[styles.sidebarLinkText, styles.optionAlternateText, styles.textLabelSupporting, styles.mb2, styles.pre]}
numberOfLines={1}
>
{chatRoomSubtitle}
</Text>
);
return (
<ScreenWrapper>
<FullPageNotFoundView shouldShow={_.isEmpty(this.props.report)}>
Expand All @@ -144,12 +158,17 @@ class ReportDetailsPage extends Component {
shouldUseFullTitle={isChatRoom || isPolicyExpenseChat || isThread}
/>
</View>
<Text
style={[styles.sidebarLinkText, styles.optionAlternateText, styles.textLabelSupporting, styles.mb2, styles.pre]}
numberOfLines={1}
>
{chatRoomSubtitle}
</Text>
{isPolicyAdmin ? (
<Pressable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #23355, we should have taken into account the scenario in which the workspace has a pending delete action, and consequently, disable navigation to that workspace.

onPress={() => {
Navigation.navigate(ROUTES.getWorkspaceSettingsRoute(this.props.report.policyID));
alitoshmatov marked this conversation as resolved.
Show resolved Hide resolved
}}
>
{chatRoomSubtitleText}
</Pressable>
) : (
chatRoomSubtitleText
)}
</View>
</View>
</View>
Expand Down