@groupeactual/ui-kit 1.7.0-beta.0 → 1.7.0-beta.4
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/dist/cjs/index.js +9 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.ts +176 -163
- package/dist/es/index.js +8 -18
- package/dist/es/index.js.map +1 -1
- package/dist/es/src/components/Accordion/Accordion.d.ts +1 -4
- package/dist/es/src/components/BannerNotification/BannerNotification.d.ts +1 -4
- package/dist/es/src/components/Breadcrumbs/Breadcrumbs.d.ts +1 -4
- package/dist/es/src/components/Button/Button.d.ts +1 -4
- package/dist/es/src/components/Chip/Chip.d.ts +2 -5
- package/dist/es/src/components/Datatable/Datatable.d.ts +1 -1
- package/dist/es/src/components/Datatable/datatable.interface.d.ts +5 -4
- package/dist/es/src/components/EmbbededNotification/EmbeddedNotification.d.ts +1 -4
- package/dist/es/src/components/Form/AutoCompleteMulti/AutoCompleteMulti.d.ts +7 -6
- package/dist/es/src/components/Form/AutoCompleteSingle/AutoCompleteSingle.d.ts +5 -7
- package/dist/es/src/components/Form/Checkbox/Checkbox.d.ts +4 -7
- package/dist/es/src/components/Form/CheckboxGroup/CheckboxGroup.d.ts +4 -12
- package/dist/es/src/components/Form/CheckboxGroup/checkboxgroup.interface.d.ts +8 -0
- package/dist/es/src/components/Form/DatePicker/DatePicker.d.ts +1 -1
- package/dist/es/src/components/Form/MultiSelect/MultiSelect.d.ts +4 -7
- package/dist/es/src/components/Form/RadioGroup/RadioGroup.d.ts +2 -5
- package/dist/es/src/components/Form/Select/Select.d.ts +5 -7
- package/dist/es/src/components/Form/Switch/Switch.d.ts +1 -4
- package/dist/es/src/components/Form/TextField/TextField.d.ts +5 -6
- package/dist/es/src/components/Form/TimePicker/TimePicker.d.ts +20 -0
- package/dist/es/src/components/Form/TimePicker/index.d.ts +1 -0
- package/dist/es/src/components/IconButton/IconButton.d.ts +5 -7
- package/dist/es/src/components/IconProvider/IconProvider.d.ts +1 -4
- package/dist/es/src/components/Link/Link.d.ts +1 -4
- package/dist/es/src/components/MenuItem/MenuItem.d.ts +7 -10
- package/dist/es/src/components/Navigation/Stepper/Step.d.ts +1 -1
- package/dist/es/src/components/Navigation/Stepper/Stepper.d.ts +1 -1
- package/dist/es/src/components/Pagination/Pagination.d.ts +3 -6
- package/dist/es/src/components/Snackbar/Snackbar.d.ts +1 -4
- package/dist/es/src/components/Text/Text.d.ts +1 -4
- package/dist/es/src/components/Tooltip/Tooltip.d.ts +5 -7
- package/dist/es/src/components/UploadDocument/FileUploaderSingle.d.ts +55 -8
- package/dist/es/src/components/UploadDocument/fileuploadersingle.interface.d.ts +5 -0
- package/dist/es/src/components/index.d.ts +2 -0
- package/dist/es/src/helpers/GooglePickerWrapper.d.ts +2 -1
- package/dist/es/src/hooks/useGooleDrivePicker.d.ts +1 -1
- package/package.json +20 -20
- package/src/components/Accordion/Accordion.tsx +4 -4
- package/src/components/BannerNotification/BannerNotification.tsx +0 -2
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +0 -2
- package/src/components/Button/Button.tsx +0 -2
- package/src/components/Chip/Chip.tsx +1 -3
- package/src/components/Datatable/Datatable.tsx +27 -6
- package/src/components/Datatable/DatatableCellRender.tsx +2 -1
- package/src/components/Datatable/datatable.interface.ts +5 -4
- package/src/components/Datatable/use-pagination-props.hook.ts +2 -2
- package/src/components/EmbbededNotification/EmbeddedNotification.tsx +0 -2
- package/src/components/Form/AutoCompleteMulti/AutoCompleteMulti.tsx +24 -9
- package/src/components/Form/AutoCompleteSingle/AutoCompleteSingle.tsx +15 -10
- package/src/components/Form/Checkbox/Checkbox.tsx +22 -25
- package/src/components/Form/CheckboxGroup/CheckboxGroup.tsx +8 -25
- package/src/components/Form/CheckboxGroup/checkboxgroup.interface.ts +22 -0
- package/src/components/Form/DatePicker/DatePicker.tsx +15 -3
- package/src/components/Form/MultiSelect/MultiSelect.tsx +33 -7
- package/src/components/Form/RadioGroup/RadioGroup.tsx +18 -23
- package/src/components/Form/Select/Select.tsx +34 -6
- package/src/components/Form/Switch/Switch.tsx +0 -2
- package/src/components/Form/TextField/TextField.tsx +120 -107
- package/src/components/Form/TimePicker/TimePicker.tsx +228 -0
- package/src/components/Form/TimePicker/index.ts +1 -0
- package/src/components/IconButton/IconButton.tsx +12 -6
- package/src/components/IconProvider/IconProvider.tsx +3 -4
- package/src/components/Link/Link.tsx +0 -2
- package/src/components/MenuItem/MenuItem.tsx +10 -39
- package/src/components/Navigation/Stepper/Step.tsx +1 -1
- package/src/components/Navigation/Stepper/Stepper.tsx +1 -1
- package/src/components/Pagination/Pagination.tsx +4 -5
- package/src/components/Snackbar/Snackbar.tsx +0 -2
- package/src/components/Text/Text.tsx +0 -2
- package/src/components/Tooltip/Tooltip.tsx +41 -32
- package/src/components/UploadDocument/FileUploaderSingle.tsx +185 -88
- package/src/components/UploadDocument/fileuploadersingle.interface.ts +5 -0
- package/src/components/index.ts +2 -0
- package/src/helpers/GooglePickerWrapper.tsx +2 -2
- package/src/hooks/useGooleDrivePicker.ts +8 -6
- package/src/types/global.d.ts +6 -4
- package/src/types/googleDrive.ts +1 -0
- package/dist/es/src/helpers/dataGetValue.d.ts +0 -2
- package/src/helpers/dataGetValue.ts +0 -22
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, {
|
|
2
|
+
ChangeEvent,
|
|
2
3
|
useCallback,
|
|
3
4
|
useEffect,
|
|
4
5
|
useMemo,
|
|
@@ -14,9 +15,9 @@ import {
|
|
|
14
15
|
faUpload,
|
|
15
16
|
} from '@fortawesome/pro-regular-svg-icons';
|
|
16
17
|
import {
|
|
17
|
-
IconDefinition,
|
|
18
18
|
faCaretDown,
|
|
19
19
|
faFileAlt,
|
|
20
|
+
faInfoCircle,
|
|
20
21
|
} from '@fortawesome/pro-solid-svg-icons';
|
|
21
22
|
import { Box, IconButton } from '@mui/material';
|
|
22
23
|
import Menu from '@mui/material/Menu';
|
|
@@ -27,11 +28,14 @@ import MenuItem from '@/components/MenuItem';
|
|
|
27
28
|
import Text from '@/components/Text';
|
|
28
29
|
import Tooltip from '@/components/Tooltip';
|
|
29
30
|
import GooglePickerWrapper from '@/helpers/GooglePickerWrapper';
|
|
30
|
-
|
|
31
|
+
|
|
32
|
+
import { acceptText } from './fileuploadersingle.interface';
|
|
31
33
|
|
|
32
34
|
export interface Props {
|
|
33
|
-
setFile: (
|
|
34
|
-
|
|
35
|
+
setFile: (_file: File | null) => void;
|
|
36
|
+
title?: string;
|
|
37
|
+
titleTooltip?: string;
|
|
38
|
+
enableGoogleDrive?: boolean;
|
|
35
39
|
googleAuthClientId?: string;
|
|
36
40
|
googleApiKey?: string;
|
|
37
41
|
error?: boolean;
|
|
@@ -39,17 +43,21 @@ export interface Props {
|
|
|
39
43
|
fileUrl?: string | null;
|
|
40
44
|
fileName?: string | null;
|
|
41
45
|
accept?: string[];
|
|
42
|
-
acceptText?:
|
|
46
|
+
acceptText?: acceptText;
|
|
43
47
|
disabledInput?: boolean;
|
|
44
|
-
title?: string;
|
|
45
48
|
children?: JSX.Element | null;
|
|
46
49
|
titleAddButton?: string;
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
_isDroppingFile?: boolean; // * Only used for storybook
|
|
51
|
+
validateFile?: (
|
|
52
|
+
_size: number,
|
|
53
|
+
_type: string,
|
|
54
|
+
_accept: string[],
|
|
55
|
+
_setUploadFileError: React.Dispatch<React.SetStateAction<boolean | string>>,
|
|
56
|
+
) => boolean;
|
|
49
57
|
removeExistingFile?: () => void;
|
|
50
58
|
onTouched?: () => void;
|
|
51
59
|
onFileDataChange?: (
|
|
52
|
-
|
|
60
|
+
_fileData: {
|
|
53
61
|
name: string;
|
|
54
62
|
size: number;
|
|
55
63
|
type?: string;
|
|
@@ -59,6 +67,52 @@ export interface Props {
|
|
|
59
67
|
) => void;
|
|
60
68
|
}
|
|
61
69
|
|
|
70
|
+
/**
|
|
71
|
+
* A single file uploader component that supports file selection from local storage or Google Drive.
|
|
72
|
+
*
|
|
73
|
+
* @param {string[]} accept - Array of accepted file types, will display acceptText message
|
|
74
|
+
* but not verify size or type of your file.
|
|
75
|
+
*
|
|
76
|
+
* Example:
|
|
77
|
+
* ```js
|
|
78
|
+
* accept={[
|
|
79
|
+
'application/pdf',
|
|
80
|
+
'image/png',
|
|
81
|
+
'image/jpeg',
|
|
82
|
+
'image/jpg',
|
|
83
|
+
]}
|
|
84
|
+
* ```
|
|
85
|
+
* @param {Object} acceptText - Object containing text for accepted file format, max size, and additional subtext.
|
|
86
|
+
*
|
|
87
|
+
* Example:
|
|
88
|
+
* ```js
|
|
89
|
+
* acceptText={{
|
|
90
|
+
maxSize: '10 Mo',
|
|
91
|
+
subText: 'Sélectionnez un fichier',
|
|
92
|
+
}}
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @param {Function} validateFile - Function to validate the file size and type.
|
|
96
|
+
*
|
|
97
|
+
* Example:
|
|
98
|
+
* ```js
|
|
99
|
+
* validateFile={(size, type, accept, setUploadFileError) => {
|
|
100
|
+
* if (size > 10 * 1024 * 1024) {
|
|
101
|
+
* setUploadFileError('Le fichier doit être inférieur à 10 Mo');
|
|
102
|
+
* return true;
|
|
103
|
+
* }
|
|
104
|
+
* if (!accept.includes(type)) {
|
|
105
|
+
* setUploadFileError('Le fichier doit être au format PDF, PNG, JPEG ou JPG');
|
|
106
|
+
* return true;
|
|
107
|
+
* }
|
|
108
|
+
* return false;
|
|
109
|
+
* }}
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @param {Function} onFileDataChange - Callback function to handle file data changes and give you all informations you need
|
|
113
|
+
* to handle google drive file.
|
|
114
|
+
*/
|
|
115
|
+
|
|
62
116
|
const FileUploaderSingle = ({
|
|
63
117
|
enableGoogleDrive = false,
|
|
64
118
|
googleAuthClientId,
|
|
@@ -66,21 +120,25 @@ const FileUploaderSingle = ({
|
|
|
66
120
|
error = false,
|
|
67
121
|
helperText = '',
|
|
68
122
|
accept = [],
|
|
69
|
-
acceptText = '',
|
|
123
|
+
acceptText = { fileFormat: '', maxSize: '', subText: '' },
|
|
70
124
|
title = '',
|
|
71
|
-
|
|
72
|
-
maxSize = 'Max. 10mo',
|
|
125
|
+
titleTooltip,
|
|
73
126
|
disabledInput = false,
|
|
74
127
|
children = null,
|
|
75
128
|
fileUrl = null,
|
|
76
129
|
fileName = null,
|
|
77
130
|
titleAddButton,
|
|
131
|
+
_isDroppingFile = false,
|
|
132
|
+
validateFile,
|
|
78
133
|
setFile,
|
|
79
134
|
removeExistingFile,
|
|
80
135
|
onTouched,
|
|
81
136
|
onFileDataChange,
|
|
82
137
|
}: Props) => {
|
|
83
|
-
const
|
|
138
|
+
const DEFAULT_COLOR = '%23CBCBCB';
|
|
139
|
+
const ERROR_COLOR = '%23b80025';
|
|
140
|
+
const DROPPING_COLOR = '%23004F88';
|
|
141
|
+
|
|
84
142
|
const [currentFile, setCurrentFile] = useState<File | null>(null);
|
|
85
143
|
const [fileData, setFileData] = useState<{
|
|
86
144
|
name: string;
|
|
@@ -90,9 +148,14 @@ const FileUploaderSingle = ({
|
|
|
90
148
|
driveAccessToken?: string;
|
|
91
149
|
} | null>(fileName ? { name: fileName, size: 0 } : null);
|
|
92
150
|
|
|
93
|
-
const [isDroppingFile, setIsDroppingFile] =
|
|
151
|
+
const [isDroppingFile, setIsDroppingFile] =
|
|
152
|
+
useState<boolean>(_isDroppingFile);
|
|
94
153
|
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
|
95
154
|
|
|
155
|
+
const [fileUploadError, setUploadFileError] = useState<string | boolean>(
|
|
156
|
+
false,
|
|
157
|
+
);
|
|
158
|
+
|
|
96
159
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
97
160
|
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
|
|
98
161
|
setAnchorEl(event.currentTarget);
|
|
@@ -101,38 +164,39 @@ const FileUploaderSingle = ({
|
|
|
101
164
|
setAnchorEl(null);
|
|
102
165
|
};
|
|
103
166
|
|
|
104
|
-
const validateFile = (size, type) => {
|
|
105
|
-
// if (size > 10 * 1024 * 1024) {
|
|
106
|
-
// setCustomFileError('Le fichier doit être inférieur à 10 Mo');
|
|
107
|
-
// setIsDroppingFile(false);
|
|
108
|
-
// return true;
|
|
109
|
-
// }
|
|
110
|
-
if (!accept.includes(type)) {
|
|
111
|
-
setCustomFileError(
|
|
112
|
-
`Le fichier doit être au format ${acceptText || extractExtensions(accept).join(', ')}`,
|
|
113
|
-
);
|
|
114
|
-
setIsDroppingFile(false);
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return false;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
167
|
const handleFileChange = useCallback(
|
|
122
|
-
|
|
123
|
-
|
|
168
|
+
(
|
|
169
|
+
_event: ChangeEvent<HTMLInputElement> | null,
|
|
170
|
+
data?: {
|
|
171
|
+
docs: {
|
|
172
|
+
name: string;
|
|
173
|
+
sizeBytes: number;
|
|
174
|
+
mimeType: string;
|
|
175
|
+
id: string;
|
|
176
|
+
}[];
|
|
177
|
+
} | null,
|
|
178
|
+
token: string | null = null,
|
|
179
|
+
accept: string[] = [],
|
|
180
|
+
fakeClick?: boolean,
|
|
181
|
+
) => {
|
|
124
182
|
if (fakeClick) {
|
|
125
183
|
fileInputRef?.current?.click();
|
|
126
184
|
}
|
|
127
185
|
handleClose();
|
|
128
186
|
onTouched?.();
|
|
187
|
+
|
|
188
|
+
// * Local File
|
|
129
189
|
if (
|
|
130
190
|
fileInputRef.current?.files &&
|
|
131
|
-
fileInputRef.current
|
|
191
|
+
fileInputRef.current.files.length > 0
|
|
132
192
|
) {
|
|
133
193
|
const file = fileInputRef.current.files[0];
|
|
134
|
-
setCurrentFile(
|
|
135
|
-
if (
|
|
194
|
+
setCurrentFile(file);
|
|
195
|
+
if (
|
|
196
|
+
validateFile &&
|
|
197
|
+
validateFile(file.size, file.type, accept, setUploadFileError)
|
|
198
|
+
) {
|
|
199
|
+
setIsDroppingFile(false);
|
|
136
200
|
return;
|
|
137
201
|
}
|
|
138
202
|
onFileDataChange?.({
|
|
@@ -140,7 +204,6 @@ const FileUploaderSingle = ({
|
|
|
140
204
|
size: Math.round(file.size / 1024),
|
|
141
205
|
type: file.type,
|
|
142
206
|
});
|
|
143
|
-
setCustomFileError(null);
|
|
144
207
|
setFileData({
|
|
145
208
|
name: file.name,
|
|
146
209
|
size: Math.round(file.size / 1024),
|
|
@@ -149,25 +212,34 @@ const FileUploaderSingle = ({
|
|
|
149
212
|
setFile(file);
|
|
150
213
|
setIsDroppingFile(false);
|
|
151
214
|
}
|
|
152
|
-
|
|
215
|
+
|
|
216
|
+
// * Google Drive
|
|
217
|
+
if (token && data && data.docs && data.docs.length > 0) {
|
|
218
|
+
const googleFile = data.docs[0];
|
|
153
219
|
const fileData = {
|
|
154
|
-
name:
|
|
155
|
-
size: Math.round(
|
|
156
|
-
type:
|
|
157
|
-
driveFileId:
|
|
220
|
+
name: googleFile.name,
|
|
221
|
+
size: Math.round(googleFile.sizeBytes / 1024),
|
|
222
|
+
type: googleFile.mimeType,
|
|
223
|
+
driveFileId: googleFile.id,
|
|
158
224
|
driveAccessToken: token,
|
|
159
225
|
};
|
|
160
|
-
if (
|
|
226
|
+
if (
|
|
227
|
+
validateFile &&
|
|
228
|
+
validateFile(
|
|
229
|
+
googleFile.sizeBytes,
|
|
230
|
+
googleFile.mimeType,
|
|
231
|
+
accept,
|
|
232
|
+
setUploadFileError,
|
|
233
|
+
)
|
|
234
|
+
) {
|
|
161
235
|
return;
|
|
162
236
|
}
|
|
163
237
|
onFileDataChange?.(fileData);
|
|
164
238
|
setIsDroppingFile(false);
|
|
165
|
-
setCustomFileError(null);
|
|
166
239
|
setFileData(fileData);
|
|
167
240
|
}
|
|
168
241
|
},
|
|
169
242
|
[
|
|
170
|
-
setCustomFileError,
|
|
171
243
|
setIsDroppingFile,
|
|
172
244
|
setCurrentFile,
|
|
173
245
|
setFileData,
|
|
@@ -188,7 +260,6 @@ const FileUploaderSingle = ({
|
|
|
188
260
|
URL.revokeObjectURL(URL.createObjectURL(currentFile));
|
|
189
261
|
setCurrentFile(null);
|
|
190
262
|
}
|
|
191
|
-
setCustomFileError(null);
|
|
192
263
|
setFileData(null);
|
|
193
264
|
setIsDroppingFile(false);
|
|
194
265
|
setFile(null);
|
|
@@ -199,30 +270,32 @@ const FileUploaderSingle = ({
|
|
|
199
270
|
}, [removeExistingFile, setFile, onFileDataChange, currentFile]);
|
|
200
271
|
|
|
201
272
|
const dashedColor = useMemo(() => {
|
|
202
|
-
if (isDroppingFile) return
|
|
203
|
-
if (error ||
|
|
204
|
-
return
|
|
205
|
-
}, [isDroppingFile, error]);
|
|
273
|
+
if (isDroppingFile) return DROPPING_COLOR;
|
|
274
|
+
if (error || fileUploadError !== false) return ERROR_COLOR;
|
|
275
|
+
return DEFAULT_COLOR;
|
|
276
|
+
}, [isDroppingFile, error, fileUploadError]);
|
|
206
277
|
|
|
207
278
|
const bgColor = useMemo(() => {
|
|
208
|
-
if (fileData?.name || disabledInput) return '
|
|
209
|
-
if (isDroppingFile) return '
|
|
279
|
+
if (fileData?.name || disabledInput) return 'greyXLight';
|
|
280
|
+
if (isDroppingFile) return 'blueHoverEquivalence';
|
|
210
281
|
return 'white';
|
|
211
282
|
}, [fileData?.name, disabledInput, isDroppingFile]);
|
|
212
283
|
|
|
213
284
|
const titleColor = useMemo(() => {
|
|
214
285
|
if (fileData?.name) return 'greyDark';
|
|
215
|
-
if (error ||
|
|
286
|
+
if (error || fileUploadError !== false) return 'redError';
|
|
216
287
|
return 'greyXDark';
|
|
217
|
-
}, [fileData?.name, error,
|
|
288
|
+
}, [fileData?.name, error, fileUploadError]);
|
|
218
289
|
|
|
219
290
|
const inputCss = useMemo(
|
|
220
291
|
() => ({
|
|
221
292
|
height: '87px',
|
|
222
293
|
backgroundImage: `url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='4' ry='4' stroke='${dashedColor}' stroke-width='2' stroke-dasharray='8%2c 8' stroke-dashoffset='0' stroke-linecap='round'/%3e%3c/svg%3e")`,
|
|
223
294
|
borderRadius: '4px',
|
|
295
|
+
py: '24px',
|
|
296
|
+
px: '22px',
|
|
224
297
|
display: 'flex',
|
|
225
|
-
justifyContent: 'space-
|
|
298
|
+
justifyContent: 'space-between',
|
|
226
299
|
position: 'relative',
|
|
227
300
|
alignItems: 'center',
|
|
228
301
|
backgroundColor: bgColor,
|
|
@@ -256,17 +329,32 @@ const FileUploaderSingle = ({
|
|
|
256
329
|
return (
|
|
257
330
|
<Box
|
|
258
331
|
data-testid="Uploader-document"
|
|
259
|
-
|
|
332
|
+
sx={{
|
|
333
|
+
pb: 3,
|
|
334
|
+
}}
|
|
260
335
|
onDragLeave={() => setIsDroppingFile(false)}
|
|
261
336
|
>
|
|
262
|
-
<
|
|
263
|
-
{
|
|
264
|
-
|
|
337
|
+
<Box sx={{ display: 'flex' }}>
|
|
338
|
+
<Text variant="body2Medium" color={titleColor} pl={1}>
|
|
339
|
+
{title}
|
|
340
|
+
</Text>
|
|
341
|
+
{titleTooltip && (
|
|
342
|
+
<Box sx={{ marginLeft: '4px' }}>
|
|
343
|
+
<Tooltip
|
|
344
|
+
title={titleTooltip}
|
|
345
|
+
sx={{
|
|
346
|
+
display: 'flex',
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
349
|
+
<IconProvider icon={faInfoCircle} size="sm" color="blueInfo" />
|
|
350
|
+
</Tooltip>
|
|
351
|
+
</Box>
|
|
352
|
+
)}
|
|
353
|
+
</Box>
|
|
265
354
|
<Tooltip
|
|
266
355
|
data-testid="tooltip"
|
|
267
356
|
title={(fileData?.name && 'Un seul fichier autorisé') || ''}
|
|
268
357
|
sx={{
|
|
269
|
-
padding: '0 !important',
|
|
270
358
|
display: (fileData?.name && 'block') || 'none',
|
|
271
359
|
}}
|
|
272
360
|
placement="top"
|
|
@@ -298,7 +386,7 @@ const FileUploaderSingle = ({
|
|
|
298
386
|
disabled={!!fileData?.name || disabledInput}
|
|
299
387
|
type="file"
|
|
300
388
|
ref={fileInputRef}
|
|
301
|
-
onChange={handleFileChange}
|
|
389
|
+
onChange={(event) => handleFileChange(event, null, null, accept)}
|
|
302
390
|
onBlur={onTouched}
|
|
303
391
|
accept={accept.join(', ')}
|
|
304
392
|
/>
|
|
@@ -319,12 +407,15 @@ const FileUploaderSingle = ({
|
|
|
319
407
|
}}
|
|
320
408
|
>
|
|
321
409
|
Format{' '}
|
|
322
|
-
{acceptText
|
|
323
|
-
|
|
324
|
-
|
|
410
|
+
{(acceptText?.fileFormat &&
|
|
411
|
+
acceptText?.fileFormat?.trim() !== ''
|
|
412
|
+
? acceptText.fileFormat
|
|
413
|
+
: extractExtensions(accept).join(', ')) + ' - '}
|
|
414
|
+
{(acceptText.maxSize && acceptText.maxSize) || 'Max 10 Mo'}
|
|
415
|
+
{acceptText.subText && (
|
|
325
416
|
<>
|
|
326
417
|
<br />
|
|
327
|
-
{subText}
|
|
418
|
+
{acceptText.subText}
|
|
328
419
|
</>
|
|
329
420
|
)}
|
|
330
421
|
</Text>
|
|
@@ -380,12 +471,17 @@ const FileUploaderSingle = ({
|
|
|
380
471
|
>
|
|
381
472
|
<MenuItem
|
|
382
473
|
testId="pc-add"
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
474
|
+
onClick={() => handleFileChange(null, null, null, [], true)}
|
|
475
|
+
>
|
|
476
|
+
<Box gap={1} display="flex">
|
|
477
|
+
<IconProvider size="sm" icon={faFolderOpen} />
|
|
478
|
+
<Text variant="body2">Depuis votre PC</Text>
|
|
479
|
+
</Box>
|
|
480
|
+
</MenuItem>
|
|
387
481
|
<GooglePickerWrapper
|
|
388
|
-
callback={(data, token) =>
|
|
482
|
+
callback={(data, token) =>
|
|
483
|
+
handleFileChange(null, data, token, accept)
|
|
484
|
+
}
|
|
389
485
|
multiselect={true}
|
|
390
486
|
navHidden={false}
|
|
391
487
|
googleAuthClientId={googleAuthClientId ?? ''}
|
|
@@ -393,12 +489,12 @@ const FileUploaderSingle = ({
|
|
|
393
489
|
scopes="https://www.googleapis.com/auth/drive.file"
|
|
394
490
|
viewId="FOLDERS"
|
|
395
491
|
>
|
|
396
|
-
<MenuItem
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
492
|
+
<MenuItem testId="drive-add" onClick={handleClose}>
|
|
493
|
+
<Box gap={1} display="flex">
|
|
494
|
+
<IconProvider size="sm" icon={faGoogleDrive} />
|
|
495
|
+
<Text variant="body2">Depuis Google Drive</Text>
|
|
496
|
+
</Box>
|
|
497
|
+
</MenuItem>
|
|
402
498
|
</GooglePickerWrapper>
|
|
403
499
|
</Menu>
|
|
404
500
|
</>
|
|
@@ -411,7 +507,7 @@ const FileUploaderSingle = ({
|
|
|
411
507
|
backgroundColor: '#FFFFFF !important',
|
|
412
508
|
},
|
|
413
509
|
}}
|
|
414
|
-
onClick={() => handleFileChange(null, null, true)}
|
|
510
|
+
onClick={() => handleFileChange(null, null, null, [], true)}
|
|
415
511
|
disabled={!!fileData?.name}
|
|
416
512
|
>
|
|
417
513
|
<IconProvider icon={faUpload} size="md" mr={1} />
|
|
@@ -421,15 +517,16 @@ const FileUploaderSingle = ({
|
|
|
421
517
|
</Box>
|
|
422
518
|
</Box>
|
|
423
519
|
</Tooltip>
|
|
424
|
-
|
|
425
|
-
{(error || customFileError || helperText) && (
|
|
520
|
+
{(error || helperText || fileUploadError !== false) && (
|
|
426
521
|
<Box pl={1} pt={1}>
|
|
427
522
|
<Text
|
|
428
523
|
variant="caption"
|
|
429
|
-
color={
|
|
524
|
+
color={
|
|
525
|
+
((error || fileUploadError !== false) && 'redError') || 'greyDark'
|
|
526
|
+
}
|
|
430
527
|
data-testid="helperText"
|
|
431
528
|
>
|
|
432
|
-
{
|
|
529
|
+
{fileUploadError !== false ? fileUploadError : helperText}
|
|
433
530
|
</Text>
|
|
434
531
|
</Box>
|
|
435
532
|
)}
|
|
@@ -439,8 +536,9 @@ const FileUploaderSingle = ({
|
|
|
439
536
|
sx={{
|
|
440
537
|
display: 'flex',
|
|
441
538
|
alignItems: 'center',
|
|
442
|
-
border:
|
|
443
|
-
|
|
539
|
+
border: '0.5px solid',
|
|
540
|
+
borderColor: error ? 'redError' : 'greyLightDefaultBorder',
|
|
541
|
+
borderRadius: '0',
|
|
444
542
|
justifyContent: 'space-between',
|
|
445
543
|
maxHeight: '50px',
|
|
446
544
|
}}
|
|
@@ -472,19 +570,18 @@ const FileUploaderSingle = ({
|
|
|
472
570
|
flexShrink: 1,
|
|
473
571
|
}}
|
|
474
572
|
>
|
|
475
|
-
{fileData?.name}
|
|
573
|
+
{fileData?.name}
|
|
476
574
|
</Text>
|
|
477
|
-
{fileData?.size && (
|
|
575
|
+
{fileData?.size && fileData.size !== 0 ? (
|
|
478
576
|
<Text
|
|
479
577
|
component="span"
|
|
480
578
|
variant="body2Regular"
|
|
481
579
|
color="greyDark"
|
|
482
|
-
sx={{ minWidth: '41px' }}
|
|
580
|
+
sx={{ minWidth: '41px', marginLeft: '8px' }}
|
|
483
581
|
>
|
|
484
|
-
{' '}
|
|
485
582
|
({fileData?.size} ko)
|
|
486
583
|
</Text>
|
|
487
|
-
)}
|
|
584
|
+
) : null}
|
|
488
585
|
</Box>
|
|
489
586
|
<Box
|
|
490
587
|
sx={{
|
package/src/components/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { default as Select } from './Form/Select';
|
|
|
6
6
|
export { default as MultiSelect } from './Form/MultiSelect';
|
|
7
7
|
export { default as Checkbox } from './Form/Checkbox';
|
|
8
8
|
export { default as CheckboxGroup } from './Form/CheckboxGroup';
|
|
9
|
+
export type { CheckboxItemType } from './Form/CheckboxGroup/checkboxgroup.interface';
|
|
9
10
|
export { default as RadioGroup } from './Form/RadioGroup';
|
|
10
11
|
export { default as Accordion } from './Accordion';
|
|
11
12
|
export { default as Breadcrumbs } from './Breadcrumbs';
|
|
@@ -26,6 +27,7 @@ export { default as Drawer } from './Modal/Drawer/Drawer';
|
|
|
26
27
|
export { default as Dialog } from './Modal/Dialog/Dialog';
|
|
27
28
|
export { default as Switch } from './Form/Switch/Switch';
|
|
28
29
|
export { default as DatePicker } from './Form/DatePicker';
|
|
30
|
+
export { default as TimePicker } from './Form/TimePicker';
|
|
29
31
|
export { default as Datatable } from './Datatable/Datatable';
|
|
30
32
|
export { default as DatatableCellRender } from './Datatable/DatatableCellRender';
|
|
31
33
|
export { default as IconButton } from './IconButton/IconButton';
|
|
@@ -2,11 +2,11 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import useGoogleDrivePicker, {
|
|
4
4
|
GOOGLE_ACTION,
|
|
5
|
+
GoogleDrivePickerData,
|
|
5
6
|
} from '@/hooks/useGooleDrivePicker';
|
|
6
7
|
|
|
7
8
|
interface GooglePickerWrapperProps {
|
|
8
|
-
|
|
9
|
-
callback: (data: any, token: string) => void;
|
|
9
|
+
callback: (_data: GoogleDrivePickerData, _token: string) => void;
|
|
10
10
|
multiselect?: boolean;
|
|
11
11
|
navHidden?: boolean;
|
|
12
12
|
googleAuthClientId: string;
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '@/types/googleDrive';
|
|
8
8
|
|
|
9
9
|
const useGoogleDrivePicker = (
|
|
10
|
-
callbackFunction: (
|
|
10
|
+
callbackFunction: (_result: GoogleDrivePickerData, _token: string) => void,
|
|
11
11
|
options: GoogleDrivePickerOptions,
|
|
12
12
|
) => {
|
|
13
13
|
const {
|
|
@@ -30,11 +30,13 @@ const useGoogleDrivePicker = (
|
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const view = new google.picker.DocsView(google.picker.ViewId[viewId ?? ''])
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const view = new google.picker.DocsView(google.picker.ViewId[viewId ?? '']);
|
|
34
|
+
|
|
35
|
+
view.setParent('root');
|
|
36
|
+
view.setIncludeFolders(true);
|
|
37
|
+
view.setSelectFolderEnabled(false);
|
|
38
|
+
view.setMimeTypes(mimeType?.join(',') ?? '');
|
|
39
|
+
|
|
38
40
|
const picker = new google.picker.PickerBuilder()
|
|
39
41
|
.setOAuthToken(innerToken)
|
|
40
42
|
.setDeveloperKey(googleApiKey)
|
package/src/types/global.d.ts
CHANGED
|
@@ -5,15 +5,17 @@ declare global {
|
|
|
5
5
|
google: {
|
|
6
6
|
accounts: {
|
|
7
7
|
oauth2: {
|
|
8
|
-
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
initTokenClient: (_params: TokenClientConfig) => any;
|
|
9
10
|
};
|
|
10
11
|
};
|
|
11
12
|
};
|
|
12
13
|
gapi: {
|
|
13
14
|
load: (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
_module: string,
|
|
16
|
+
_params: {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
callback: (_param: any) => void;
|
|
17
19
|
},
|
|
18
20
|
) => void;
|
|
19
21
|
};
|
package/src/types/googleDrive.ts
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Haystack } from '@/types/googleDrive';
|
|
2
|
-
|
|
3
|
-
export function dataGetValue(
|
|
4
|
-
object: Haystack,
|
|
5
|
-
key: string | number,
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
-
defaultValue: any = null,
|
|
8
|
-
): object | number | string | null {
|
|
9
|
-
try {
|
|
10
|
-
const resolved = key
|
|
11
|
-
.toString()
|
|
12
|
-
.split('.')
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
.reduce(function (prev: { [x: string]: any }, curr: string | number) {
|
|
15
|
-
return prev ? prev[curr] : defaultValue;
|
|
16
|
-
}, object);
|
|
17
|
-
|
|
18
|
-
return typeof resolved !== 'undefined' ? resolved : defaultValue;
|
|
19
|
-
} catch {
|
|
20
|
-
return defaultValue;
|
|
21
|
-
}
|
|
22
|
-
}
|