@addsign/moje-agenda-shared-lib 2.0.66 → 2.0.68

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.
Files changed (58) hide show
  1. package/dist/Calendar-DWT4e7Th.js.map +1 -1
  2. package/dist/Combination-DmhTQmbL.js +996 -0
  3. package/dist/Combination-DmhTQmbL.js.map +1 -0
  4. package/dist/Dialog-3u5-ws89.js +424 -0
  5. package/dist/Dialog-3u5-ws89.js.map +1 -0
  6. package/dist/Dialog-CCrUyF91.js.map +1 -1
  7. package/dist/assets/style.css +3 -3
  8. package/dist/components/datatable/DataTableServer.js +349 -252
  9. package/dist/components/datatable/DataTableServer.js.map +1 -1
  10. package/dist/components/form/FileInputForm.d.ts +14 -0
  11. package/dist/components/form/FileInputForm.js +173 -0
  12. package/dist/components/form/FileInputForm.js.map +1 -0
  13. package/dist/components/form/FileInputFormMultiple.d.ts +16 -0
  14. package/dist/components/form/FileInputFormMultiple.js +240 -0
  15. package/dist/components/form/FileInputFormMultiple.js.map +1 -0
  16. package/dist/components/form/FileInputFull.d.ts +17 -0
  17. package/dist/components/form/FileInputFull.js +188 -0
  18. package/dist/components/form/FileInputFull.js.map +1 -0
  19. package/dist/components/form/FileInputFullMultiple.d.ts +19 -0
  20. package/dist/components/form/FileInputFullMultiple.js +226 -0
  21. package/dist/components/form/FileInputFullMultiple.js.map +1 -0
  22. package/dist/components/ui/Combobox.js.map +1 -1
  23. package/dist/components/ui/checkbox.js.map +1 -1
  24. package/dist/components/ui/command.js.map +1 -1
  25. package/dist/components/ui/multi-select.js.map +1 -1
  26. package/dist/components/ui/radioGroup.js.map +1 -1
  27. package/dist/components/ui/toast.js.map +1 -1
  28. package/dist/handleErrors-B2be_Hgy.js +31615 -0
  29. package/dist/handleErrors-B2be_Hgy.js.map +1 -0
  30. package/dist/handleErrors-P52guX3U.js +32 -0
  31. package/dist/handleErrors-P52guX3U.js.map +1 -0
  32. package/dist/index-BikTN7j8.js +2266 -0
  33. package/dist/index-BikTN7j8.js.map +1 -0
  34. package/dist/main.d.ts +2 -0
  35. package/dist/main.js +34 -30
  36. package/dist/main.js.map +1 -1
  37. package/dist/popover-BLI2Jq-c.js +319 -0
  38. package/dist/popover-BLI2Jq-c.js.map +1 -0
  39. package/dist/popover-CcrzvSk7.js.map +1 -1
  40. package/dist/tslib.es6-e8r3nMQ9.js +172 -0
  41. package/dist/tslib.es6-e8r3nMQ9.js.map +1 -0
  42. package/dist/types.d.ts +1 -0
  43. package/dist/types.js.map +1 -1
  44. package/lib/components/datatable/DataTableServer.tsx +165 -42
  45. package/lib/components/form/FileInputForm.tsx +184 -0
  46. package/lib/components/form/FileInputFormMultiple.tsx +220 -0
  47. package/lib/components/ui/Calendar.tsx +0 -2
  48. package/lib/components/ui/Combobox.tsx +0 -2
  49. package/lib/components/ui/Dialog.tsx +0 -2
  50. package/lib/components/ui/checkbox.tsx +0 -2
  51. package/lib/components/ui/command.tsx +0 -2
  52. package/lib/components/ui/multi-select.tsx +387 -387
  53. package/lib/components/ui/popover.tsx +0 -2
  54. package/lib/components/ui/radioGroup.tsx +0 -2
  55. package/lib/components/ui/toast.tsx +0 -1
  56. package/lib/main.ts +2 -0
  57. package/lib/types.ts +1 -0
  58. package/package.json +1 -2
@@ -0,0 +1,220 @@
1
+ import React, { useState, useCallback, useEffect } from "react";
2
+ import { useDropzone } from "react-dropzone";
3
+ import { MdDeleteOutline, MdInsertDriveFile } from "react-icons/md";
4
+ import { AxiosError } from "axios";
5
+ import { cn } from "../../utils/utils";
6
+ import { handleErrors } from "@addsign/moje-agenda-shared-lib";
7
+ import { IAttachment } from "../../types";
8
+ import { useFederationContext, useFormField } from "../../main";
9
+
10
+ interface FileInputFormMultipleProps {
11
+ name: string;
12
+ value?: IAttachment[] | null;
13
+ onFilesChanged: (files: IAttachment[]) => void;
14
+ description?: string;
15
+ disabled?: boolean;
16
+ initialFilesReadOnly?: boolean;
17
+ initialFileIds?: number[];
18
+ attachmentName?: string;
19
+ attachmentType?: string;
20
+ }
21
+
22
+ interface IAttachmentReadOnly extends IAttachment {
23
+ readonly?: boolean;
24
+ }
25
+
26
+ const MAX_FILE_SIZE = 1024 * 1024; // 1MB
27
+
28
+ const FileInputFormMultiple: React.FC<FileInputFormMultipleProps> = ({
29
+ value,
30
+ onFilesChanged,
31
+ name,
32
+ description,
33
+ disabled,
34
+ initialFilesReadOnly = true,
35
+ initialFileIds,
36
+ attachmentName,
37
+ attachmentType,
38
+ }) => {
39
+ const [fileDataList, setFileDataList] = useState<IAttachmentReadOnly[]>(
40
+ value?.map((file) => ({
41
+ ...file,
42
+ readonly: initialFilesReadOnly && initialFileIds?.includes(file.id),
43
+ })) || []
44
+ );
45
+
46
+ const federationContext = useFederationContext();
47
+
48
+ const { error } = useFormField();
49
+ const hasError = !!error;
50
+ useEffect(() => {
51
+ if (!value || value.length === 0) {
52
+ setFileDataList([]);
53
+ return;
54
+ }
55
+
56
+ setFileDataList(
57
+ value.map((file) => ({
58
+ ...file,
59
+ readonly: initialFilesReadOnly && initialFileIds?.includes(file.id),
60
+ }))
61
+ );
62
+ }, [value, initialFilesReadOnly, initialFileIds]);
63
+
64
+ const onDrop = useCallback(
65
+ async (acceptedFiles: File[]) => {
66
+ const uploadedFiles = await Promise.all(
67
+ acceptedFiles.map(async (file) => {
68
+ if (file.size > MAX_FILE_SIZE) {
69
+ // Handle the case when the file size is exceeded
70
+ federationContext.emitter.emit("message", {
71
+ title: "Velikost souboru byla překročena",
72
+ message: `Maximální povolená velikost je ${MAX_FILE_SIZE / (1024 * 1024)} MB.`,
73
+ classes: "bg-danger ",
74
+ timeout: 0,
75
+ type: "error",
76
+ });
77
+
78
+ return null;
79
+ }
80
+
81
+ const formData = new FormData();
82
+
83
+ // Add the JSON data object
84
+ const dataObject = {
85
+ ...(attachmentName && { attachmentName }),
86
+ ...(attachmentType && { attachmentType }),
87
+ };
88
+
89
+ formData.append(
90
+ "data",
91
+ new Blob([JSON.stringify(dataObject)], { type: "application/json" })
92
+ );
93
+ formData.append("file", file);
94
+
95
+ try {
96
+ const response =
97
+ await federationContext.apiClient.post<IAttachment>(
98
+ "/files/upload",
99
+ formData,
100
+ {
101
+ headers: {
102
+ "Content-Type": "multipart/form-data",
103
+ },
104
+ }
105
+ );
106
+ return response.data;
107
+ } catch (error) {
108
+ handleErrors(error as AxiosError, federationContext.emitter);
109
+ console.error("There was an error!", error);
110
+ return null;
111
+ }
112
+ })
113
+ );
114
+
115
+ const validFiles = uploadedFiles.filter(
116
+ (file) => file !== null
117
+ ) as IAttachment[];
118
+ const updatedFileDataList = [...fileDataList, ...validFiles];
119
+ setFileDataList(updatedFileDataList);
120
+ onFilesChanged(updatedFileDataList);
121
+ },
122
+ [
123
+ federationContext,
124
+ fileDataList,
125
+ onFilesChanged,
126
+ attachmentName,
127
+ attachmentType,
128
+ ]
129
+ );
130
+
131
+ const { getRootProps, getInputProps, isDragActive } = useDropzone({
132
+ onDrop,
133
+ disabled,
134
+ });
135
+
136
+ const handleRemove = (fileId: number) => {
137
+ const updatedFileDataList = fileDataList.filter(
138
+ (file) => file.id !== fileId
139
+ );
140
+ setFileDataList(updatedFileDataList);
141
+ onFilesChanged(updatedFileDataList);
142
+ };
143
+
144
+ if (disabled === true && fileDataList.length === 0) {
145
+ return null;
146
+ }
147
+
148
+ return (
149
+ <div
150
+ className="w-full min-h-30 flex-col justify-start items-start gap-1.5 inline-flex sharedLibrary"
151
+ data-cy={"file-input-form-multiple-" + name}
152
+ >
153
+ <div className="self-stretch flex-col justify-start items-start gap-1.5 flex">
154
+ <div
155
+ className={cn(
156
+ `self-stretch px-3 py-2 rounded-lg justify-start items-center gap-2 outline-none border bg-transparent `,
157
+ hasError &&
158
+ "outline-4 outline-red-200 outline-offset-0 border-none ",
159
+ disabled ? "bg-gray-100" : "bg-transparent"
160
+ )}
161
+ >
162
+ {!disabled && (
163
+ <div
164
+ {...getRootProps()}
165
+ className={`w-full p-4 border-dashed cursor-pointer
166
+ border-2 rounded-lg text-center hover:bg-gray-100
167
+ ${isDragActive ? "border-indigo-300 bg-indigo-50" : "border-gray-300"}`}
168
+ >
169
+ <input {...getInputProps()} id={name} />
170
+ <p className="text-gray-500">
171
+ {isDragActive
172
+ ? "Sem přetáhněte soubory"
173
+ : "Klikněte pro nahrání, nebo nahrajte přetažením souborů"}
174
+ </p>
175
+ </div>
176
+ )}
177
+ <div className="w-full">
178
+ {fileDataList.map((file) => (
179
+ <div
180
+ key={file.id}
181
+ className="w-full flex items-center justify-between py-2 border-b "
182
+ >
183
+ <div className="flex items-center content-center">
184
+ <MdInsertDriveFile style={{ fontSize: "2rem" }} />
185
+ <a
186
+ href={`/api/files/download/${file.id}`}
187
+ className="pl-2 text-left underline text-primary"
188
+ target="_blank"
189
+ >
190
+ {file.filename}
191
+ </a>
192
+ </div>
193
+ {!disabled && file.readonly !== true && (
194
+ <div
195
+ onClick={() => handleRemove(file.id)}
196
+ className="text-gray-600 cursor-pointer hover:text-primary hover:bg-gray-200 rounded-full ml-4"
197
+ >
198
+ <MdDeleteOutline
199
+ style={{ fontSize: "1.5rem", margin: "10px" }}
200
+ />
201
+ </div>
202
+ )}
203
+ </div>
204
+ ))}
205
+ </div>
206
+ </div>
207
+ </div>
208
+ {description && (
209
+ <div
210
+ className="HintText self-stretch text-slate-600 text-sm font-normal leading-tight"
211
+ id={name + ":description"}
212
+ >
213
+ {description}
214
+ </div>
215
+ )}
216
+ </div>
217
+ );
218
+ };
219
+
220
+ export default FileInputFormMultiple;
@@ -1,5 +1,3 @@
1
- "use client";
2
-
3
1
  import * as React from "react";
4
2
  import { ChevronLeft, ChevronRight } from "lucide-react";
5
3
  import { DayPicker } from "react-day-picker";
@@ -1,5 +1,3 @@
1
- "use client";
2
-
3
1
  import * as React from "react";
4
2
  import { Check, ChevronsUpDown, Plus, X } from "lucide-react";
5
3
 
@@ -1,5 +1,3 @@
1
- "use client";
2
-
3
1
  import * as React from "react";
4
2
  import * as DialogPrimitive from "@radix-ui/react-dialog";
5
3
  import { X } from "lucide-react";
@@ -1,5 +1,3 @@
1
- "use client";
2
-
3
1
  import * as React from "react";
4
2
  import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
5
3
  import { Check } from "lucide-react";
@@ -1,5 +1,3 @@
1
- "use client";
2
-
3
1
  import * as React from "react";
4
2
  import { type DialogProps } from "@radix-ui/react-dialog";
5
3
  import { Command as CommandPrimitive } from "cmdk";