-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Scan - No error pop-up and scan expense with corrupted PDF can be submitted via QAB #44778
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0caf904
feat: corrupt pdf detection on scan page.
Krishna2323 2a76f6d
Merge branch 'Expensify:main' into krishna2323/test/43645
Krishna2323 4cbf8e2
add pdf validation for native.
Krishna2323 a26c5b6
Merge branch 'Expensify:main' into krishna2323/test/43645
Krishna2323 80fa7bb
corrupt pdf alert fix for android.
Krishna2323 65c1537
Merge branch 'Expensify:main' into krishna2323/test/43645
Krishna2323 3f1fafa
Merge branch 'Expensify:main' into krishna2323/issue/43645
Krishna2323 2a7cbe9
minor updated.
Krishna2323 458c75d
cleanup.
Krishna2323 85e166e
minor fix.
Krishna2323 e4eb9a2
minor update/
Krishna2323 29ad495
refactor.
Krishna2323 881dba7
fix rendering issue.
Krishna2323 33b3912
minor update.
Krishna2323 1a5c19b
Merge branch 'Expensify:main' into krishna2323/issue/43645
Krishna2323 f36966d
minor updates.
Krishna2323 1a71c50
Merge branch 'Expensify:main' into krishna2323/issue/43645
Krishna2323 24b07d5
add invisible pdf styling.
Krishna2323 ace0862
add comment.
Krishna2323 105356b
add comment.
Krishna2323 8d553b0
minor fix.
Krishna2323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
|
@@ -25,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'; | ||
|
@@ -63,7 +64,7 @@ function IOURequestStepScan({ | |
const [isAttachmentInvalid, setIsAttachmentInvalid] = useState(false); | ||
const [attachmentInvalidReasonTitle, setAttachmentInvalidReasonTitle] = useState<TranslationPaths>(); | ||
const [attachmentInvalidReason, setAttachmentValidReason] = useState<TranslationPaths>(); | ||
|
||
const [pdfFile, setPdfFile] = useState<null | FileObject>(null); | ||
const [receiptImageTopPosition, setReceiptImageTopPosition] = useState(0); | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
const {translate} = useLocalize(); | ||
|
@@ -188,6 +189,7 @@ function IOURequestStepScan({ | |
setIsAttachmentInvalid(isInvalid); | ||
setAttachmentInvalidReasonTitle(title); | ||
setAttachmentValidReason(reason); | ||
setPdfFile(null); | ||
}; | ||
|
||
function validateReceipt(file: FileObject) { | ||
|
@@ -212,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(() => { | ||
|
@@ -425,11 +417,17 @@ 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 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you explain the check for a not validated pdf here? |
||
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 | ||
|
@@ -519,9 +517,27 @@ function IOURequestStepScan({ | |
[], | ||
); | ||
|
||
const PDFThumbnailView = pdfFile ? ( | ||
<PDFThumbnail | ||
style={styles.invisiblePDF} | ||
previewSourceURL={pdfFile.uri ?? ''} | ||
onLoadSuccess={() => { | ||
setPdfFile(null); | ||
setReceiptAndNavigate(pdfFile, true); | ||
}} | ||
onPassword={() => { | ||
setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.protectedPDFNotSupported'); | ||
}} | ||
onLoadError={() => { | ||
setUploadReceiptError(true, 'attachmentPicker.attachmentError', 'attachmentPicker.errorWhileSelectingCorruptedAttachment'); | ||
}} | ||
/> | ||
) : null; | ||
|
||
const mobileCameraView = () => ( | ||
<> | ||
<View style={[styles.cameraView]}> | ||
{PDFThumbnailView} | ||
{((cameraPermissionState === 'prompt' && !isQueriedPermissionState) || (cameraPermissionState === 'granted' && isEmptyObject(videoConstraints))) && ( | ||
<ActivityIndicator | ||
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE} | ||
|
@@ -620,6 +636,7 @@ function IOURequestStepScan({ | |
|
||
const desktopUploadView = () => ( | ||
<> | ||
{PDFThumbnailView} | ||
<View onLayout={({nativeEvent}) => setReceiptImageTopPosition(PixelRatio.roundToNearestPixel((nativeEvent.layout as DOMRect).top))}> | ||
<ReceiptUpload | ||
width={CONST.RECEIPT.ICON_SIZE} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we call this with null here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for some reason PDF isn't re-rendering on android native when file is changed to another file so we need to set it to null first.