diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 3b192bd39c72..7d7597c103c0 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -2414,6 +2414,7 @@ const ROUTES = { route: 'share/share-details/:reportOrAccountID', getRoute: (reportOrAccountID: string) => `share/share-details/${reportOrAccountID}` as const, }, + SHARE_DETAILS_ATTACHMENT: 'share/details/:reportOrAccountID/attachment', SHARE_SUBMIT_DETAILS: { route: 'share/submit-details/:reportOrAccountID', getRoute: (reportOrAccountID: string) => `share/submit-details/${reportOrAccountID}` as const, diff --git a/src/SCREENS.ts b/src/SCREENS.ts index acbdd26627cb..f651d0e26973 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -791,6 +791,7 @@ const SCREENS = { SHARE: { ROOT: 'Share_Root', SHARE_DETAILS: 'Share_Details', + SHARE_DETAILS_ATTACHMENT: 'Share_Details_Attachment', SUBMIT_DETAILS: 'Submit_Details', }, TRANSACTION_RECEIPT: 'TransactionReceipt', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index 7434e4ff9c72..dfa339785594 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -56,6 +56,8 @@ import SCREENS from '@src/SCREENS'; import type ReactComponentModule from '@src/types/utils/ReactComponentModule'; import useModalStackScreenOptions from './useModalStackScreenOptions'; +const loadAttachmentModalScreen = () => require('../../../../pages/media/AttachmentModalScreen').default; + type Screens = Partial React.ComponentType>>; const OPTIONS_PER_SCREEN: Partial> = { @@ -896,6 +898,7 @@ const RestrictedActionModalStackNavigator = createModalStackNavigator({ [SCREENS.SHARE.ROOT]: () => require('@pages/Share/ShareRootPage').default, [SCREENS.SHARE.SHARE_DETAILS]: () => require('@pages/Share/ShareDetailsPage').default, + [SCREENS.SHARE.SHARE_DETAILS_ATTACHMENT]: loadAttachmentModalScreen, [SCREENS.SHARE.SUBMIT_DETAILS]: () => require('@pages/Share/SubmitDetailsPage').default, }); diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 8f024598db67..9bca1bb44e65 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -1882,6 +1882,7 @@ const config: LinkingOptions['config'] = { }, }, [SCREENS.SHARE.SHARE_DETAILS]: {path: ROUTES.SHARE_DETAILS.route}, + [SCREENS.SHARE.SHARE_DETAILS_ATTACHMENT]: {path: ROUTES.SHARE_DETAILS_ATTACHMENT}, [SCREENS.SHARE.SUBMIT_DETAILS]: {path: ROUTES.SHARE_SUBMIT_DETAILS.route}, }, }, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 28ad145a4de6..298b054e5ad6 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -2440,6 +2440,7 @@ type SharedScreensParamList = { type ShareNavigatorParamList = { [SCREENS.SHARE.ROOT]: undefined; [SCREENS.SHARE.SHARE_DETAILS]: {reportOrAccountID: string}; + [SCREENS.SHARE.SHARE_DETAILS_ATTACHMENT]: {reportOrAccountID: string}; [SCREENS.SHARE.SUBMIT_DETAILS]: {reportOrAccountID: string}; }; @@ -2521,6 +2522,12 @@ type AttachmentModalScreensParamList = { iouType: IOUType; readonly: string; }; + [SCREENS.SHARE.SHARE_DETAILS_ATTACHMENT]: AttachmentModalContainerModalProps & { + source?: AvatarSource; + fallbackSource?: AvatarSource; + originalFileName?: string; + headerTitle?: string; + }; }; type AuthScreensParamList = SharedScreensParamList & diff --git a/src/pages/Share/ShareDetailsPage.tsx b/src/pages/Share/ShareDetailsPage.tsx index faa42e5705d5..1ea715172b17 100644 --- a/src/pages/Share/ShareDetailsPage.tsx +++ b/src/pages/Share/ShareDetailsPage.tsx @@ -1,9 +1,8 @@ import type {StackScreenProps} from '@react-navigation/stack'; import reportsSelector from '@selectors/Attributes'; -import React, {useEffect, useMemo, useState} from 'react'; -import {SafeAreaView, View} from 'react-native'; +import React, {useCallback, useContext, useEffect, useMemo, useState} from 'react'; +import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import AttachmentModal from '@components/AttachmentModal'; import AttachmentPreview from '@components/AttachmentPreview'; import Button from '@components/Button'; import FixedFooter from '@components/FixedFooter'; @@ -28,6 +27,7 @@ import {getReportDisplayOption} from '@libs/OptionsListUtils'; import {shouldValidateFile} from '@libs/ReceiptUtils'; import {getReportOrDraftReport, isDraftReport} from '@libs/ReportUtils'; import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; +import AttachmentModalContext from '@pages/media/AttachmentModalScreen/AttachmentModalContext'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -41,11 +41,9 @@ import {showErrorAlert} from './ShareRootPage'; type ShareDetailsPageProps = StackScreenProps; -function ShareDetailsPage({ - route: { - params: {reportOrAccountID}, - }, -}: ShareDetailsPageProps) { +function ShareDetailsPage({route}: ShareDetailsPageProps) { + const {reportOrAccountID} = route.params; + const styles = useThemeStyles(); const {translate} = useLocalize(); const [unknownUserDetails] = useOnyx(ONYXKEYS.SHARE_UNKNOWN_USER_DETAILS, {canBeMissing: true}); @@ -67,6 +65,17 @@ function ShareDetailsPage({ const validateFileName = shouldUsePreValidatedFile ? getFileName(validatedFile?.uri ?? CONST.ATTACHMENT_IMAGE_DEFAULT_NAME) : getFileName(currentAttachment?.content ?? ''); const fileType = shouldUsePreValidatedFile ? (validatedFile?.type ?? CONST.SHARE_FILE_MIMETYPE.JPEG) : (currentAttachment?.mimeType ?? ''); + const reportAttachmentsContext = useContext(AttachmentModalContext); + const showAttachmentModalScreen = useCallback(() => { + reportAttachmentsContext.setCurrentAttachment({ + source: fileSource, + headerTitle: validateFileName, + originalFileName: validateFileName, + fallbackSource: FallbackAvatar, + }); + Navigation.navigate(ROUTES.SHARE_DETAILS_ATTACHMENT); + }, [reportAttachmentsContext, fileSource, validateFileName]); + useEffect(() => { if (!currentAttachment?.content || errorTitle) { return; @@ -203,25 +212,14 @@ function ShareDetailsPage({ {translate('common.attachment')} - - - {({show}) => ( - { - showErrorAlert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); - }} - /> - )} - - + { + showErrorAlert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); + }} + /> )} diff --git a/src/pages/media/AttachmentModalScreen/index.tsx b/src/pages/media/AttachmentModalScreen/index.tsx index cbd1a9edf8dc..b85e55e9ea93 100644 --- a/src/pages/media/AttachmentModalScreen/index.tsx +++ b/src/pages/media/AttachmentModalScreen/index.tsx @@ -5,6 +5,7 @@ import ProfileAvatarModalContent from './routes/ProfileAvatarModalContent'; import ReportAddAttachmentModalContent from './routes/report/ReportAddAttachmentModalContent'; import ReportAttachmentModalContent from './routes/report/ReportAttachmentModalContent'; import ReportAvatarModalContent from './routes/report/ReportAvatarModalContent'; +import ShareDetailsAttachmentModalContent from './routes/ShareDetailsAttachmentModalContent'; import TransactionReceiptModalContent from './routes/TransactionReceiptModalContent'; import WorkspaceAvatarModalContent from './routes/WorkspaceAvatarModalContent'; import type {AttachmentModalScreenProps, AttachmentModalScreenType} from './types'; @@ -81,6 +82,15 @@ function AttachmentModalScreen({route, ); } + if (route.name === SCREENS.SHARE.SHARE_DETAILS_ATTACHMENT) { + return ( + } + navigation={navigation as NavigationType} + /> + ); + } + return null; } diff --git a/src/pages/media/AttachmentModalScreen/routes/ShareDetailsAttachmentModalContent.tsx b/src/pages/media/AttachmentModalScreen/routes/ShareDetailsAttachmentModalContent.tsx new file mode 100644 index 000000000000..c162ce37ed85 --- /dev/null +++ b/src/pages/media/AttachmentModalScreen/routes/ShareDetailsAttachmentModalContent.tsx @@ -0,0 +1,41 @@ +import React, {useMemo} from 'react'; +import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; +import type {AttachmentModalBaseContentProps} from '@pages/media/AttachmentModalScreen/AttachmentModalBaseContent/types'; +import AttachmentModalContainer from '@pages/media/AttachmentModalScreen/AttachmentModalContainer'; +import type {AttachmentModalScreenProps} from '@pages/media/AttachmentModalScreen/types'; +import type SCREENS from '@src/SCREENS'; +import useDownloadAttachment from './hooks/useDownloadAttachment'; +import useReportAttachmentModalType from './hooks/useReportAttachmentModalType'; + +function ShareDetailsAttachmentModalContent({route, navigation}: AttachmentModalScreenProps) { + const {source: sourceParam, originalFileName: originalFileNameParam, headerTitle, onShow, onClose} = route.params; + + const source = useMemo(() => Number(sourceParam) || (typeof sourceParam === 'string' ? tryResolveUrlFromApiRoot(decodeURIComponent(sourceParam)) : undefined), [sourceParam]); + const originalFileName = originalFileNameParam ?? ''; + + const onDownloadAttachment = useDownloadAttachment({}); + + const contentProps = useMemo( + () => ({ + source, + originalFileName, + headerTitle, + onDownloadAttachment, + }), + [headerTitle, onDownloadAttachment, originalFileName, source], + ); + + const modalType = useReportAttachmentModalType(source); + return ( + + navigation={navigation} + contentProps={contentProps} + modalType={modalType} + onShow={onShow} + onClose={onClose} + /> + ); +} +ShareDetailsAttachmentModalContent.displayName = 'ReportAttachmentModalContent'; + +export default ShareDetailsAttachmentModalContent; diff --git a/src/pages/media/AttachmentModalScreen/types.ts b/src/pages/media/AttachmentModalScreen/types.ts index b106b7eeebb7..1c0417787679 100644 --- a/src/pages/media/AttachmentModalScreen/types.ts +++ b/src/pages/media/AttachmentModalScreen/types.ts @@ -33,7 +33,8 @@ type AttachmentModalScreenType = | typeof SCREENS.PROFILE_AVATAR | typeof SCREENS.WORKSPACE_AVATAR | typeof SCREENS.TRANSACTION_RECEIPT - | typeof SCREENS.MONEY_REQUEST.RECEIPT_PREVIEW; + | typeof SCREENS.MONEY_REQUEST.RECEIPT_PREVIEW + | typeof SCREENS.SHARE.SHARE_DETAILS_ATTACHMENT; type AttachmentModalScreenBaseParams = AttachmentModalBaseContentProps & AttachmentModalContainerModalProps;