trithuc-mvc-react 1.6.4 → 1.6.6
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/components/DataManagement/EditorForm.jsx +4 -0
- package/components/DataManagement/FormField.jsx +15 -0
- package/components/DataManagement/TableRowRender.jsx +3 -3
- package/components/DataManagement/TableToolbar.jsx +3 -2
- package/components/DataManagement/index.jsx +2 -0
- package/components/DataManagement/upload/RhfUploadAvatar.jsx +65 -0
- package/package.json +1 -1
|
@@ -82,6 +82,10 @@ function EditorForm({ fields, submitRef }) {
|
|
|
82
82
|
if (data[field]) {
|
|
83
83
|
data[field] = JSON.stringify(data[field]);
|
|
84
84
|
}
|
|
85
|
+
} else if (type == "avatar") {
|
|
86
|
+
if (data[field]?.urlFile) {
|
|
87
|
+
data[field] = data[field].urlFile;
|
|
88
|
+
}
|
|
85
89
|
}
|
|
86
90
|
return data;
|
|
87
91
|
}, data);
|
|
@@ -20,6 +20,7 @@ import { useCallback, useEffect, } from "react";
|
|
|
20
20
|
import moment from "moment/moment";
|
|
21
21
|
import { DEFAULT_DATE_FORMAT } from "../../constants";
|
|
22
22
|
import UploadMultipleFile from "./upload/UploadMultipleFile";
|
|
23
|
+
import RhfUploadAvatar from "./upload/RhfUploadAvatar";
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
FormField.propTypes = {
|
|
@@ -276,6 +277,20 @@ function FormField({
|
|
|
276
277
|
}}
|
|
277
278
|
/>
|
|
278
279
|
);
|
|
280
|
+
case "avatar":
|
|
281
|
+
return (
|
|
282
|
+
<Controller
|
|
283
|
+
name={name}
|
|
284
|
+
control={control}
|
|
285
|
+
render={({ field, fieldState: { error } }) => {
|
|
286
|
+
return (
|
|
287
|
+
<>
|
|
288
|
+
<RhfUploadAvatar name={"AnhDaiDien"} />
|
|
289
|
+
</>
|
|
290
|
+
);
|
|
291
|
+
}}
|
|
292
|
+
/>
|
|
293
|
+
);
|
|
279
294
|
}
|
|
280
295
|
}
|
|
281
296
|
|
|
@@ -71,7 +71,7 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
|
|
|
71
71
|
{!disableCellThaoTac && <TableCell align="center">
|
|
72
72
|
{canEdit && (
|
|
73
73
|
<Tooltip title="Chỉnh sửa">
|
|
74
|
-
<IconButton onClick={() => onEdit(row)}>
|
|
74
|
+
<IconButton size={downXl ? "small" : "medium"} onClick={() => onEdit(row)}>
|
|
75
75
|
<EditOutlined color="primary" />
|
|
76
76
|
</IconButton>
|
|
77
77
|
</Tooltip>
|
|
@@ -79,7 +79,7 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
|
|
|
79
79
|
|
|
80
80
|
{canDelete && (
|
|
81
81
|
<Tooltip title="Xóa">
|
|
82
|
-
<IconButton
|
|
82
|
+
<IconButton size={downXl ? "small" : "medium"}
|
|
83
83
|
onClick={() => {
|
|
84
84
|
onDelete(row[selectedField]);
|
|
85
85
|
}}
|
|
@@ -90,7 +90,7 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
|
|
|
90
90
|
)}
|
|
91
91
|
{tableActionsOnTable.map(({ title, onClick, element }) => (
|
|
92
92
|
<Tooltip key={title} title={title}>
|
|
93
|
-
<IconButton
|
|
93
|
+
<IconButton size={downXl ? "small" : "medium"}
|
|
94
94
|
onClick={() => {
|
|
95
95
|
onClick(row);
|
|
96
96
|
}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Checkbox, IconButton, Tooltip, Typography, Box } from "@mui/material";
|
|
1
|
+
import { Checkbox, IconButton, Tooltip, Typography, Box, useMediaQuery } from "@mui/material";
|
|
2
2
|
import { Delete } from "@mui/icons-material";
|
|
3
3
|
import { usePermission } from "./hooks";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
@@ -10,6 +10,7 @@ const TableToolbar = ({ numSelected, onSelectAllClick, rowCount, onDeleteMultipl
|
|
|
10
10
|
const theme = useTheme();
|
|
11
11
|
const isLight = theme.palette.mode === "light";
|
|
12
12
|
const { canDeleteMulti } = usePermission();
|
|
13
|
+
const downXl = useMediaQuery(theme.breakpoints.down("xl"));
|
|
13
14
|
|
|
14
15
|
return (
|
|
15
16
|
numSelected > 0 && (
|
|
@@ -39,7 +40,7 @@ const TableToolbar = ({ numSelected, onSelectAllClick, rowCount, onDeleteMultipl
|
|
|
39
40
|
|
|
40
41
|
{canDeleteMulti && (
|
|
41
42
|
<Tooltip title="Xóa tất cả" onClick={onDeleteMultiple}>
|
|
42
|
-
<IconButton>
|
|
43
|
+
<IconButton size={downXl ? "small" : "medium"} >
|
|
43
44
|
<Delete color="primary" />
|
|
44
45
|
</IconButton>
|
|
45
46
|
</Tooltip>
|
|
@@ -59,6 +59,7 @@ function DataManagement({
|
|
|
59
59
|
onAddClick = () => {},
|
|
60
60
|
onEditClick = () => {},
|
|
61
61
|
tabPanel,
|
|
62
|
+
backParentNavigator,
|
|
62
63
|
slotProps = {
|
|
63
64
|
header: {
|
|
64
65
|
sx: {}
|
|
@@ -175,6 +176,7 @@ function DataManagement({
|
|
|
175
176
|
<Card>
|
|
176
177
|
{tabPanel}
|
|
177
178
|
<FilterGod filters={filters} elementSize={elementSize} />
|
|
179
|
+
{backParentNavigator}
|
|
178
180
|
<DataTable />
|
|
179
181
|
</Card>
|
|
180
182
|
</FormProvider>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { uploadFile } from "@/apis/index";
|
|
3
|
+
import UploadAvatar from './UploadAvatar'
|
|
4
|
+
import { FormHelperText, Typography } from "@mui/material/index";
|
|
5
|
+
import bytesToSize from "@/utils/bytesToSize";
|
|
6
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
7
|
+
|
|
8
|
+
const RhfUploadAvatar = ({ name }) => {
|
|
9
|
+
const { control, setValue } = useFormContext();
|
|
10
|
+
const handleDrop = useCallback(
|
|
11
|
+
async (acceptedFiles) => {
|
|
12
|
+
const file = acceptedFiles[0];
|
|
13
|
+
|
|
14
|
+
const formData = new FormData();
|
|
15
|
+
formData.append("file", file);
|
|
16
|
+
const data = await uploadFile(formData);
|
|
17
|
+
|
|
18
|
+
if (file) {
|
|
19
|
+
setValue(name, {
|
|
20
|
+
...file,
|
|
21
|
+
preview: URL.createObjectURL(file),
|
|
22
|
+
urlFile: JSON.parse(data[0])?.urlFile
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
[setValue, name]
|
|
27
|
+
);
|
|
28
|
+
return (
|
|
29
|
+
<Controller
|
|
30
|
+
control={control}
|
|
31
|
+
name={name}
|
|
32
|
+
render={({ field: { value }, fieldState: { error } }) => (
|
|
33
|
+
<>
|
|
34
|
+
<UploadAvatar
|
|
35
|
+
accept="image/*"
|
|
36
|
+
file={value}
|
|
37
|
+
maxSize={3145728}
|
|
38
|
+
onDrop={handleDrop}
|
|
39
|
+
error={Boolean(error)}
|
|
40
|
+
helperText={error?.message}
|
|
41
|
+
caption={
|
|
42
|
+
<Typography
|
|
43
|
+
variant="caption"
|
|
44
|
+
sx={{
|
|
45
|
+
mt: 2,
|
|
46
|
+
mx: "auto",
|
|
47
|
+
display: "block",
|
|
48
|
+
textAlign: "center",
|
|
49
|
+
color: "text.secondary"
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
cho phép *.jpeg, *.jpg, *.png, *.gif
|
|
53
|
+
<br /> max size of {bytesToSize(3145728)}
|
|
54
|
+
</Typography>
|
|
55
|
+
}
|
|
56
|
+
/>
|
|
57
|
+
<FormHelperText error sx={{ px: 2, textAlign: "center" }}>
|
|
58
|
+
{error?.message}
|
|
59
|
+
</FormHelperText>
|
|
60
|
+
</>
|
|
61
|
+
)}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
export default RhfUploadAvatar;
|