Skip to content

Commit

Permalink
rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
nkdengineer committed May 4, 2024
1 parent 8407f6d commit 535848c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5476,7 +5476,7 @@ function temporary_getMoneyRequestOptions(
/**
* Invoice sender, invoice receiver and auto-invited admins cannot leave
*/
function canJoinOrLeaveInvoiceRoom(report: OnyxEntry<Report>): boolean {
function canLeaveInvoiceRoom(report: OnyxEntry<Report>): boolean {
if (!isInvoiceRoom(report)) {
return false;
}
Expand Down Expand Up @@ -6405,7 +6405,7 @@ function canJoinChat(report: OnyxEntry<Report>, parentReportAction: OnyxEntry<Re
}

// Anyone viewing these chat types is already a participant and therefore cannot join
if (isRootGroupChat(report) || isSelfDM(report)) {
if (isRootGroupChat(report) || isSelfDM(report) || isInvoiceRoom(report)) {
return false;
}

Expand All @@ -6414,17 +6414,17 @@ function canJoinChat(report: OnyxEntry<Report>, parentReportAction: OnyxEntry<Re
return false;
}

if (canJoinOrLeaveInvoiceRoom(report)) {
return true;
}

return isChatThread(report) || isUserCreatedPolicyRoom(report) || isNonAdminOrOwnerOfPolicyExpenseChat(report, policy);
}

/**
* Whether the user can leave a report
*/
function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boolean {
if (report?.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
return false;
}

// Anyone viewing these chat types is already a participant and therefore cannot leave
if (isSelfDM(report) || isRootGroupChat(report)) {
return false;
Expand All @@ -6435,7 +6435,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo
return false;
}

if (canJoinOrLeaveInvoiceRoom(report)) {
if (canLeaveInvoiceRoom(report)) {
return true;
}

Expand Down
5 changes: 1 addition & 4 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
const isInvoiceReport = useMemo(() => ReportUtils.isInvoiceReport(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]);
Expand All @@ -107,8 +105,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
const isPrivateNotesFetchTriggered = report?.isLoadingPrivateNotes !== undefined;

const isSelfDM = useMemo(() => ReportUtils.isSelfDM(report), [report]);
const canLeave =
!isSelfDM && (isChatThread || isUserCreatedPolicyRoom || canLeaveRoom || canLeavePolicyExpenseChat) && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
const canLeave = ReportUtils.canLeaveChat(report, policy ?? null);

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.
Expand Down

0 comments on commit 535848c

Please sign in to comment.