@addsign/moje-agenda-shared-lib 2.0.62 → 2.0.63
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/components/form/FileInput.d.ts +2 -6
- package/dist/components/form/FileInput.js +10 -12
- package/dist/components/form/FileInput.js.map +1 -1
- package/dist/components/form/FileInputMultiple.d.ts +1 -5
- package/dist/components/form/FileInputMultiple.js +8 -12
- package/dist/components/form/FileInputMultiple.js.map +1 -1
- package/dist/form-Bb28hcCd.js +404 -0
- package/dist/form-Bb28hcCd.js.map +1 -0
- package/lib/components/form/FileInput.tsx +211 -222
- package/lib/components/form/FileInputMultiple.tsx +9 -14
- package/package.json +1 -1
|
@@ -1,222 +1,211 @@
|
|
|
1
|
-
import React, { useState, useEffect, useCallback } from "react";
|
|
2
|
-
import { useDropzone } from "react-dropzone";
|
|
3
|
-
import { handleErrors, useFederationContext } from "../../main";
|
|
4
|
-
import { MdDeleteOutline, MdInsertDriveFile } from "react-icons/md";
|
|
5
|
-
import { AxiosError } from "axios";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
attachmentName?: string;
|
|
26
|
-
attachmentType?: string;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
attachmentName,
|
|
41
|
-
attachmentType,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
...(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
federationContext.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
`
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
className="HintText self-stretch text-red-600 text-sm font-normal leading-tight"
|
|
213
|
-
id={name + ":error"}
|
|
214
|
-
>
|
|
215
|
-
{errors[name]?.message}
|
|
216
|
-
</div>
|
|
217
|
-
)}
|
|
218
|
-
</div>
|
|
219
|
-
);
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
export default FileInput;
|
|
1
|
+
import React, { useState, useEffect, useCallback } from "react";
|
|
2
|
+
import { useDropzone } from "react-dropzone";
|
|
3
|
+
import { handleErrors, useFederationContext } from "../../main";
|
|
4
|
+
import { MdDeleteOutline, MdInsertDriveFile } from "react-icons/md";
|
|
5
|
+
import { AxiosError } from "axios";
|
|
6
|
+
import { cn } from "../../utils/utils";
|
|
7
|
+
|
|
8
|
+
export interface FileData {
|
|
9
|
+
id: number;
|
|
10
|
+
mimeType: string;
|
|
11
|
+
size: number;
|
|
12
|
+
filename: string;
|
|
13
|
+
createdByEmpId: string;
|
|
14
|
+
created: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface FileInputProps {
|
|
18
|
+
name: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
initialFile?: FileData;
|
|
21
|
+
onFileChanged: (e: any) => void;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
description?: string;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
attachmentName?: string;
|
|
26
|
+
attachmentType?: string;
|
|
27
|
+
hasError?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const MAX_FILE_SIZE = 1024 * 1024; // 1MB
|
|
31
|
+
|
|
32
|
+
const FileInput: React.FC<FileInputProps> = ({
|
|
33
|
+
initialFile,
|
|
34
|
+
onFileChanged,
|
|
35
|
+
label,
|
|
36
|
+
name,
|
|
37
|
+
required,
|
|
38
|
+
description,
|
|
39
|
+
disabled,
|
|
40
|
+
attachmentName,
|
|
41
|
+
attachmentType,
|
|
42
|
+
hasError,
|
|
43
|
+
}) => {
|
|
44
|
+
const [fileData, setFileData] = useState<FileData | null>(
|
|
45
|
+
initialFile || null
|
|
46
|
+
);
|
|
47
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
48
|
+
|
|
49
|
+
const federationContext = useFederationContext();
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (initialFile) {
|
|
52
|
+
setFileData(initialFile);
|
|
53
|
+
}
|
|
54
|
+
}, [initialFile]);
|
|
55
|
+
|
|
56
|
+
const onDrop = useCallback(
|
|
57
|
+
async (acceptedFiles: File[]) => {
|
|
58
|
+
if (acceptedFiles.length > 0) {
|
|
59
|
+
const file = acceptedFiles[0];
|
|
60
|
+
|
|
61
|
+
if (file.size > MAX_FILE_SIZE) {
|
|
62
|
+
// Handle the case when the file size is exceeded
|
|
63
|
+
federationContext.emitter.emit("message", {
|
|
64
|
+
title: "Velikost souboru byla překročena",
|
|
65
|
+
message: `Maximální povolená velikost je ${MAX_FILE_SIZE / (1024 * 1024)} MB.`,
|
|
66
|
+
classes: "bg-danger ",
|
|
67
|
+
timeout: 0,
|
|
68
|
+
type: "error",
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const formData = new FormData();
|
|
74
|
+
|
|
75
|
+
// Add the JSON data object
|
|
76
|
+
const dataObject = {
|
|
77
|
+
...(attachmentName && { attachmentName }),
|
|
78
|
+
...(attachmentType && { attachmentType }),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
formData.append(
|
|
82
|
+
"data",
|
|
83
|
+
new Blob([JSON.stringify(dataObject)], { type: "application/json" })
|
|
84
|
+
);
|
|
85
|
+
formData.append("file", file);
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const response = await federationContext.apiClient.post<FileData>(
|
|
89
|
+
"/files/upload",
|
|
90
|
+
formData,
|
|
91
|
+
{
|
|
92
|
+
headers: {
|
|
93
|
+
"Content-Type": "multipart/form-data",
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
setFileData(response.data);
|
|
98
|
+
onFileChanged({
|
|
99
|
+
target: { name, value: response.data.id.toString() },
|
|
100
|
+
});
|
|
101
|
+
setIsFocused(false);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
handleErrors(error as AxiosError, federationContext.emitter);
|
|
104
|
+
console.error("There was an error!", error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
[
|
|
109
|
+
federationContext.apiClient,
|
|
110
|
+
federationContext.emitter,
|
|
111
|
+
onFileChanged,
|
|
112
|
+
name,
|
|
113
|
+
attachmentName,
|
|
114
|
+
attachmentType,
|
|
115
|
+
]
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
119
|
+
onDrop,
|
|
120
|
+
disabled,
|
|
121
|
+
multiple: false,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const handleRemove = () => {
|
|
125
|
+
setFileData(null);
|
|
126
|
+
onFileChanged({ target: { name, value: null } });
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<div className="w-full min-h-30 flex-col justify-start items-start gap-1.5 inline-flex sharedLibrary">
|
|
131
|
+
<div className="self-stretch flex-col justify-start items-start gap-1.5 flex">
|
|
132
|
+
{label && (
|
|
133
|
+
<label
|
|
134
|
+
className="text-slate-700 text-sm leading-tight font-medium"
|
|
135
|
+
htmlFor={name}
|
|
136
|
+
>
|
|
137
|
+
{label} {required ? "*" : ""}
|
|
138
|
+
</label>
|
|
139
|
+
)}
|
|
140
|
+
<div
|
|
141
|
+
className={cn(
|
|
142
|
+
`self-stretch px-2 py-2 rounded-lg justify-start items-center gap-2 inline-flex outline-none border`,
|
|
143
|
+
isFocused &&
|
|
144
|
+
!hasError &&
|
|
145
|
+
"outline-4 outline-indigo-200 outline-offset-0 border-indigo-300",
|
|
146
|
+
|
|
147
|
+
hasError &&
|
|
148
|
+
"outline-4 outline-red-200 outline-offset-0 border-none",
|
|
149
|
+
!isFocused && hasError && "border-red-200 ",
|
|
150
|
+
disabled ? "bg-gray-100" : "bg-transparent"
|
|
151
|
+
)}
|
|
152
|
+
onFocus={() => setIsFocused(true)}
|
|
153
|
+
onBlur={() => setIsFocused(false)}
|
|
154
|
+
>
|
|
155
|
+
<div className="flex relative grow shrink basis-0 min-h-5 lg:min-h-[32px] justify-start items-stretch gap-2 max-w-full ">
|
|
156
|
+
{!fileData ? (
|
|
157
|
+
<div
|
|
158
|
+
{...getRootProps()}
|
|
159
|
+
className={`w-full p-4 border-dashed border-2 rounded-lg text-center ${
|
|
160
|
+
isDragActive
|
|
161
|
+
? "border-indigo-300 bg-indigo-50"
|
|
162
|
+
: "border-gray-300"
|
|
163
|
+
}`}
|
|
164
|
+
>
|
|
165
|
+
<input {...getInputProps()} id={name} />
|
|
166
|
+
<p className="text-gray-500">
|
|
167
|
+
{isDragActive
|
|
168
|
+
? "Sem přetáhněte soubor"
|
|
169
|
+
: "Klikněte pro nahrání, nebo nahrajte přetažením souboru"}
|
|
170
|
+
</p>
|
|
171
|
+
</div>
|
|
172
|
+
) : (
|
|
173
|
+
<div className="w-full flex items-center justify-between">
|
|
174
|
+
<div className=" flex">
|
|
175
|
+
<MdInsertDriveFile style={{ fontSize: "2rem" }} />
|
|
176
|
+
<a
|
|
177
|
+
href={`/api/files/download/${fileData.id}`}
|
|
178
|
+
className="pl-2 text-left underline text-primary"
|
|
179
|
+
target="_blank"
|
|
180
|
+
>
|
|
181
|
+
{fileData.filename}
|
|
182
|
+
</a>
|
|
183
|
+
</div>
|
|
184
|
+
{!disabled && (
|
|
185
|
+
<div
|
|
186
|
+
onClick={handleRemove}
|
|
187
|
+
className="text-gray-600 cursor-pointer hover:text-primary hover:bg-gray-200 rounded-full ml-4"
|
|
188
|
+
>
|
|
189
|
+
<MdDeleteOutline
|
|
190
|
+
style={{ fontSize: "1.5rem", margin: "15px" }}
|
|
191
|
+
/>
|
|
192
|
+
</div>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
)}
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
</div>
|
|
199
|
+
{description && (
|
|
200
|
+
<div
|
|
201
|
+
className="HintText self-stretch text-slate-600 text-sm font-normal leading-tight"
|
|
202
|
+
id={name + ":description"}
|
|
203
|
+
>
|
|
204
|
+
{description}
|
|
205
|
+
</div>
|
|
206
|
+
)}
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export default FileInput;
|
|
@@ -4,6 +4,7 @@ import { MdDeleteOutline, MdInsertDriveFile } from "react-icons/md";
|
|
|
4
4
|
import { IAttachment } from "../../types";
|
|
5
5
|
import { handleErrors, useFederationContext } from "../../main";
|
|
6
6
|
import { AxiosError } from "axios";
|
|
7
|
+
import { cn } from "../../utils/utils";
|
|
7
8
|
|
|
8
9
|
interface FileInputMultipleProps {
|
|
9
10
|
name: string;
|
|
@@ -13,10 +14,10 @@ interface FileInputMultipleProps {
|
|
|
13
14
|
required?: boolean;
|
|
14
15
|
description?: string;
|
|
15
16
|
disabled?: boolean;
|
|
16
|
-
errors?: { [key: string]: { message: string } };
|
|
17
17
|
initialFilesReadOnly?: boolean;
|
|
18
18
|
attachmentName?: string;
|
|
19
19
|
attachmentType?: string;
|
|
20
|
+
hasError?: boolean;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
interface IAttachmentReadOnly extends IAttachment {
|
|
@@ -33,10 +34,10 @@ const FileInputMultiple: React.FC<FileInputMultipleProps> = ({
|
|
|
33
34
|
required,
|
|
34
35
|
description,
|
|
35
36
|
disabled,
|
|
36
|
-
errors = {},
|
|
37
37
|
initialFilesReadOnly = true,
|
|
38
38
|
attachmentName,
|
|
39
39
|
attachmentType,
|
|
40
|
+
hasError,
|
|
40
41
|
}) => {
|
|
41
42
|
const [fileDataList, setFileDataList] = useState<IAttachmentReadOnly[]>(
|
|
42
43
|
initialFiles
|
|
@@ -163,10 +164,12 @@ const FileInputMultiple: React.FC<FileInputMultipleProps> = ({
|
|
|
163
164
|
</label>
|
|
164
165
|
)}
|
|
165
166
|
<div
|
|
166
|
-
className={
|
|
167
|
-
`self-stretch px-3 py-2 rounded-lg justify-start items-center gap-2 outline-none border bg-transparent
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
className={cn(
|
|
168
|
+
`self-stretch px-3 py-2 rounded-lg justify-start items-center gap-2 outline-none border bg-transparent `,
|
|
169
|
+
hasError &&
|
|
170
|
+
"outline-4 outline-red-200 outline-offset-0 border-none ",
|
|
171
|
+
disabled ? "bg-gray-100" : "bg-transparent"
|
|
172
|
+
)}
|
|
170
173
|
>
|
|
171
174
|
{!disabled && (
|
|
172
175
|
<div
|
|
@@ -222,14 +225,6 @@ const FileInputMultiple: React.FC<FileInputMultipleProps> = ({
|
|
|
222
225
|
{description}
|
|
223
226
|
</div>
|
|
224
227
|
)}
|
|
225
|
-
{errors[name] && (
|
|
226
|
-
<div
|
|
227
|
-
className="HintText self-stretch text-red-600 text-sm font-normal leading-tight"
|
|
228
|
-
id={name + ":error"}
|
|
229
|
-
>
|
|
230
|
-
{errors[name]?.message}
|
|
231
|
-
</div>
|
|
232
|
-
)}
|
|
233
228
|
</div>
|
|
234
229
|
);
|
|
235
230
|
};
|