-
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
Move Leave button into a row of the Report Details page #40979
Merged
marcaaron
merged 11 commits into
Expensify:main
from
ZhenjaHorbach:move-leave-button-into-row-of-the-report-details-page
May 3, 2024
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5762ea4
Move Leave button into a row of the Report Details page
ZhenjaHorbach 468e2ed
Update conditions for ReportDetailsPage
ZhenjaHorbach 6984db6
Move ChatDetailsQuickActionsBar and update styles
ZhenjaHorbach ab6a28a
Fix bug with ability leave chatRoom
ZhenjaHorbach cb50951
Update condition for canJoin
ZhenjaHorbach 5c0982b
Update branch
ZhenjaHorbach c0be6a1
Merge branch 'main' into move-leave-button-into-row-of-the-report-det…
ZhenjaHorbach 6a8908a
Fix comments and update HeaderView for GroupChat
ZhenjaHorbach eee05d6
Fix conflicts
ZhenjaHorbach 8c5f825
Revert changes
ZhenjaHorbach f02a4d4
Merge branch 'main' into move-leave-button-into-row-of-the-report-det…
ZhenjaHorbach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||
import {useRoute} from '@react-navigation/native'; | ||||||
import type {StackScreenProps} from '@react-navigation/stack'; | ||||||
import React, {useEffect, useMemo} from 'react'; | ||||||
import React, {useCallback, useEffect, useMemo, useState} from 'react'; | ||||||
import {View} from 'react-native'; | ||||||
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; | ||||||
import {withOnyx} from 'react-native-onyx'; | ||||||
|
@@ -29,6 +29,7 @@ import * as OptionsListUtils from '@libs/OptionsListUtils'; | |||||
import * as PolicyUtils from '@libs/PolicyUtils'; | ||||||
import * as ReportUtils from '@libs/ReportUtils'; | ||||||
import * as Report from '@userActions/Report'; | ||||||
import ConfirmModal from '@src/components/ConfirmModal'; | ||||||
import CONST from '@src/CONST'; | ||||||
import type {TranslationPaths} from '@src/languages/types'; | ||||||
import ONYXKEYS from '@src/ONYXKEYS'; | ||||||
|
@@ -49,6 +50,7 @@ type ReportDetailsPageMenuItem = { | |||||
action: () => void; | ||||||
brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS>; | ||||||
subtitle?: number; | ||||||
shouldShowRightIcon?: boolean; | ||||||
}; | ||||||
|
||||||
type ReportDetailsPageOnyxProps = { | ||||||
|
@@ -65,10 +67,12 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |||||
const {isOffline} = useNetwork(); | ||||||
const styles = useThemeStyles(); | ||||||
const route = useRoute(); | ||||||
const [isLastMemberLeavingGroupModalVisible, setIsLastMemberLeavingGroupModalVisible] = useState(false); | ||||||
const policy = useMemo(() => policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? ''}`], [policies, report?.policyID]); | ||||||
const isPolicyAdmin = useMemo(() => PolicyUtils.isPolicyAdmin(policy ?? null), [policy]); | ||||||
const isPolicyEmployee = useMemo(() => PolicyUtils.isPolicyEmployee(report?.policyID ?? '', policies), [report?.policyID, policies]); | ||||||
const shouldUseFullTitle = useMemo(() => ReportUtils.shouldUseFullTitleToDisplay(report), [report]); | ||||||
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); | ||||||
const isChatRoom = useMemo(() => ReportUtils.isChatRoom(report), [report]); | ||||||
const isUserCreatedPolicyRoom = useMemo(() => ReportUtils.isUserCreatedPolicyRoom(report), [report]); | ||||||
const isDefaultRoom = useMemo(() => ReportUtils.isDefaultRoom(report), [report]); | ||||||
|
@@ -77,6 +81,8 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |||||
const isMoneyRequestReport = useMemo(() => ReportUtils.isMoneyRequestReport(report), [report]); | ||||||
const canEditReportDescription = useMemo(() => ReportUtils.canEditReportDescription(report, policy), [report, policy]); | ||||||
const shouldShowReportDescription = isChatRoom && (canEditReportDescription || report.description !== ''); | ||||||
const canLeaveRoom = ReportUtils.canLeaveRoom(report, isPolicyEmployee); | ||||||
const canLeavePolicyExpenseChat = ReportUtils.canLeavePolicyExpenseChat(report, policy ?? {}); | ||||||
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- policy is a dependency because `getChatRoomSubtitle` calls `getPolicyName` which in turn retrieves the value from the `policy` value stored in Onyx | ||||||
const chatRoomSubtitle = useMemo(() => ReportUtils.getChatRoomSubtitle(report), [report, policy]); | ||||||
|
@@ -97,10 +103,11 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |||||
return !pendingMember || pendingMember.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ? accountID : []; | ||||||
}); | ||||||
|
||||||
const isGroupDMChat = useMemo(() => ReportUtils.isDM(report) && participants.length > 1, [report, participants.length]); | ||||||
const isPrivateNotesFetchTriggered = report?.isLoadingPrivateNotes !== undefined; | ||||||
|
||||||
const isSelfDM = useMemo(() => ReportUtils.isSelfDM(report), [report]); | ||||||
const canJoinOrLeave = !isSelfDM && !isGroupChat && (isChatThread || isUserCreatedPolicyRoom || canLeaveRoom || canLeavePolicyExpenseChat); | ||||||
const canJoin = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; | ||||||
|
||||||
useEffect(() => { | ||||||
// Do not fetch private notes if isLoadingPrivateNotes is already defined, or if the network is offline, or if the report is a self DM. | ||||||
|
@@ -111,23 +118,22 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |||||
Report.getReportPrivateNote(report?.reportID ?? ''); | ||||||
}, [report?.reportID, isOffline, isPrivateNotesFetchTriggered, isSelfDM]); | ||||||
|
||||||
const leaveChat = useCallback(() => { | ||||||
if (isChatRoom) { | ||||||
const isWorkspaceMemberLeavingWorkspaceRoom = (report.visibility === CONST.REPORT.VISIBILITY.RESTRICTED || isPolicyExpenseChat) && isPolicyEmployee; | ||||||
Report.leaveRoom(report.reportID, isWorkspaceMemberLeavingWorkspaceRoom); | ||||||
return; | ||||||
} | ||||||
Report.leaveGroupChat(report.reportID); | ||||||
}, [isChatRoom, isPolicyEmployee, isPolicyExpenseChat, report.reportID, report.visibility]); | ||||||
|
||||||
const menuItems: ReportDetailsPageMenuItem[] = useMemo(() => { | ||||||
const items: ReportDetailsPageMenuItem[] = []; | ||||||
|
||||||
if (isSelfDM) { | ||||||
return []; | ||||||
} | ||||||
|
||||||
if (!isGroupDMChat) { | ||||||
items.push({ | ||||||
key: CONST.REPORT_DETAILS_MENU_ITEM.SHARE_CODE, | ||||||
translationKey: 'common.shareCode', | ||||||
icon: Expensicons.QrCode, | ||||||
isAnonymousAction: true, | ||||||
action: () => Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS_SHARE_CODE.getRoute(report?.reportID ?? '')), | ||||||
}); | ||||||
} | ||||||
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. Yeah so - in removing this for all chats we need to show the |
||||||
|
||||||
if (isArchivedRoom) { | ||||||
return items; | ||||||
} | ||||||
|
@@ -194,21 +200,42 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |||||
}); | ||||||
} | ||||||
|
||||||
if (isGroupChat || (isChatRoom && canJoinOrLeave && !canJoin)) { | ||||||
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.
Suggested change
|
||||||
items.push({ | ||||||
key: CONST.REPORT_DETAILS_MENU_ITEM.LEAVE_ROOM, | ||||||
translationKey: 'common.leave', | ||||||
icon: Expensicons.Exit, | ||||||
isAnonymousAction: true, | ||||||
shouldShowRightIcon: false, | ||||||
action: () => { | ||||||
if (Object.keys(report?.participants ?? {}).length === 1 && isGroupChat) { | ||||||
setIsLastMemberLeavingGroupModalVisible(true); | ||||||
return; | ||||||
} | ||||||
|
||||||
leaveChat(); | ||||||
}, | ||||||
}); | ||||||
} | ||||||
|
||||||
return items; | ||||||
}, [ | ||||||
isSelfDM, | ||||||
isArchivedRoom, | ||||||
participants.length, | ||||||
isGroupChat, | ||||||
isDefaultRoom, | ||||||
isChatThread, | ||||||
isMoneyRequestReport, | ||||||
report, | ||||||
isGroupDMChat, | ||||||
isPolicyEmployee, | ||||||
isUserCreatedPolicyRoom, | ||||||
session, | ||||||
isSelfDM, | ||||||
isDefaultRoom, | ||||||
participants.length, | ||||||
report, | ||||||
isMoneyRequestReport, | ||||||
isChatRoom, | ||||||
canJoinOrLeave, | ||||||
canJoin, | ||||||
activeChatMembers.length, | ||||||
isGroupChat, | ||||||
session, | ||||||
leaveChat, | ||||||
]); | ||||||
|
||||||
const displayNamesWithTooltips = useMemo(() => { | ||||||
|
@@ -313,7 +340,10 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |||||
</View> | ||||||
</View> | ||||||
{shouldShowReportDescription && ( | ||||||
<OfflineWithFeedback pendingAction={report.pendingFields?.description}> | ||||||
<OfflineWithFeedback | ||||||
pendingAction={report.pendingFields?.description} | ||||||
style={styles.mb5} | ||||||
> | ||||||
<MenuItemWithTopDescription | ||||||
shouldShowRightIcon={canEditReportDescription} | ||||||
interactive={canEditReportDescription} | ||||||
|
@@ -325,7 +355,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |||||
/> | ||||||
</OfflineWithFeedback> | ||||||
)} | ||||||
{isGroupChat && <ChatDetailsQuickActionsBar report={report} />} | ||||||
{(isGroupChat || isChatRoom) && <ChatDetailsQuickActionsBar report={report} />} | ||||||
{menuItems.map((item) => { | ||||||
const brickRoadIndicator = | ||||||
ReportUtils.hasReportNameError(report) && item.key === CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined; | ||||||
|
@@ -337,12 +367,25 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD | |||||
icon={item.icon} | ||||||
onPress={item.action} | ||||||
isAnonymousAction={item.isAnonymousAction} | ||||||
shouldShowRightIcon | ||||||
shouldShowRightIcon={item.shouldShowRightIcon ?? true} | ||||||
brickRoadIndicator={brickRoadIndicator ?? item.brickRoadIndicator} | ||||||
/> | ||||||
); | ||||||
})} | ||||||
</ScrollView> | ||||||
<ConfirmModal | ||||||
danger | ||||||
title={translate('groupChat.lastMemberTitle')} | ||||||
isVisible={isLastMemberLeavingGroupModalVisible} | ||||||
onConfirm={() => { | ||||||
setIsLastMemberLeavingGroupModalVisible(false); | ||||||
Report.leaveGroupChat(report.reportID); | ||||||
}} | ||||||
onCancel={() => setIsLastMemberLeavingGroupModalVisible(false)} | ||||||
prompt={translate('groupChat.lastMemberWarning')} | ||||||
confirmText={translate('common.leave')} | ||||||
cancelText={translate('common.cancel')} | ||||||
/> | ||||||
</FullPageNotFoundView> | ||||||
</ScreenWrapper> | ||||||
); | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
canJoinOrLeave
is only used once. I think we should remove this variable