From b7cda7b1303ea30676314504d8a3bb0e57e93d9e Mon Sep 17 00:00:00 2001 From: charan h s Date: Fri, 21 Jul 2023 06:50:54 +0530 Subject: [PATCH 01/15] Webkitdirectory added --- src/components/DragAndDrop/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/DragAndDrop/index.js b/src/components/DragAndDrop/index.js index 5c5d17a4a272..536509c98926 100644 --- a/src/components/DragAndDrop/index.js +++ b/src/components/DragAndDrop/index.js @@ -84,6 +84,7 @@ class DragAndDrop extends React.Component { addEventListeners() { this.dropZone = document.getElementById(this.props.dropZoneId); + document.documentElement.setAttribute('webkitdirectory',"") this.dropZoneRect = this.calculateDropZoneClientReact(); document.addEventListener('dragover', this.dropZoneDragListener); document.addEventListener('dragenter', this.dropZoneDragListener); @@ -93,6 +94,7 @@ class DragAndDrop extends React.Component { } removeEventListeners() { + document.documentElement.removeAttribute('webkitdirectory') document.removeEventListener('dragover', this.dropZoneDragListener); document.removeEventListener('dragenter', this.dropZoneDragListener); document.removeEventListener('dragleave', this.dropZoneDragListener); From d841c888e7f69eae6aab82e139fa3d1958ff790c Mon Sep 17 00:00:00 2001 From: charan h s Date: Fri, 21 Jul 2023 06:56:14 +0530 Subject: [PATCH 02/15] checking file is a folder --- src/components/AttachmentModal.js | 18 +++++++++++++----- src/pages/home/report/ReportActionCompose.js | 6 +++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index bb648c155840..393c361f229e 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -177,12 +177,19 @@ function AttachmentModal(props) { setIsAttachmentInvalid(false); }, []); /** - * @param {Object} _file + * @param {Object} _data * @returns {Boolean} */ const isValidFile = useCallback( - (_file) => { + (_data) => { + const _file = _data.getAsFile(); const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(_file, 'name', '')); + if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { + setIsAttachmentInvalid(true); + setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.attachmentError')); + setAttachmentInvalidReason(props.translate('attachmentPicker.folderNotAllowedMessage')); + return false; + } if (_.contains(CONST.API_ATTACHMENT_VALIDATIONS.UNALLOWED_EXTENSIONS, fileExtension.toLowerCase())) { const invalidReason = props.translate('attachmentPicker.notAllowedExtension'); @@ -212,15 +219,16 @@ function AttachmentModal(props) { [props.translate], ); /** - * @param {Object} _file + * @param {Object} _data */ const validateAndDisplayFileToUpload = useCallback( - (_file) => { + (_data) => { + const _file = _data.getAsFile(); if (!_file) { return; } - if (!isValidFile(_file)) { + if (!isValidFile(_data)) { return; } diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 8155f09b2aac..ba432c7bf186 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -1127,9 +1127,9 @@ class ReportActionCompose extends React.Component { return; } - const file = lodashGet(e, ['dataTransfer', 'files', 0]); - - displayFileInModal(file); + const data = lodashGet(e, ['dataTransfer', 'items', 0]); + + displayFileInModal(data); this.setState({isDraggingOver: false}); }} From 319006fc9a4e864929b5a106e20c0b90c26be730 Mon Sep 17 00:00:00 2001 From: charan h s Date: Fri, 21 Jul 2023 06:57:13 +0530 Subject: [PATCH 03/15] update error message --- src/languages/en.js | 1 + src/languages/es.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/languages/en.js b/src/languages/en.js index 47cc8d209735..293707097426 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -168,6 +168,7 @@ export default { sizeNotMet: 'Attachment size must be greater than 240 bytes.', wrongFileType: 'Attachment is the wrong type', notAllowedExtension: 'This filetype is not allowed', + folderNotAllowedMessage: 'Uploading folder is not allowed.' }, avatarCropModal: { title: 'Edit photo', diff --git a/src/languages/es.js b/src/languages/es.js index 5eea74099e4c..7f90e7acdc87 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -167,6 +167,8 @@ export default { sizeNotMet: 'El archivo adjunto debe ser mas grande que 240 bytes.', wrongFileType: 'El tipo del archivo adjunto es incorrecto', notAllowedExtension: 'Este tipo de archivo no está permitido', + folderNotAllowedMessage: 'No se permite subir carpetas.' + }, avatarCropModal: { title: 'Editar foto', From f02b0ca8d69c32352f4040338b3f38d9c5dc134e Mon Sep 17 00:00:00 2001 From: charan h s Date: Fri, 21 Jul 2023 15:38:25 +0530 Subject: [PATCH 04/15] checking file is data object --- src/components/AttachmentModal.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 393c361f229e..d71ca17a39d2 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -177,12 +177,12 @@ function AttachmentModal(props) { setIsAttachmentInvalid(false); }, []); /** + * @param {Object} _file * @param {Object} _data * @returns {Boolean} */ const isValidFile = useCallback( - (_data) => { - const _file = _data.getAsFile(); + (_file,_data) => { const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(_file, 'name', '')); if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { setIsAttachmentInvalid(true); @@ -223,12 +223,15 @@ function AttachmentModal(props) { */ const validateAndDisplayFileToUpload = useCallback( (_data) => { - const _file = _data.getAsFile(); + let _file = _data + if (typeof _data.getAsFile === 'function' ){ + _file = _data.getAsFile(); + } if (!_file) { return; } - if (!isValidFile(_data)) { + if (!isValidFile(_file,_data)) { return; } From c2c30d28e2c482691d1293294b334adb3d8e39fc Mon Sep 17 00:00:00 2001 From: charan h s Date: Tue, 25 Jul 2023 00:41:46 +0530 Subject: [PATCH 05/15] isDirectoryCheck added --- src/components/AttachmentModal.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index d71ca17a39d2..c935f22ac628 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -178,21 +178,13 @@ function AttachmentModal(props) { }, []); /** * @param {Object} _file - * @param {Object} _data * @returns {Boolean} */ const isValidFile = useCallback( - (_file,_data) => { + (_file) => { const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(_file, 'name', '')); - if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { - setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.attachmentError')); - setAttachmentInvalidReason(props.translate('attachmentPicker.folderNotAllowedMessage')); - return false; - } if (_.contains(CONST.API_ATTACHMENT_VALIDATIONS.UNALLOWED_EXTENSIONS, fileExtension.toLowerCase())) { const invalidReason = props.translate('attachmentPicker.notAllowedExtension'); - setIsAttachmentInvalid(true); setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.wrongFileType')); setAttachmentInvalidReason(invalidReason); @@ -218,11 +210,28 @@ function AttachmentModal(props) { // eslint-disable-next-line react-hooks/exhaustive-deps [props.translate], ); + /** + * @param {Object} _data + * @returns {Boolean} + */ + const isDirectoryCheck = useCallback((_data) => { + if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { + setIsAttachmentInvalid(true); + setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.attachmentError')); + setAttachmentInvalidReason(props.translate('attachmentPicker.folderNotAllowedMessage')); + return false; + } + return true + + },[props.translate]) /** * @param {Object} _data */ const validateAndDisplayFileToUpload = useCallback( (_data) => { + if(!isDirectoryCheck(_data)) { + return; + } let _file = _data if (typeof _data.getAsFile === 'function' ){ _file = _data.getAsFile(); @@ -231,7 +240,7 @@ function AttachmentModal(props) { return; } - if (!isValidFile(_file,_data)) { + if (!isValidFile(_file)) { return; } From 4e8b68d8cbfc36c5823be64028a04d179f45ebfc Mon Sep 17 00:00:00 2001 From: charan h s Date: Tue, 25 Jul 2023 23:19:48 +0530 Subject: [PATCH 06/15] prettier changes --- src/components/AttachmentModal.js | 28 +++++++++++--------- src/components/DragAndDrop/index.js | 4 +-- src/languages/en.js | 2 +- src/languages/es.js | 3 +-- src/pages/home/report/ReportActionCompose.js | 4 +-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index c935f22ac628..21fd2f583c9f 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -214,26 +214,28 @@ function AttachmentModal(props) { * @param {Object} _data * @returns {Boolean} */ - const isDirectoryCheck = useCallback((_data) => { - if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { - setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.attachmentError')); - setAttachmentInvalidReason(props.translate('attachmentPicker.folderNotAllowedMessage')); - return false; - } - return true - - },[props.translate]) + const isDirectoryCheck = useCallback( + (_data) => { + if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { + setIsAttachmentInvalid(true); + setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.attachmentError')); + setAttachmentInvalidReason(props.translate('attachmentPicker.folderNotAllowedMessage')); + return false; + } + return true; + }, + [props.translate], + ); /** * @param {Object} _data */ const validateAndDisplayFileToUpload = useCallback( (_data) => { - if(!isDirectoryCheck(_data)) { + if (!isDirectoryCheck(_data)) { return; } - let _file = _data - if (typeof _data.getAsFile === 'function' ){ + let _file = _data; + if (typeof _data.getAsFile === 'function') { _file = _data.getAsFile(); } if (!_file) { diff --git a/src/components/DragAndDrop/index.js b/src/components/DragAndDrop/index.js index 536509c98926..974aad4ba7e5 100644 --- a/src/components/DragAndDrop/index.js +++ b/src/components/DragAndDrop/index.js @@ -84,7 +84,7 @@ class DragAndDrop extends React.Component { addEventListeners() { this.dropZone = document.getElementById(this.props.dropZoneId); - document.documentElement.setAttribute('webkitdirectory',"") + document.documentElement.setAttribute('webkitdirectory', ''); this.dropZoneRect = this.calculateDropZoneClientReact(); document.addEventListener('dragover', this.dropZoneDragListener); document.addEventListener('dragenter', this.dropZoneDragListener); @@ -94,7 +94,7 @@ class DragAndDrop extends React.Component { } removeEventListeners() { - document.documentElement.removeAttribute('webkitdirectory') + document.documentElement.removeAttribute('webkitdirectory'); document.removeEventListener('dragover', this.dropZoneDragListener); document.removeEventListener('dragenter', this.dropZoneDragListener); document.removeEventListener('dragleave', this.dropZoneDragListener); diff --git a/src/languages/en.js b/src/languages/en.js index 293707097426..e07f02dbcadf 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -168,7 +168,7 @@ export default { sizeNotMet: 'Attachment size must be greater than 240 bytes.', wrongFileType: 'Attachment is the wrong type', notAllowedExtension: 'This filetype is not allowed', - folderNotAllowedMessage: 'Uploading folder is not allowed.' + folderNotAllowedMessage: 'Uploading folder is not allowed.', }, avatarCropModal: { title: 'Edit photo', diff --git a/src/languages/es.js b/src/languages/es.js index 7f90e7acdc87..8d917865f2c4 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -167,8 +167,7 @@ export default { sizeNotMet: 'El archivo adjunto debe ser mas grande que 240 bytes.', wrongFileType: 'El tipo del archivo adjunto es incorrecto', notAllowedExtension: 'Este tipo de archivo no está permitido', - folderNotAllowedMessage: 'No se permite subir carpetas.' - + folderNotAllowedMessage: 'No se permite subir carpetas.', }, avatarCropModal: { title: 'Editar foto', diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index ba432c7bf186..9e7efbdb49b9 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -1127,8 +1127,8 @@ class ReportActionCompose extends React.Component { return; } - const data = lodashGet(e, ['dataTransfer', 'items', 0]); - + const data = lodashGet(e, ['dataTransfer', 'items', 0]); + displayFileInModal(data); this.setState({isDraggingOver: false}); From ff278da0576a22deb44758e9b07ca19421de33f8 Mon Sep 17 00:00:00 2001 From: charan h s Date: Tue, 25 Jul 2023 23:57:02 +0530 Subject: [PATCH 07/15] lint issue resloved --- src/components/AttachmentModal.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 21fd2f583c9f..fbb41599df62 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -224,6 +224,7 @@ function AttachmentModal(props) { } return true; }, + // eslint-disable-next-line react-hooks/exhaustive-deps [props.translate], ); /** @@ -234,6 +235,7 @@ function AttachmentModal(props) { if (!isDirectoryCheck(_data)) { return; } + /* eslint no-underscore-dangle: 0 */ let _file = _data; if (typeof _data.getAsFile === 'function') { _file = _data.getAsFile(); @@ -270,7 +272,7 @@ function AttachmentModal(props) { setModalType(inputModalType); } }, - [isValidFile, getModalType], + [isValidFile, getModalType,isDirectoryCheck], ); /** From 200b387b2bb67912404dba20218d04fbf3601685 Mon Sep 17 00:00:00 2001 From: charan h s Date: Thu, 27 Jul 2023 02:08:14 +0530 Subject: [PATCH 08/15] File name change --- src/components/AttachmentModal.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index fbb41599df62..0b4ef368cdee 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -235,25 +235,24 @@ function AttachmentModal(props) { if (!isDirectoryCheck(_data)) { return; } - /* eslint no-underscore-dangle: 0 */ - let _file = _data; + let fileObject = _data; if (typeof _data.getAsFile === 'function') { - _file = _data.getAsFile(); + fileObject = _data.getAsFile(); } - if (!_file) { + if (!fileObject) { return; } - if (!isValidFile(_file)) { + if (!isValidFile(fileObject)) { return; } - if (_file instanceof File) { + if (fileObject instanceof File) { /** * Cleaning file name, done here so that it covers all cases: * upload, drag and drop, copy-paste */ - let updatedFile = _file; + let updatedFile = fileObject; const cleanName = FileUtils.cleanFileName(updatedFile.name); if (updatedFile.name !== cleanName) { updatedFile = new File([updatedFile], cleanName, {type: updatedFile.type}); @@ -265,14 +264,14 @@ function AttachmentModal(props) { setFile(updatedFile); setModalType(inputModalType); } else { - const inputModalType = getModalType(_file.uri, _file); + const inputModalType = getModalType(fileObject.uri, fileObject); setIsModalOpen(true); - setSource(_file.uri); - setFile(_file); + setSource(fileObject.uri); + setFile(fileObject); setModalType(inputModalType); } }, - [isValidFile, getModalType,isDirectoryCheck], + [isValidFile, getModalType, isDirectoryCheck], ); /** From 11b8334824e5fe86c9069d916c15be4508d4e877 Mon Sep 17 00:00:00 2001 From: charan h s Date: Thu, 27 Jul 2023 23:41:48 +0530 Subject: [PATCH 09/15] Error message update --- src/languages/en.js | 2 +- src/languages/es.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/languages/en.js b/src/languages/en.js index e07f02dbcadf..6b4f9f1b2f8f 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -168,7 +168,7 @@ export default { sizeNotMet: 'Attachment size must be greater than 240 bytes.', wrongFileType: 'Attachment is the wrong type', notAllowedExtension: 'This filetype is not allowed', - folderNotAllowedMessage: 'Uploading folder is not allowed.', + folderNotAllowedMessage: 'Uploading a folder is not allowed. Try a different file. ', }, avatarCropModal: { title: 'Edit photo', diff --git a/src/languages/es.js b/src/languages/es.js index 8d917865f2c4..305c99c811bf 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -167,7 +167,7 @@ export default { sizeNotMet: 'El archivo adjunto debe ser mas grande que 240 bytes.', wrongFileType: 'El tipo del archivo adjunto es incorrecto', notAllowedExtension: 'Este tipo de archivo no está permitido', - folderNotAllowedMessage: 'No se permite subir carpetas.', + folderNotAllowedMessage: 'No se permite subir carpetas. Pruebe con un archivo diferente.', }, avatarCropModal: { title: 'Editar foto', From 74f59f94fcb234ad59749212cd88e3c75082041d Mon Sep 17 00:00:00 2001 From: charan h s Date: Fri, 28 Jul 2023 00:11:53 +0530 Subject: [PATCH 10/15] Correct spanish translated message --- src/languages/en.js | 2 +- src/languages/es.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/languages/en.js b/src/languages/en.js index 6b4f9f1b2f8f..ba48aaae81d2 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -168,7 +168,7 @@ export default { sizeNotMet: 'Attachment size must be greater than 240 bytes.', wrongFileType: 'Attachment is the wrong type', notAllowedExtension: 'This filetype is not allowed', - folderNotAllowedMessage: 'Uploading a folder is not allowed. Try a different file. ', + folderNotAllowedMessage: 'Uploading a folder is not allowed. Try a different file.', }, avatarCropModal: { title: 'Edit photo', diff --git a/src/languages/es.js b/src/languages/es.js index 305c99c811bf..f08ba177212b 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -167,7 +167,7 @@ export default { sizeNotMet: 'El archivo adjunto debe ser mas grande que 240 bytes.', wrongFileType: 'El tipo del archivo adjunto es incorrecto', notAllowedExtension: 'Este tipo de archivo no está permitido', - folderNotAllowedMessage: 'No se permite subir carpetas. Pruebe con un archivo diferente.', + folderNotAllowedMessage: 'Subir una carpeta no está permitido. Prueba con otro archivo.', }, avatarCropModal: { title: 'Editar foto', From d50952c5af8dcec3b4de1c29bbe7fb35cca263c8 Mon Sep 17 00:00:00 2001 From: charan h s Date: Sat, 29 Jul 2023 08:21:33 +0530 Subject: [PATCH 11/15] Minor changes after merge --- src/hooks/useDragAndDrop.js | 3 ++- src/pages/home/report/ReportActionCompose.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hooks/useDragAndDrop.js b/src/hooks/useDragAndDrop.js index 98df70085a72..6a2d12fd1c65 100644 --- a/src/hooks/useDragAndDrop.js +++ b/src/hooks/useDragAndDrop.js @@ -100,6 +100,7 @@ export default function useDragAndDrop({dropZone, onDrop = () => {}, shouldAllow // Note that the dragover event needs to be called with `event.preventDefault` in order for the drop event to be fired: // https://stackoverflow.com/questions/21339924/drop-event-not-firing-in-chrome + dropZoneRef.setAttribute('webkitdirectory', ''); dropZoneRef.addEventListener(DRAG_OVER_EVENT, dropZoneDragHandler); dropZoneRef.addEventListener(DRAG_ENTER_EVENT, dropZoneDragHandler); dropZoneRef.addEventListener(DRAG_LEAVE_EVENT, dropZoneDragHandler); @@ -108,7 +109,7 @@ export default function useDragAndDrop({dropZone, onDrop = () => {}, shouldAllow if (!dropZoneRef) { return; } - + dropZoneRef.removeAttribute('webkitdirectory'); dropZoneRef.removeEventListener(DRAG_OVER_EVENT, dropZoneDragHandler); dropZoneRef.removeEventListener(DRAG_ENTER_EVENT, dropZoneDragHandler); dropZoneRef.removeEventListener(DRAG_LEAVE_EVENT, dropZoneDragHandler); diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 644a90216091..a49d894cd4c6 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -1188,8 +1188,8 @@ class ReportActionCompose extends React.Component { if (this.state.isAttachmentPreviewActive) { return; } - const file = lodashGet(e, ['dataTransfer', 'files', 0]); - displayFileInModal(file); + const data = lodashGet(e, ['dataTransfer', 'items', 0]); + displayFileInModal(data); }} /> From 0fd3a741b492b5adf6cf0debabe16cdf69ef6ed8 Mon Sep 17 00:00:00 2001 From: charan h s Date: Tue, 1 Aug 2023 23:26:42 +0530 Subject: [PATCH 12/15] props.translate to translate(useLocalize) --- src/components/AttachmentModal.js | 35 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 0b4ef368cdee..b798e90b8790 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -7,6 +7,7 @@ import lodashExtend from 'lodash/extend'; import _ from 'underscore'; import CONST from '../CONST'; import Modal from './Modal'; +import useLocalize from '../hooks/useLocalize'; import AttachmentView from './AttachmentView'; import AttachmentCarousel from './AttachmentCarousel'; import styles from '../styles/styles'; @@ -105,6 +106,7 @@ function AttachmentModal(props) { } : undefined, ); + const {translate} = useLocalize(); const onCarouselAttachmentChange = props.onCarouselAttachmentChange; @@ -130,11 +132,10 @@ function AttachmentModal(props) { */ const getModalType = useCallback( (sourceURL, _file) => - sourceURL && (Str.isPDF(sourceURL) || (_file && Str.isPDF(_file.name || props.translate('attachmentView.unknownFilename')))) + sourceURL && (Str.isPDF(sourceURL) || (_file && Str.isPDF(_file.name || translate('attachmentView.unknownFilename')))) ? CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE : CONST.MODAL.MODAL_TYPE.CENTERED, - // eslint-disable-next-line react-hooks/exhaustive-deps - [props.translate], + [translate], ); /** * Download the currently viewed attachment. @@ -184,31 +185,30 @@ function AttachmentModal(props) { (_file) => { const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(_file, 'name', '')); if (_.contains(CONST.API_ATTACHMENT_VALIDATIONS.UNALLOWED_EXTENSIONS, fileExtension.toLowerCase())) { - const invalidReason = props.translate('attachmentPicker.notAllowedExtension'); + const invalidReason = translate('attachmentPicker.notAllowedExtension'); setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.wrongFileType')); + setAttachmentInvalidReasonTitle(translate('attachmentPicker.wrongFileType')); setAttachmentInvalidReason(invalidReason); return false; } if (lodashGet(_file, 'size', 0) > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.attachmentTooLarge')); - setAttachmentInvalidReason(props.translate('attachmentPicker.sizeExceeded')); + setAttachmentInvalidReasonTitle(translate('attachmentPicker.attachmentTooLarge')); + setAttachmentInvalidReason(translate('attachmentPicker.sizeExceeded')); return false; } if (lodashGet(_file, 'size', 0) < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.attachmentTooSmall')); - setAttachmentInvalidReason(props.translate('attachmentPicker.sizeNotMet')); + setAttachmentInvalidReasonTitle(translate('attachmentPicker.attachmentTooSmall')); + setAttachmentInvalidReason(translate('attachmentPicker.sizeNotMet')); return false; } return true; }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [props.translate], + [translate], ); /** * @param {Object} _data @@ -218,14 +218,13 @@ function AttachmentModal(props) { (_data) => { if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle(props.translate('attachmentPicker.attachmentError')); - setAttachmentInvalidReason(props.translate('attachmentPicker.folderNotAllowedMessage')); + setAttachmentInvalidReasonTitle(translate('attachmentPicker.attachmentError')); + setAttachmentInvalidReason(translate('attachmentPicker.folderNotAllowedMessage')); return false; } return true; }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [props.translate], + [translate], ); /** * @param {Object} _data @@ -331,7 +330,7 @@ function AttachmentModal(props) { > {props.isSmallScreenWidth && } downloadAttachment(source)} @@ -370,7 +369,7 @@ function AttachmentModal(props) { success style={[styles.buttonConfirm, props.isSmallScreenWidth ? {} : styles.attachmentButtonBigScreen]} textStyles={[styles.buttonConfirmText]} - text={props.translate('common.send')} + text={translate('common.send')} onPress={submitAndClose} disabled={isConfirmButtonDisabled} pressOnEnter @@ -387,7 +386,7 @@ function AttachmentModal(props) { onCancel={closeConfirmModal} isVisible={isAttachmentInvalid} prompt={attachmentInvalidReason} - confirmText={props.translate('common.close')} + confirmText={translate('common.close')} shouldShowCancelButton={false} /> From 216f5e7991da882b8adf3a85de6ec1549ab7dfb7 Mon Sep 17 00:00:00 2001 From: charan h s Date: Thu, 3 Aug 2023 16:26:46 +0530 Subject: [PATCH 13/15] propsTranslate to localize Translate --- src/components/AttachmentModal.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index a7826dbe00d8..41448d381394 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -221,8 +221,8 @@ function AttachmentModal(props) { (_data) => { if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle(translate('attachmentPicker.attachmentError')); - setAttachmentInvalidReason(translate('attachmentPicker.folderNotAllowedMessage')); + setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError'); + setAttachmentInvalidReason('attachmentPicker.folderNotAllowedMessage'); return false; } return true; @@ -385,12 +385,12 @@ function AttachmentModal(props) { From 2bc09e00360c95cb5df81bceb6a7138740b0670c Mon Sep 17 00:00:00 2001 From: charan h s Date: Thu, 3 Aug 2023 21:28:04 +0530 Subject: [PATCH 14/15] removed unnecessary translate dep --- src/components/AttachmentModal.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 41448d381394..6f573f5cf287 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -211,7 +211,7 @@ function AttachmentModal(props) { return true; }, - [translate], + [], ); /** * @param {Object} _data @@ -227,7 +227,7 @@ function AttachmentModal(props) { } return true; }, - [translate], + [], ); /** From f137541b66df14015a0277f163a8e63356a5b4d1 Mon Sep 17 00:00:00 2001 From: charan h s Date: Thu, 3 Aug 2023 21:33:09 +0530 Subject: [PATCH 15/15] prettier --- src/components/AttachmentModal.js | 72 ++++++++++++++----------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 6f573f5cf287..7bfd6e30f398 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -183,52 +183,46 @@ function AttachmentModal(props) { * @param {Object} _file * @returns {Boolean} */ - const isValidFile = useCallback( - (_file) => { - const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(_file, 'name', '')); - if (_.contains(CONST.API_ATTACHMENT_VALIDATIONS.UNALLOWED_EXTENSIONS, fileExtension.toLowerCase())) { - const invalidReason = 'attachmentPicker.notAllowedExtension'; - - setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle('attachmentPicker.wrongFileType'); - setAttachmentInvalidReason(invalidReason); - return false; - } + const isValidFile = useCallback((_file) => { + const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(_file, 'name', '')); + if (_.contains(CONST.API_ATTACHMENT_VALIDATIONS.UNALLOWED_EXTENSIONS, fileExtension.toLowerCase())) { + const invalidReason = 'attachmentPicker.notAllowedExtension'; + + setIsAttachmentInvalid(true); + setAttachmentInvalidReasonTitle('attachmentPicker.wrongFileType'); + setAttachmentInvalidReason(invalidReason); + return false; + } - if (lodashGet(_file, 'size', 0) > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { - setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle('attachmentPicker.attachmentTooLarge'); - setAttachmentInvalidReason('attachmentPicker.sizeExceeded'); - return false; - } + if (lodashGet(_file, 'size', 0) > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { + setIsAttachmentInvalid(true); + setAttachmentInvalidReasonTitle('attachmentPicker.attachmentTooLarge'); + setAttachmentInvalidReason('attachmentPicker.sizeExceeded'); + return false; + } - if (lodashGet(_file, 'size', 0) < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { - setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle('attachmentPicker.attachmentTooSmall'); - setAttachmentInvalidReason('attachmentPicker.sizeNotMet'); - return false; - } + if (lodashGet(_file, 'size', 0) < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { + setIsAttachmentInvalid(true); + setAttachmentInvalidReasonTitle('attachmentPicker.attachmentTooSmall'); + setAttachmentInvalidReason('attachmentPicker.sizeNotMet'); + return false; + } - return true; - }, - [], - ); + return true; + }, []); /** * @param {Object} _data * @returns {Boolean} */ - const isDirectoryCheck = useCallback( - (_data) => { - if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { - setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError'); - setAttachmentInvalidReason('attachmentPicker.folderNotAllowedMessage'); - return false; - } - return true; - }, - [], - ); + const isDirectoryCheck = useCallback((_data) => { + if (typeof _data.webkitGetAsEntry === 'function' && _data.webkitGetAsEntry().isDirectory) { + setIsAttachmentInvalid(true); + setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError'); + setAttachmentInvalidReason('attachmentPicker.folderNotAllowedMessage'); + return false; + } + return true; + }, []); /** * @param {Object} _data