@controleonline/ui-common 1.2.85 → 1.2.86
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
|
@@ -11,7 +11,8 @@ import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
|
11
11
|
import { useStore } from '@store';
|
|
12
12
|
import AnimatedModal from './AnimatedModal';
|
|
13
13
|
import { useMessage } from '@controleonline/ui-common/src/react/components/MessageService';
|
|
14
|
-
import
|
|
14
|
+
import ImportsPage from '@controleonline/ui-common/src/react/pages/Imports';
|
|
15
|
+
import { useState } from 'react';
|
|
15
16
|
import { resolveSystemErrorMessage } from '@controleonline/ui-common/src/react/utils/systemErrorMessage';
|
|
16
17
|
import styles from './AddImportModal.styles';
|
|
17
18
|
|
|
@@ -66,16 +67,19 @@ const AddImportModal = ({
|
|
|
66
67
|
buttonIcon: themeColors.buttonIcon || themeColors.buttonText,
|
|
67
68
|
};
|
|
68
69
|
|
|
69
|
-
|
|
70
|
+
const [showImportList, setShowImportList] = useState(false);
|
|
71
|
+
const [importResult, setImportResult] = useState(null); // true = success, false = error
|
|
72
|
+
const [uploading, setUploading] = useState(false);
|
|
70
73
|
|
|
71
74
|
const handleUploadImportFile = async ({ file }) => {
|
|
72
75
|
if (_allowedExtensions.length > 0) {
|
|
73
|
-
const extensionRegex = new RegExp(
|
|
76
|
+
const extensionRegex = new RegExp(`\\\\.(${_allowedExtensions.join('|')})$`, 'i');
|
|
74
77
|
if (!file?.name?.toLowerCase().match(extensionRegex)) {
|
|
75
78
|
throw new Error(_helperLabel);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
|
|
82
|
+
setUploading(true);
|
|
79
83
|
try {
|
|
80
84
|
await importActions.uploadImportFile({
|
|
81
85
|
file,
|
|
@@ -83,18 +87,25 @@ const AddImportModal = ({
|
|
|
83
87
|
peopleId: currentCompany.id,
|
|
84
88
|
});
|
|
85
89
|
showSuccess(_importSuccessLabel);
|
|
90
|
+
// Indicate successful import and open import list
|
|
91
|
+
setImportResult(true);
|
|
92
|
+
setShowImportList(true);
|
|
86
93
|
if (onSuccess) onSuccess();
|
|
87
|
-
handleClose();
|
|
88
94
|
return file;
|
|
89
95
|
} catch (error) {
|
|
90
96
|
const importFeedback =
|
|
91
97
|
resolveSystemErrorMessage(error) || _importErrorLabel;
|
|
92
98
|
showError(importFeedback);
|
|
99
|
+
setImportResult(false);
|
|
93
100
|
throw new Error(importFeedback);
|
|
101
|
+
} finally {
|
|
102
|
+
setUploading(false);
|
|
94
103
|
}
|
|
95
104
|
};
|
|
96
105
|
|
|
97
106
|
const handleClose = () => {
|
|
107
|
+
setShowImportList(false);
|
|
108
|
+
setImportResult(null);
|
|
98
109
|
onClose();
|
|
99
110
|
};
|
|
100
111
|
|
|
@@ -112,53 +123,26 @@ const AddImportModal = ({
|
|
|
112
123
|
</TouchableOpacity>
|
|
113
124
|
</View>
|
|
114
125
|
|
|
115
|
-
<ScrollView style={styles.content}>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
uploadResultAlreadyAttached
|
|
135
|
-
requireEntity={false}
|
|
136
|
-
onUploadFile={handleUploadImportFile}
|
|
137
|
-
renderTrigger={({openManager, uploading}) => (
|
|
138
|
-
<TouchableOpacity
|
|
139
|
-
onPress={openManager}
|
|
140
|
-
disabled={uploading}
|
|
141
|
-
style={[
|
|
142
|
-
styles.filePicker,
|
|
143
|
-
{
|
|
144
|
-
backgroundColor: buttonPalette.buttonBackground,
|
|
145
|
-
borderColor: buttonPalette.buttonBorder,
|
|
146
|
-
},
|
|
147
|
-
]}
|
|
148
|
-
>
|
|
149
|
-
<Text numberOfLines={1} style={[styles.fileName, { color: buttonPalette.buttonText }]}>
|
|
150
|
-
{selectFileLabel}
|
|
151
|
-
</Text>
|
|
152
|
-
{uploading ? (
|
|
153
|
-
<ActivityIndicator color={buttonPalette.buttonIcon} />
|
|
154
|
-
) : (
|
|
155
|
-
<Icon name="upload-file" size={22} color={buttonPalette.buttonIcon} />
|
|
156
|
-
)}
|
|
157
|
-
</TouchableOpacity>
|
|
158
|
-
)}
|
|
159
|
-
/>
|
|
126
|
+
<ScrollView style={styles.content} keyboardShouldPersistTaps="always">
|
|
127
|
+
<TouchableOpacity
|
|
128
|
+
onPress={handleUploadImportFile}
|
|
129
|
+
style={[styles.filePicker, { backgroundColor: buttonPalette.buttonBackground, borderColor: buttonPalette.buttonBorder }]}
|
|
130
|
+
>
|
|
131
|
+
<Text numberOfLines={1} style={[styles.fileName, { color: buttonPalette.buttonText }]}>{_selectFileLabel}</Text>
|
|
132
|
+
{uploading ? (
|
|
133
|
+
<ActivityIndicator color={buttonPalette.buttonIcon} />
|
|
134
|
+
) : (
|
|
135
|
+
<Icon name="upload-file" size={22} color={buttonPalette.buttonIcon} />
|
|
136
|
+
)}
|
|
137
|
+
</TouchableOpacity>
|
|
138
|
+
<TouchableOpacity
|
|
139
|
+
onPress={() => setShowImportList(true)}
|
|
140
|
+
style={[styles.filePicker, { marginTop: 10, backgroundColor: buttonPalette.buttonBackground, borderColor: buttonPalette.buttonBorder }]}
|
|
141
|
+
>
|
|
142
|
+
<Text style={[styles.fileName, { color: buttonPalette.buttonText }]}>{global.t?.t('imports', 'button', 'view_imports') || 'View Imports'}</Text>
|
|
143
|
+
</TouchableOpacity>
|
|
144
|
+
</ScrollView>
|
|
160
145
|
|
|
161
|
-
</ScrollView>
|
|
162
146
|
|
|
163
147
|
<View style={styles.footer}>
|
|
164
148
|
<TouchableOpacity onPress={handleClose} style={styles.secondaryButton}>
|