Skip to content

Commit

Permalink
Merge pull request #42312 from Ahmed-Abdella/handle-openning-attachme…
Browse files Browse the repository at this point in the history
…nts-without-access

Display blocking view and remove download button when user have no access to the report
  • Loading branch information
tylerkaraszewski authored May 30, 2024
2 parents a628b89 + f7fbbe6 commit 42e67e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import Str from 'expensify-common/lib/str';
import React, {memo, useCallback, useEffect, useMemo, useState} from 'react';
import {Animated, Keyboard, View} from 'react-native';
Expand Down Expand Up @@ -462,7 +463,7 @@ function AttachmentModal({
let shouldShowThreeDotsButton = false;
if (!isEmptyObject(report)) {
headerTitleNew = translate(isReceiptAttachment ? 'common.receipt' : 'common.attachment');
shouldShowDownloadButton = allowDownload && isDownloadButtonReadyToBeShown && !isReceiptAttachment && !isOffline;
shouldShowDownloadButton = allowDownload && isDownloadButtonReadyToBeShown && !shouldShowNotFoundPage && !isReceiptAttachment && !isOffline;
shouldShowThreeDotsButton = isReceiptAttachment && isModalOpen && threeDotsMenuItems.length !== 0;
}
const context = useMemo(
Expand Down Expand Up @@ -526,7 +527,8 @@ function AttachmentModal({
onLinkPress={() => Navigation.dismissModal()}
/>
)}
{!isEmptyObject(report) && !isReceiptAttachment ? (
{!shouldShowNotFoundPage && (
!isEmptyObject(report) && !isReceiptAttachment ? (
<AttachmentCarousel
accountID={accountID}
type={type}
Expand All @@ -540,7 +542,7 @@ function AttachmentModal({
!!sourceForAttachmentView &&
shouldLoadAttachment &&
!isLoading &&
!shouldShowNotFoundPage && (
(
<AttachmentCarouselPagerContext.Provider value={context}>
<AttachmentView
containerStyles={[styles.mh5]}
Expand All @@ -556,7 +558,7 @@ function AttachmentModal({
/>
</AttachmentCarouselPagerContext.Provider>
)
)}
))}
</View>
{/* If we have an onConfirm method show a confirmation button */}
{!!onConfirm && (
Expand Down
4 changes: 4 additions & 0 deletions src/pages/home/report/ReportAttachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type {AuthScreensParamList} from '@libs/Navigation/types';
import * as ReportUtils from '@libs/ReportUtils';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {useOnyx} from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';

type ReportAttachmentsProps = StackScreenProps<AuthScreensParamList, typeof SCREENS.ATTACHMENTS>;

Expand All @@ -16,6 +18,7 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
const type = route.params.type;
const accountID = route.params.accountID;
const report = ReportUtils.getReport(reportID);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP)

// In native the imported images sources are of type number. Ref: https://reactnative.dev/docs/image#imagesource
const source = Number(route.params.source) || route.params.source;
Expand All @@ -42,6 +45,7 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
ComposerFocusManager.setReadyToFocus();
}}
onCarouselAttachmentChange={onCarouselAttachmentChange}
shouldShowNotFoundPage={!isLoadingApp && !report?.reportID}
/>
);
}
Expand Down

0 comments on commit 42e67e7

Please sign in to comment.