-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add possibility to leave from workspaces and workspace expense chats #35671
Changes from 17 commits
107f84c
4111039
52b16ce
5788e86
2114adb
eb62992
3775ad0
cf3b66e
95b8741
af8c733
8a3473f
d27f6e4
0ce1db1
9fde01e
a8b9da5
184a6cd
eb6d577
8ddf9be
ea03623
d850c85
5ca68a6
f40cedd
f8c8395
80caecd
ceff5e2
1dc5932
44bcc09
4b48baf
fb038eb
9e9f7bf
6aa6b13
d40d9ff
5c192b8
c55cd13
92fe2a5
2b955b3
24f3740
2c2ae9f
9a48ebb
858a872
0b12883
4de342a
0f9a909
e63bb9e
6b2efac
8ab074e
223d3ff
97cab94
5313900
7db78ee
b028a6f
d07e04a
7321ad2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import Navigation from '@libs/Navigation/Navigation'; | |
import type {ReportWithoutHasDraft} from '@libs/OnyxSelectors/reportWithoutHasDraftSelector'; | ||
import reportWithoutHasDraftSelector from '@libs/OnyxSelectors/reportWithoutHasDraftSelector'; | ||
import * as OptionsListUtils from '@libs/OptionsListUtils'; | ||
import * as PolicyUtils from '@libs/PolicyUtils'; | ||
import * as ReportActionsUtils from '@libs/ReportActionsUtils'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import * as Link from '@userActions/Link'; | ||
|
@@ -98,6 +99,8 @@ function HeaderView({report, personalDetails, parentReport, parentReportAction, | |
const isUserCreatedPolicyRoom = ReportUtils.isUserCreatedPolicyRoom(report); | ||
const isPolicyMember = useMemo(() => !isEmptyObject(policy), [policy]); | ||
const canLeaveRoom = ReportUtils.canLeaveRoom(report, isPolicyMember); | ||
const canLeavePolicyExpenseChat = | ||
isPolicyExpenseChat && !(PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPolicyOwner(policy, session?.accountID ?? -1) || ReportUtils.isReportOwner(report)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a utility function for this in |
||
const reportDescription = ReportUtils.getReportDescriptionText(report); | ||
const policyName = ReportUtils.getPolicyName(report, true); | ||
const policyDescription = ReportUtils.getPolicyDescriptionText(policy); | ||
|
@@ -144,9 +147,9 @@ function HeaderView({report, personalDetails, parentReport, parentReportAction, | |
Report.updateNotificationPreference(reportID, report.notificationPreference, CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, false, report.parentReportID, report.parentReportActionID), | ||
); | ||
|
||
const canJoinOrLeave = !isSelfDM && (isChatThread || isUserCreatedPolicyRoom || canLeaveRoom); | ||
const canJoinOrLeave = !isSelfDM && (isChatThread || isUserCreatedPolicyRoom || canLeaveRoom || canLeavePolicyExpenseChat); | ||
const canJoin = canJoinOrLeave && !isWhisperAction && report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; | ||
const canLeave = canJoinOrLeave && ((isChatThread && !!report.notificationPreference?.length) || isUserCreatedPolicyRoom || canLeaveRoom); | ||
const canLeave = canJoinOrLeave && ((isChatThread && !!report.notificationPreference?.length) || isUserCreatedPolicyRoom || canLeaveRoom || canLeavePolicyExpenseChat); | ||
if (canJoin) { | ||
threeDotMenuItems.push({ | ||
icon: Expensicons.ChatBubbles, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,11 @@ import * as ReportUtils from '@libs/ReportUtils'; | |
import type {AvatarSource} from '@libs/UserUtils'; | ||
import * as App from '@userActions/App'; | ||
import * as Policy from '@userActions/Policy'; | ||
import * as Session from '@userActions/Session'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type {PolicyMembers, Policy as PolicyType, ReimbursementAccount, Report} from '@src/types/onyx'; | ||
import type {PolicyMembers, Policy as PolicyType, ReimbursementAccount, Report, Session as SessionType} from '@src/types/onyx'; | ||
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; | ||
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading'; | ||
|
@@ -79,6 +80,9 @@ type WorkspaceListPageOnyxProps = { | |
|
||
/** All reports shared with the user (coming from Onyx) */ | ||
reports: OnyxCollection<Report>; | ||
|
||
/** Session info for the currently logged in user. */ | ||
session: OnyxEntry<SessionType>; | ||
}; | ||
|
||
type WorkspaceListPageProps = WithPolicyAndFullscreenLoadingProps & WorkspaceListPageOnyxProps; | ||
|
@@ -114,7 +118,7 @@ function dismissWorkspaceError(policyID: string, pendingAction: OnyxCommon.Pendi | |
throw new Error('Not implemented'); | ||
} | ||
|
||
function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, reports}: WorkspaceListPageProps) { | ||
function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, reports, session}: WorkspaceListPageProps) { | ||
const theme = useTheme(); | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
|
@@ -148,6 +152,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r | |
const getMenuItem = useCallback( | ||
({item, index}: GetMenuItem) => { | ||
const isAdmin = item.role === CONST.POLICY.ROLE.ADMIN; | ||
const isOwner = item.ownerAccountID === session?.accountID; | ||
// Menu options to navigate to the chat report of #admins and #announce room. | ||
// For navigation, the chat report ids may be unavailable due to the missing chat reports in Onyx. | ||
// In such cases, let us use the available chat report ids from the policy. | ||
|
@@ -165,6 +170,14 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r | |
}); | ||
} | ||
|
||
if (!(isAdmin || isOwner)) { | ||
threeDotsMenuItems.push({ | ||
icon: Expensicons.ChatBubbles, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi 👋 coming from #46248. Pretty minor issue and part of the polish issue. We should be using the |
||
text: translate('common.leave'), | ||
onSelected: Session.checkIfActionIsAllowed(() => Policy.removeMembers([session?.accountID ?? 0], item.policyID ?? '')), | ||
rezkiy37 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
|
||
if (isAdmin && item.adminRoom) { | ||
threeDotsMenuItems.push({ | ||
icon: Expensicons.Hashtag, | ||
|
@@ -214,7 +227,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r | |
</PressableWithoutFeedback> | ||
); | ||
}, | ||
[isLessThanMediumScreen, styles.mb3, styles.mh5, styles.ph5, styles.hoveredComponentBG, translate], | ||
[session?.accountID, styles.mh5, styles.mb3, styles.ph5, styles.hoveredComponentBG, translate, isLessThanMediumScreen], | ||
); | ||
|
||
const listHeaderComponent = useCallback(() => { | ||
|
@@ -444,5 +457,8 @@ export default withPolicyAndFullscreenLoading( | |
reports: { | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
}, | ||
session: { | ||
key: ONYXKEYS.SESSION, | ||
}, | ||
})(WorkspacesListPage), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment for this function.