@controleonline/ui-common 1.2.83 → 1.2.84

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.83",
3
+ "version": "1.2.84",
4
4
  "author": "ControleOnline",
5
5
  "description": "ControleOnline Common Quasar UI Component",
6
6
  "license": "MIT",
@@ -15,7 +15,35 @@ import DefaultUpload from '@controleonline/ui-default/src/react/components/uploa
15
15
  import { resolveSystemErrorMessage } from '@controleonline/ui-common/src/react/utils/systemErrorMessage';
16
16
  import styles from './AddImportModal.styles';
17
17
 
18
- const AddImportModal = ({ visible, onClose, onSuccess, context = {} }) => {
18
+ const AddImportModal = ({
19
+ visible,
20
+ onClose,
21
+ onSuccess,
22
+ context = {},
23
+ allowedExtensions = [],
24
+ acceptedTypes = '*/*',
25
+ helperLabel,
26
+ modalTitle,
27
+ fileLabel,
28
+ selectFileLabel,
29
+ cancelLabel,
30
+ importSuccessLabel,
31
+ importErrorLabel,
32
+ }) => {
33
+ const fallbackModalTitle = global.t?.t('imports', 'title', 'new_import');
34
+ const fallbackFileLabel = global.t?.t('imports', 'label', 'file');
35
+ const fallbackSelectFileLabel = global.t?.t('imports', 'button', 'select_file');
36
+ const fallbackCancelLabel = global.t?.t('imports', 'button', 'cancel');
37
+ const fallbackSuccessLabel = global.t?.t('imports', 'success', 'import_sent_successfully');
38
+ const fallbackErrorLabel = global.t?.t('imports', 'error', 'error_sending_import');
39
+ const fallbackInvalidFileLabel = global.t?.t('imports', 'message', 'invalid_file_extension');
40
+ const _modalTitle = modalTitle ?? fallbackModalTitle;
41
+ const _fileLabel = fileLabel ?? fallbackFileLabel;
42
+ const _selectFileLabel = selectFileLabel ?? fallbackSelectFileLabel;
43
+ const _cancelLabel = cancelLabel ?? fallbackCancelLabel;
44
+ const _importSuccessLabel = importSuccessLabel ?? fallbackSuccessLabel;
45
+ const _importErrorLabel = importErrorLabel ?? fallbackErrorLabel;
46
+ const _helperLabel = helperLabel ?? fallbackInvalidFileLabel;
19
47
  const { showError, showSuccess } = useMessage();
20
48
  const peopleStore = useStore('people');
21
49
  const importsStore = useStore('imports');
@@ -31,17 +59,14 @@ const AddImportModal = ({ visible, onClose, onSuccess, context = {} }) => {
31
59
  buttonIcon: themeColors.buttonIcon || themeColors.buttonText,
32
60
  };
33
61
 
34
- const modalTitle = global.t?.t('imports', 'title', 'new_import');
35
- const csvLabel = global.t?.t('imports', 'label', 'csv_file');
36
- const selectFileLabel = global.t?.t('imports', 'button', 'select_file');
37
- const cancelLabel = global.t?.t('imports', 'button', 'cancel');
38
- const csvOnlyLabel = global.t?.t('imports', 'message', 'only_csv_files_are_allowed');
39
- const importSuccessLabel = global.t?.t('imports', 'success', 'import_sent_successfully');
40
- const importErrorLabel = global.t?.t('imports', 'error', 'error_sending_import');
62
+
41
63
 
42
64
  const handleUploadImportFile = async ({ file }) => {
43
- if (!file?.name?.toLowerCase().endsWith('.csv')) {
44
- throw new Error(csvOnlyLabel);
65
+ if (allowedExtensions.length > 0) {
66
+ const extensionRegex = new RegExp(`\\.(${allowedExtensions.join('|')})$`, 'i');
67
+ if (!file?.name?.toLowerCase().match(extensionRegex)) {
68
+ throw new Error(_helperLabel);
69
+ }
45
70
  }
46
71
 
47
72
  try {
@@ -50,13 +75,13 @@ const AddImportModal = ({ visible, onClose, onSuccess, context = {} }) => {
50
75
  importType: context.context,
51
76
  peopleId: currentCompany.id,
52
77
  });
53
- showSuccess(importSuccessLabel);
78
+ showSuccess(_importSuccessLabel);
54
79
  if (onSuccess) onSuccess();
55
80
  handleClose();
56
81
  return file;
57
82
  } catch (error) {
58
83
  const importFeedback =
59
- resolveSystemErrorMessage(error) || importErrorLabel;
84
+ resolveSystemErrorMessage(error) || _importErrorLabel;
60
85
  showError(importFeedback);
61
86
  throw new Error(importFeedback);
62
87
  }
@@ -74,31 +99,30 @@ const AddImportModal = ({ visible, onClose, onSuccess, context = {} }) => {
74
99
  >
75
100
  <View style={styles.sheet}>
76
101
  <View style={styles.header}>
77
- <Text style={styles.title}>{modalTitle}</Text>
102
+ <Text style={styles.title}>{_modalTitle}</Text>
78
103
  <TouchableOpacity onPress={handleClose}>
79
104
  <Icon name="close" size={24} />
80
105
  </TouchableOpacity>
81
106
  </View>
82
107
 
83
108
  <ScrollView style={styles.content}>
84
- <Text style={styles.label}>{csvLabel}</Text>
109
+ <Text style={styles.label>{_fileLabel}</Text>
85
110
  <DefaultUpload
86
- relationStoreName="imports"
87
111
  relationField="import"
88
112
  relationResource="imports"
89
113
  entityId={context.context || 'import'}
90
114
  companyId={currentCompany.id}
91
115
  context={`imports-${context.context || 'default'}`}
92
116
  libraryContexts={[`imports-${context.context || 'default'}`]}
93
- acceptedTypes="text/csv,.csv"
117
+ acceptedTypes={acceptedTypes}
94
118
  fileType=""
95
- title={csvLabel}
96
- triggerLabel={selectFileLabel}
97
- managerTitle={modalTitle}
98
- searchPlaceholder={selectFileLabel}
99
- uploadButtonLabel={selectFileLabel}
119
+ title={_fileLabel}
120
+ triggerLabel={_selectFileLabel}
121
+ managerTitle={_modalTitle}
122
+ searchPlaceholder={_selectFileLabel}
123
+ uploadButtonLabel={_selectFileLabel}
100
124
  emptyAttachmentLabel=""
101
- emptyLibraryLabel={selectFileLabel}
125
+ emptyLibraryLabel={_selectFileLabel}
102
126
  showInlineContent={false}
103
127
  uploadResultAlreadyAttached
104
128
  requireEntity={false}
@@ -126,14 +150,12 @@ const AddImportModal = ({ visible, onClose, onSuccess, context = {} }) => {
126
150
  </TouchableOpacity>
127
151
  )}
128
152
  />
129
- <Text style={styles.helperText}>
130
- {csvOnlyLabel}
131
- </Text>
153
+
132
154
  </ScrollView>
133
155
 
134
156
  <View style={styles.footer}>
135
157
  <TouchableOpacity onPress={handleClose} style={styles.secondaryButton}>
136
- <Text>{cancelLabel}</Text>
158
+ <Text>{_cancelLabel}</Text>
137
159
  </TouchableOpacity>
138
160
  </View>
139
161
  </View>