@controleonline/ui-common 1.2.82 → 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 +1 -1
- package/src/api/index.js +31 -5
- package/src/react/components/AddImportModal.js +48 -26
package/package.json
CHANGED
package/src/api/index.js
CHANGED
|
@@ -391,12 +391,38 @@ export const api = {
|
|
|
391
391
|
|
|
392
392
|
return safeUri;
|
|
393
393
|
},
|
|
394
|
-
|
|
395
|
-
|
|
394
|
+
get: async function (uri, options = {}) {
|
|
395
|
+
return await this.fetch(uri, {
|
|
396
|
+
...options,
|
|
397
|
+
method: 'GET',
|
|
398
|
+
});
|
|
399
|
+
},
|
|
400
|
+
post: async function (uri, body = {}, options = {}) {
|
|
401
|
+
return await this.fetch(uri, {
|
|
402
|
+
...options,
|
|
396
403
|
method: 'POST',
|
|
397
|
-
body
|
|
398
|
-
};
|
|
399
|
-
|
|
404
|
+
body,
|
|
405
|
+
});
|
|
406
|
+
},
|
|
407
|
+
put: async function (uri, body = {}, options = {}) {
|
|
408
|
+
return await this.fetch(uri, {
|
|
409
|
+
...options,
|
|
410
|
+
method: 'PUT',
|
|
411
|
+
body,
|
|
412
|
+
});
|
|
413
|
+
},
|
|
414
|
+
patch: async function (uri, body = {}, options = {}) {
|
|
415
|
+
return await this.fetch(uri, {
|
|
416
|
+
...options,
|
|
417
|
+
method: 'PATCH',
|
|
418
|
+
body,
|
|
419
|
+
});
|
|
420
|
+
},
|
|
421
|
+
delete: async function (uri, options = {}) {
|
|
422
|
+
return await this.fetch(uri, {
|
|
423
|
+
...options,
|
|
424
|
+
method: 'DELETE',
|
|
425
|
+
});
|
|
400
426
|
},
|
|
401
427
|
loadSmokeIndex: async function (config = {}) {
|
|
402
428
|
return await requestSmoke('/tests', {}, config);
|
|
@@ -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 = ({
|
|
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
|
-
|
|
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 (
|
|
44
|
-
|
|
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(
|
|
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) ||
|
|
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}>{
|
|
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
|
|
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=
|
|
117
|
+
acceptedTypes={acceptedTypes}
|
|
94
118
|
fileType=""
|
|
95
|
-
title={
|
|
96
|
-
triggerLabel={
|
|
97
|
-
managerTitle={
|
|
98
|
-
searchPlaceholder={
|
|
99
|
-
uploadButtonLabel={
|
|
119
|
+
title={_fileLabel}
|
|
120
|
+
triggerLabel={_selectFileLabel}
|
|
121
|
+
managerTitle={_modalTitle}
|
|
122
|
+
searchPlaceholder={_selectFileLabel}
|
|
123
|
+
uploadButtonLabel={_selectFileLabel}
|
|
100
124
|
emptyAttachmentLabel=""
|
|
101
|
-
emptyLibraryLabel={
|
|
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
|
-
|
|
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>{
|
|
158
|
+
<Text>{_cancelLabel}</Text>
|
|
137
159
|
</TouchableOpacity>
|
|
138
160
|
</View>
|
|
139
161
|
</View>
|