@widergy/mobile-ui 1.30.0 → 1.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.30.1](https://github.com/widergy/mobile-ui/compare/v1.30.0...v1.30.1) (2024-11-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * [EVE-4316] attachment list fix ([055a2c5](https://github.com/widergy/mobile-ui/commit/055a2c508c266b763777d8c13a13f6d8f07265ab))
7
+
1
8
  # [1.30.0](https://github.com/widergy/mobile-ui/compare/v1.29.5...v1.30.0) (2024-10-30)
2
9
 
3
10
 
@@ -13,7 +13,13 @@ import UTBottomSheet from '../UTBottomSheet';
13
13
  import UTButton from '../UTButton';
14
14
 
15
15
  import { DEFAULT_MAX_SIZE } from './constants';
16
- import { getInitialValuesFrom, isFileFormatInvalid, isFileSizeInvaid, isFileTypeInvalid } from './utils';
16
+ import {
17
+ getDocumentPickerType,
18
+ getInitialValuesFrom,
19
+ isFileFormatInvalid,
20
+ isFileSizeInvaid,
21
+ isFileTypeInvalid
22
+ } from './utils';
17
23
  import filePickerPropTypes from './propTypes';
18
24
  import Picker from './components/Picker';
19
25
  import styles from './styles';
@@ -70,7 +76,7 @@ const MultipleFilePicker = ({
70
76
  const onPickFiles = async () => {
71
77
  const documents = await DocumentPicker.pick({
72
78
  allowMultiSelection: true,
73
- type: allowedTypes ?? DocumentPicker.types.allFiles
79
+ type: isEmpty(allowedTypes) ? DocumentPicker.types.allFiles : allowedTypes.map(getDocumentPickerType)
74
80
  });
75
81
 
76
82
  if (uploadedFiles.length + documents.length > maxFiles)
@@ -1,5 +1,44 @@
1
- import { PDFDocument } from 'pdf-lib';
2
1
  import { isEmpty } from 'lodash';
2
+ import { PDFDocument } from 'pdf-lib';
3
+ // eslint-disable-next-line import/no-unresolved
4
+ import DocumentPicker from 'react-native-document-picker';
5
+
6
+ const mimeTypes = {
7
+ allFiles: '*/*',
8
+ audio: 'audio/*',
9
+ csv: 'text/csv',
10
+ doc: 'application/msword',
11
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
12
+ images: 'image/*',
13
+ json: 'application/json',
14
+ pdf: 'application/pdf',
15
+ plainText: 'text/plain',
16
+ ppt: 'application/vnd.ms-powerpoint',
17
+ pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
18
+ video: 'video/*',
19
+ xls: 'application/vnd.ms-excel',
20
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
21
+ zip: 'application/zip'
22
+ };
23
+
24
+ const extensions = {
25
+ allFiles: '*',
26
+ audio:
27
+ '.3g2 .3gp .aac .adt .adts .aif .aifc .aiff .asf .au .m3u .m4a .m4b .mid .midi .mp2 .mp3 .rmi .snd .wav .wax .wma',
28
+ csv: '.csv',
29
+ doc: '.doc',
30
+ docx: '.docx',
31
+ images: '.jpeg .jpg .png .gif .bmp .svg .heic .heif',
32
+ json: '.json',
33
+ pdf: '.pdf',
34
+ plainText: '.txt',
35
+ ppt: '.ppt',
36
+ pptx: '.pptx',
37
+ video: '.mp4 .avi .mov .wmv',
38
+ xls: '.xls',
39
+ xlsx: '.xlsx',
40
+ zip: '.zip .gz'
41
+ };
3
42
 
4
43
  const lengthMatches = (length1, length2, toleranceInPercentage) => {
5
44
  const delta = length1 * (toleranceInPercentage / 100);
@@ -39,11 +78,19 @@ const pdfAspectRatioValidation = async (file, allowedPDFUploadSizes) => {
39
78
  });
40
79
  };
41
80
 
81
+ export const getFileType = extension =>
82
+ Object.entries(extensions).find(([, value]) => value.includes(extension))[0];
83
+
84
+ export const getMimeType = extension => {
85
+ const fileType = getFileType(extension);
86
+ const mimeType = mimeTypes[fileType];
87
+ return mimeType.replace('*', extension.replace(/\./g, ''));
88
+ };
89
+
90
+ export const getDocumentPickerType = extension => DocumentPicker.types[getFileType(extension)];
91
+
42
92
  export const isFileTypeInvalid = (document, allowedTypes, fileTypeError, onError) => {
43
- const isInvalid = !(
44
- allowedTypes.includes(document.type) ||
45
- (document.type.includes('image') && allowedTypes.includes('image/*'))
46
- );
93
+ const isInvalid = !allowedTypes.map(getMimeType).includes(document.type);
47
94
  if (isInvalid) onError(fileTypeError || 'Tipo de archivo inválido.');
48
95
  return isInvalid;
49
96
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@widergy/mobile-ui",
3
3
  "description": "Widergy Mobile Components",
4
4
  "author": "widergy",
5
- "version": "1.30.0",
5
+ "version": "1.30.1",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [