@controleonline/ui-common 1.2.84 → 1.2.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@controleonline/ui-common",
3
- "version": "1.2.84",
3
+ "version": "1.2.85",
4
4
  "author": "ControleOnline",
5
5
  "description": "ControleOnline Common Quasar UI Component",
6
6
  "license": "MIT",
@@ -20,8 +20,8 @@ const AddImportModal = ({
20
20
  onClose,
21
21
  onSuccess,
22
22
  context = {},
23
- allowedExtensions = [],
24
- acceptedTypes = '*/*',
23
+ allowedExtensions = [], // default will be set to ['csv'] if empty
24
+ // acceptedTypes will be derived from allowedExtensions for security
25
25
  helperLabel,
26
26
  modalTitle,
27
27
  fileLabel,
@@ -29,6 +29,7 @@ const AddImportModal = ({
29
29
  cancelLabel,
30
30
  importSuccessLabel,
31
31
  importErrorLabel,
32
+ importType = null,
32
33
  }) => {
33
34
  const fallbackModalTitle = global.t?.t('imports', 'title', 'new_import');
34
35
  const fallbackFileLabel = global.t?.t('imports', 'label', 'file');
@@ -44,6 +45,12 @@ const AddImportModal = ({
44
45
  const _importSuccessLabel = importSuccessLabel ?? fallbackSuccessLabel;
45
46
  const _importErrorLabel = importErrorLabel ?? fallbackErrorLabel;
46
47
  const _helperLabel = helperLabel ?? fallbackInvalidFileLabel;
48
+ // Resolve allowed extensions securely – default to CSV only
49
+ const _allowedExtensions = (allowedExtensions && allowedExtensions.length > 0) ? allowedExtensions : ['csv'];
50
+ // Build acceptedTypes string for file input (e.g., ".csv,.xml,.zip")
51
+ const _acceptedTypes = _allowedExtensions.map(ext => `.${ext}`).join(',');
52
+ // Determine import type: prioritize prop, then infer from allowed extensions, default to 'csv'
53
+ const _importType = importType ?? (_allowedExtensions.includes('xml') ? 'xml' : (_allowedExtensions.includes('zip') ? 'zip' : 'csv'));
47
54
  const { showError, showSuccess } = useMessage();
48
55
  const peopleStore = useStore('people');
49
56
  const importsStore = useStore('imports');
@@ -62,8 +69,8 @@ const AddImportModal = ({
62
69
 
63
70
 
64
71
  const handleUploadImportFile = async ({ file }) => {
65
- if (allowedExtensions.length > 0) {
66
- const extensionRegex = new RegExp(`\\.(${allowedExtensions.join('|')})$`, 'i');
72
+ if (_allowedExtensions.length > 0) {
73
+ const extensionRegex = new RegExp(`\\.(${_allowedExtensions.join('|')})$`, 'i');
67
74
  if (!file?.name?.toLowerCase().match(extensionRegex)) {
68
75
  throw new Error(_helperLabel);
69
76
  }
@@ -72,7 +79,7 @@ const AddImportModal = ({
72
79
  try {
73
80
  await importActions.uploadImportFile({
74
81
  file,
75
- importType: context.context,
82
+ importType: _importType,
76
83
  peopleId: currentCompany.id,
77
84
  });
78
85
  showSuccess(_importSuccessLabel);
@@ -106,7 +113,7 @@ const AddImportModal = ({
106
113
  </View>
107
114
 
108
115
  <ScrollView style={styles.content}>
109
- <Text style={styles.label>{_fileLabel}</Text>
116
+ <Text style={styles.label}>{_fileLabel}</Text>
110
117
  <DefaultUpload
111
118
  relationField="import"
112
119
  relationResource="imports"
@@ -114,7 +121,7 @@ const AddImportModal = ({
114
121
  companyId={currentCompany.id}
115
122
  context={`imports-${context.context || 'default'}`}
116
123
  libraryContexts={[`imports-${context.context || 'default'}`]}
117
- acceptedTypes={acceptedTypes}
124
+ acceptedTypes={_acceptedTypes}
118
125
  fileType=""
119
126
  title={_fileLabel}
120
127
  triggerLabel={_selectFileLabel}