trithuc-mvc-react 2.6.4 → 2.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/DataTable.jsx +21 -8
- package/components/DataManagement/EditorForm.jsx +24 -5
- package/components/DataManagement/FormField.jsx +15 -0
- package/components/DataManagement/index.jsx +18 -2
- package/components/DataManagement/upload/RhfUploadAvatar.jsx +3 -3
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ import { TableRowRender } from "./TableRowRender";
|
|
|
13
13
|
import TableToolbar from "./TableToolbar";
|
|
14
14
|
import { useDataTable } from "./hooks";
|
|
15
15
|
import { usePermission } from "../../hooks";
|
|
16
|
+
import { URL_APPLICATION ,URL_APPLICATION_API } from "@/constants";
|
|
16
17
|
const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit, disableDelete }) => {
|
|
17
18
|
const {
|
|
18
19
|
tableName,
|
|
@@ -46,14 +47,18 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
|
|
|
46
47
|
// keepPreviousData: true,
|
|
47
48
|
onSuccess: ({ PermissionModel, status }) => {
|
|
48
49
|
if (status) {
|
|
49
|
-
|
|
50
|
+
setPermission(PermissionModel);
|
|
50
51
|
// console.log("LOAD LAI PermissionModel");
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
});
|
|
54
55
|
const changeStatusMutation = useMutation(changeStatusDataToTable, {
|
|
55
|
-
onSuccess: () => {
|
|
56
|
-
|
|
56
|
+
onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }) => {
|
|
57
|
+
if (URL_APPLICATION_API) {
|
|
58
|
+
toast.success(message);
|
|
59
|
+
}else{
|
|
60
|
+
toast.success("Thay đổi trạng thái thành công !");
|
|
61
|
+
}
|
|
57
62
|
queryClient.invalidateQueries({ queryKey: [tableName] });
|
|
58
63
|
},
|
|
59
64
|
onError: () => {
|
|
@@ -61,9 +66,13 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
|
|
|
61
66
|
}
|
|
62
67
|
});
|
|
63
68
|
const deleteMutation = useMutation(deleteDataFromTable, {
|
|
64
|
-
onSuccess: ({ status }) => {
|
|
65
|
-
if (status) {
|
|
66
|
-
|
|
69
|
+
onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }) => {
|
|
70
|
+
if (status) {
|
|
71
|
+
if (URL_APPLICATION_API) {
|
|
72
|
+
toast.success(message);
|
|
73
|
+
}else{
|
|
74
|
+
toast.success("Xóa thành công !");
|
|
75
|
+
}
|
|
67
76
|
} else {
|
|
68
77
|
toast.error(" Có lỗi xảy ra !");
|
|
69
78
|
}
|
|
@@ -75,8 +84,12 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
|
|
|
75
84
|
}
|
|
76
85
|
});
|
|
77
86
|
const deleteMultipleMutation = useMutation(deleteMultipleDataFromTable, {
|
|
78
|
-
onSuccess: () => {
|
|
79
|
-
|
|
87
|
+
onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }) => {
|
|
88
|
+
if (URL_APPLICATION_API) {
|
|
89
|
+
toast.success(message);
|
|
90
|
+
}else{
|
|
91
|
+
toast.success("Xóa thành công !");
|
|
92
|
+
}
|
|
80
93
|
setSelectedItems([]);
|
|
81
94
|
queryClient.invalidateQueries({ queryKey: [tableName] });
|
|
82
95
|
},
|
|
@@ -11,6 +11,7 @@ import { saveDataToTable } from "../../api";
|
|
|
11
11
|
import { toast } from "react-toastify";
|
|
12
12
|
import { useDataTable } from "./hooks";
|
|
13
13
|
import FormField from "./FormField";
|
|
14
|
+
import { URL_APPLICATION ,URL_APPLICATION_API } from "@/constants";
|
|
14
15
|
import { yupResolver } from "@hookform/resolvers/yup";
|
|
15
16
|
EditorForm.propTypes = {
|
|
16
17
|
fields: PropTypes.array
|
|
@@ -61,7 +62,14 @@ function EditorForm({ fields, submitRef }) {
|
|
|
61
62
|
} catch (e) {
|
|
62
63
|
fileValue = [];
|
|
63
64
|
}
|
|
64
|
-
setValue(field, fileValue);
|
|
65
|
+
setValue(field, URL_APPLICATION + fileValue);
|
|
66
|
+
} else if (type === "imageavatar") {
|
|
67
|
+
try {
|
|
68
|
+
let fileValue = selectedEditItem[field];
|
|
69
|
+
setValue(field, URL_APPLICATION + fileValue);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.log(error);
|
|
72
|
+
}
|
|
65
73
|
} else {
|
|
66
74
|
setValue(field, selectedEditItem[field]);
|
|
67
75
|
}
|
|
@@ -84,13 +92,18 @@ function EditorForm({ fields, submitRef }) {
|
|
|
84
92
|
}, [selectedEditItem]);
|
|
85
93
|
|
|
86
94
|
const saveMutation = useMutation(saveDataToTable, {
|
|
87
|
-
onSuccess: ({ status = false }, { data: { Id } }) => {
|
|
95
|
+
onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }, { data: { Id } }) => {
|
|
88
96
|
if (status) {
|
|
89
|
-
|
|
97
|
+
if (URL_APPLICATION_API) {
|
|
98
|
+
toast.success(message);
|
|
99
|
+
}else{
|
|
100
|
+
toast.success(Id == 0 ? "Thêm thành công!" : "Cập nhật thành công!");
|
|
101
|
+
}
|
|
90
102
|
queryClient.invalidateQueries(tableName);
|
|
91
103
|
setOpenEditorDialog(false);
|
|
92
104
|
} else {
|
|
93
|
-
|
|
105
|
+
console.log(status, Id);
|
|
106
|
+
toast.error(message);
|
|
94
107
|
}
|
|
95
108
|
},
|
|
96
109
|
onError: () => {
|
|
@@ -115,10 +128,16 @@ function EditorForm({ fields, submitRef }) {
|
|
|
115
128
|
if (data[field]) {
|
|
116
129
|
data[field] = JSON.stringify(data[field]);
|
|
117
130
|
}
|
|
118
|
-
} else if (type
|
|
131
|
+
} else if (type === "avatar") {
|
|
119
132
|
if (data[field]?.urlFile) {
|
|
120
133
|
data[field] = data[field].urlFile;
|
|
121
134
|
}
|
|
135
|
+
} else if (type === "imageavatar") {
|
|
136
|
+
if (data[field]?.urlFile) {
|
|
137
|
+
data[field] = data[field]?.urlFile?.replaceAll(URL_APPLICATION, "");
|
|
138
|
+
} else if (data[field]) {
|
|
139
|
+
data[field] = data[field]?.replaceAll(URL_APPLICATION, "");
|
|
140
|
+
}
|
|
122
141
|
}
|
|
123
142
|
return data;
|
|
124
143
|
}, data);
|
|
@@ -372,6 +372,21 @@ function FormField({
|
|
|
372
372
|
}}
|
|
373
373
|
/>
|
|
374
374
|
);
|
|
375
|
+
case "imageavatar":
|
|
376
|
+
return (
|
|
377
|
+
<Controller
|
|
378
|
+
name={name}
|
|
379
|
+
control={control}
|
|
380
|
+
disabled={disabled}
|
|
381
|
+
render={({ field, fieldState: { error } }) => {
|
|
382
|
+
return (
|
|
383
|
+
<>
|
|
384
|
+
<RhfUploadAvatar name={name} disabled={disabled} />
|
|
385
|
+
</>
|
|
386
|
+
);
|
|
387
|
+
}}
|
|
388
|
+
/>
|
|
389
|
+
);
|
|
375
390
|
}
|
|
376
391
|
}
|
|
377
392
|
|
|
@@ -37,6 +37,7 @@ DataManagement.propTypes = {
|
|
|
37
37
|
disableStatus: PropTypes.bool,
|
|
38
38
|
disableAdd: PropTypes.bool,
|
|
39
39
|
disableCellThaoTac: PropTypes.bool,
|
|
40
|
+
reserPage: PropTypes.string,
|
|
40
41
|
statusKey: PropTypes.string,
|
|
41
42
|
tableActions: PropTypes.array,
|
|
42
43
|
disableEditor: PropTypes.bool,
|
|
@@ -52,6 +53,7 @@ const getDefaultValues = (filters = []) => {
|
|
|
52
53
|
return defaultValues;
|
|
53
54
|
};
|
|
54
55
|
function DataManagement({
|
|
56
|
+
reserPage = false,
|
|
55
57
|
sttLuyKe = false,
|
|
56
58
|
columns = [],
|
|
57
59
|
title,
|
|
@@ -87,7 +89,7 @@ function DataManagement({
|
|
|
87
89
|
const [selectedEditItem, setSelectedEditItem] = useState(null);
|
|
88
90
|
const [openViewDialog, setOpenViewDialog] = useState(false);
|
|
89
91
|
|
|
90
|
-
const { canCreate } = usePermission(apiUrl?apiUrl:tableName);
|
|
92
|
+
const { canCreate } = usePermission(apiUrl ? apiUrl : tableName);
|
|
91
93
|
const { defaults, filters } = useMemo(() => {
|
|
92
94
|
const filters = tableFilters.filter(({ type }) => type !== "default");
|
|
93
95
|
const defaultFilters = tableFilters.filter(({ type }) => type === "default");
|
|
@@ -113,9 +115,16 @@ function DataManagement({
|
|
|
113
115
|
const [dataSearch, setDataSearch] = useState({ ...defaults, ...getDefaultValues(filters) });
|
|
114
116
|
const [page, setPage] = useState(0);
|
|
115
117
|
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (reserPage) {
|
|
120
|
+
setPage(0);
|
|
121
|
+
}
|
|
122
|
+
}, [reserPage]);
|
|
123
|
+
|
|
116
124
|
const values = useMemo(() => {
|
|
117
125
|
const hasTabpanel = !!tabPanel;
|
|
118
126
|
return {
|
|
127
|
+
reserPage,
|
|
119
128
|
sttLuyKe,
|
|
120
129
|
apiUrl,
|
|
121
130
|
tableName,
|
|
@@ -140,6 +149,7 @@ function DataManagement({
|
|
|
140
149
|
defaultRowsPerPage
|
|
141
150
|
};
|
|
142
151
|
}, [
|
|
152
|
+
reserPage,
|
|
143
153
|
sttLuyKe,
|
|
144
154
|
apiUrl,
|
|
145
155
|
tableName,
|
|
@@ -215,7 +225,13 @@ function DataManagement({
|
|
|
215
225
|
{tabPanel}
|
|
216
226
|
<FilterGod filters={filters} elementSize={elementSize} setPage={setPage} />
|
|
217
227
|
{backParentNavigator}
|
|
218
|
-
<DataTable
|
|
228
|
+
<DataTable
|
|
229
|
+
multipleActions={multipleActions}
|
|
230
|
+
page={page}
|
|
231
|
+
setPage={setPage}
|
|
232
|
+
disableEdit={disableEdit}
|
|
233
|
+
disableDelete={disableDelete}
|
|
234
|
+
/>
|
|
219
235
|
</Card>
|
|
220
236
|
</FormProvider>
|
|
221
237
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import { uploadFile } from "@/apis/index";
|
|
3
|
-
import
|
|
3
|
+
import { URL_APPLICATION } from "@/constants";
|
|
4
|
+
import UploadAvatar from "./UploadAvatar";
|
|
4
5
|
import { FormHelperText, Typography } from "@mui/material/index";
|
|
5
6
|
import bytesToSize from "@/utils/bytesToSize";
|
|
6
7
|
import { Controller, useFormContext } from "react-hook-form";
|
|
@@ -14,7 +15,6 @@ const RhfUploadAvatar = ({ name, disabled }) => {
|
|
|
14
15
|
const formData = new FormData();
|
|
15
16
|
formData.append("file", file);
|
|
16
17
|
const data = await uploadFile(formData);
|
|
17
|
-
|
|
18
18
|
if (file) {
|
|
19
19
|
setValue(name, {
|
|
20
20
|
...file,
|
|
@@ -35,7 +35,7 @@ const RhfUploadAvatar = ({ name, disabled }) => {
|
|
|
35
35
|
accept="image/*"
|
|
36
36
|
file={value}
|
|
37
37
|
maxSize={31457280}
|
|
38
|
-
onDrop={!disabled ? handleDrop : () => {
|
|
38
|
+
onDrop={!disabled ? handleDrop : () => {}}
|
|
39
39
|
error={Boolean(error)}
|
|
40
40
|
helperText={error?.message}
|
|
41
41
|
caption={
|