@@ -45,6 +45,18 @@ function useFilesValidation(proceedWithFilesAction: (files: FileObject[]) => voi
4545 const filesToValidate = useRef < FileObject [ ] > ( [ ] ) ;
4646 const collectedErrors = useRef < ErrorObject [ ] > ( [ ] ) ;
4747
48+ const deduplicateErrors = useCallback ( ( errors : ErrorObject [ ] ) => {
49+ const uniqueErrors = new Set < string > ( ) ;
50+ return errors . filter ( ( error ) => {
51+ const key = `${ error . error } -${ error . fileExtension ?? '' } ` ;
52+ if ( uniqueErrors . has ( key ) ) {
53+ return false ;
54+ }
55+ uniqueErrors . add ( key ) ;
56+ return true ;
57+ } ) ;
58+ } , [ ] ) ;
59+
4860 const resetValidationState = useCallback ( ( ) => {
4961 setIsErrorModalVisible ( false ) ;
5062 setPdfFilesToRender ( [ ] ) ;
@@ -120,7 +132,7 @@ function useFilesValidation(proceedWithFilesAction: (files: FileObject[]) => voi
120132 }
121133
122134 if ( collectedErrors . current . length > 0 ) {
123- const uniqueErrors = Array . from ( new Set ( collectedErrors . current . map ( ( error ) => JSON . stringify ( error ) ) ) ) . map ( ( errorStr ) => JSON . parse ( errorStr ) as ErrorObject ) ;
135+ const uniqueErrors = deduplicateErrors ( collectedErrors . current ) ;
124136 setErrorQueue ( uniqueErrors ) ;
125137 setCurrentErrorIndex ( 0 ) ;
126138 const firstError = uniqueErrors . at ( 0 ) ;
@@ -135,9 +147,14 @@ function useFilesValidation(proceedWithFilesAction: (files: FileObject[]) => voi
135147 proceedWithFilesAction ( validFiles . current ) ;
136148 resetValidationState ( ) ;
137149 }
138- } , [ pdfFilesToRender . length , proceedWithFilesAction , resetValidationState ] ) ;
150+ } , [ deduplicateErrors , pdfFilesToRender . length , proceedWithFilesAction , resetValidationState ] ) ;
139151
140152 const validateAndResizeFiles = ( files : FileObject [ ] ) => {
153+ // Early return for empty files
154+ if ( files . length === 0 ) {
155+ return ;
156+ }
157+
141158 // Reset collected errors for new validation
142159 collectedErrors . current = [ ] ;
143160
@@ -261,21 +278,21 @@ function useFilesValidation(proceedWithFilesAction: (files: FileObject[]) => voi
261278 style = { styles . invisiblePDF }
262279 previewSourceURL = { file . uri ?? '' }
263280 onLoadSuccess = { ( ) => {
264- validatedPDFs . current = [ ... ( validatedPDFs . current ?? [ ] ) , file ] ;
265- validFiles . current = [ ... ( validFiles . current ?? [ ] ) , file ] ;
281+ validatedPDFs . current . push ( file ) ;
282+ validFiles . current . push ( file ) ;
266283 checkIfAllValidatedAndProceed ( ) ;
267284 } }
268285 onPassword = { ( ) => {
269- validatedPDFs . current = [ ... ( validatedPDFs . current ?? [ ] ) , file ] ;
286+ validatedPDFs . current . push ( file ) ;
270287 if ( isValidatingReceipts ) {
271288 collectedErrors . current . push ( { error : CONST . FILE_VALIDATION_ERRORS . PROTECTED_FILE } ) ;
272289 } else {
273- validFiles . current = [ ... ( validFiles . current ?? [ ] ) , file ] ;
290+ validFiles . current . push ( file ) ;
274291 }
275292 checkIfAllValidatedAndProceed ( ) ;
276293 } }
277294 onLoadError = { ( ) => {
278- validatedPDFs . current = [ ... ( validatedPDFs . current ?? [ ] ) , file ] ;
295+ validatedPDFs . current . push ( file ) ;
279296 collectedErrors . current . push ( { error : CONST . FILE_VALIDATION_ERRORS . FILE_CORRUPTED } ) ;
280297 checkIfAllValidatedAndProceed ( ) ;
281298 } }
@@ -287,21 +304,21 @@ function useFilesValidation(proceedWithFilesAction: (files: FileObject[]) => voi
287304 if ( ! fileError ) {
288305 return '' ;
289306 }
290- const prompt = getFileValidationErrorText ( fileError , { fileType : invalidFileExtension } ) . reason ;
291- if ( fileError === CONST . FILE_VALIDATION_ERRORS . WRONG_FILE_TYPE_MULTIPLE ) {
307+ const prompt = getFileValidationErrorText ( fileError , { fileType : invalidFileExtension } , isValidatingReceipts ) . reason ;
308+ if ( fileError === CONST . FILE_VALIDATION_ERRORS . WRONG_FILE_TYPE_MULTIPLE || fileError === CONST . FILE_VALIDATION_ERRORS . WRONG_FILE_TYPE ) {
292309 return (
293310 < Text >
294311 { prompt }
295- < TextLink href = "" > { translate ( 'attachmentPicker.learnMoreAboutSupportedFiles' ) } </ TextLink >
312+ < TextLink href = { CONST . BULK_UPLOAD_HELP_URL } > { translate ( 'attachmentPicker.learnMoreAboutSupportedFiles' ) } </ TextLink >
296313 </ Text >
297314 ) ;
298315 }
299316 return prompt ;
300- } , [ fileError , invalidFileExtension , translate ] ) ;
317+ } , [ fileError , invalidFileExtension , isValidatingReceipts , translate ] ) ;
301318
302319 const ErrorModal = (
303320 < ConfirmModal
304- title = { getFileValidationErrorText ( fileError , { fileType : invalidFileExtension } ) . title }
321+ title = { getFileValidationErrorText ( fileError , { fileType : invalidFileExtension } , isValidatingReceipts ) . title }
305322 onConfirm = { onConfirm }
306323 onCancel = { hideModalAndReset }
307324 isVisible = { isErrorModalVisible }
0 commit comments