trithuc-mvc-react 1.6.3 → 1.6.5
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/TableHead.jsx +2 -2
- package/components/DataManagement/TableRowRender.jsx +3 -3
- package/components/DataManagement/index.jsx +3 -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
|
|
|
@@ -2,7 +2,7 @@ import { Checkbox, TableRow, TableCell, TableHead as MuiTableHead, useTheme, use
|
|
|
2
2
|
import { useDataTable, usePermission } from "./hooks";
|
|
3
3
|
export function TableHead({ numSelected, rowCount, onSelectAllClick, headLabel }) {
|
|
4
4
|
const { canEdit } = usePermission();
|
|
5
|
-
const { disableStatus } = useDataTable();
|
|
5
|
+
const { disableStatus,disableCellThaoTac } = useDataTable();
|
|
6
6
|
const theme = useTheme();
|
|
7
7
|
const downXl = useMediaQuery(theme.breakpoints.down("xl"));
|
|
8
8
|
return (
|
|
@@ -23,7 +23,7 @@ export function TableHead({ numSelected, rowCount, onSelectAllClick, headLabel }
|
|
|
23
23
|
</TableCell>
|
|
24
24
|
))}
|
|
25
25
|
{!disableStatus && canEdit && <TableCell sx={{ textAlign: "center" }}>Kích hoạt</TableCell>}
|
|
26
|
-
<TableCell sx={{ minWidth: "136px", textAlign: "center" }}>Thao tác</TableCell>
|
|
26
|
+
{!disableCellThaoTac && <TableCell sx={{ minWidth: "136px", textAlign: "center" }}>Thao tác</TableCell>}
|
|
27
27
|
</TableRow>
|
|
28
28
|
</MuiTableHead>
|
|
29
29
|
);
|
|
@@ -9,7 +9,7 @@ import MoreMenu from "../MoreMenu";
|
|
|
9
9
|
import { useMemo } from "react";
|
|
10
10
|
|
|
11
11
|
export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus, onDelete, onEdit }) => {
|
|
12
|
-
const { selectedField, columns, statusKey, disableStatus, tableActions } = useDataTable();
|
|
12
|
+
const { selectedField, columns, statusKey, disableStatus, tableActions,disableCellThaoTac } = useDataTable();
|
|
13
13
|
const { canEdit, canDelete, canView, canAction } = usePermission();
|
|
14
14
|
|
|
15
15
|
const { tableActionsOnTable, tableActionsOnMoreMenu } = useMemo(() => {
|
|
@@ -68,7 +68,7 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
|
|
|
68
68
|
</TableCell>
|
|
69
69
|
)}
|
|
70
70
|
|
|
71
|
-
<TableCell align="center">
|
|
71
|
+
{!disableCellThaoTac && <TableCell align="center">
|
|
72
72
|
{canEdit && (
|
|
73
73
|
<Tooltip title="Chỉnh sửa">
|
|
74
74
|
<IconButton onClick={() => onEdit(row)}>
|
|
@@ -101,7 +101,7 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
|
|
|
101
101
|
))}
|
|
102
102
|
|
|
103
103
|
{<MoreMenu actions={tableActionsOnMoreMenu} data={row} />}
|
|
104
|
-
</TableCell>
|
|
104
|
+
</TableCell>}
|
|
105
105
|
</TableRow>
|
|
106
106
|
);
|
|
107
107
|
};
|
|
@@ -33,6 +33,7 @@ DataManagement.propTypes = {
|
|
|
33
33
|
validationSchema: PropTypes.object,
|
|
34
34
|
disableStatus: PropTypes.bool,
|
|
35
35
|
disableAdd: PropTypes.bool,
|
|
36
|
+
disableCellThaoTac: PropTypes.bool,
|
|
36
37
|
statusKey: PropTypes.string,
|
|
37
38
|
tableActions: PropTypes.array,
|
|
38
39
|
disableEditor: PropTypes.bool,
|
|
@@ -52,6 +53,7 @@ function DataManagement({
|
|
|
52
53
|
statusKey = "Status",
|
|
53
54
|
disableStatus = false,
|
|
54
55
|
disableAdd = false,
|
|
56
|
+
disableCellThaoTac = false,
|
|
55
57
|
tableActions = [],
|
|
56
58
|
disableEditor = false,
|
|
57
59
|
onAddClick = () => {},
|
|
@@ -109,6 +111,7 @@ function DataManagement({
|
|
|
109
111
|
validationSchema,
|
|
110
112
|
statusKey,
|
|
111
113
|
disableStatus,
|
|
114
|
+
disableCellThaoTac,
|
|
112
115
|
disableAdd,
|
|
113
116
|
tableActions
|
|
114
117
|
};
|
|
@@ -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;
|