@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@controleonline/ui-common",
3
- "version": "1.2.85",
3
+ "version": "1.2.86",
4
4
  "author": "ControleOnline",
5
5
  "description": "ControleOnline Common Quasar UI Component",
6
6
  "license": "MIT",
@@ -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 DefaultUpload from '@controleonline/ui-default/src/react/components/upload/DefaultUpload';
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(`\\.(${_allowedExtensions.join('|')})$`, 'i');
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
- <Text style={styles.label}>{_fileLabel}</Text>
117
- <DefaultUpload
118
- relationField="import"
119
- relationResource="imports"
120
- entityId={context.context || 'import'}
121
- companyId={currentCompany.id}
122
- context={`imports-${context.context || 'default'}`}
123
- libraryContexts={[`imports-${context.context || 'default'}`]}
124
- acceptedTypes={_acceptedTypes}
125
- fileType=""
126
- title={_fileLabel}
127
- triggerLabel={_selectFileLabel}
128
- managerTitle={_modalTitle}
129
- searchPlaceholder={_selectFileLabel}
130
- uploadButtonLabel={_selectFileLabel}
131
- emptyAttachmentLabel=""
132
- emptyLibraryLabel={_selectFileLabel}
133
- showInlineContent={false}
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}>
@@ -400,7 +400,9 @@ const Imports = ({ context = {}, onClose }) => {
400
400
  onSuccess={() => {
401
401
  setCurrentPage(1);
402
402
  fetchImports(searchQuery, 1);
403
+ if (onImportComplete) onImportComplete();
403
404
  }}
405
+ onImportComplete={onImportComplete}
404
406
  />
405
407
  </View>
406
408
  );