From 0caf904a92c4690ca17520127b7ec193eba32c0a Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Thu, 13 Jun 2024 20:59:02 +0530 Subject: [PATCH 01/15] feat: corrupt pdf detection on scan page. Signed-off-by: Krishna Gupta --- src/components/PDFThumbnail/index.tsx | 10 +++- src/components/PDFThumbnail/types.ts | 1 + .../request/step/IOURequestStepScan/index.tsx | 50 ++++++++++++++++++- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/components/PDFThumbnail/index.tsx b/src/components/PDFThumbnail/index.tsx index 8e79c027cf03..f064229f0739 100644 --- a/src/components/PDFThumbnail/index.tsx +++ b/src/components/PDFThumbnail/index.tsx @@ -12,7 +12,7 @@ if (!pdfjs.GlobalWorkerOptions.workerSrc) { pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'})); } -function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword, onLoadError}: PDFThumbnailProps) { +function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword, onLoadError, onLoadSuccess}: PDFThumbnailProps) { const styles = useThemeStyles(); const [failedToLoad, setFailedToLoad] = useState(false); @@ -30,6 +30,12 @@ function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, ena onLoad={() => { setFailedToLoad(false); }} + onLoadSuccess={() => { + if (!onLoadSuccess) { + return; + } + onLoadSuccess(); + }} onLoadError={() => { if (onLoadError) { onLoadError(); @@ -43,7 +49,7 @@ function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, ena ), - [isAuthTokenRequired, previewSourceURL, onPassword, onLoadError], + [isAuthTokenRequired, previewSourceURL, onPassword, onLoadError, onLoadSuccess], ); return ( diff --git a/src/components/PDFThumbnail/types.ts b/src/components/PDFThumbnail/types.ts index 349669ecc33e..512b5afc2d6f 100644 --- a/src/components/PDFThumbnail/types.ts +++ b/src/components/PDFThumbnail/types.ts @@ -18,6 +18,7 @@ type PDFThumbnailProps = { /** Callback to call if PDF can't be loaded(corrupted) */ onLoadError?: () => void; + onLoadSuccess?: () => void; }; export default PDFThumbnailProps; diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 8dc26e97920e..6a3c0ea5eadd 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -1,3 +1,4 @@ +import {Str} from 'expensify-common'; import React, {useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState} from 'react'; import {ActivityIndicator, PanResponder, PixelRatio, View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; @@ -14,6 +15,7 @@ import CopyTextToClipboard from '@components/CopyTextToClipboard'; import {DragAndDropContext} from '@components/DragAndDrop/Provider'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; +import PDFThumbnail from '@components/PDFThumbnail'; import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; import Text from '@components/Text'; import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails'; @@ -62,7 +64,7 @@ function IOURequestStepScan({ const [isAttachmentInvalid, setIsAttachmentInvalid] = useState(false); const [attachmentInvalidReasonTitle, setAttachmentInvalidReasonTitle] = useState(); const [attachmentInvalidReason, setAttachmentValidReason] = useState(); - + const [pdfFile, setPdfFile] = useState(null); const [receiptImageTopPosition, setReceiptImageTopPosition] = useState(0); const {isSmallScreenWidth} = useWindowDimensions(); const {translate} = useLocalize(); @@ -187,6 +189,7 @@ function IOURequestStepScan({ setIsAttachmentInvalid(isInvalid); setAttachmentInvalidReasonTitle(title); setAttachmentValidReason(reason); + setPdfFile(null); }; function validateReceipt(file: FileObject) { @@ -415,11 +418,15 @@ function IOURequestStepScan({ /** * Sets the Receipt objects and navigates the user to the next page */ - const setReceiptAndNavigate = (file: FileObject) => { + const setReceiptAndNavigate = (file: FileObject, isPdfValidated?: boolean) => { validateReceipt(file).then((isFileValid) => { if (!isFileValid) { return; } + if (Str.isPDF(file.name ?? '') && !isPdfValidated) { + setPdfFile(file); + return; + } // Store the receipt on the transaction object in Onyx const source = URL.createObjectURL(file as Blob); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -512,6 +519,28 @@ function IOURequestStepScan({ const mobileCameraView = () => ( <> + {pdfFile && ( + { + setPdfFile(null); + setReceiptAndNavigate(pdfFile, true); + }} + onPassword={() => { + // setIsAttachmentInvalid(true); + // setInvalidAttachmentPromt(translate('attachmentPicker.protectedPDFNotSupported')); + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + }} + onLoadError={() => { + // setInvalidAttachmentPromt(translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); + // setIsAttachmentInvalid(true); + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + }} + /> + )} {((cameraPermissionState === 'prompt' && !isQueriedPermissionState) || (cameraPermissionState === 'granted' && isEmptyObject(videoConstraints))) && ( ( <> + {pdfFile && ( + + { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + }} + onLoadSuccess={() => { + setPdfFile(null); + setReceiptAndNavigate(pdfFile, true); + }} + onLoadError={() => { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + }} + /> + + )} setReceiptImageTopPosition(PixelRatio.roundToNearestPixel((nativeEvent.layout as DOMRect).top))}> Date: Thu, 20 Jun 2024 01:24:02 +0530 Subject: [PATCH 02/15] add pdf validation for native. Signed-off-by: Krishna Gupta --- src/components/PDFThumbnail/index.native.tsx | 14 +++++-- .../step/IOURequestStepScan/index.native.tsx | 40 ++++++++++++++++++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/components/PDFThumbnail/index.native.tsx b/src/components/PDFThumbnail/index.native.tsx index 27d41ede3263..66a42f6f0830 100644 --- a/src/components/PDFThumbnail/index.native.tsx +++ b/src/components/PDFThumbnail/index.native.tsx @@ -7,7 +7,7 @@ import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import PDFThumbnailError from './PDFThumbnailError'; import type PDFThumbnailProps from './types'; -function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword, onLoadError}: PDFThumbnailProps) { +function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword, onLoadError, onLoadSuccess}: PDFThumbnailProps) { const styles = useThemeStyles(); const sizeStyles = [styles.w100, styles.h100]; const [failedToLoad, setFailedToLoad] = useState(false); @@ -24,15 +24,21 @@ function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, ena singlePage style={sizeStyles} onError={(error) => { - if (onLoadError) { - onLoadError(); - } if ('message' in error && typeof error.message === 'string' && error.message.match(/password/i) && onPassword) { onPassword(); return; } + if (onLoadError) { + onLoadError(); + } setFailedToLoad(true); }} + onLoadComplete={() => { + if (!onLoadSuccess) { + return; + } + onLoadSuccess(); + }} /> )} {failedToLoad && } diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 029bbf91727f..32e23904c201 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -1,4 +1,5 @@ import {useFocusEffect} from '@react-navigation/core'; +import {Str} from 'expensify-common'; import React, {useCallback, useMemo, useRef, useState} from 'react'; import {ActivityIndicator, Alert, AppState, InteractionManager, View} from 'react-native'; import {Gesture, GestureDetector} from 'react-native-gesture-handler'; @@ -16,6 +17,7 @@ import Button from '@components/Button'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; import ImageSVG from '@components/ImageSVG'; +import PDFThumbnail from '@components/PDFThumbnail'; import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; import Text from '@components/Text'; import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails'; @@ -65,6 +67,8 @@ function IOURequestStepScan({ const [cameraPermissionStatus, setCameraPermissionStatus] = useState(null); const [didCapturePhoto, setDidCapturePhoto] = useState(false); + const [pdfFile, setPdfFile] = useState(null); + const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction); const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? ''; const transactionTaxAmount = transaction?.taxAmount ?? 0; @@ -379,11 +383,16 @@ function IOURequestStepScan({ /** * Sets the Receipt objects and navigates the user to the next page */ - const setReceiptAndNavigate = (file: FileObject) => { + const setReceiptAndNavigate = (file: FileObject, isPdfValidated?: boolean) => { if (!validateReceipt(file)) { return; } + if (Str.isPDF(file.name ?? '') && !isPdfValidated) { + setPdfFile(file); + return; + } + // Store the receipt on the transaction object in Onyx // On Android devices, fetching blob for a file with name containing spaces fails to retrieve the type of file. // So, let us also save the file type in receipt for later use during blob fetch @@ -454,6 +463,35 @@ function IOURequestStepScan({ shouldShowWrapper={!!backTo} testID={IOURequestStepScan.displayName} > + {pdfFile && ( + + { + setPdfFile(null); + setReceiptAndNavigate(pdfFile, true); + }} + onPassword={() => { + // setIsAttachmentInvalid(true); + // setInvalidAttachmentPromt(translate('attachmentPicker.protectedPDFNotSupported')); + // setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.protectedPDFNotSupported')); + }} + onLoadError={() => { + // setInvalidAttachmentPromt(translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); + // setIsAttachmentInvalid(true); + // setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + console.log('EeROR'); + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); + }} + /> + + )} {cameraPermissionStatus !== RESULTS.GRANTED && ( Date: Sun, 23 Jun 2024 22:04:16 +0530 Subject: [PATCH 03/15] corrupt pdf alert fix for android. Signed-off-by: Krishna Gupta --- .../step/IOURequestStepScan/index.native.tsx | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index cdf16d485d13..4b1981f37473 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -463,35 +463,28 @@ function IOURequestStepScan({ shouldShowWrapper={!!backTo} testID={IOURequestStepScan.displayName} > - {pdfFile && ( - - { - setPdfFile(null); - setReceiptAndNavigate(pdfFile, true); - }} - onPassword={() => { - // setIsAttachmentInvalid(true); - // setInvalidAttachmentPromt(translate('attachmentPicker.protectedPDFNotSupported')); - // setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); - setPdfFile(null); - Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.protectedPDFNotSupported')); - }} - onLoadError={() => { - // setInvalidAttachmentPromt(translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); - // setIsAttachmentInvalid(true); - // setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); - console.log('EeROR'); - setPdfFile(null); - Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); - }} - /> - - )} + + {pdfFile && ( + + { + setPdfFile(null); + setReceiptAndNavigate(pdfFile, true); + }} + onPassword={() => { + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.protectedPDFNotSupported')); + }} + onLoadError={() => { + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); + }} + /> + + )} + {cameraPermissionStatus !== RESULTS.GRANTED && ( Date: Sat, 6 Jul 2024 17:12:48 +0530 Subject: [PATCH 04/15] minor updated. Signed-off-by: Krishna Gupta --- src/components/PDFThumbnail/types.ts | 2 + .../step/IOURequestStepScan/index.native.tsx | 39 ++++++++++--------- .../request/step/IOURequestStepScan/index.tsx | 37 ++++++++---------- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/components/PDFThumbnail/types.ts b/src/components/PDFThumbnail/types.ts index 512b5afc2d6f..3d79e7c026d2 100644 --- a/src/components/PDFThumbnail/types.ts +++ b/src/components/PDFThumbnail/types.ts @@ -18,6 +18,8 @@ type PDFThumbnailProps = { /** Callback to call if PDF can't be loaded(corrupted) */ onLoadError?: () => void; + + /** Callback to call if PDF is loaded */ onLoadSuccess?: () => void; }; diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 4b1981f37473..8eeb7f12ad70 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -464,26 +464,27 @@ function IOURequestStepScan({ testID={IOURequestStepScan.displayName} > - {pdfFile && ( - - { - setPdfFile(null); + + { + setPdfFile(null); + if (pdfFile) { setReceiptAndNavigate(pdfFile, true); - }} - onPassword={() => { - setPdfFile(null); - Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.protectedPDFNotSupported')); - }} - onLoadError={() => { - setPdfFile(null); - Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); - }} - /> - - )} + } + }} + onPassword={() => { + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.protectedPDFNotSupported')); + }} + onLoadError={() => { + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); + }} + /> + {cameraPermissionStatus !== RESULTS.GRANTED && ( diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 714019b8c28e..e98aee8c05a4 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -529,28 +529,23 @@ function IOURequestStepScan({ const mobileCameraView = () => ( <> - {pdfFile && ( - { - setPdfFile(null); + { + setPdfFile(null); + if (pdfFile) { setReceiptAndNavigate(pdfFile, true); - }} - onPassword={() => { - // setIsAttachmentInvalid(true); - // setInvalidAttachmentPromt(translate('attachmentPicker.protectedPDFNotSupported')); - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); - }} - onLoadError={() => { - // setInvalidAttachmentPromt(translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); - // setIsAttachmentInvalid(true); - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); - }} - /> - )} + } + }} + onPassword={() => { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + }} + onLoadError={() => { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + }} + /> {((cameraPermissionState === 'prompt' && !isQueriedPermissionState) || (cameraPermissionState === 'granted' && isEmptyObject(videoConstraints))) && ( Date: Sat, 6 Jul 2024 18:18:35 +0530 Subject: [PATCH 05/15] cleanup. Signed-off-by: Krishna Gupta --- .../MoneyRequestConfirmationListFooter.tsx | 30 +------------------ .../request/step/IOURequestStepScan/index.tsx | 11 ------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index 8dfff6466ab9..203420dfe042 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -1,7 +1,7 @@ import {format} from 'date-fns'; import {Str} from 'expensify-common'; import lodashIsEqual from 'lodash/isEqual'; -import React, {memo, useMemo, useReducer, useState} from 'react'; +import React, {memo, useMemo, useReducer} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {useOnyx} from 'react-native-onyx'; @@ -29,7 +29,6 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {Participant} from '@src/types/onyx/IOU'; import type {Unit} from '@src/types/onyx/Policy'; import ConfirmedRoute from './ConfirmedRoute'; -import ConfirmModal from './ConfirmModal'; import MenuItem from './MenuItem'; import MenuItemWithTopDescription from './MenuItemWithTopDescription'; import PDFThumbnail from './PDFThumbnail'; @@ -224,9 +223,6 @@ function MoneyRequestConfirmationListFooter({ // A flag and a toggler for showing the rest of the form fields const [shouldExpandFields, toggleShouldExpandFields] = useReducer((state) => !state, false); - const [isAttachmentInvalid, setIsAttachmentInvalid] = useState(false); - const [invalidAttachmentPrompt, setInvalidAttachmentPrompt] = useState(translate('attachmentPicker.protectedPDFNotSupported')); - // A flag for showing the tags field // TODO: remove the !isTypeInvoice from this condition after BE supports tags for invoices: https://github.com/Expensify/App/issues/41281 const shouldShowTags = useMemo(() => isPolicyExpenseChat && OptionsListUtils.hasEnabledTags(policyTagLists) && !isTypeInvoice, [isPolicyExpenseChat, isTypeInvoice, policyTagLists]); @@ -546,16 +542,6 @@ function MoneyRequestConfirmationListFooter({ { - setIsAttachmentInvalid(true); - setInvalidAttachmentPrompt(translate('attachmentPicker.protectedPDFNotSupported')); - }} - onLoadError={() => { - setInvalidAttachmentPrompt(translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); - setIsAttachmentInvalid(true); - }} /> ) : ( @@ -590,7 +576,6 @@ function MoneyRequestConfirmationListFooter({ translate, shouldDisplayReceipt, resolvedReceiptImage, - isAttachmentInvalid, isThumbnail, resolvedThumbnail, receiptThumbnail, @@ -601,10 +586,6 @@ function MoneyRequestConfirmationListFooter({ ], ); - const navigateBack = () => { - Navigation.goBack(ROUTES.MONEY_REQUEST_CREATE_TAB_SCAN.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID)); - }; - return ( <> {isTypeInvoice && ( @@ -654,15 +635,6 @@ function MoneyRequestConfirmationListFooter({ /> )} {shouldShowAllFields && supplementaryFields} - ); } diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index e98aee8c05a4..aa550c0e0578 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -27,7 +27,6 @@ import useWindowDimensions from '@hooks/useWindowDimensions'; import * as Browser from '@libs/Browser'; import * as FileUtils from '@libs/fileDownload/FileUtils'; import getCurrentPosition from '@libs/getCurrentPosition'; -import isPdfFilePasswordProtected from '@libs/isPdfFilePasswordProtected'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; @@ -215,16 +214,6 @@ function IOURequestStepScan({ setUploadReceiptError(true, 'attachmentPicker.attachmentTooSmall', 'attachmentPicker.sizeNotMet'); return false; } - - if (fileExtension === 'pdf') { - return isPdfFilePasswordProtected(file).then((isProtected: boolean) => { - if (isProtected) { - setUploadReceiptError(true, 'attachmentPicker.wrongFileType', 'attachmentPicker.protectedPDFNotSupported'); - return false; - } - return true; - }); - } return true; }) .catch(() => { From 85e166e9bb5b8610a6a6452ce0295be82c9413a9 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sat, 6 Jul 2024 18:28:50 +0530 Subject: [PATCH 06/15] minor fix. Signed-off-by: Krishna Gupta --- src/pages/iou/request/step/IOURequestStepScan/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index aa550c0e0578..842a5955ecb8 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -529,7 +529,7 @@ function IOURequestStepScan({ } }} onPassword={() => { - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.protectedPDFNotSupported'); }} onLoadError={() => { setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); From e4eb9a2af62710d3676df12cd7cc6c3c1ca3aa3b Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sat, 6 Jul 2024 18:32:45 +0530 Subject: [PATCH 07/15] minor update/ Signed-off-by: Krishna Gupta --- .../request/step/IOURequestStepScan/index.tsx | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 842a5955ecb8..1ed619d5b64d 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -633,23 +633,24 @@ function IOURequestStepScan({ const desktopUploadView = () => ( <> - {pdfFile && ( - - { - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); - }} - onLoadSuccess={() => { - setPdfFile(null); + + { + setPdfFile(null); + if (pdfFile) { setReceiptAndNavigate(pdfFile, true); - }} - onLoadError={() => { - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); - }} - /> - - )} + } + }} + onPassword={() => { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.protectedPDFNotSupported'); + }} + onLoadError={() => { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + }} + /> + setReceiptImageTopPosition(PixelRatio.roundToNearestPixel((nativeEvent.layout as DOMRect).top))}> Date: Sat, 6 Jul 2024 18:35:36 +0530 Subject: [PATCH 08/15] refactor. Signed-off-by: Krishna Gupta --- .../request/step/IOURequestStepScan/index.tsx | 59 ++++++++----------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 1ed619d5b64d..a6d87f019051 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -515,26 +515,32 @@ function IOURequestStepScan({ [], ); + const PDFThumbnailView = ( + + { + setPdfFile(null); + if (pdfFile) { + setReceiptAndNavigate(pdfFile, true); + } + }} + onPassword={() => { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.protectedPDFNotSupported'); + }} + onLoadError={() => { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + }} + /> + + ); + const mobileCameraView = () => ( <> - { - setPdfFile(null); - if (pdfFile) { - setReceiptAndNavigate(pdfFile, true); - } - }} - onPassword={() => { - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.protectedPDFNotSupported'); - }} - onLoadError={() => { - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); - }} - /> + {PDFThumbnailView} {((cameraPermissionState === 'prompt' && !isQueriedPermissionState) || (cameraPermissionState === 'granted' && isEmptyObject(videoConstraints))) && ( ( <> - - { - setPdfFile(null); - if (pdfFile) { - setReceiptAndNavigate(pdfFile, true); - } - }} - onPassword={() => { - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.protectedPDFNotSupported'); - }} - onLoadError={() => { - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); - }} - /> - + {PDFThumbnailView} setReceiptImageTopPosition(PixelRatio.roundToNearestPixel((nativeEvent.layout as DOMRect).top))}> Date: Sun, 7 Jul 2024 03:22:42 +0530 Subject: [PATCH 09/15] fix rendering issue. Signed-off-by: Krishna Gupta --- .../iou/request/step/IOURequestStepScan/index.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index a6d87f019051..3b5c4d08a797 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -515,17 +515,14 @@ function IOURequestStepScan({ [], ); - const PDFThumbnailView = ( + const PDFThumbnailView = pdfFile ? ( { setPdfFile(null); - if (pdfFile) { - setReceiptAndNavigate(pdfFile, true); - } + setReceiptAndNavigate(pdfFile, true); }} onPassword={() => { setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.protectedPDFNotSupported'); @@ -535,7 +532,7 @@ function IOURequestStepScan({ }} /> - ); + ) : null; const mobileCameraView = () => ( <> From 33b3912aedb1bd479e7eaa56ac7c64e118102884 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sun, 7 Jul 2024 04:29:01 +0530 Subject: [PATCH 10/15] minor update. Signed-off-by: Krishna Gupta --- .../step/IOURequestStepScan/index.native.tsx | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 8eeb7f12ad70..2c83cbcc5b28 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -464,27 +464,28 @@ function IOURequestStepScan({ testID={IOURequestStepScan.displayName} > - - { - setPdfFile(null); - if (pdfFile) { - setReceiptAndNavigate(pdfFile, true); - } - }} - onPassword={() => { - setPdfFile(null); - Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.protectedPDFNotSupported')); - }} - onLoadError={() => { - setPdfFile(null); - Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); - }} - /> - + {pdfFile && ( + + { + setPdfFile(null); + if (pdfFile) { + setReceiptAndNavigate(pdfFile, true); + } + }} + onPassword={() => { + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.protectedPDFNotSupported')); + }} + onLoadError={() => { + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); + }} + /> + + )} {cameraPermissionStatus !== RESULTS.GRANTED && ( From f36966d714fac2551de721c5e8245b89bfe8ff84 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Wed, 10 Jul 2024 07:11:10 +0530 Subject: [PATCH 11/15] minor updates. Signed-off-by: krishna2323 --- .../step/IOURequestStepScan/index.native.tsx | 44 +++++++++---------- .../request/step/IOURequestStepScan/index.tsx | 30 ++++++------- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 2eaee3de34d3..7cba6339f4d5 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -464,30 +464,26 @@ function IOURequestStepScan({ shouldShowWrapper={!!backTo} testID={IOURequestStepScan.displayName} > - - {pdfFile && ( - - { - setPdfFile(null); - if (pdfFile) { - setReceiptAndNavigate(pdfFile, true); - } - }} - onPassword={() => { - setPdfFile(null); - Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.protectedPDFNotSupported')); - }} - onLoadError={() => { - setPdfFile(null); - Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); - }} - /> - - )} - + {pdfFile && ( + { + setPdfFile(null); + if (pdfFile) { + setReceiptAndNavigate(pdfFile, true); + } + }} + onPassword={() => { + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.protectedPDFNotSupported')); + }} + onLoadError={() => { + setPdfFile(null); + Alert.alert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); + }} + /> + )} {cameraPermissionStatus !== RESULTS.GRANTED && ( - { - setPdfFile(null); - setReceiptAndNavigate(pdfFile, true); - }} - onPassword={() => { - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.protectedPDFNotSupported'); - }} - onLoadError={() => { - setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); - }} - /> - + { + setPdfFile(null); + setReceiptAndNavigate(pdfFile, true); + }} + onPassword={() => { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.protectedPDFNotSupported'); + }} + onLoadError={() => { + setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); + }} + /> ) : null; const mobileCameraView = () => ( From 24b07d52ff6aeb8ce9b72a2b179d2c5f731ad397 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Mon, 15 Jul 2024 12:28:14 +0530 Subject: [PATCH 12/15] add invisible pdf styling. Signed-off-by: krishna2323 --- .../iou/request/step/IOURequestStepScan/index.native.tsx | 2 +- src/pages/iou/request/step/IOURequestStepScan/index.tsx | 2 +- src/styles/index.ts | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 5348926e2524..f997c89dee65 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -466,7 +466,7 @@ function IOURequestStepScan({ > {pdfFile && ( { setPdfFile(null); diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index a58da1feee48..16b33561f684 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -517,7 +517,7 @@ function IOURequestStepScan({ const PDFThumbnailView = pdfFile ? ( { setPdfFile(null); diff --git a/src/styles/index.ts b/src/styles/index.ts index 9d7bc9ab05ad..41edeb52b5d3 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -1038,6 +1038,13 @@ const styles = (theme: ThemeColors) => justifyContent: 'center', }, + invisiblePdf: { + position: 'absolute', + opacity: 0, + width: 1, + height: 1, + }, + headerAnonymousFooter: { color: theme.heading, fontFamily: FontUtils.fontFamily.platform.EXP_NEW_KANSAS_MEDIUM, From ace0862561c0b434b4462c2bc48d20f516e0f0b8 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Mon, 15 Jul 2024 12:36:13 +0530 Subject: [PATCH 13/15] add comment. Signed-off-by: krishna2323 --- src/pages/iou/request/step/IOURequestStepScan/index.native.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index f997c89dee65..6aa70653c602 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -389,6 +389,7 @@ function IOURequestStepScan({ return; } + // If we have a pdf file and if it is not validated then set the pdf file for validation and return if (Str.isPDF(file.name ?? '') && !isPdfValidated) { setPdfFile(file); return; From 105356b10f314c37f2d71e8d4d438ea7e31a3052 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Mon, 15 Jul 2024 13:17:45 +0530 Subject: [PATCH 14/15] add comment. Signed-off-by: krishna2323 --- src/pages/iou/request/step/IOURequestStepScan/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 16b33561f684..7b7deb9ff163 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -422,6 +422,8 @@ function IOURequestStepScan({ if (!isFileValid) { return; } + + // If we have a pdf file and if it is not validated then set the pdf file for validation and return if (Str.isPDF(file.name ?? '') && !isPdfValidated) { setPdfFile(file); return; From 8d553b0a43897db325281ab70e095c2ddca2c704 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 16 Jul 2024 05:17:45 +0530 Subject: [PATCH 15/15] minor fix. Signed-off-by: krishna2323 --- src/pages/iou/request/step/IOURequestStepScan/index.native.tsx | 2 +- src/pages/iou/request/step/IOURequestStepScan/index.tsx | 2 +- src/styles/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 6aa70653c602..434f8a87b853 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -467,7 +467,7 @@ function IOURequestStepScan({ > {pdfFile && ( { setPdfFile(null); diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 7b7deb9ff163..387a09a35107 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -519,7 +519,7 @@ function IOURequestStepScan({ const PDFThumbnailView = pdfFile ? ( { setPdfFile(null); diff --git a/src/styles/index.ts b/src/styles/index.ts index 41edeb52b5d3..fc91920eeae5 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -1038,7 +1038,7 @@ const styles = (theme: ThemeColors) => justifyContent: 'center', }, - invisiblePdf: { + invisiblePDF: { position: 'absolute', opacity: 0, width: 1,