proje-react-panel 1.0.15 → 1.0.17-test-8
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/.vscode/launch.json +10 -0
- package/dist/components/components/FormField.d.ts +6 -1
- package/dist/components/components/InnerForm.d.ts +9 -4
- package/dist/components/components/Uploader.d.ts +8 -0
- package/dist/components/components/index.d.ts +1 -1
- package/dist/components/components/list/Datagrid.d.ts +9 -0
- package/dist/components/components/list/EmptyList.d.ts +2 -0
- package/dist/components/components/list/FilterPopup.d.ts +11 -0
- package/dist/components/components/list/ListPage.d.ts +20 -0
- package/dist/components/components/list/Pagination.d.ts +11 -0
- package/dist/components/components/list/index.d.ts +0 -0
- package/dist/components/list/Datagrid.d.ts +8 -4
- package/dist/components/list/EmptyList.d.ts +2 -0
- package/dist/components/list/FilterPopup.d.ts +10 -0
- package/dist/components/pages/FormPage.d.ts +10 -3
- package/dist/components/pages/ListPage.d.ts +2 -1
- package/dist/decorators/form/Input.d.ts +8 -3
- package/dist/decorators/list/Cell.d.ts +14 -2
- package/dist/decorators/list/List.d.ts +26 -4
- package/dist/decorators/list/ListData.d.ts +4 -4
- package/dist/decorators/list/getListFields.d.ts +2 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.esm.js +1 -1
- package/dist/types/AnyClass.d.ts +1 -1
- package/dist/types/ScreenCreatorData.d.ts +5 -5
- package/package.json +9 -3
- package/src/assets/icons/svg/create.svg +9 -0
- package/src/assets/icons/svg/filter.svg +3 -0
- package/src/assets/icons/svg/pencil.svg +8 -0
- package/src/assets/icons/svg/search.svg +8 -0
- package/src/assets/icons/svg/trash.svg +8 -0
- package/src/components/components/FormField.tsx +52 -9
- package/src/components/components/InnerForm.tsx +53 -15
- package/src/components/components/Uploader.tsx +66 -0
- package/src/components/components/index.ts +2 -2
- package/src/components/components/list/Datagrid.tsx +135 -0
- package/src/components/components/list/EmptyList.tsx +26 -0
- package/src/components/components/list/FilterPopup.tsx +202 -0
- package/src/components/components/list/ListPage.tsx +176 -0
- package/src/components/pages/FormPage.tsx +12 -3
- package/src/decorators/form/Input.ts +7 -4
- package/src/decorators/form/getFormFields.ts +1 -0
- package/src/decorators/list/Cell.ts +24 -14
- package/src/decorators/list/List.ts +26 -11
- package/src/decorators/list/ListData.ts +5 -5
- package/src/decorators/list/getListFields.ts +8 -8
- package/src/index.ts +8 -3
- package/src/styles/filter-popup.scss +134 -0
- package/src/styles/form.scss +2 -4
- package/src/styles/index.scss +18 -22
- package/src/styles/list.scss +151 -8
- package/src/styles/uploader.scss +86 -0
- package/src/types/AnyClass.ts +3 -1
- package/src/types/ScreenCreatorData.ts +12 -12
- package/src/types/svg.d.ts +5 -0
- package/src/components/components/ImageUploader.tsx +0 -301
- package/src/components/list/Datagrid.tsx +0 -101
- package/src/components/pages/ListPage.tsx +0 -85
- /package/src/components/{list → components/list}/Pagination.tsx +0 -0
- /package/src/components/{list → components/list}/index.ts +0 -0
- /package/src/styles/{_scrollbar.scss → utils/scrollbar.scss} +0 -0
package/src/styles/list.scss
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
@import '
|
1
|
+
@import 'utils/scrollbar';
|
2
2
|
$header-height: 60px;
|
3
3
|
$footer-height: 60px;
|
4
4
|
$datagrid-height: calc(100vh - ($header-height + $footer-height));
|
5
5
|
.list {
|
6
6
|
width: 100%;
|
7
|
-
padding: 0 0 0 16px;
|
8
|
-
border-radius: 8px;
|
9
|
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
10
7
|
background-color: #2b2b2b;
|
11
8
|
color: #e0e0e0;
|
12
9
|
max-height: 100vh;
|
@@ -16,11 +13,51 @@ $datagrid-height: calc(100vh - ($header-height + $footer-height));
|
|
16
13
|
|
17
14
|
.list-header {
|
18
15
|
height: $header-height;
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
display: flex;
|
17
|
+
align-items: center;
|
18
|
+
justify-content: space-between;
|
19
|
+
padding: 0 24px;
|
20
|
+
background: linear-gradient(90deg, #2b2b2b 0%, #3c3c3c 100%);
|
21
|
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
22
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
23
|
+
|
24
|
+
.header-title {
|
25
|
+
font-size: 20px;
|
26
|
+
font-weight: 600;
|
27
|
+
color: #ffffff;
|
28
|
+
text-transform: uppercase;
|
29
|
+
letter-spacing: 0.5px;
|
30
|
+
}
|
31
|
+
|
32
|
+
.header-actions {
|
33
|
+
display: flex;
|
34
|
+
gap: 16px;
|
35
|
+
align-items: center;
|
36
|
+
|
37
|
+
.create-button {
|
38
|
+
padding: 8px 16px;
|
39
|
+
background-color: #4caf50;
|
40
|
+
color: white;
|
41
|
+
border-radius: 4px;
|
42
|
+
text-decoration: none;
|
43
|
+
font-size: 14px;
|
44
|
+
font-weight: 500;
|
45
|
+
transition: background-color 0.2s ease;
|
46
|
+
|
47
|
+
&:hover {
|
48
|
+
background-color: #45a049;
|
49
|
+
}
|
50
|
+
.icon-create {
|
51
|
+
fill: currentColor;
|
52
|
+
stroke: none;
|
53
|
+
position: relative;
|
54
|
+
top: 2px;
|
55
|
+
right: 2px;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
23
59
|
}
|
60
|
+
|
24
61
|
.list-footer {
|
25
62
|
display: flex;
|
26
63
|
justify-content: space-between;
|
@@ -32,6 +69,7 @@ $datagrid-height: calc(100vh - ($header-height + $footer-height));
|
|
32
69
|
color: #ffffff;
|
33
70
|
}
|
34
71
|
.datagrid {
|
72
|
+
padding: 0 0 0 8px;
|
35
73
|
height: $datagrid-height;
|
36
74
|
min-height: $datagrid-height;
|
37
75
|
max-height: $datagrid-height;
|
@@ -65,4 +103,109 @@ $datagrid-height: calc(100vh - ($header-height + $footer-height));
|
|
65
103
|
background-color: #444444;
|
66
104
|
}
|
67
105
|
}
|
106
|
+
|
107
|
+
.empty-list {
|
108
|
+
display: flex;
|
109
|
+
align-items: center;
|
110
|
+
justify-content: center;
|
111
|
+
height: 100%;
|
112
|
+
width: 100%;
|
113
|
+
padding: 2rem;
|
114
|
+
|
115
|
+
.empty-list-content {
|
116
|
+
text-align: center;
|
117
|
+
color: #888;
|
118
|
+
|
119
|
+
svg {
|
120
|
+
margin-bottom: 1rem;
|
121
|
+
color: #666;
|
122
|
+
}
|
123
|
+
|
124
|
+
h3 {
|
125
|
+
font-size: 1.5rem;
|
126
|
+
margin-bottom: 0.5rem;
|
127
|
+
font-weight: 500;
|
128
|
+
color: #fff;
|
129
|
+
}
|
130
|
+
|
131
|
+
p {
|
132
|
+
font-size: 1rem;
|
133
|
+
color: #888;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
.util-cell-link {
|
140
|
+
display: flex;
|
141
|
+
align-items: center;
|
142
|
+
gap: 8px;
|
143
|
+
color: #666;
|
144
|
+
text-decoration: none;
|
145
|
+
transition: color 0.2s ease;
|
146
|
+
&.util-cell-link-remove {
|
147
|
+
cursor: pointer;
|
148
|
+
}
|
149
|
+
&:hover {
|
150
|
+
color: #333;
|
151
|
+
}
|
152
|
+
|
153
|
+
.icon {
|
154
|
+
width: 16px;
|
155
|
+
height: 16px;
|
156
|
+
stroke: none;
|
157
|
+
&.icon-trash {
|
158
|
+
fill: #ff0000;
|
159
|
+
stroke: none;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
.util-cell-label {
|
164
|
+
font-size: 14px;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
.filter-button {
|
169
|
+
background-color: #4caf50;
|
170
|
+
color: white;
|
171
|
+
border: none;
|
172
|
+
padding: 8px 16px;
|
173
|
+
border-radius: 4px;
|
174
|
+
cursor: pointer;
|
175
|
+
transition: background-color 0.2s ease;
|
176
|
+
|
177
|
+
&:hover {
|
178
|
+
background-color: #45a049;
|
179
|
+
}
|
180
|
+
.icon-filter {
|
181
|
+
position: relative;
|
182
|
+
top: 2px;
|
183
|
+
right: 2px;
|
184
|
+
width: 15px;
|
185
|
+
height: 15px;
|
186
|
+
stroke: currentColor;
|
187
|
+
stroke-width: 2;
|
188
|
+
fill: none;
|
189
|
+
&.active {
|
190
|
+
fill: currentColor;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
.header-custom {
|
195
|
+
display: flex;
|
196
|
+
flex: 1;
|
197
|
+
align-items: center;
|
198
|
+
justify-content: flex-start;
|
199
|
+
padding: 0 24px;
|
200
|
+
gap: 16px;
|
201
|
+
a {
|
202
|
+
padding: 8px 16px;
|
203
|
+
background-color: #4caf50;
|
204
|
+
color: white;
|
205
|
+
border-radius: 4px;
|
206
|
+
text-decoration: none;
|
207
|
+
font-size: 14px;
|
208
|
+
font-weight: 500;
|
209
|
+
transition: background-color 0.2s ease;
|
210
|
+
}
|
68
211
|
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
.uploader {
|
2
|
+
&-container {
|
3
|
+
padding: 1.5rem;
|
4
|
+
border: 2px dashed var(--border-color, #e0e0e0);
|
5
|
+
border-radius: 8px;
|
6
|
+
background-color: var(--bg-color, #fafafa);
|
7
|
+
transition: all 0.3s ease;
|
8
|
+
|
9
|
+
&:hover {
|
10
|
+
border-color: var(--primary-color, #2196f3);
|
11
|
+
background-color: var(--bg-hover-color, #f5f5f5);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
&-button {
|
16
|
+
background-color: var(--primary-color, #2196f3);
|
17
|
+
color: var(--button-text-color, white);
|
18
|
+
padding: 0.75rem 1.5rem;
|
19
|
+
border: none;
|
20
|
+
border-radius: 4px;
|
21
|
+
font-weight: 500;
|
22
|
+
cursor: pointer;
|
23
|
+
transition: background-color 0.3s ease;
|
24
|
+
|
25
|
+
&:hover {
|
26
|
+
background-color: var(--primary-hover-color, #1976d2);
|
27
|
+
}
|
28
|
+
|
29
|
+
&:active {
|
30
|
+
background-color: var(--primary-active-color, #1565c0);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
&-files {
|
35
|
+
margin-top: 1.5rem;
|
36
|
+
display: grid;
|
37
|
+
gap: 1rem;
|
38
|
+
}
|
39
|
+
|
40
|
+
&-file {
|
41
|
+
background-color: var(--file-bg-color, white);
|
42
|
+
padding: 1rem;
|
43
|
+
border-radius: 6px;
|
44
|
+
box-shadow: 0 2px 4px var(--shadow-color, rgba(0, 0, 0, 0.05));
|
45
|
+
display: grid;
|
46
|
+
gap: 0.5rem;
|
47
|
+
|
48
|
+
p {
|
49
|
+
margin: 0;
|
50
|
+
color: var(--text-color, #424242);
|
51
|
+
font-size: 0.875rem;
|
52
|
+
|
53
|
+
&:first-child {
|
54
|
+
color: var(--primary-color, #1976d2);
|
55
|
+
font-weight: 500;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
:root {
|
62
|
+
--border-color: #424242;
|
63
|
+
--bg-color: #1e1e1e;
|
64
|
+
--bg-hover-color: #2d2d2d;
|
65
|
+
--primary-color: #64b5f6;
|
66
|
+
--primary-hover-color: #42a5f5;
|
67
|
+
--primary-active-color: #2196f3;
|
68
|
+
--button-text-color: #ffffff;
|
69
|
+
--file-bg-color: #2d2d2d;
|
70
|
+
--shadow-color: rgba(0, 0, 0, 0.2);
|
71
|
+
--text-color: #e0e0e0;
|
72
|
+
}
|
73
|
+
|
74
|
+
// Dark theme
|
75
|
+
[data-theme='dark'] {
|
76
|
+
--border-color: #424242;
|
77
|
+
--bg-color: #1e1e1e;
|
78
|
+
--bg-hover-color: #2d2d2d;
|
79
|
+
--primary-color: #64b5f6;
|
80
|
+
--primary-hover-color: #42a5f5;
|
81
|
+
--primary-active-color: #2196f3;
|
82
|
+
--button-text-color: #ffffff;
|
83
|
+
--file-bg-color: #2d2d2d;
|
84
|
+
--shadow-color: rgba(0, 0, 0, 0.2);
|
85
|
+
--text-color: #e0e0e0;
|
86
|
+
}
|
package/src/types/AnyClass.ts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
import { CellOptions } from
|
2
|
-
import { CrudOptions } from
|
3
|
-
import { InputOptions } from
|
4
|
-
import { ListOptions } from
|
5
|
-
|
1
|
+
import { CellOptions } from '../decorators/list/Cell';
|
2
|
+
import { CrudOptions } from '../decorators/Crud';
|
3
|
+
import { InputOptions } from '../decorators/form/Input';
|
4
|
+
import { ListOptions } from '../decorators/list/List';
|
5
|
+
//TODO: remove
|
6
6
|
export interface ScreenCreatorData {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
resolver: any;
|
8
|
+
fields: string[];
|
9
|
+
inputs: InputOptions[];
|
10
|
+
crud?: CrudOptions;
|
11
|
+
path: string;
|
12
|
+
list?: ListOptions<any>;
|
13
|
+
cells: CellOptions[];
|
14
14
|
}
|
@@ -1,301 +0,0 @@
|
|
1
|
-
import React, { useEffect } from "react";
|
2
|
-
import { useFormContext } from "react-hook-form";
|
3
|
-
import { bytesToSize } from "../../utils/format";
|
4
|
-
|
5
|
-
interface ThumbnailImageProps {
|
6
|
-
name: string;
|
7
|
-
src: string;
|
8
|
-
size: number;
|
9
|
-
style?: React.CSSProperties;
|
10
|
-
}
|
11
|
-
|
12
|
-
interface MultipleImageUploaderProps {
|
13
|
-
value?: Array<{ file: File; image: string; remove?: boolean }>;
|
14
|
-
onError?: (error: string | null) => void;
|
15
|
-
onClear?: () => void;
|
16
|
-
reset?: any;
|
17
|
-
onFilesChange?: (files: File[]) => void;
|
18
|
-
}
|
19
|
-
|
20
|
-
interface FileWithPreview {
|
21
|
-
file: File;
|
22
|
-
image: string;
|
23
|
-
}
|
24
|
-
|
25
|
-
const uploadState = Object.freeze({
|
26
|
-
BEFORE: "before",
|
27
|
-
HOVER: "hover",
|
28
|
-
AFTER: "after",
|
29
|
-
} as const);
|
30
|
-
|
31
|
-
type UploadStateType = (typeof uploadState)[keyof typeof uploadState];
|
32
|
-
|
33
|
-
function ThumbnailImage(props: ThumbnailImageProps) {
|
34
|
-
return (
|
35
|
-
<div>
|
36
|
-
<img {...props} style={{ width: 100 }} />
|
37
|
-
<p>
|
38
|
-
{props.name} <span style={{ whiteSpace: "none" }}>({bytesToSize(props.size)})</span>
|
39
|
-
</p>
|
40
|
-
</div>
|
41
|
-
);
|
42
|
-
}
|
43
|
-
|
44
|
-
export function ImageUploader() {
|
45
|
-
const {
|
46
|
-
register,
|
47
|
-
formState: { errors },
|
48
|
-
watch,
|
49
|
-
setValue,
|
50
|
-
clearErrors,
|
51
|
-
setError,
|
52
|
-
} = useFormContext();
|
53
|
-
const up = watch("uploader");
|
54
|
-
|
55
|
-
useEffect(() => {
|
56
|
-
register("uploader", { required: true });
|
57
|
-
}, [register]);
|
58
|
-
|
59
|
-
return (
|
60
|
-
<div>
|
61
|
-
<span className="form-error" style={{ bottom: 2, top: "unset" }}>
|
62
|
-
{errors.uploader?.type === "required" && "At least 1 image is required!"}
|
63
|
-
{errors.uploader?.type === "custom" && errors.uploader.message?.toString()}
|
64
|
-
</span>
|
65
|
-
<MultipleImageUploader
|
66
|
-
reset={up}
|
67
|
-
onError={(data: string | null) => {
|
68
|
-
if (!data) {
|
69
|
-
setValue("uploader", { files: [] });
|
70
|
-
clearErrors("uploader");
|
71
|
-
} else {
|
72
|
-
setError("uploader", {
|
73
|
-
type: "custom",
|
74
|
-
message: data,
|
75
|
-
});
|
76
|
-
}
|
77
|
-
}}
|
78
|
-
onClear={() => {
|
79
|
-
setValue("uploader", { files: [] });
|
80
|
-
clearErrors("uploader");
|
81
|
-
}}
|
82
|
-
onFilesChange={(files) => {
|
83
|
-
setValue("uploader", { files });
|
84
|
-
}}
|
85
|
-
/>
|
86
|
-
</div>
|
87
|
-
);
|
88
|
-
}
|
89
|
-
|
90
|
-
export function MultipleImageUploader(props: MultipleImageUploaderProps) {
|
91
|
-
const [currentUploadState, setUploadState] = React.useState<UploadStateType>(uploadState.BEFORE);
|
92
|
-
const [images, setImages] = React.useState<Array<{ file: File; image: string; remove?: boolean }>>(
|
93
|
-
props.value || []
|
94
|
-
);
|
95
|
-
const [files, setFiles] = React.useState<FileWithPreview[]>([]);
|
96
|
-
const [counter, setCounter] = React.useState(0);
|
97
|
-
console.log("files", files);
|
98
|
-
const dropzoneElement = React.useRef<HTMLDivElement>(null);
|
99
|
-
const imageInputRef = React.useRef<HTMLInputElement>(null);
|
100
|
-
|
101
|
-
React.useEffect(() => {
|
102
|
-
const element = dropzoneElement.current;
|
103
|
-
if (!element) return;
|
104
|
-
|
105
|
-
const handleDragEnter = (e: DragEvent) => {
|
106
|
-
e.preventDefault();
|
107
|
-
e.stopPropagation();
|
108
|
-
dragEnter();
|
109
|
-
};
|
110
|
-
|
111
|
-
const handleDragLeave = (e: DragEvent) => {
|
112
|
-
e.preventDefault();
|
113
|
-
e.stopPropagation();
|
114
|
-
dragLeave();
|
115
|
-
};
|
116
|
-
|
117
|
-
const handleDragOver = (e: DragEvent) => {
|
118
|
-
e.preventDefault();
|
119
|
-
e.stopPropagation();
|
120
|
-
};
|
121
|
-
|
122
|
-
const handleDrop = (e: DragEvent) => {
|
123
|
-
e.preventDefault();
|
124
|
-
e.stopPropagation();
|
125
|
-
setCounter(0);
|
126
|
-
const droppedFiles = e.dataTransfer?.files;
|
127
|
-
if (!droppedFiles) return;
|
128
|
-
|
129
|
-
setFiles([]);
|
130
|
-
setUploadState(uploadState.AFTER);
|
131
|
-
|
132
|
-
const newFiles: File[] = [];
|
133
|
-
for (let i = 0; i < droppedFiles.length; i++) {
|
134
|
-
const reader = new FileReader();
|
135
|
-
reader.onload = (event) => {
|
136
|
-
if (!event.target) return;
|
137
|
-
const check = onFileChange([
|
138
|
-
...files,
|
139
|
-
{ file: droppedFiles[i], image: event.target.result as string },
|
140
|
-
]);
|
141
|
-
if (check) {
|
142
|
-
newFiles.push(droppedFiles[i]);
|
143
|
-
if (imageInputRef.current) {
|
144
|
-
imageInputRef.current.files = droppedFiles;
|
145
|
-
}
|
146
|
-
setFiles([]);
|
147
|
-
}
|
148
|
-
// Notify parent of file changes
|
149
|
-
if (props.onFilesChange) {
|
150
|
-
props.onFilesChange(newFiles);
|
151
|
-
}
|
152
|
-
};
|
153
|
-
reader.readAsDataURL(droppedFiles[i]);
|
154
|
-
}
|
155
|
-
if (imageInputRef.current) {
|
156
|
-
imageInputRef.current.files = droppedFiles;
|
157
|
-
}
|
158
|
-
};
|
159
|
-
|
160
|
-
element.addEventListener("dragenter", handleDragEnter, false);
|
161
|
-
element.addEventListener("dragleave", handleDragLeave, false);
|
162
|
-
element.addEventListener("dragover", handleDragOver, false);
|
163
|
-
element.addEventListener("drop", handleDrop, false);
|
164
|
-
|
165
|
-
return () => {
|
166
|
-
element.removeEventListener("dragenter", handleDragEnter);
|
167
|
-
element.removeEventListener("dragleave", handleDragLeave);
|
168
|
-
element.removeEventListener("dragover", handleDragOver);
|
169
|
-
element.removeEventListener("drop", handleDrop);
|
170
|
-
};
|
171
|
-
}, [files]);
|
172
|
-
|
173
|
-
const dragEnter = () => {
|
174
|
-
setCounter((prev) => prev + 1);
|
175
|
-
setUploadState(uploadState.HOVER);
|
176
|
-
};
|
177
|
-
|
178
|
-
const dragLeave = () => {
|
179
|
-
setCounter((prev) => {
|
180
|
-
if (prev - 1 === 0) {
|
181
|
-
setUploadState(uploadState.BEFORE);
|
182
|
-
return 0;
|
183
|
-
}
|
184
|
-
return prev - 1;
|
185
|
-
});
|
186
|
-
};
|
187
|
-
|
188
|
-
const clickRemoveImage = (i: number) => {
|
189
|
-
const sources = [...images];
|
190
|
-
sources[i].remove = !sources[i].remove;
|
191
|
-
setImages(sources);
|
192
|
-
};
|
193
|
-
|
194
|
-
const clickRemoveFile = () => {
|
195
|
-
setFiles([]);
|
196
|
-
if (imageInputRef.current) {
|
197
|
-
imageInputRef.current.value = "";
|
198
|
-
}
|
199
|
-
props.onClear?.();
|
200
|
-
};
|
201
|
-
|
202
|
-
const checkValid = (filesInner: FileWithPreview[]): string | null => {
|
203
|
-
if (!filesInner) return null;
|
204
|
-
if (filesInner.length >= 10) return "you can't send more than 10 images";
|
205
|
-
for (let i = 0; i < filesInner.length; i++) {
|
206
|
-
const file = filesInner[i].file;
|
207
|
-
const split = file.name.split(".");
|
208
|
-
if (!["png", "jpg", "jpeg"].includes(split[split.length - 1])) {
|
209
|
-
return `Extension of the file can only be "png", "jpg" or "jpeg" `;
|
210
|
-
}
|
211
|
-
if (file) {
|
212
|
-
if (file.size > 1048576) {
|
213
|
-
return `Size of "${file.name}" can't be bigger than 1mb`;
|
214
|
-
}
|
215
|
-
}
|
216
|
-
}
|
217
|
-
return null;
|
218
|
-
};
|
219
|
-
|
220
|
-
const onFileChange = (filesInner: FileWithPreview[]): string | null => {
|
221
|
-
const check = checkValid(filesInner);
|
222
|
-
if (!check) {
|
223
|
-
setFiles(filesInner);
|
224
|
-
}
|
225
|
-
props.onError?.(check);
|
226
|
-
return check;
|
227
|
-
};
|
228
|
-
|
229
|
-
const renderImages = () => {
|
230
|
-
const imageElements = [];
|
231
|
-
if (files) {
|
232
|
-
console.log("---->", files);
|
233
|
-
for (let i = 0; i < files.length; i++) {
|
234
|
-
let imageClassName = "image";
|
235
|
-
imageElements.push(
|
236
|
-
<div key={i} className="image-container">
|
237
|
-
<div className={imageClassName}>
|
238
|
-
<ThumbnailImage name={files[i].file.name} src={files[i].image} size={files[i].file.size} />
|
239
|
-
</div>
|
240
|
-
</div>
|
241
|
-
);
|
242
|
-
}
|
243
|
-
}
|
244
|
-
return imageElements;
|
245
|
-
};
|
246
|
-
|
247
|
-
return (
|
248
|
-
<div ref={dropzoneElement} className={"multi-image form-element dropzone " + currentUploadState}>
|
249
|
-
<input ref={imageInputRef} type="file" style={{ display: "none" }} className="target" name={"file"} />
|
250
|
-
<div className="container">
|
251
|
-
<button className="trash" onClick={clickRemoveFile} type="button">
|
252
|
-
Delete All
|
253
|
-
</button>
|
254
|
-
{renderImages()}
|
255
|
-
<div>
|
256
|
-
<button
|
257
|
-
type={"button"}
|
258
|
-
onClick={() => {
|
259
|
-
const fileInput = document.getElementById("file__") as HTMLInputElement;
|
260
|
-
if (fileInput) {
|
261
|
-
fileInput.click();
|
262
|
-
}
|
263
|
-
}}
|
264
|
-
className="plus">
|
265
|
-
<span>
|
266
|
-
+ Add Image
|
267
|
-
<p>Drag image here or Select Image</p>
|
268
|
-
</span>
|
269
|
-
</button>
|
270
|
-
</div>
|
271
|
-
<input
|
272
|
-
hidden
|
273
|
-
id={"file__"}
|
274
|
-
multiple
|
275
|
-
type={"file"}
|
276
|
-
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
|
277
|
-
const selectedFiles = event.target.files;
|
278
|
-
if (!selectedFiles) return;
|
279
|
-
|
280
|
-
setFiles([]);
|
281
|
-
setUploadState(uploadState.AFTER);
|
282
|
-
for (let i = 0; i < selectedFiles.length; i++) {
|
283
|
-
const reader = new FileReader();
|
284
|
-
reader.onload = (eventInner) => {
|
285
|
-
if (!eventInner.target) return;
|
286
|
-
onFileChange([
|
287
|
-
...files,
|
288
|
-
{ file: selectedFiles[i], image: eventInner.target.result as string },
|
289
|
-
]);
|
290
|
-
};
|
291
|
-
reader.readAsDataURL(selectedFiles[i]);
|
292
|
-
}
|
293
|
-
if (imageInputRef.current) {
|
294
|
-
imageInputRef.current.files = selectedFiles;
|
295
|
-
}
|
296
|
-
}}
|
297
|
-
/>
|
298
|
-
</div>
|
299
|
-
</div>
|
300
|
-
);
|
301
|
-
}
|
@@ -1,101 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { CellOptions } from '../../decorators/list/Cell';
|
3
|
-
import { Link } from 'react-router';
|
4
|
-
import { useAppStore } from '../../store/store';
|
5
|
-
import { ImageCellOptions } from '../../decorators/list/ImageCell';
|
6
|
-
|
7
|
-
interface ListProps<T> {
|
8
|
-
data: T[];
|
9
|
-
cells: CellOptions[];
|
10
|
-
}
|
11
|
-
|
12
|
-
export function Datagrid<T>({ data, cells }: ListProps<T>) {
|
13
|
-
if (!data || data.length === 0) {
|
14
|
-
return <div>No items available</div>;
|
15
|
-
}
|
16
|
-
|
17
|
-
return (
|
18
|
-
<div className="datagrid">
|
19
|
-
<table className="datagrid-table">
|
20
|
-
<thead>
|
21
|
-
<tr>
|
22
|
-
{cells.map(cellOptions => (
|
23
|
-
<th key={cellOptions.name}>{cellOptions.title ?? cellOptions.name}</th>
|
24
|
-
))}
|
25
|
-
<th />
|
26
|
-
<th>Delete</th>
|
27
|
-
</tr>
|
28
|
-
</thead>
|
29
|
-
<tbody>
|
30
|
-
{data.map((item, index) => (
|
31
|
-
<tr key={index}>
|
32
|
-
{cells.map(cellOptions => {
|
33
|
-
// @ts-ignore
|
34
|
-
const value = item[cellOptions.name];
|
35
|
-
let render = value ?? '-'; // Default value if the field is undefined or null
|
36
|
-
|
37
|
-
switch (cellOptions.type) {
|
38
|
-
case 'date':
|
39
|
-
if (value) {
|
40
|
-
const date = new Date(value);
|
41
|
-
render = `${date.getDate().toString().padStart(2, '0')}/${(
|
42
|
-
date.getMonth() + 1
|
43
|
-
)
|
44
|
-
.toString()
|
45
|
-
.padStart(
|
46
|
-
2,
|
47
|
-
'0'
|
48
|
-
)}/${date.getFullYear()} ${date.getHours().toString().padStart(2, '0')}:${date
|
49
|
-
.getMinutes()
|
50
|
-
.toString()
|
51
|
-
.padStart(2, '0')}`;
|
52
|
-
}
|
53
|
-
break;
|
54
|
-
|
55
|
-
case 'image': {
|
56
|
-
const imageCellOptions = cellOptions as ImageCellOptions;
|
57
|
-
render = (
|
58
|
-
<img
|
59
|
-
width={100}
|
60
|
-
height={100}
|
61
|
-
src={imageCellOptions.baseUrl + value}
|
62
|
-
style={{ objectFit: 'contain' }}
|
63
|
-
/>
|
64
|
-
);
|
65
|
-
break;
|
66
|
-
}
|
67
|
-
case 'string':
|
68
|
-
default:
|
69
|
-
render = value ? value.toString() : (cellOptions?.placeHolder ?? '-'); // Handles string type or default fallback
|
70
|
-
break;
|
71
|
-
}
|
72
|
-
/*
|
73
|
-
if (cellOptions.linkTo) {
|
74
|
-
render = <Link to={cellOptions.linkTo(item)}>{formattedValue}</Link>;
|
75
|
-
}
|
76
|
-
*/
|
77
|
-
return <td key={cellOptions.name}>{render}</td>;
|
78
|
-
})}
|
79
|
-
<td>
|
80
|
-
{/*@ts-ignore*/}
|
81
|
-
<Link to={'edit/' + (item?.id ?? '-')}>Edit</Link>
|
82
|
-
{/*@ts-ignore*/}
|
83
|
-
<Link to={'details/' + (item?.id ?? '-')}>Details</Link>
|
84
|
-
</td>
|
85
|
-
<td>
|
86
|
-
<button
|
87
|
-
onClick={() => {
|
88
|
-
/*@ts-ignore*/
|
89
|
-
//CrudApi.delete({ ...fetchSettings, token }, screen.controller, item?.id);
|
90
|
-
}}
|
91
|
-
>
|
92
|
-
Delete
|
93
|
-
</button>
|
94
|
-
</td>
|
95
|
-
</tr>
|
96
|
-
))}
|
97
|
-
</tbody>
|
98
|
-
</table>
|
99
|
-
</div>
|
100
|
-
);
|
101
|
-
}
|