Skip to content

Commit 87eedb0

Browse files
authored
Merge pull request Expensify#75161 from Krishna2323/krishna2323/issue/73833
fix: The send attachment modal is not closed when admin changes who can post to Admins only.
2 parents 4e60a2f + fce6269 commit 87eedb0

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

  • src/pages/media/AttachmentModalScreen/routes/report/ReportAddAttachmentModalContent

src/pages/media/AttachmentModalScreen/routes/report/ReportAddAttachmentModalContent/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
22
import type {View} from 'react-native';
33
import useNetwork from '@hooks/useNetwork';
44
import useOnyx from '@hooks/useOnyx';
5+
import useReportIsArchived from '@hooks/useReportIsArchived';
56
import {openReport} from '@libs/actions/Report';
67
import validateAttachmentFile from '@libs/AttachmentUtils';
78
import type {AttachmentValidationResult} from '@libs/AttachmentUtils';
89
import {getValidatedImageSource} from '@libs/AvatarUtils';
9-
import {isReportNotFound} from '@libs/ReportUtils';
10+
import Navigation from '@libs/Navigation/Navigation';
11+
import {canUserPerformWriteAction, isReportNotFound} from '@libs/ReportUtils';
1012
import type {AttachmentModalBaseContentProps} from '@pages/media/AttachmentModalScreen/AttachmentModalBaseContent/types';
1113
import AttachmentModalContainer from '@pages/media/AttachmentModalScreen/AttachmentModalContainer';
1214
import useDownloadAttachment from '@pages/media/AttachmentModalScreen/routes/hooks/useDownloadAttachment';
@@ -45,7 +47,8 @@ function ReportAddAttachmentModalContent({route, navigation}: AttachmentModalScr
4547
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, {
4648
canBeMissing: false,
4749
});
48-
50+
const isReportArchived = useReportIsArchived(reportID);
51+
const canPerformWriteAction = canUserPerformWriteAction(report, isReportArchived);
4952
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
5053
const {isOffline} = useNetwork();
5154

@@ -62,6 +65,14 @@ function ReportAddAttachmentModalContent({route, navigation}: AttachmentModalScr
6265
openReport(reportID, reportActionID);
6366
}, [reportID, reportActionID]);
6467

68+
// Close the modal if user loses write access (e.g., admin switches "Who can post" to Admins only)
69+
useEffect(() => {
70+
if (canPerformWriteAction || !report || isEmptyObject(report)) {
71+
return;
72+
}
73+
Navigation.dismissModal();
74+
}, [canPerformWriteAction, report]);
75+
6576
useEffect(() => {
6677
if (!reportID || !shouldFetchReport) {
6778
return;

0 commit comments

Comments
 (0)