@@ -2,11 +2,13 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
22import type { View } from 'react-native' ;
33import useNetwork from '@hooks/useNetwork' ;
44import useOnyx from '@hooks/useOnyx' ;
5+ import useReportIsArchived from '@hooks/useReportIsArchived' ;
56import { openReport } from '@libs/actions/Report' ;
67import validateAttachmentFile from '@libs/AttachmentUtils' ;
78import type { AttachmentValidationResult } from '@libs/AttachmentUtils' ;
89import { getValidatedImageSource } from '@libs/AvatarUtils' ;
9- import { isReportNotFound } from '@libs/ReportUtils' ;
10+ import Navigation from '@libs/Navigation/Navigation' ;
11+ import { canUserPerformWriteAction , isReportNotFound } from '@libs/ReportUtils' ;
1012import type { AttachmentModalBaseContentProps } from '@pages/media/AttachmentModalScreen/AttachmentModalBaseContent/types' ;
1113import AttachmentModalContainer from '@pages/media/AttachmentModalScreen/AttachmentModalContainer' ;
1214import 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