From a986d03a897d7e4a1aebaf820c71682de9627704 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 6 Jun 2025 12:12:55 +0200 Subject: [PATCH 01/14] refactor: update FileObject imports --- .../AttachmentPicker/index.native.tsx | 2 +- src/components/AttachmentPicker/index.tsx | 2 +- src/components/AttachmentPicker/types.ts | 2 +- src/components/Attachments/types.ts | 2 +- src/components/AvatarWithImagePicker.tsx | 216 +++++++++--------- .../Composer/implementation/index.native.tsx | 2 +- src/components/Composer/types.ts | 2 +- src/components/FilePicker/index.native.tsx | 2 +- src/components/FilePicker/types.ts | 2 +- src/components/Form/types.ts | 2 +- .../ImportOnyxState/BaseImportOnyxState.tsx | 2 +- .../ImportOnyxState/index.native.tsx | 4 +- src/components/ImportOnyxState/index.tsx | 4 +- src/components/ImportSpreadsheet.tsx | 2 +- src/components/UploadFile.tsx | 2 +- .../AddCommentOrAttachmentParams.ts | 2 +- ...veCorpayOnboardingBeneficialOwnerParams.ts | 2 +- ...rpayOnboardingDirectorInformationParams.ts | 2 +- src/libs/AttachmentUtils.ts | 105 +++++++++ .../index.native.ts | 7 + .../attachmentModalScreenOptions/index.ts | 9 + src/libs/ReportUtils.ts | 2 +- src/libs/actions/Report.ts | 2 +- .../actions/setTestReceipt/index.native.ts | 2 +- src/libs/actions/setTestReceipt/types.ts | 2 +- src/libs/fileDownload/FileUtils.ts | 2 +- .../heicConverter/index.native.ts | 2 +- src/libs/fileDownload/heicConverter/types.ts | 2 +- src/libs/isFileUploadable/index.native.ts | 2 +- src/libs/isFileUploadable/index.ts | 2 +- .../Documents.tsx | 2 +- .../SignerInfo/subSteps/UploadDocuments.tsx | 2 +- ...DetailsAndOwnerFilesForBeneficialOwners.ts | 2 +- ...ignerDetailsAndSignerFilesForSignerInfo.ts | 2 +- .../utils/getValuesForBeneficialOwner.ts | 2 +- .../NonUSD/utils/getValuesForSignerInfo.ts | 2 +- src/pages/Search/SearchPage.tsx | 2 +- src/pages/Share/ShareRootPage.tsx | 2 +- .../AttachmentPickerWithMenuItems.tsx | 2 +- .../ComposerWithSuggestions.tsx | 2 +- .../ReportActionCompose.tsx | 2 +- .../step/IOURequestStepConfirmation.tsx | 2 +- .../step/IOURequestStepScan/index.native.tsx | 2 +- .../request/step/IOURequestStepScan/index.tsx | 2 +- .../request/step/IOURequestStepScan/types.ts | 2 +- src/stories/Composer.stories.tsx | 2 +- src/types/form/ReimbursementAccountForm.ts | 2 +- src/types/utils/SvgIconComponent.ts | 5 + 48 files changed, 281 insertions(+), 151 deletions(-) create mode 100644 src/libs/AttachmentUtils.ts create mode 100644 src/libs/Navigation/AppNavigator/attachmentModalScreenOptions/index.native.ts create mode 100644 src/libs/Navigation/AppNavigator/attachmentModalScreenOptions/index.ts create mode 100644 src/types/utils/SvgIconComponent.ts diff --git a/src/components/AttachmentPicker/index.native.tsx b/src/components/AttachmentPicker/index.native.tsx index 12b7df052152..edcd5e698d67 100644 --- a/src/components/AttachmentPicker/index.native.tsx +++ b/src/components/AttachmentPicker/index.native.tsx @@ -8,7 +8,6 @@ import RNFetchBlob from 'react-native-blob-util'; import {launchImageLibrary} from 'react-native-image-picker'; import type {Asset, Callback, CameraOptions, ImageLibraryOptions, ImagePickerResponse} from 'react-native-image-picker'; import ImageSize from 'react-native-image-size'; -import type {FileObject, ImagePickerResponse as FileResponse} from '@components/AttachmentModal'; import * as Expensicons from '@components/Icon/Expensicons'; import MenuItem from '@components/MenuItem'; import Popover from '@components/Popover'; @@ -20,6 +19,7 @@ import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import {cleanFileName, showCameraPermissionsAlert, verifyFileFormat} from '@libs/fileDownload/FileUtils'; +import type {FileObject, ImagePickerResponse as FileResponse} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import type IconAsset from '@src/types/utils/IconAsset'; diff --git a/src/components/AttachmentPicker/index.tsx b/src/components/AttachmentPicker/index.tsx index 5b4dd6c4d7f2..1b11bdcf047e 100644 --- a/src/components/AttachmentPicker/index.tsx +++ b/src/components/AttachmentPicker/index.tsx @@ -1,8 +1,8 @@ import React, {useRef} from 'react'; import type {ValueOf} from 'type-fest'; -import type {FileObject} from '@components/AttachmentModal'; import {isMobileChrome} from '@libs/Browser'; import Visibility from '@libs/Visibility'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type AttachmentPickerProps from './types'; diff --git a/src/components/AttachmentPicker/types.ts b/src/components/AttachmentPicker/types.ts index b39f95e9198a..3a857ea6cb74 100644 --- a/src/components/AttachmentPicker/types.ts +++ b/src/components/AttachmentPicker/types.ts @@ -1,6 +1,6 @@ import type {ReactNode} from 'react'; import type {ValueOf} from 'type-fest'; -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type CONST from '@src/CONST'; type PickerOptions = { diff --git a/src/components/Attachments/types.ts b/src/components/Attachments/types.ts index f394799dfce4..617b9e80c3af 100644 --- a/src/components/Attachments/types.ts +++ b/src/components/Attachments/types.ts @@ -1,4 +1,4 @@ -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type IconAsset from '@src/types/utils/IconAsset'; type AttachmentSource = string | IconAsset | number; diff --git a/src/components/AvatarWithImagePicker.tsx b/src/components/AvatarWithImagePicker.tsx index f07afb9c4513..d99a81c8b6d3 100644 --- a/src/components/AvatarWithImagePicker.tsx +++ b/src/components/AvatarWithImagePicker.tsx @@ -1,5 +1,5 @@ import {useIsFocused} from '@react-navigation/native'; -import React, {useCallback, useEffect, useRef, useState} from 'react'; +import React, {useCallback, useContext, useEffect, useRef, useState} from 'react'; import {StyleSheet, View} from 'react-native'; import type {ImageStyle, StyleProp, ViewStyle} from 'react-native'; import useLocalize from '@hooks/useLocalize'; @@ -10,13 +10,15 @@ import {isSafari} from '@libs/Browser'; import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types'; import {splitExtensionFromFileName, validateImageForCorruption} from '@libs/fileDownload/FileUtils'; import getImageResolution from '@libs/fileDownload/getImageResolution'; +import Navigation from '@libs/Navigation/Navigation'; import type {AvatarSource} from '@libs/UserUtils'; +import AttachmentModalContext from '@pages/media/AttachmentModalScreen/AttachmentModalContext'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; +import ROUTES from '@src/ROUTES'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type IconAsset from '@src/types/utils/IconAsset'; -import AttachmentModal from './AttachmentModal'; import type {FileObject} from './AttachmentModal'; import AttachmentPicker from './AttachmentPicker'; import Avatar from './Avatar'; @@ -330,115 +332,117 @@ function AvatarWithImagePicker({ [disabled, enablePreview, isUsingDefaultAvatar, onViewPhotoPress, showAvatarCropModal], ); + const reportAttachmentsContext = useContext(AttachmentModalContext); + const showAttachmentModalScreen = useCallback(() => { + reportAttachmentsContext.setCurrentAttachment({ + source: previewSource, + fallbackSource: fallbackIcon, + headerTitle, + originalFileName, + maybeIcon: isUsingDefaultAvatar, + }); + Navigation.navigate(ROUTES.ATTACHMENTS.getRoute()); + }, [fallbackIcon, headerTitle, isUsingDefaultAvatar, originalFileName, previewSource, reportAttachmentsContext]); + return ( - - {({show}) => ( - - {({openPicker}) => { - const menuItems = createMenuItems(openPicker); - - // If the current avatar isn't a default avatar and we are not overriding this behavior allow the "View Photo" option - if (!shouldDisableViewPhoto && !isUsingDefaultAvatar) { - menuItems.push({ - icon: Expensicons.Eye, - text: translate('avatarWithImagePicker.viewPhoto'), - onSelected: () => { - if (typeof onViewPhotoPress !== 'function') { - show(); - return; - } - onViewPhotoPress(); - }, - shouldCallAfterModalHide: true, - }); - } - - return ( - <> - { + const menuItems = createMenuItems(openPicker); + + // If the current avatar isn't a default avatar and we are not overriding this behavior allow the "View Photo" option + if (!shouldDisableViewPhoto && !isUsingDefaultAvatar) { + menuItems.push({ + icon: Expensicons.Eye, + text: translate('avatarWithImagePicker.viewPhoto'), + onSelected: () => { + if (typeof onViewPhotoPress !== 'function') { + showAttachmentModalScreen(); + return; + } + onViewPhotoPress(); + }, + shouldCallAfterModalHide: true, + }); + } + + return ( + <> + + + onPressAvatar(openPicker)} + accessibilityRole={CONST.ROLE.BUTTON} + accessibilityLabel={translate('avatarWithImagePicker.editImage')} + disabled={isAvatarCropModalOpen || (disabled && !enablePreview)} + disabledStyle={disabledStyle} + style={[styles.pRelative, type === CONST.ICON_TYPE_AVATAR && styles.alignSelfCenter, avatarStyle]} + ref={anchorRef} > - - onPressAvatar(openPicker)} - accessibilityRole={CONST.ROLE.BUTTON} - accessibilityLabel={translate('avatarWithImagePicker.editImage')} - disabled={isAvatarCropModalOpen || (disabled && !enablePreview)} - disabledStyle={disabledStyle} - style={[styles.pRelative, type === CONST.ICON_TYPE_AVATAR && styles.alignSelfCenter, avatarStyle]} - ref={anchorRef} - > - - {source ? ( - - ) : ( - - )} - - {!disabled && ( - - - - )} - - - - setIsMenuVisible(false)} - onItemSelected={(item, index) => { - setIsMenuVisible(false); - // In order for the file picker to open dynamically, the click - // function must be called from within an event handler that was initiated - // by the user on Safari. - if (index === 0 && isSafari()) { - openPicker({ - onPicked: (data) => showAvatarCropModal(data.at(0) ?? {}), - }); - } - }} - menuItems={menuItems} - anchorPosition={shouldUseStyleUtilityForAnchorPosition ? styles.popoverMenuOffset(windowWidth) : popoverPosition} - anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}} - withoutOverlay - anchorRef={anchorRef} - /> - - ); - }} - - )} - + + {source ? ( + + ) : ( + + )} + + {!disabled && ( + + + + )} + + + + setIsMenuVisible(false)} + onItemSelected={(item, index) => { + setIsMenuVisible(false); + // In order for the file picker to open dynamically, the click + // function must be called from within an event handler that was initiated + // by the user on Safari. + if (index === 0 && isSafari()) { + openPicker({ + onPicked: (data) => showAvatarCropModal(data.at(0) ?? {}), + }); + } + }} + menuItems={menuItems} + anchorPosition={shouldUseStyleUtilityForAnchorPosition ? styles.popoverMenuOffset(windowWidth) : popoverPosition} + anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}} + withoutOverlay + anchorRef={anchorRef} + /> + + ); + }} + {!!errorData.validationError && ( = []; diff --git a/src/components/Composer/types.ts b/src/components/Composer/types.ts index f4814bd1d9cb..7ecf77add492 100644 --- a/src/components/Composer/types.ts +++ b/src/components/Composer/types.ts @@ -1,5 +1,5 @@ import type {NativeSyntheticEvent, StyleProp, TextInputProps, TextInputSelectionChangeEventData, TextStyle} from 'react-native'; -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; type TextSelection = { start: number; diff --git a/src/components/FilePicker/index.native.tsx b/src/components/FilePicker/index.native.tsx index e1e0e78b676a..a7eb47347b08 100644 --- a/src/components/FilePicker/index.native.tsx +++ b/src/components/FilePicker/index.native.tsx @@ -2,9 +2,9 @@ import {keepLocalCopy, pick, types} from '@react-native-documents/picker'; import React, {useCallback, useRef} from 'react'; import {Alert} from 'react-native'; import RNFetchBlob from 'react-native-blob-util'; -import type {FileObject} from '@components/AttachmentModal'; import useLocalize from '@hooks/useLocalize'; import {cleanFileName} from '@libs/fileDownload/FileUtils'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type FilePickerProps from './types'; type LocalCopy = { diff --git a/src/components/FilePicker/types.ts b/src/components/FilePicker/types.ts index f2887ea4425b..f7b5a8b94e0a 100644 --- a/src/components/FilePicker/types.ts +++ b/src/components/FilePicker/types.ts @@ -1,5 +1,5 @@ import type {ReactNode} from 'react'; -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; type PickerOptions = { /** A callback that will be called with the selected file. */ diff --git a/src/components/Form/types.ts b/src/components/Form/types.ts index c135946f70f2..f8ab47fc6d47 100644 --- a/src/components/Form/types.ts +++ b/src/components/Form/types.ts @@ -6,7 +6,6 @@ import type AddressSearch from '@components/AddressSearch'; import type AmountForm from '@components/AmountForm'; import type AmountPicker from '@components/AmountPicker'; import type AmountTextInput from '@components/AmountTextInput'; -import type {FileObject} from '@components/AttachmentModal'; import type CheckboxWithLabel from '@components/CheckboxWithLabel'; import type CountryPicker from '@components/CountryPicker'; import type CountrySelector from '@components/CountrySelector'; @@ -27,6 +26,7 @@ import type TimeModalPicker from '@components/TimeModalPicker'; import type UploadFile from '@components/UploadFile'; import type ValuePicker from '@components/ValuePicker'; import type ConstantSelector from '@pages/Debug/ConstantSelector'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type BusinessTypePicker from '@pages/ReimbursementAccount/USD/BusinessInfo/subSteps/TypeBusiness/BusinessTypePicker'; import type DimensionTypeSelector from '@pages/workspace/accounting/intacct/import/DimensionTypeSelector'; import type NetSuiteCustomFieldMappingPicker from '@pages/workspace/accounting/netsuite/import/NetSuiteImportCustomFieldNew/NetSuiteCustomFieldMappingPicker'; diff --git a/src/components/ImportOnyxState/BaseImportOnyxState.tsx b/src/components/ImportOnyxState/BaseImportOnyxState.tsx index 3362bc764446..a93b5dfa643e 100644 --- a/src/components/ImportOnyxState/BaseImportOnyxState.tsx +++ b/src/components/ImportOnyxState/BaseImportOnyxState.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import type {FileObject} from '@components/AttachmentModal'; import AttachmentPicker from '@components/AttachmentPicker'; import DecisionModal from '@components/DecisionModal'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -7,6 +6,7 @@ import MenuItem from '@components/MenuItem'; import useLocalize from '@hooks/useLocalize'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; function BaseImportOnyxState({ onFileRead, diff --git a/src/components/ImportOnyxState/index.native.tsx b/src/components/ImportOnyxState/index.native.tsx index e3eca1993313..189e035d50e7 100644 --- a/src/components/ImportOnyxState/index.native.tsx +++ b/src/components/ImportOnyxState/index.native.tsx @@ -1,12 +1,12 @@ import React, {useState} from 'react'; import ReactNativeBlobUtil from 'react-native-blob-util'; import {useOnyx} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; import {setIsUsingImportedState, setPreservedUserSession} from '@libs/actions/App'; import {setShouldForceOffline} from '@libs/actions/Network'; import {rollbackOngoingRequest} from '@libs/actions/PersistedRequests'; import {cleanAndTransformState, importState} from '@libs/ImportOnyxStateUtils'; import Navigation from '@libs/Navigation/Navigation'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type {OnyxValues} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -26,7 +26,7 @@ function readOnyxFile(fileUri: string) { export default function ImportOnyxState({setIsLoading}: ImportOnyxStateProps) { const [isErrorModalVisible, setIsErrorModalVisible] = useState(false); - const [session] = useOnyx(ONYXKEYS.SESSION); + const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); const handleFileRead = (file: FileObject) => { if (!file.uri) { diff --git a/src/components/ImportOnyxState/index.tsx b/src/components/ImportOnyxState/index.tsx index 8f199a176539..024994ef2b0b 100644 --- a/src/components/ImportOnyxState/index.tsx +++ b/src/components/ImportOnyxState/index.tsx @@ -1,11 +1,11 @@ import React, {useState} from 'react'; import {useOnyx} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; import {setIsUsingImportedState, setPreservedUserSession} from '@libs/actions/App'; import {setShouldForceOffline} from '@libs/actions/Network'; import {rollbackOngoingRequest} from '@libs/actions/PersistedRequests'; import {cleanAndTransformState, importState} from '@libs/ImportOnyxStateUtils'; import Navigation from '@libs/Navigation/Navigation'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type {OnyxValues} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -14,7 +14,7 @@ import type ImportOnyxStateProps from './types'; export default function ImportOnyxState({setIsLoading}: ImportOnyxStateProps) { const [isErrorModalVisible, setIsErrorModalVisible] = useState(false); - const [session] = useOnyx(ONYXKEYS.SESSION); + const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false}); const handleFileRead = (file: FileObject) => { if (!file.uri) { diff --git a/src/components/ImportSpreadsheet.tsx b/src/components/ImportSpreadsheet.tsx index 64fe65241294..6f8f69fdab1a 100644 --- a/src/components/ImportSpreadsheet.tsx +++ b/src/components/ImportSpreadsheet.tsx @@ -11,11 +11,11 @@ import {setSpreadsheetData} from '@libs/actions/ImportSpreadsheet'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; import {splitExtensionFromFileName} from '@libs/fileDownload/FileUtils'; import Navigation from '@libs/Navigation/Navigation'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route as Routes} from '@src/ROUTES'; -import type {FileObject} from './AttachmentModal'; import Button from './Button'; import ConfirmModal from './ConfirmModal'; import DragAndDropConsumer from './DragAndDrop/Consumer'; diff --git a/src/components/UploadFile.tsx b/src/components/UploadFile.tsx index a7e394c164a6..b58eddf02de0 100644 --- a/src/components/UploadFile.tsx +++ b/src/components/UploadFile.tsx @@ -6,8 +6,8 @@ import useLocalize from '@hooks/useLocalize'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import {splitExtensionFromFileName} from '@libs/fileDownload/FileUtils'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; -import type {FileObject} from './AttachmentModal'; import AttachmentPicker from './AttachmentPicker'; import Button from './Button'; import DotIndicatorMessage from './DotIndicatorMessage'; diff --git a/src/libs/API/parameters/AddCommentOrAttachmentParams.ts b/src/libs/API/parameters/AddCommentOrAttachmentParams.ts index b2ee6bbc6661..b7a377b97a5e 100644 --- a/src/libs/API/parameters/AddCommentOrAttachmentParams.ts +++ b/src/libs/API/parameters/AddCommentOrAttachmentParams.ts @@ -1,4 +1,4 @@ -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; type AddCommentOrAttachmentParams = { reportID: string; diff --git a/src/libs/API/parameters/SaveCorpayOnboardingBeneficialOwnerParams.ts b/src/libs/API/parameters/SaveCorpayOnboardingBeneficialOwnerParams.ts index 58a9d261011d..d4fa717c868e 100644 --- a/src/libs/API/parameters/SaveCorpayOnboardingBeneficialOwnerParams.ts +++ b/src/libs/API/parameters/SaveCorpayOnboardingBeneficialOwnerParams.ts @@ -1,4 +1,4 @@ -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type {BeneficialOwnerDataKey} from '@src/types/form/ReimbursementAccountForm'; type SaveCorpayOnboardingBeneficialOwnerParams = { diff --git a/src/libs/API/parameters/SaveCorpayOnboardingDirectorInformationParams.ts b/src/libs/API/parameters/SaveCorpayOnboardingDirectorInformationParams.ts index bbbd1e0ac8f9..9a1db2a2f4b2 100644 --- a/src/libs/API/parameters/SaveCorpayOnboardingDirectorInformationParams.ts +++ b/src/libs/API/parameters/SaveCorpayOnboardingDirectorInformationParams.ts @@ -1,4 +1,4 @@ -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; type SaveCorpayOnboardingDirectorInformationParams = { inputs: string; diff --git a/src/libs/AttachmentUtils.ts b/src/libs/AttachmentUtils.ts new file mode 100644 index 000000000000..eea91499fa66 --- /dev/null +++ b/src/libs/AttachmentUtils.ts @@ -0,0 +1,105 @@ +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; +import CONST from '@src/CONST'; +import {cleanFileName, validateImageForCorruption} from './fileDownload/FileUtils'; + +type AttachmentValidationError = CorruptionError | 'fileDoesNotExist' | 'fileInvalid'; +type ValidResult = { + isValid: true; + fileType: 'file' | 'uri'; + source: string; + file: FileObject; +}; +type InvalidResult = { + isValid: false; + error: AttachmentValidationError; +}; + +type AttachmentValidationResult = ValidResult | InvalidResult; + +function validateAttachmentFile(file: FileObject): Promise { + if (!file || !isDirectoryCheck(file)) { + return Promise.resolve({isValid: false, error: 'fileDoesNotExist'}); + } + + let fileObject = file; + if ('getAsFile' in file && typeof file.getAsFile === 'function') { + fileObject = file.getAsFile() as FileObject; + } + if (!fileObject) { + return Promise.resolve({isValid: false, error: 'fileInvalid'}); + } + + return isFileCorrupted(fileObject).then((corruptionResult) => { + if (!corruptionResult.isValid) { + return corruptionResult as InvalidResult; + } + + if (fileObject instanceof File) { + /** + * Cleaning file name, done here so that it covers all cases: + * upload, drag and drop, copy-paste + */ + let updatedFile = fileObject; + const cleanName = cleanFileName(updatedFile.name); + if (updatedFile.name !== cleanName) { + updatedFile = new File([updatedFile], cleanName, {type: updatedFile.type}); + } + const inputSource = URL.createObjectURL(updatedFile); + updatedFile.uri = inputSource; + + return {isValid: true, fileType: 'file', source: inputSource, file: updatedFile} as ValidResult; + } + + return {isValid: true, fileType: 'uri', source: fileObject.uri, file: fileObject} as ValidResult; + }); +} + +type CorruptionError = 'tooLarge' | 'tooSmall' | 'error'; +type NoCorruptionResult = { + isValid: true; +}; +type CorruptionResult = { + isValid: false; + error: CorruptionError; +}; +type AttachmentCorruptionValidationResult = NoCorruptionResult | CorruptionResult; + +function isFileCorrupted(fileObject: FileObject): Promise { + return validateImageForCorruption(fileObject) + .then(() => { + if (fileObject.size && fileObject.size > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { + return { + isValid: false, + error: 'tooLarge', + } satisfies AttachmentCorruptionValidationResult; + } + + if (fileObject.size && fileObject.size < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { + return { + isValid: false, + error: 'tooSmall', + } satisfies AttachmentCorruptionValidationResult; + } + + return { + isValid: true, + } satisfies AttachmentCorruptionValidationResult; + }) + .catch(() => { + return { + isValid: false, + error: 'error', + }; + }); +} + +function isDirectoryCheck(data: FileObject) { + if ('webkitGetAsEntry' in data && (data as DataTransferItem).webkitGetAsEntry()?.isDirectory) { + return false; + } + + return true; +} + +export default validateAttachmentFile; +export type {AttachmentValidationResult}; diff --git a/src/libs/Navigation/AppNavigator/attachmentModalScreenOptions/index.native.ts b/src/libs/Navigation/AppNavigator/attachmentModalScreenOptions/index.native.ts new file mode 100644 index 000000000000..176911f1d05e --- /dev/null +++ b/src/libs/Navigation/AppNavigator/attachmentModalScreenOptions/index.native.ts @@ -0,0 +1,7 @@ +import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types'; + +const attachmentModalScreenOptions: PlatformStackNavigationOptions = { + headerShown: false, +}; + +export default attachmentModalScreenOptions; diff --git a/src/libs/Navigation/AppNavigator/attachmentModalScreenOptions/index.ts b/src/libs/Navigation/AppNavigator/attachmentModalScreenOptions/index.ts new file mode 100644 index 000000000000..88e2b90d0740 --- /dev/null +++ b/src/libs/Navigation/AppNavigator/attachmentModalScreenOptions/index.ts @@ -0,0 +1,9 @@ +import Presentation from '@libs/Navigation/PlatformStackNavigation/navigationOptions/presentation'; +import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types'; + +const attachmentModalScreenOptions: PlatformStackNavigationOptions = { + headerShown: false, + presentation: Presentation.TRANSPARENT_MODAL, +}; + +export default attachmentModalScreenOptions; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c07da3e53973..0d9d5fbd30c5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -13,11 +13,11 @@ import Onyx from 'react-native-onyx'; import type {SvgProps} from 'react-native-svg'; import type {OriginalMessageChangePolicy, OriginalMessageExportIntegration, OriginalMessageModifiedExpense, OriginalMessageMovedTransaction} from 'src/types/onyx/OriginalMessage'; import type {SetRequired, TupleToUnion, ValueOf} from 'type-fest'; -import type {FileObject} from '@components/AttachmentModal'; import {FallbackAvatar, IntacctSquare, NetSuiteSquare, QBOSquare, XeroSquare} from '@components/Icon/Expensicons'; import * as defaultGroupAvatars from '@components/Icon/GroupDefaultAvatars'; import * as defaultWorkspaceAvatars from '@components/Icon/WorkspaceDefaultAvatars'; import type {MoneyRequestAmountInputProps} from '@components/MoneyRequestAmountInput'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type {IOUAction, IOUType, OnboardingAccounting, OnboardingCompanySize, OnboardingPurpose, OnboardingTaskLinks} from '@src/CONST'; import CONST from '@src/CONST'; import type {ParentNavigationSummaryParams} from '@src/languages/params'; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 3fec9e2daeab..6ed0500a6d9c 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -7,7 +7,6 @@ import type {NullishDeep, OnyxCollection, OnyxCollectionInputValue, OnyxEntry, O import Onyx from 'react-native-onyx'; import type {PartialDeep, ValueOf} from 'type-fest'; import type {Emoji} from '@assets/emojis/types'; -import type {FileObject} from '@components/AttachmentModal'; import * as ActiveClientManager from '@libs/ActiveClientManager'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import * as API from '@libs/API'; @@ -153,6 +152,7 @@ import shouldSkipDeepLinkNavigation from '@libs/shouldSkipDeepLinkNavigation'; import playSound, {SOUNDS} from '@libs/Sound'; import {addTrailingForwardSlash} from '@libs/Url'; import Visibility from '@libs/Visibility'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONFIG from '@src/CONFIG'; import type {OnboardingAccounting, OnboardingCompanySize} from '@src/CONST'; import CONST from '@src/CONST'; diff --git a/src/libs/actions/setTestReceipt/index.native.ts b/src/libs/actions/setTestReceipt/index.native.ts index 49d547708edb..26b2df5539df 100644 --- a/src/libs/actions/setTestReceipt/index.native.ts +++ b/src/libs/actions/setTestReceipt/index.native.ts @@ -1,7 +1,7 @@ import {Image} from 'react-native'; import ReactNativeBlobUtil from 'react-native-blob-util'; -import type {FileObject} from '@components/AttachmentModal'; import Log from '@libs/Log'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import getFile from './getFile'; import type {SetTestReceipt} from './types'; diff --git a/src/libs/actions/setTestReceipt/types.ts b/src/libs/actions/setTestReceipt/types.ts index 785ea115bea3..b92ab18e3b3f 100644 --- a/src/libs/actions/setTestReceipt/types.ts +++ b/src/libs/actions/setTestReceipt/types.ts @@ -1,5 +1,5 @@ import type {ImageSourcePropType} from 'react-native'; -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; type OnFileRead = (source: string, file: FileObject, filename: string) => void; diff --git a/src/libs/fileDownload/FileUtils.ts b/src/libs/fileDownload/FileUtils.ts index 81fcb9847a2e..872068f9a72e 100644 --- a/src/libs/fileDownload/FileUtils.ts +++ b/src/libs/fileDownload/FileUtils.ts @@ -2,12 +2,12 @@ import {Str} from 'expensify-common'; import {Alert, Linking, Platform} from 'react-native'; import ImageSize from 'react-native-image-size'; import type {TupleToUnion} from 'type-fest'; -import type {FileObject} from '@components/AttachmentModal'; import DateUtils from '@libs/DateUtils'; import getPlatform from '@libs/getPlatform'; import {translateLocal} from '@libs/Localize'; import Log from '@libs/Log'; import saveLastRoute from '@libs/saveLastRoute'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import getImageManipulator from './getImageManipulator'; diff --git a/src/libs/fileDownload/heicConverter/index.native.ts b/src/libs/fileDownload/heicConverter/index.native.ts index b7f9c3798a40..04ec5e4f3e78 100644 --- a/src/libs/fileDownload/heicConverter/index.native.ts +++ b/src/libs/fileDownload/heicConverter/index.native.ts @@ -1,6 +1,6 @@ import {ImageManipulator, SaveFormat} from 'expo-image-manipulator'; -import type {FileObject} from '@components/AttachmentModal'; import {verifyFileFormat} from '@libs/fileDownload/FileUtils'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {HeicConverterFunction} from './types'; diff --git a/src/libs/fileDownload/heicConverter/types.ts b/src/libs/fileDownload/heicConverter/types.ts index 126d7dcb4ef8..21eda49bc34d 100644 --- a/src/libs/fileDownload/heicConverter/types.ts +++ b/src/libs/fileDownload/heicConverter/types.ts @@ -1,4 +1,4 @@ -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; type HeicConverterCallbacks = { onSuccess?: (convertedFile: FileObject) => void; diff --git a/src/libs/isFileUploadable/index.native.ts b/src/libs/isFileUploadable/index.native.ts index 602d2c319a74..c6226d86d652 100644 --- a/src/libs/isFileUploadable/index.native.ts +++ b/src/libs/isFileUploadable/index.native.ts @@ -1,4 +1,4 @@ -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; function isFileUploadable(file: FileObject | undefined): boolean { // Native platforms only require the object to include the `uri` property. diff --git a/src/libs/isFileUploadable/index.ts b/src/libs/isFileUploadable/index.ts index a2f985ed109d..1b0b63a87331 100644 --- a/src/libs/isFileUploadable/index.ts +++ b/src/libs/isFileUploadable/index.ts @@ -1,4 +1,4 @@ -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; function isFileUploadable(file: FileObject | undefined): boolean { return file instanceof Blob; diff --git a/src/pages/ReimbursementAccount/NonUSD/BeneficialOwnerInfo/BeneficialOwnerDetailsFormSubSteps/Documents.tsx b/src/pages/ReimbursementAccount/NonUSD/BeneficialOwnerInfo/BeneficialOwnerDetailsFormSubSteps/Documents.tsx index 515afdcd250b..49ce16260d74 100644 --- a/src/pages/ReimbursementAccount/NonUSD/BeneficialOwnerInfo/BeneficialOwnerDetailsFormSubSteps/Documents.tsx +++ b/src/pages/ReimbursementAccount/NonUSD/BeneficialOwnerInfo/BeneficialOwnerDetailsFormSubSteps/Documents.tsx @@ -1,7 +1,6 @@ import React, {useCallback, useMemo, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; @@ -12,6 +11,7 @@ import useReimbursementAccountStepFormSubmit from '@hooks/useReimbursementAccoun import type {SubStepProps} from '@hooks/useSubStep/types'; import useThemeStyles from '@hooks/useThemeStyles'; import {getFieldRequiredErrors} from '@libs/ValidationUtils'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import getNeededDocumentsStatusForBeneficialOwner from '@pages/ReimbursementAccount/NonUSD/utils/getNeededDocumentsStatusForBeneficialOwner'; import {clearErrorFields, setDraftValues, setErrorFields} from '@userActions/FormActions'; import CONST from '@src/CONST'; diff --git a/src/pages/ReimbursementAccount/NonUSD/SignerInfo/subSteps/UploadDocuments.tsx b/src/pages/ReimbursementAccount/NonUSD/SignerInfo/subSteps/UploadDocuments.tsx index 7eca7cddafdd..0f95f7215d77 100644 --- a/src/pages/ReimbursementAccount/NonUSD/SignerInfo/subSteps/UploadDocuments.tsx +++ b/src/pages/ReimbursementAccount/NonUSD/SignerInfo/subSteps/UploadDocuments.tsx @@ -1,7 +1,6 @@ import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; import Button from '@components/Button'; import DotIndicatorMessage from '@components/DotIndicatorMessage'; import FormProvider from '@components/Form/FormProvider'; @@ -15,6 +14,7 @@ import type {SubStepProps} from '@hooks/useSubStep/types'; import useThemeStyles from '@hooks/useThemeStyles'; import {getEnvironmentURL} from '@libs/Environment/Environment'; import {getFieldRequiredErrors} from '@libs/ValidationUtils'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import getNeededDocumentsStatusForSignerInfo from '@pages/ReimbursementAccount/NonUSD/utils/getNeededDocumentsStatusForSignerInfo'; import WhyLink from '@pages/ReimbursementAccount/NonUSD/WhyLink'; import {clearErrorFields, setDraftValues, setErrorFields} from '@userActions/FormActions'; diff --git a/src/pages/ReimbursementAccount/NonUSD/utils/getOwnerDetailsAndOwnerFilesForBeneficialOwners.ts b/src/pages/ReimbursementAccount/NonUSD/utils/getOwnerDetailsAndOwnerFilesForBeneficialOwners.ts index eeabcc9fa340..1b249f0a5054 100644 --- a/src/pages/ReimbursementAccount/NonUSD/utils/getOwnerDetailsAndOwnerFilesForBeneficialOwners.ts +++ b/src/pages/ReimbursementAccount/NonUSD/utils/getOwnerDetailsAndOwnerFilesForBeneficialOwners.ts @@ -1,5 +1,5 @@ import type {OnyxEntry} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {BeneficialOwnerDataKey, ReimbursementAccountForm} from '@src/types/form/ReimbursementAccountForm'; diff --git a/src/pages/ReimbursementAccount/NonUSD/utils/getSignerDetailsAndSignerFilesForSignerInfo.ts b/src/pages/ReimbursementAccount/NonUSD/utils/getSignerDetailsAndSignerFilesForSignerInfo.ts index f19a8bae0b8a..e7bd442802b5 100644 --- a/src/pages/ReimbursementAccount/NonUSD/utils/getSignerDetailsAndSignerFilesForSignerInfo.ts +++ b/src/pages/ReimbursementAccount/NonUSD/utils/getSignerDetailsAndSignerFilesForSignerInfo.ts @@ -1,5 +1,5 @@ import type {OnyxEntry} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {ReimbursementAccountForm} from '@src/types/form'; import type {BeneficialOwnerDataKey, SignerInfoStepProps} from '@src/types/form/ReimbursementAccountForm'; diff --git a/src/pages/ReimbursementAccount/NonUSD/utils/getValuesForBeneficialOwner.ts b/src/pages/ReimbursementAccount/NonUSD/utils/getValuesForBeneficialOwner.ts index 4483328718a8..991af2fc9f08 100644 --- a/src/pages/ReimbursementAccount/NonUSD/utils/getValuesForBeneficialOwner.ts +++ b/src/pages/ReimbursementAccount/NonUSD/utils/getValuesForBeneficialOwner.ts @@ -1,5 +1,5 @@ import type {OnyxEntry} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {ReimbursementAccountForm} from '@src/types/form'; diff --git a/src/pages/ReimbursementAccount/NonUSD/utils/getValuesForSignerInfo.ts b/src/pages/ReimbursementAccount/NonUSD/utils/getValuesForSignerInfo.ts index db98dd7d14db..bf3d7ae40d03 100644 --- a/src/pages/ReimbursementAccount/NonUSD/utils/getValuesForSignerInfo.ts +++ b/src/pages/ReimbursementAccount/NonUSD/utils/getValuesForSignerInfo.ts @@ -1,5 +1,5 @@ import type {OnyxEntry} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {ReimbursementAccountForm} from '@src/types/form'; diff --git a/src/pages/Search/SearchPage.tsx b/src/pages/Search/SearchPage.tsx index 4acf66993081..0a9cb205254a 100644 --- a/src/pages/Search/SearchPage.tsx +++ b/src/pages/Search/SearchPage.tsx @@ -1,7 +1,6 @@ import {Str} from 'expensify-common'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {InteractionManager, View} from 'react-native'; -import type {FileObject} from '@components/AttachmentModal'; import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types'; import ConfirmModal from '@components/ConfirmModal'; @@ -46,6 +45,7 @@ import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types'; import {hasVBBA} from '@libs/PolicyUtils'; import {generateReportID} from '@libs/ReportUtils'; import {buildCannedSearchQuery, buildSearchQueryJSON} from '@libs/SearchQueryUtils'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import variables from '@styles/variables'; import {initMoneyRequest, setMoneyRequestReceipt} from '@userActions/IOU'; import CONST from '@src/CONST'; diff --git a/src/pages/Share/ShareRootPage.tsx b/src/pages/Share/ShareRootPage.tsx index fb9e2aada6bc..970bcbcf840a 100644 --- a/src/pages/Share/ShareRootPage.tsx +++ b/src/pages/Share/ShareRootPage.tsx @@ -1,6 +1,5 @@ import React, {useCallback, useEffect, useRef, useState} from 'react'; import {Alert, AppState, View} from 'react-native'; -import type {FileObject} from '@components/AttachmentModal'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import TabNavigatorSkeleton from '@components/Skeletons/TabNavigatorSkeleton'; @@ -13,6 +12,7 @@ import {splitExtensionFromFileName, validateImageForCorruption} from '@libs/file import Navigation from '@libs/Navigation/Navigation'; import OnyxTabNavigator, {TopTab} from '@libs/Navigation/OnyxTabNavigator'; import ShareActionHandler from '@libs/ShareActionHandlerModule'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {ShareTempFile} from '@src/types/onyx'; diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 9707ba7d8c20..c56f596efd1d 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -3,7 +3,6 @@ import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {useOnyx} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; import AttachmentPicker from '@components/AttachmentPicker'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -23,6 +22,7 @@ import getIconForAction from '@libs/getIconForAction'; import Navigation from '@libs/Navigation/Navigation'; import {canCreateTaskInReport, getPayeeName, isPaidGroupPolicy, isPolicyExpenseChat, isReportOwner, temporary_getMoneyRequestOptions} from '@libs/ReportUtils'; import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import {startMoneyRequest} from '@userActions/IOU'; import {close} from '@userActions/Modal'; import {createNewReport, setIsComposerFullSize} from '@userActions/Report'; diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 8adfa3ef8a31..c7d04bf9cf86 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -18,7 +18,6 @@ import type {OnyxEntry} from 'react-native-onyx'; import {useOnyx} from 'react-native-onyx'; import {useAnimatedRef, useSharedValue} from 'react-native-reanimated'; import type {Emoji} from '@assets/emojis/types'; -import type {FileObject} from '@components/AttachmentModal'; import type {MeasureParentContainerAndCursorCallback} from '@components/AutoCompleteSuggestions/types'; import Composer from '@components/Composer'; import type {CustomSelectionChangeEvent, TextSelection} from '@components/Composer/types'; @@ -50,6 +49,7 @@ import getScrollPosition from '@pages/home/report/ReportActionCompose/getScrollP import type {SuggestionsRef} from '@pages/home/report/ReportActionCompose/ReportActionCompose'; import SilentCommentUpdater from '@pages/home/report/ReportActionCompose/SilentCommentUpdater'; import Suggestions from '@pages/home/report/ReportActionCompose/Suggestions'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import {isEmojiPickerVisible} from '@userActions/EmojiPickerAction'; import type {OnEmojiSelected} from '@userActions/EmojiPickerAction'; import {inputFocusChange} from '@userActions/InputFocus'; diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx index 69fac1ed7ade..1d1ceca0db0c 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx @@ -8,7 +8,6 @@ import {useOnyx} from 'react-native-onyx'; import {runOnUI, useSharedValue} from 'react-native-reanimated'; import type {Emoji} from '@assets/emojis/types'; import * as ActionSheetAwareScrollView from '@components/ActionSheetAwareScrollView'; -import type {FileObject} from '@components/AttachmentModal'; import AttachmentModal from '@components/AttachmentModal'; import DropZoneUI from '@components/DropZoneUI'; import EmojiPickerButton from '@components/EmojiPicker/EmojiPickerButton'; @@ -39,6 +38,7 @@ import willBlurTextInputOnTapOutsideFunc from '@libs/willBlurTextInputOnTapOutsi import ParticipantLocalTime from '@pages/home/report/ParticipantLocalTime'; import ReportDropUI from '@pages/home/report/ReportDropUI'; import ReportTypingIndicator from '@pages/home/report/ReportTypingIndicator'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import {hideEmojiPicker, isActive as isActiveEmojiPickerAction} from '@userActions/EmojiPickerAction'; import {addAttachment as addAttachmentReportActions, setIsComposerFullSize} from '@userActions/Report'; import Timing from '@userActions/Timing'; diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 83044766863a..e4e600352cba 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -2,7 +2,6 @@ import {Str} from 'expensify-common'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; import ConfirmModal from '@components/ConfirmModal'; import DragAndDropProvider from '@components/DragAndDrop/Provider'; import DropZoneUI from '@components/DropZoneUI'; @@ -36,6 +35,7 @@ import Performance from '@libs/Performance'; import {generateReportID, getBankAccountRoute, getReportOrDraftReport, isProcessingReport, isReportOutstanding, isSelectedManagerMcTest} from '@libs/ReportUtils'; import {getDefaultTaxCode, getRateID, getRequestType, getValidWaypoints, isScanRequest} from '@libs/TransactionUtils'; import ReceiptDropUI from '@pages/iou/ReceiptDropUI'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type {GpsPoint} from '@userActions/IOU'; import { checkIfScanFileCanBeRead, diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 5dd093b6a850..e1c84462c101 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -15,7 +15,6 @@ import type {TupleToUnion} from 'type-fest'; import TestReceipt from '@assets/images/fake-receipt.png'; import Hand from '@assets/images/hand.svg'; import Shutter from '@assets/images/shutter.svg'; -import type {FileObject} from '@components/AttachmentModal'; import AttachmentPicker from '@components/AttachmentPicker'; import Button from '@components/Button'; import {useFullScreenLoader} from '@components/FullScreenLoaderContext'; @@ -50,6 +49,7 @@ import {getDefaultTaxCode} from '@libs/TransactionUtils'; import StepScreenWrapper from '@pages/iou/request/step/StepScreenWrapper'; import withFullTransactionOrNotFound from '@pages/iou/request/step/withFullTransactionOrNotFound'; import withWritableReportOrNotFound from '@pages/iou/request/step/withWritableReportOrNotFound'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import { getMoneyRequestParticipantsFromReport, replaceReceipt, diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 39170bad19b3..736957b6ee5a 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -12,7 +12,6 @@ import TestReceipt from '@assets/images/fake-receipt.png'; import Hand from '@assets/images/hand.svg'; import ReceiptUpload from '@assets/images/receipt-upload.svg'; import Shutter from '@assets/images/shutter.svg'; -import type {FileObject} from '@components/AttachmentModal'; import AttachmentPicker from '@components/AttachmentPicker'; import Button from '@components/Button'; import ConfirmModal from '@components/ConfirmModal'; @@ -53,6 +52,7 @@ import ReceiptDropUI from '@pages/iou/ReceiptDropUI'; import StepScreenDragAndDropWrapper from '@pages/iou/request/step/StepScreenDragAndDropWrapper'; import withFullTransactionOrNotFound from '@pages/iou/request/step/withFullTransactionOrNotFound'; import withWritableReportOrNotFound from '@pages/iou/request/step/withWritableReportOrNotFound'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type {GpsPoint} from '@userActions/IOU'; import { checkIfScanFileCanBeRead, diff --git a/src/pages/iou/request/step/IOURequestStepScan/types.ts b/src/pages/iou/request/step/IOURequestStepScan/types.ts index c74335ccd850..0fe95f9dba4c 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/types.ts +++ b/src/pages/iou/request/step/IOURequestStepScan/types.ts @@ -1,7 +1,7 @@ import type {OnyxEntry} from 'react-native-onyx'; -import type {FileObject} from '@components/AttachmentModal'; import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; import type {WithWritableReportOrNotFoundProps} from '@pages/iou/request/step/withWritableReportOrNotFound'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; diff --git a/src/stories/Composer.stories.tsx b/src/stories/Composer.stories.tsx index efb8e05614e2..cdf70313d87d 100644 --- a/src/stories/Composer.stories.tsx +++ b/src/stories/Composer.stories.tsx @@ -3,13 +3,13 @@ import type {Meta} from '@storybook/react'; import {ExpensiMark} from 'expensify-common'; import React, {useState} from 'react'; import {Image, View} from 'react-native'; -import type {FileObject} from '@components/AttachmentModal'; import Composer from '@components/Composer'; import type {ComposerProps, CustomSelectionChangeEvent, TextSelection} from '@components/Composer/types'; import RenderHTML from '@components/RenderHTML'; import Text from '@components/Text'; import withNavigationFallback from '@components/withNavigationFallback'; import useStyleUtils from '@hooks/useStyleUtils'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; // eslint-disable-next-line no-restricted-imports import {defaultTheme} from '@styles/theme'; import {defaultStyles} from '@src/styles'; diff --git a/src/types/form/ReimbursementAccountForm.ts b/src/types/form/ReimbursementAccountForm.ts index 05be26da7e0f..9127c09763a2 100644 --- a/src/types/form/ReimbursementAccountForm.ts +++ b/src/types/form/ReimbursementAccountForm.ts @@ -1,4 +1,4 @@ -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type {Country} from '@src/CONST'; import type DeepValueOf from '@src/types/utils/DeepValueOf'; import type Form from './Form'; diff --git a/src/types/utils/SvgIconComponent.ts b/src/types/utils/SvgIconComponent.ts new file mode 100644 index 000000000000..c13e155a450d --- /dev/null +++ b/src/types/utils/SvgIconComponent.ts @@ -0,0 +1,5 @@ +import type {SvgProps} from 'react-native-svg'; + +type SvgIconComponent = React.FC; + +export default SvgIconComponent; From 72a6c0eed0c66169e3870afdd5da54764c8e11f4 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Fri, 6 Jun 2025 12:26:01 +0200 Subject: [PATCH 02/14] fix: update FileObject usage and update deprecated `expo-image-manipulator` logic --- .../getImageManipulator/index.native.ts | 22 ++++++++++------- .../fileDownload/getImageManipulator/index.ts | 24 +++++++++++-------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/libs/fileDownload/getImageManipulator/index.native.ts b/src/libs/fileDownload/getImageManipulator/index.native.ts index 07b97d2e375b..f78fb1006032 100644 --- a/src/libs/fileDownload/getImageManipulator/index.native.ts +++ b/src/libs/fileDownload/getImageManipulator/index.native.ts @@ -1,13 +1,17 @@ -import {manipulateAsync} from 'expo-image-manipulator'; -import type {FileObject} from '@components/AttachmentModal'; +import {ImageManipulator} from 'expo-image-manipulator'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type ImageManipulatorConfig from './type'; export default function getImageManipulator({fileUri, width, height, type, fileName}: ImageManipulatorConfig): Promise { - return manipulateAsync(fileUri ?? '', [{resize: {width, height}}]).then((result) => ({ - uri: result.uri, - width: result.width, - height: result.height, - type, - name: fileName, - })); + return ImageManipulator.manipulate(fileUri ?? '') + .resize({width, height}) + .renderAsync() + .then((image) => image.saveAsync()) + .then((result) => ({ + uri: result.uri, + width: result.width, + height: result.height, + type, + name: fileName, + })); } diff --git a/src/libs/fileDownload/getImageManipulator/index.ts b/src/libs/fileDownload/getImageManipulator/index.ts index 87319978caa8..d9743c23d9cc 100644 --- a/src/libs/fileDownload/getImageManipulator/index.ts +++ b/src/libs/fileDownload/getImageManipulator/index.ts @@ -1,14 +1,18 @@ -import {manipulateAsync} from 'expo-image-manipulator'; +import {ImageManipulator} from 'expo-image-manipulator'; import type ImageManipulatorConfig from './type'; export default function getImageManipulator({fileUri, width, height, fileName}: ImageManipulatorConfig): Promise { - return manipulateAsync(fileUri ?? '', [{resize: {width, height}}]).then((result) => - fetch(result.uri) - .then((res) => res.blob()) - .then((blob) => { - const resizedFile = new File([blob], `${fileName}.jpeg`, {type: 'image/jpeg'}); - resizedFile.uri = URL.createObjectURL(resizedFile); - return resizedFile; - }), - ); + return ImageManipulator.manipulate(fileUri ?? '') + .resize({width, height}) + .renderAsync() + .then((image) => image.saveAsync()) + .then((result) => + fetch(result.uri) + .then((res) => res.blob()) + .then((blob) => { + const resizedFile = new File([blob], `${fileName}.jpeg`, {type: 'image/jpeg'}); + resizedFile.uri = URL.createObjectURL(resizedFile); + return resizedFile; + }), + ); } From 4395d88d71f964a54e4f8b552bfb897d36b845e3 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 11 Jun 2025 16:54:18 +0200 Subject: [PATCH 03/14] update FileObject import --- src/hooks/useFileValidation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useFileValidation.ts b/src/hooks/useFileValidation.ts index 480c4cc77d53..37de0e013367 100644 --- a/src/hooks/useFileValidation.ts +++ b/src/hooks/useFileValidation.ts @@ -1,7 +1,7 @@ import {Str} from 'expensify-common'; import {useState} from 'react'; -import type {FileObject} from '@components/AttachmentModal'; import {resizeImageIfNeeded, validateReceipt} from '@libs/fileDownload/FileUtils'; +import {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; From bd360f6c19bd72db651091b9b88967a5590b2f93 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 11 Jun 2025 16:54:30 +0200 Subject: [PATCH 04/14] fix: eslint --- src/hooks/useFileValidation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useFileValidation.ts b/src/hooks/useFileValidation.ts index 37de0e013367..88621ef8dbb7 100644 --- a/src/hooks/useFileValidation.ts +++ b/src/hooks/useFileValidation.ts @@ -1,7 +1,7 @@ import {Str} from 'expensify-common'; import {useState} from 'react'; import {resizeImageIfNeeded, validateReceipt} from '@libs/fileDownload/FileUtils'; -import {FileObject} from '@pages/media/AttachmentModalScreen/types'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; From 855039e7fc03995af02f9ef8c78a9a6f10d0764f Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 11 Jun 2025 16:58:46 +0200 Subject: [PATCH 05/14] Delete SvgIconComponent.ts --- src/types/utils/SvgIconComponent.ts | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/types/utils/SvgIconComponent.ts diff --git a/src/types/utils/SvgIconComponent.ts b/src/types/utils/SvgIconComponent.ts deleted file mode 100644 index c13e155a450d..000000000000 --- a/src/types/utils/SvgIconComponent.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type {SvgProps} from 'react-native-svg'; - -type SvgIconComponent = React.FC; - -export default SvgIconComponent; From c8e3c15c8d99861f1d351eed2be0428e2e4b625d Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 11 Jun 2025 17:01:52 +0200 Subject: [PATCH 06/14] fix: typos --- src/libs/ReportActionsUtils.ts | 8 ++++---- src/pages/home/report/PureReportActionItem.tsx | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 3407e181370f..9e8b4e9cbb3b 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -2529,7 +2529,7 @@ function getRenamedAction(reportAction: OnyxEntry) { +function getAddedApprovalRuleMessage(reportAction: OnyxEntry) { const {name, approverAccountID, approverEmail, field, approverName} = getOriginalMessage(reportAction as ReportAction) ?? {}; @@ -2545,7 +2545,7 @@ function getAddedApprovaRulelMessage(reportAction: OnyxEntry) { return getReportActionText(reportAction); } -function getDeletedApprovaRulelMessage(reportAction: OnyxEntry) { +function getDeletedApprovalRuleMessage(reportAction: OnyxEntry) { const {name, approverAccountID, approverEmail, field, approverName} = getOriginalMessage(reportAction as ReportAction) ?? {}; @@ -2781,8 +2781,8 @@ export { getNumberOfMoneyRequests, getOneTransactionThreadReportID, getOriginalMessage, - getAddedApprovaRulelMessage, - getDeletedApprovaRulelMessage, + getAddedApprovalRuleMessage, + getDeletedApprovalRuleMessage, getUpdatedApprovalRuleMessage, getRemovedFromApprovalChainMessage, getDemotedFromWorkspaceMessage, diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index 6b9056513e2b..d08c4f732454 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -58,9 +58,9 @@ import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils'; import {getCleanedTagName} from '@libs/PolicyUtils'; import { extractLinksFromMessageHtml, - getAddedApprovaRulelMessage, + getAddedApprovalRuleMessage, getAddedConnectionMessage, - getDeletedApprovaRulelMessage, + getDeletedApprovalRuleMessage, getDemotedFromWorkspaceMessage, getDismissedViolationMessageText, getIntegrationSyncFailedMessage, @@ -1122,9 +1122,9 @@ function PureReportActionItem({ } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_EMPLOYEE) { children = ; } else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_APPROVER_RULE)) { - children = ; + children = ; } else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_APPROVER_RULE)) { - children = ; + children = ; } else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_APPROVER_RULE)) { children = ; } else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REMOVED_FROM_APPROVAL_CHAIN)) { From 95363c8e8d1e810b74074b83045938a7b672ab67 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 11 Jun 2025 17:52:30 +0200 Subject: [PATCH 07/14] Update AvatarWithImagePicker.tsx --- src/components/AvatarWithImagePicker.tsx | 218 +++++++++++------------ 1 file changed, 107 insertions(+), 111 deletions(-) diff --git a/src/components/AvatarWithImagePicker.tsx b/src/components/AvatarWithImagePicker.tsx index d99a81c8b6d3..bc64444f9b6a 100644 --- a/src/components/AvatarWithImagePicker.tsx +++ b/src/components/AvatarWithImagePicker.tsx @@ -1,5 +1,5 @@ import {useIsFocused} from '@react-navigation/native'; -import React, {useCallback, useContext, useEffect, useRef, useState} from 'react'; +import React, {useCallback, useEffect, useRef, useState} from 'react'; import {StyleSheet, View} from 'react-native'; import type {ImageStyle, StyleProp, ViewStyle} from 'react-native'; import useLocalize from '@hooks/useLocalize'; @@ -10,16 +10,14 @@ import {isSafari} from '@libs/Browser'; import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types'; import {splitExtensionFromFileName, validateImageForCorruption} from '@libs/fileDownload/FileUtils'; import getImageResolution from '@libs/fileDownload/getImageResolution'; -import Navigation from '@libs/Navigation/Navigation'; import type {AvatarSource} from '@libs/UserUtils'; -import AttachmentModalContext from '@pages/media/AttachmentModalScreen/AttachmentModalContext'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; -import ROUTES from '@src/ROUTES'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type IconAsset from '@src/types/utils/IconAsset'; -import type {FileObject} from './AttachmentModal'; +import AttachmentModal from './AttachmentModal'; import AttachmentPicker from './AttachmentPicker'; import Avatar from './Avatar'; import AvatarCropModal from './AvatarCropModal/AvatarCropModal'; @@ -332,117 +330,115 @@ function AvatarWithImagePicker({ [disabled, enablePreview, isUsingDefaultAvatar, onViewPhotoPress, showAvatarCropModal], ); - const reportAttachmentsContext = useContext(AttachmentModalContext); - const showAttachmentModalScreen = useCallback(() => { - reportAttachmentsContext.setCurrentAttachment({ - source: previewSource, - fallbackSource: fallbackIcon, - headerTitle, - originalFileName, - maybeIcon: isUsingDefaultAvatar, - }); - Navigation.navigate(ROUTES.ATTACHMENTS.getRoute()); - }, [fallbackIcon, headerTitle, isUsingDefaultAvatar, originalFileName, previewSource, reportAttachmentsContext]); - return ( - - {({openPicker}) => { - const menuItems = createMenuItems(openPicker); - - // If the current avatar isn't a default avatar and we are not overriding this behavior allow the "View Photo" option - if (!shouldDisableViewPhoto && !isUsingDefaultAvatar) { - menuItems.push({ - icon: Expensicons.Eye, - text: translate('avatarWithImagePicker.viewPhoto'), - onSelected: () => { - if (typeof onViewPhotoPress !== 'function') { - showAttachmentModalScreen(); - return; - } - onViewPhotoPress(); - }, - shouldCallAfterModalHide: true, - }); - } - - return ( - <> - - - onPressAvatar(openPicker)} - accessibilityRole={CONST.ROLE.BUTTON} - accessibilityLabel={translate('avatarWithImagePicker.editImage')} - disabled={isAvatarCropModalOpen || (disabled && !enablePreview)} - disabledStyle={disabledStyle} - style={[styles.pRelative, type === CONST.ICON_TYPE_AVATAR && styles.alignSelfCenter, avatarStyle]} - ref={anchorRef} + {({show}) => ( + + {({openPicker}) => { + const menuItems = createMenuItems(openPicker); + + // If the current avatar isn't a default avatar and we are not overriding this behavior allow the "View Photo" option + if (!shouldDisableViewPhoto && !isUsingDefaultAvatar) { + menuItems.push({ + icon: Expensicons.Eye, + text: translate('avatarWithImagePicker.viewPhoto'), + onSelected: () => { + if (typeof onViewPhotoPress !== 'function') { + show(); + return; + } + onViewPhotoPress(); + }, + shouldCallAfterModalHide: true, + }); + } + + return ( + <> + - - {source ? ( - - ) : ( - - )} - - {!disabled && ( - - - - )} - - - - setIsMenuVisible(false)} - onItemSelected={(item, index) => { - setIsMenuVisible(false); - // In order for the file picker to open dynamically, the click - // function must be called from within an event handler that was initiated - // by the user on Safari. - if (index === 0 && isSafari()) { - openPicker({ - onPicked: (data) => showAvatarCropModal(data.at(0) ?? {}), - }); - } - }} - menuItems={menuItems} - anchorPosition={shouldUseStyleUtilityForAnchorPosition ? styles.popoverMenuOffset(windowWidth) : popoverPosition} - anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}} - withoutOverlay - anchorRef={anchorRef} - /> - - ); - }} - + + onPressAvatar(openPicker)} + accessibilityRole={CONST.ROLE.BUTTON} + accessibilityLabel={translate('avatarWithImagePicker.editImage')} + disabled={isAvatarCropModalOpen || (disabled && !enablePreview)} + disabledStyle={disabledStyle} + style={[styles.pRelative, type === CONST.ICON_TYPE_AVATAR && styles.alignSelfCenter, avatarStyle]} + ref={anchorRef} + > + + {source ? ( + + ) : ( + + )} + + {!disabled && ( + + + + )} + + + + setIsMenuVisible(false)} + onItemSelected={(item, index) => { + setIsMenuVisible(false); + // In order for the file picker to open dynamically, the click + // function must be called from within an event handler that was initiated + // by the user on Safari. + if (index === 0 && isSafari()) { + openPicker({ + onPicked: (data) => showAvatarCropModal(data.at(0) ?? {}), + }); + } + }} + menuItems={menuItems} + anchorPosition={shouldUseStyleUtilityForAnchorPosition ? styles.popoverMenuOffset(windowWidth) : popoverPosition} + anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}} + withoutOverlay + anchorRef={anchorRef} + /> + + ); + }} + + )} + {!!errorData.validationError && ( Date: Wed, 11 Jun 2025 17:16:05 +0200 Subject: [PATCH 08/14] fix: eslint check, `getPolicy` deprecated --- src/libs/ReportActionsUtils.ts | 6 ++---- src/libs/SidebarUtils.ts | 2 +- .../report/ContextMenu/BaseReportActionContextMenu.tsx | 2 ++ src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 8 +++++--- src/pages/home/report/PureReportActionItem.tsx | 5 ++++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 9e8b4e9cbb3b..6b3ba00dc5bf 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -10,7 +10,7 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {Card, Locale, OnyxInputOrEntry, OriginalMessageIOU, PrivatePersonalDetails} from '@src/types/onyx'; +import type {Card, Locale, OnyxInputOrEntry, OriginalMessageIOU, Policy, PrivatePersonalDetails} from '@src/types/onyx'; import type {JoinWorkspaceResolution, OriginalMessageChangeLog, OriginalMessageExportIntegration} from '@src/types/onyx/OriginalMessage'; import type {PolicyReportFieldType} from '@src/types/onyx/Policy'; import type Report from '@src/types/onyx/Report'; @@ -2063,7 +2063,7 @@ function getWorkspaceFrequencyUpdateMessage(action: ReportAction): string { }); } -function getWorkspaceCategoryUpdateMessage(action: ReportAction, policyID?: string): string { +function getWorkspaceCategoryUpdateMessage(action: ReportAction, policy?: OnyxEntry): string { const {categoryName, oldValue, newName, oldName, updatedField, newValue, currency} = getOriginalMessage(action as ReportAction) ?? {}; @@ -2127,8 +2127,6 @@ function getWorkspaceCategoryUpdateMessage(action: ReportAction, policyID?: stri } if (updatedField === 'maxAmountNoReceipt' && typeof oldValue !== 'boolean' && typeof newValue !== 'boolean') { - const policy = getPolicy(policyID); - const maxExpenseAmountToDisplay = policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE ? 0 : policy?.maxExpenseAmountNoReceipt; const formatAmount = () => convertToShortDisplayString(maxExpenseAmountToDisplay, policy?.outputCurrency ?? CONST.CURRENCY.USD); diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index a848555936ae..4705c4a92648 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -634,7 +634,7 @@ function getOptionData({ isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_CATEGORY) || isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.SET_CATEGORY_NAME) ) { - result.alternateText = getWorkspaceCategoryUpdateMessage(lastAction); + result.alternateText = getWorkspaceCategoryUpdateMessage(lastAction, policy); } else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_LIST_NAME)) { result.alternateText = getCleanedTagName(getTagListNameUpdatedMessage(lastAction) ?? ''); } else if (isTagModificationAction(lastAction?.actionName)) { diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index 7febb8a9f72e..cbed004de8fc 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -152,6 +152,7 @@ function BaseReportActionContextMenu({ const [originalReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${originalReportID}`, {canBeMissing: true}); const isOriginalReportArchived = useReportIsArchived(originalReportID); const policyID = report?.policyID; + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: true}); const reportAction: OnyxEntry = useMemo(() => { if (isEmptyObject(reportActions) || reportActionID === '0' || reportActionID === '-1' || !reportActionID) { @@ -225,6 +226,7 @@ function BaseReportActionContextMenu({ moneyRequestAction, areHoldRequirementsMet, account, + policy, }), ); diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 65d1de66b950..5bb2881a9019 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -126,7 +126,7 @@ import { import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; -import type {Account, Beta, Card, Download as DownloadOnyx, OnyxInputOrEntry, ReportAction, ReportActionReactions, Report as ReportType, Transaction} from '@src/types/onyx'; +import type {Account, Beta, Card, Download as DownloadOnyx, OnyxInputOrEntry, Policy, ReportAction, ReportActionReactions, Report as ReportType, Transaction} from '@src/types/onyx'; import type IconAsset from '@src/types/utils/IconAsset'; import KeyboardUtils from '@src/utils/keyboard'; import type {ContextMenuAnchor} from './ReportActionContextMenu'; @@ -170,6 +170,7 @@ type ShouldShow = (args: { moneyRequestAction: ReportAction | undefined; areHoldRequirementsMet: boolean; account: OnyxEntry; + policy?: OnyxEntry; }) => boolean; type ContextMenuActionPayload = { @@ -191,6 +192,7 @@ type ContextMenuActionPayload = { anchorRef?: MutableRefObject; moneyRequestAction: ReportAction | undefined; card?: Card; + policy?: OnyxEntry; }; type OnPress = (closePopover: boolean, payload: ContextMenuActionPayload, selection?: string, reportID?: string, draftMessage?: string) => void; @@ -482,7 +484,7 @@ const ContextMenuActions: ContextMenuAction[] = [ // If return value is true, we switch the `text` and `icon` on // `ContextMenuItem` with `successText` and `successIcon` which will fall back to // the `text` and `icon` - onPress: (closePopover, {reportAction, transaction, selection, report, reportID, card}) => { + onPress: (closePopover, {reportAction, transaction, selection, report, reportID, card, policy}) => { const isReportPreviewAction = isReportPreviewActionReportActionsUtils(reportAction); const messageHtml = getActionHtml(reportAction); const messageText = getReportActionMessageText(reportAction); @@ -532,7 +534,7 @@ const ContextMenuActions: ContextMenuAction[] = [ reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_CATEGORY || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.SET_CATEGORY_NAME ) { - Clipboard.setString(getWorkspaceCategoryUpdateMessage(reportAction)); + Clipboard.setString(getWorkspaceCategoryUpdateMessage(reportAction, policy)); } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_LIST_NAME) { Clipboard.setString(getCleanedTagName(getTagListNameUpdatedMessage(reportAction))); } else if (isTagModificationAction(reportAction.actionName)) { diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index d08c4f732454..cae35de6ad31 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -3,6 +3,7 @@ import mapValues from 'lodash/mapValues'; import React, {memo, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react'; import type {GestureResponderEvent, TextInput} from 'react-native'; import {InteractionManager, Keyboard, View} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {Emoji} from '@assets/emojis/types'; @@ -161,6 +162,7 @@ import {isAnonymousUser, signOutAndRedirectToSignIn} from '@userActions/Session' import {isBlockedFromConcierge} from '@userActions/User'; import type {IOUAction} from '@src/CONST'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; import type {Errors} from '@src/types/onyx/OnyxCommon'; @@ -413,6 +415,7 @@ function PureReportActionItem({ const theme = useTheme(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: true}); const [isContextMenuActive, setIsContextMenuActive] = useState(() => isActiveReportAction(action.reportActionID)); const [isEmojiPickerActive, setIsEmojiPickerActive] = useState(); const [isPaymentMethodPopoverActive, setIsPaymentMethodPopoverActive] = useState(); @@ -1086,7 +1089,7 @@ function PureReportActionItem({ action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_CATEGORY || action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.SET_CATEGORY_NAME ) { - children = ; + children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_LIST_NAME) { children = ; } else if (isTagModificationAction(action.actionName)) { From 135b4b1ec7f830ac323676c862a6df75d41aa4f2 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 11 Jun 2025 18:00:48 +0200 Subject: [PATCH 09/14] fix: eslint --- src/libs/SidebarUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 4705c4a92648..9688f4316767 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -24,10 +24,10 @@ import Parser from './Parser'; import Performance from './Performance'; import {getCleanedTagName, getPolicy} from './PolicyUtils'; import { - getAddedApprovaRulelMessage, + getAddedApprovalRuleMessage, getAddedConnectionMessage, getCardIssuedMessage, - getDeletedApprovaRulelMessage, + getDeletedApprovalRuleMessage, getIntegrationSyncFailedMessage, getLastVisibleMessage, getMessageOfOldDotReportAction, @@ -689,9 +689,9 @@ function getOptionData({ } else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_AUDIT_RATE) { result.alternateText = getUpdatedAuditRateMessage(lastAction); } else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_APPROVER_RULE) { - result.alternateText = getAddedApprovaRulelMessage(lastAction); + result.alternateText = getAddedApprovalRuleMessage(lastAction); } else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_APPROVER_RULE) { - result.alternateText = getDeletedApprovaRulelMessage(lastAction); + result.alternateText = getDeletedApprovalRuleMessage(lastAction); } else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_APPROVER_RULE) { result.alternateText = getUpdatedApprovalRuleMessage(lastAction); } else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_MANUAL_APPROVAL_THRESHOLD) { From dd4f1709083cf5631c58e03ba2a44db19d172c6f Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 11 Jun 2025 18:11:12 +0200 Subject: [PATCH 10/14] Update ContextMenuActions.tsx --- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 5bb2881a9019..014ab5b58273 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -23,10 +23,10 @@ import {getCleanedTagName} from '@libs/PolicyUtils'; import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager'; import { getActionableMentionWhisperMessage, - getAddedApprovaRulelMessage, + getAddedApprovalRuleMessage, getAddedConnectionMessage, getCardIssuedMessage, - getDeletedApprovaRulelMessage, + getDeletedApprovalRuleMessage, getExportIntegrationMessageHTML, getIntegrationSyncFailedMessage, getIOUReportIDFromReportActionPreview, @@ -649,9 +649,9 @@ const ContextMenuActions: ContextMenuAction[] = [ } else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_AUDIT_RATE)) { setClipboardMessage(getUpdatedAuditRateMessage(reportAction)); } else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_APPROVER_RULE)) { - setClipboardMessage(getAddedApprovaRulelMessage(reportAction)); + setClipboardMessage(getAddedApprovalRuleMessage(reportAction)); } else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_APPROVER_RULE)) { - setClipboardMessage(getDeletedApprovaRulelMessage(reportAction)); + setClipboardMessage(getDeletedApprovalRuleMessage(reportAction)); } else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_APPROVER_RULE)) { setClipboardMessage(getUpdatedApprovalRuleMessage(reportAction)); } else if (isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_MANUAL_APPROVAL_THRESHOLD)) { From e8b3fbab57a045d3e4d5f686e891ecf7f11207c1 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 11 Jun 2025 18:42:13 +0200 Subject: [PATCH 11/14] fix: PureReportActionItem should be a pure function --- src/pages/home/report/PureReportActionItem.tsx | 7 ++++--- src/pages/home/report/ReportActionItem.tsx | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index cae35de6ad31..185229f8c25c 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -3,7 +3,6 @@ import mapValues from 'lodash/mapValues'; import React, {memo, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react'; import type {GestureResponderEvent, TextInput} from 'react-native'; import {InteractionManager, Keyboard, View} from 'react-native'; -import {useOnyx} from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import type {Emoji} from '@assets/emojis/types'; @@ -162,7 +161,6 @@ import {isAnonymousUser, signOutAndRedirectToSignIn} from '@userActions/Session' import {isBlockedFromConcierge} from '@userActions/User'; import type {IOUAction} from '@src/CONST'; import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; import type {Errors} from '@src/types/onyx/OnyxCommon'; @@ -189,6 +187,9 @@ type PureReportActionItemProps = { /** Report for this action */ report: OnyxEntry; + /** Policy for this action */ + policy?: OnyxEntry; + /** The transaction thread report associated with the report for this action, if any */ transactionThreadReport?: OnyxEntry; @@ -363,6 +364,7 @@ const isEmptyHTML = ({props: {html}}: T): boolean = function PureReportActionItem({ action, report, + policy, transactionThreadReport, linkedReportActionID, displayAsGroup, @@ -415,7 +417,6 @@ function PureReportActionItem({ const theme = useTheme(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); - const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: true}); const [isContextMenuActive, setIsContextMenuActive] = useState(() => isActiveReportAction(action.reportActionID)); const [isEmojiPickerActive, setIsEmojiPickerActive] = useState(); const [isPaymentMethodPopoverActive, setIsPaymentMethodPopoverActive] = useState(); diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index effdf7ef985a..53e843f4e910 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -54,6 +54,7 @@ function ReportActionItem({action, report, shouldShowDraftMessage = true, ...pro }, }); const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getIOUReportIDFromReportActionPreview(action)}`, {canBeMissing: true}); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: true}); const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${action.reportActionID}`, {canBeMissing: true}); const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET, {canBeMissing: false}); const [linkedTransactionRouteError] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${isMoneyRequestAction(action) && getOriginalMessage(action)?.IOUTransactionID}`, { @@ -79,6 +80,7 @@ function ReportActionItem({action, report, shouldShowDraftMessage = true, ...pro {...props} action={action} report={report} + policy={policy} draftMessage={draftMessage} iouReport={iouReport} emojiReactions={emojiReactions} From 818060b306b4d0f1a0d1265319dd5abb0ec28b49 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Wed, 11 Jun 2025 18:50:34 +0200 Subject: [PATCH 12/14] fix: remove unnecessary policy param --- src/libs/SidebarUtils.ts | 2 +- .../report/ContextMenu/BaseReportActionContextMenu.tsx | 2 -- src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 8 +++----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 9688f4316767..abf2e6fc07ec 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -634,7 +634,7 @@ function getOptionData({ isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_CATEGORY) || isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.SET_CATEGORY_NAME) ) { - result.alternateText = getWorkspaceCategoryUpdateMessage(lastAction, policy); + result.alternateText = getWorkspaceCategoryUpdateMessage(lastAction); } else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_LIST_NAME)) { result.alternateText = getCleanedTagName(getTagListNameUpdatedMessage(lastAction) ?? ''); } else if (isTagModificationAction(lastAction?.actionName)) { diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx index cbed004de8fc..7febb8a9f72e 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx @@ -152,7 +152,6 @@ function BaseReportActionContextMenu({ const [originalReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${originalReportID}`, {canBeMissing: true}); const isOriginalReportArchived = useReportIsArchived(originalReportID); const policyID = report?.policyID; - const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: true}); const reportAction: OnyxEntry = useMemo(() => { if (isEmptyObject(reportActions) || reportActionID === '0' || reportActionID === '-1' || !reportActionID) { @@ -226,7 +225,6 @@ function BaseReportActionContextMenu({ moneyRequestAction, areHoldRequirementsMet, account, - policy, }), ); diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 014ab5b58273..878954cced95 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -126,7 +126,7 @@ import { import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; -import type {Account, Beta, Card, Download as DownloadOnyx, OnyxInputOrEntry, Policy, ReportAction, ReportActionReactions, Report as ReportType, Transaction} from '@src/types/onyx'; +import type {Account, Beta, Card, Download as DownloadOnyx, OnyxInputOrEntry, ReportAction, ReportActionReactions, Report as ReportType, Transaction} from '@src/types/onyx'; import type IconAsset from '@src/types/utils/IconAsset'; import KeyboardUtils from '@src/utils/keyboard'; import type {ContextMenuAnchor} from './ReportActionContextMenu'; @@ -170,7 +170,6 @@ type ShouldShow = (args: { moneyRequestAction: ReportAction | undefined; areHoldRequirementsMet: boolean; account: OnyxEntry; - policy?: OnyxEntry; }) => boolean; type ContextMenuActionPayload = { @@ -192,7 +191,6 @@ type ContextMenuActionPayload = { anchorRef?: MutableRefObject; moneyRequestAction: ReportAction | undefined; card?: Card; - policy?: OnyxEntry; }; type OnPress = (closePopover: boolean, payload: ContextMenuActionPayload, selection?: string, reportID?: string, draftMessage?: string) => void; @@ -484,7 +482,7 @@ const ContextMenuActions: ContextMenuAction[] = [ // If return value is true, we switch the `text` and `icon` on // `ContextMenuItem` with `successText` and `successIcon` which will fall back to // the `text` and `icon` - onPress: (closePopover, {reportAction, transaction, selection, report, reportID, card, policy}) => { + onPress: (closePopover, {reportAction, transaction, selection, report, reportID, card}) => { const isReportPreviewAction = isReportPreviewActionReportActionsUtils(reportAction); const messageHtml = getActionHtml(reportAction); const messageText = getReportActionMessageText(reportAction); @@ -534,7 +532,7 @@ const ContextMenuActions: ContextMenuAction[] = [ reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_CATEGORY || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.SET_CATEGORY_NAME ) { - Clipboard.setString(getWorkspaceCategoryUpdateMessage(reportAction, policy)); + Clipboard.setString(getWorkspaceCategoryUpdateMessage(reportAction)); } else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_LIST_NAME) { Clipboard.setString(getCleanedTagName(getTagListNameUpdatedMessage(reportAction))); } else if (isTagModificationAction(reportAction.actionName)) { From 2f7ac48067898c27010ed3c12cde144900845716 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 12 Jun 2025 15:22:45 +0200 Subject: [PATCH 13/14] revert: image manipulator changes --- .../getImageManipulator/index.native.ts | 22 +++++++---------- .../fileDownload/getImageManipulator/index.ts | 24 ++++++++----------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/libs/fileDownload/getImageManipulator/index.native.ts b/src/libs/fileDownload/getImageManipulator/index.native.ts index f78fb1006032..07b97d2e375b 100644 --- a/src/libs/fileDownload/getImageManipulator/index.native.ts +++ b/src/libs/fileDownload/getImageManipulator/index.native.ts @@ -1,17 +1,13 @@ -import {ImageManipulator} from 'expo-image-manipulator'; -import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; +import {manipulateAsync} from 'expo-image-manipulator'; +import type {FileObject} from '@components/AttachmentModal'; import type ImageManipulatorConfig from './type'; export default function getImageManipulator({fileUri, width, height, type, fileName}: ImageManipulatorConfig): Promise { - return ImageManipulator.manipulate(fileUri ?? '') - .resize({width, height}) - .renderAsync() - .then((image) => image.saveAsync()) - .then((result) => ({ - uri: result.uri, - width: result.width, - height: result.height, - type, - name: fileName, - })); + return manipulateAsync(fileUri ?? '', [{resize: {width, height}}]).then((result) => ({ + uri: result.uri, + width: result.width, + height: result.height, + type, + name: fileName, + })); } diff --git a/src/libs/fileDownload/getImageManipulator/index.ts b/src/libs/fileDownload/getImageManipulator/index.ts index d9743c23d9cc..87319978caa8 100644 --- a/src/libs/fileDownload/getImageManipulator/index.ts +++ b/src/libs/fileDownload/getImageManipulator/index.ts @@ -1,18 +1,14 @@ -import {ImageManipulator} from 'expo-image-manipulator'; +import {manipulateAsync} from 'expo-image-manipulator'; import type ImageManipulatorConfig from './type'; export default function getImageManipulator({fileUri, width, height, fileName}: ImageManipulatorConfig): Promise { - return ImageManipulator.manipulate(fileUri ?? '') - .resize({width, height}) - .renderAsync() - .then((image) => image.saveAsync()) - .then((result) => - fetch(result.uri) - .then((res) => res.blob()) - .then((blob) => { - const resizedFile = new File([blob], `${fileName}.jpeg`, {type: 'image/jpeg'}); - resizedFile.uri = URL.createObjectURL(resizedFile); - return resizedFile; - }), - ); + return manipulateAsync(fileUri ?? '', [{resize: {width, height}}]).then((result) => + fetch(result.uri) + .then((res) => res.blob()) + .then((blob) => { + const resizedFile = new File([blob], `${fileName}.jpeg`, {type: 'image/jpeg'}); + resizedFile.uri = URL.createObjectURL(resizedFile); + return resizedFile; + }), + ); } From 67437cd36713b9c4860cf71a1789b1c757c5b75f Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 12 Jun 2025 15:24:28 +0200 Subject: [PATCH 14/14] fix: update FileObject import --- src/libs/fileDownload/getImageManipulator/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/fileDownload/getImageManipulator/index.native.ts b/src/libs/fileDownload/getImageManipulator/index.native.ts index 07b97d2e375b..d9d9c17e400f 100644 --- a/src/libs/fileDownload/getImageManipulator/index.native.ts +++ b/src/libs/fileDownload/getImageManipulator/index.native.ts @@ -1,5 +1,5 @@ import {manipulateAsync} from 'expo-image-manipulator'; -import type {FileObject} from '@components/AttachmentModal'; +import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type ImageManipulatorConfig from './type'; export default function getImageManipulator({fileUri, width, height, type, fileName}: ImageManipulatorConfig): Promise {