trithuc-mvc-react 1.6.7 → 1.6.9
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/DataTable.jsx +10 -8
- package/components/DataManagement/EditorForm.jsx +3 -1
- package/components/DataManagement/FormField.jsx +1 -1
- package/components/DataManagement/TableRowRender.jsx +8 -8
- package/components/DataManagement/ViewDetailDialog.jsx +1 -1
- package/components/DataManagement/index.jsx +24 -28
- package/components/DataManagement/upload/RhfUploadAvatar.jsx +2 -2
- package/components/DataManagement/upload/UploadMultipleFile.jsx +6 -5
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ import TableToolbar from "./TableToolbar";
|
|
|
14
14
|
import { useDataTable, usePermission } from "./hooks";
|
|
15
15
|
|
|
16
16
|
const DataTable = () => {
|
|
17
|
-
const { tableName, selectedField, columns, dataSearch, setOpenEditorDialog, setSelectedEditItem,setOpenViewDialog } = useDataTable();
|
|
17
|
+
const { tableName, selectedField, columns, dataSearch, setOpenEditorDialog, setSelectedEditItem, setOpenViewDialog, onEditClick } = useDataTable();
|
|
18
18
|
const { setPermission, Permission } = usePermission();
|
|
19
19
|
const queryClient = useQueryClient();
|
|
20
20
|
const confirm = useConfirm();
|
|
@@ -80,7 +80,7 @@ const DataTable = () => {
|
|
|
80
80
|
tableName
|
|
81
81
|
});
|
|
82
82
|
})
|
|
83
|
-
.catch(() => {});
|
|
83
|
+
.catch(() => { });
|
|
84
84
|
};
|
|
85
85
|
const handleChangeStatus = (Id) => {
|
|
86
86
|
changeStatusMutation.mutate({
|
|
@@ -91,6 +91,8 @@ const DataTable = () => {
|
|
|
91
91
|
const handlEdit = (item) => {
|
|
92
92
|
setOpenEditorDialog(true);
|
|
93
93
|
setSelectedEditItem(item);
|
|
94
|
+
onEditClick(item);
|
|
95
|
+
|
|
94
96
|
};
|
|
95
97
|
const handlViewDetail = (item) => {
|
|
96
98
|
setOpenViewDialog(true);
|
|
@@ -99,17 +101,17 @@ const DataTable = () => {
|
|
|
99
101
|
const { rows, total } = useMemo(() => {
|
|
100
102
|
let rows = data?.data ?? [];
|
|
101
103
|
let total = data?.total ?? 0;
|
|
102
|
-
|
|
104
|
+
|
|
103
105
|
return {
|
|
104
106
|
rows: rows,
|
|
105
107
|
total
|
|
106
108
|
};
|
|
107
109
|
}, [data]);
|
|
108
110
|
|
|
109
|
-
useEffect(()=>{
|
|
111
|
+
useEffect(() => {
|
|
110
112
|
let PermissionModel = data?.PermissionModel;
|
|
111
|
-
PermissionModel&&setPermission(PermissionModel);
|
|
112
|
-
},[rows])
|
|
113
|
+
PermissionModel && setPermission(PermissionModel);
|
|
114
|
+
}, [rows])
|
|
113
115
|
|
|
114
116
|
const handleChangePage = (event, newPage) => {
|
|
115
117
|
setPage(newPage);
|
|
@@ -151,7 +153,7 @@ const DataTable = () => {
|
|
|
151
153
|
ids: selected
|
|
152
154
|
});
|
|
153
155
|
})
|
|
154
|
-
.catch(() => {});
|
|
156
|
+
.catch(() => { });
|
|
155
157
|
};
|
|
156
158
|
const theme = useTheme();
|
|
157
159
|
const downXL = useMediaQuery(theme.breakpoints.down("xl"));
|
|
@@ -184,7 +186,7 @@ const DataTable = () => {
|
|
|
184
186
|
selected={isSelected(row[selectedField])}
|
|
185
187
|
onSelect={handleSelect}
|
|
186
188
|
onEdit={handlEdit}
|
|
187
|
-
|
|
189
|
+
onView={handlViewDetail}
|
|
188
190
|
onChangeStatus={handleChangeStatus}
|
|
189
191
|
onDelete={handleDelete}
|
|
190
192
|
/>
|
|
@@ -115,7 +115,8 @@ function EditorForm({ fields, submitRef }) {
|
|
|
115
115
|
keyLabel,
|
|
116
116
|
keyValue,
|
|
117
117
|
keyValueLabel,
|
|
118
|
-
required
|
|
118
|
+
required,
|
|
119
|
+
disabled=false
|
|
119
120
|
}) => {
|
|
120
121
|
return (
|
|
121
122
|
<Grid item md={size?.md} xs={size?.xs} sm={size?.sm} key={field}>
|
|
@@ -133,6 +134,7 @@ function EditorForm({ fields, submitRef }) {
|
|
|
133
134
|
keyValue={keyValue}
|
|
134
135
|
size={elementSize}
|
|
135
136
|
required={required}
|
|
137
|
+
disabled={disabled}
|
|
136
138
|
/>
|
|
137
139
|
</Grid>
|
|
138
140
|
);
|
|
@@ -9,8 +9,8 @@ import { styled, useTheme } from "@mui/material/styles";
|
|
|
9
9
|
import MoreMenu from "../MoreMenu";
|
|
10
10
|
import { useMemo } from "react";
|
|
11
11
|
|
|
12
|
-
export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus, onDelete, onEdit }) => {
|
|
13
|
-
const { selectedField, columns, statusKey, disableStatus, tableActions,disableCellThaoTac } = useDataTable();
|
|
12
|
+
export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus, onDelete, onEdit, onView }) => {
|
|
13
|
+
const { selectedField, columns, statusKey, disableStatus, tableActions, disableCellThaoTac } = useDataTable();
|
|
14
14
|
const { canEdit, canDelete, canView, canAction } = usePermission();
|
|
15
15
|
|
|
16
16
|
const { tableActionsOnTable, tableActionsOnMoreMenu } = useMemo(() => {
|
|
@@ -27,8 +27,8 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
|
|
|
27
27
|
const tableActionsOnMoreMenu = tableActionsAfterFilter.filter(({ isOnTable = false }) => !isOnTable);
|
|
28
28
|
return { tableActionsOnTable, tableActionsOnMoreMenu };
|
|
29
29
|
}, [canView, canAction, tableActions]);
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
const downXl = useMediaQuery(theme.breakpoints.down("xl"));
|
|
32
32
|
return (
|
|
33
33
|
<TableRow hover key={row[selectedField]} selected={selected}>
|
|
34
34
|
<TableCell padding="checkbox">
|
|
@@ -77,13 +77,13 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
|
|
|
77
77
|
</IconButton>
|
|
78
78
|
</Tooltip>
|
|
79
79
|
)}
|
|
80
|
-
|
|
81
|
-
<Tooltip title="Xem chi tiết">
|
|
82
|
-
<IconButton onClick={() =>
|
|
80
|
+
{canView && !tableActions?.some(({ permissionType }) => permissionType == "view") && (
|
|
81
|
+
<Tooltip title="Xem chi tiết modal">
|
|
82
|
+
<IconButton onClick={() => onView(row)}>
|
|
83
83
|
<RemoveRedEyeOutlinedIcon color="info" />
|
|
84
84
|
</IconButton>
|
|
85
85
|
</Tooltip>
|
|
86
|
-
)}
|
|
86
|
+
)}
|
|
87
87
|
{canDelete && (
|
|
88
88
|
<Tooltip title="Xóa">
|
|
89
89
|
<IconButton size={downXl ? "small" : "medium"}
|
|
@@ -74,7 +74,7 @@ function ViewDetailDialog({ open, onClose = () => { }, fields = [] }) {
|
|
|
74
74
|
return (
|
|
75
75
|
<Dialog open={open} onClose={onClose} maxWidth="md" fullWidth={true} scroll={'body'}>
|
|
76
76
|
<DialogTitle>
|
|
77
|
-
Xem
|
|
77
|
+
Xem chi tiết
|
|
78
78
|
<IconButton
|
|
79
79
|
aria-label="close"
|
|
80
80
|
onClick={onClose}
|
|
@@ -13,7 +13,7 @@ import ViewDetailDialog from "./ViewDetailDialog";
|
|
|
13
13
|
|
|
14
14
|
import ExportExcelButton from "./ExportExcelButton";
|
|
15
15
|
import { FilterGod } from "./FilterGod";
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
|
|
18
18
|
DataManagement.propTypes = {
|
|
19
19
|
columns: PropTypes.array,
|
|
@@ -57,8 +57,8 @@ function DataManagement({
|
|
|
57
57
|
disableCellThaoTac = false,
|
|
58
58
|
tableActions = [],
|
|
59
59
|
disableEditor = false,
|
|
60
|
-
onAddClick = () => {},
|
|
61
|
-
onEditClick = () => {},
|
|
60
|
+
onAddClick = () => { },
|
|
61
|
+
onEditClick = () => { },
|
|
62
62
|
tabPanel,
|
|
63
63
|
backParentNavigator,
|
|
64
64
|
slotProps = {
|
|
@@ -91,11 +91,7 @@ function DataManagement({
|
|
|
91
91
|
return elementSize;
|
|
92
92
|
}, [upXL]);
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
if (selectedEditItem && disableEditor) {
|
|
96
|
-
onEditClick(selectedEditItem);
|
|
97
|
-
}
|
|
98
|
-
}, [selectedEditItem]);
|
|
94
|
+
|
|
99
95
|
useEffect(() => {
|
|
100
96
|
setDataSearch({ ...dataSearch, ...defaults });
|
|
101
97
|
}, [filters]);
|
|
@@ -109,6 +105,7 @@ function DataManagement({
|
|
|
109
105
|
selectedEditItem,
|
|
110
106
|
setSelectedEditItem,
|
|
111
107
|
setOpenEditorDialog,
|
|
108
|
+
setOpenViewDialog,
|
|
112
109
|
dataSearch,
|
|
113
110
|
setDataSearch,
|
|
114
111
|
validationSchema,
|
|
@@ -117,10 +114,9 @@ function DataManagement({
|
|
|
117
114
|
disableCellThaoTac,
|
|
118
115
|
disableAdd,
|
|
119
116
|
tableActions,
|
|
120
|
-
|
|
121
|
-
setOpenViewDialog
|
|
117
|
+
onEditClick
|
|
122
118
|
};
|
|
123
|
-
}, [tableName, selectedField, columns, selectedEditItem, dataSearch, setDataSearch, validationSchema, tableActions, openViewDialog, setOpenViewDialog]);
|
|
119
|
+
}, [tableName, selectedField, columns, selectedEditItem, dataSearch, setDataSearch, validationSchema, tableActions, openViewDialog, setOpenViewDialog, onEditClick]);
|
|
124
120
|
const permissionValues = useMemo(() => {
|
|
125
121
|
return {
|
|
126
122
|
Permission,
|
|
@@ -157,22 +153,22 @@ function DataManagement({
|
|
|
157
153
|
|
|
158
154
|
<ExportExcelButton tableName={tableName} data={dataSearch} size={elementSize} />
|
|
159
155
|
{(!Permission || Permission.Create) && (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
156
|
+
(!disableAdd) && (
|
|
157
|
+
<Button
|
|
158
|
+
size={elementSize}
|
|
159
|
+
variant="contained"
|
|
160
|
+
startIcon={<Add fontSize="inherit" />}
|
|
161
|
+
onClick={(e) => {
|
|
162
|
+
if (!disableEditor) {
|
|
163
|
+
setOpenEditorDialog(true);
|
|
164
|
+
setSelectedEditItem(null);
|
|
165
|
+
}
|
|
166
|
+
onAddClick(e);
|
|
167
|
+
}}
|
|
168
|
+
>
|
|
169
|
+
Thêm
|
|
170
|
+
</Button>
|
|
171
|
+
)
|
|
176
172
|
)}
|
|
177
173
|
</Stack>
|
|
178
174
|
</Stack>
|
|
@@ -192,7 +188,7 @@ function DataManagement({
|
|
|
192
188
|
fields={editorFields}
|
|
193
189
|
/>
|
|
194
190
|
)}
|
|
195
|
-
|
|
191
|
+
<ViewDetailDialog open={openViewDialog} onClose={() => setOpenViewDialog(false)} fields={editorFields} />
|
|
196
192
|
</PermissionContext.Provider>
|
|
197
193
|
</DataTableContext.Provider>
|
|
198
194
|
</>
|
|
@@ -5,7 +5,7 @@ import { FormHelperText, Typography } from "@mui/material/index";
|
|
|
5
5
|
import bytesToSize from "@/utils/bytesToSize";
|
|
6
6
|
import { Controller, useFormContext } from "react-hook-form";
|
|
7
7
|
|
|
8
|
-
const RhfUploadAvatar = ({ name }) => {
|
|
8
|
+
const RhfUploadAvatar = ({ name, disabled }) => {
|
|
9
9
|
const { control, setValue } = useFormContext();
|
|
10
10
|
const handleDrop = useCallback(
|
|
11
11
|
async (acceptedFiles) => {
|
|
@@ -35,7 +35,7 @@ const RhfUploadAvatar = ({ name }) => {
|
|
|
35
35
|
accept="image/*"
|
|
36
36
|
file={value}
|
|
37
37
|
maxSize={3145728}
|
|
38
|
-
onDrop={handleDrop}
|
|
38
|
+
onDrop={!disabled ? handleDrop : () => { }}
|
|
39
39
|
error={Boolean(error)}
|
|
40
40
|
helperText={error?.message}
|
|
41
41
|
caption={
|
|
@@ -5,7 +5,7 @@ import UploadMultiFile from "trithuc-mvc-react/components/DataManagement/upload/
|
|
|
5
5
|
import { useCallback, useState } from "react";
|
|
6
6
|
import { saveFilesToServer } from "@/utils";
|
|
7
7
|
|
|
8
|
-
const UploadMultipleFile = ({ name, label }) => {
|
|
8
|
+
const UploadMultipleFile = ({ name, label, disabled }) => {
|
|
9
9
|
const { control, getValues, setValue } = useFormContext();
|
|
10
10
|
const [isLoadingUpfile, setIsLoadingUpfile] = useState(false);
|
|
11
11
|
|
|
@@ -37,12 +37,13 @@ const UploadMultipleFile = ({ name, label }) => {
|
|
|
37
37
|
<>
|
|
38
38
|
|
|
39
39
|
<UploadMultiFile
|
|
40
|
+
disabled={disabled}
|
|
40
41
|
maxSize={3145728}
|
|
41
42
|
accept="*"
|
|
42
43
|
files={field.value}
|
|
43
|
-
onDrop={handleDrop}
|
|
44
|
-
onRemove={handleRemove}
|
|
45
|
-
onRemoveAll={handleRemoveAll}
|
|
44
|
+
onDrop={!disabled ? handleDrop : () => { }} // disabled lúc ở model view thì ko được chọn ảnh
|
|
45
|
+
onRemove={!disabled ?handleRemove : () => { }}
|
|
46
|
+
onRemoveAll={!disabled? handleRemoveAll: () => { }}
|
|
46
47
|
error={Boolean(error)}
|
|
47
48
|
/>
|
|
48
49
|
{isLoadingUpfile && <LinearProgress />}
|
|
@@ -57,4 +58,4 @@ const UploadMultipleFile = ({ name, label }) => {
|
|
|
57
58
|
/>
|
|
58
59
|
);
|
|
59
60
|
};
|
|
60
|
-
export default UploadMultipleFile
|
|
61
|
+
export default UploadMultipleFile;
|