trithuc-mvc-react 2.6.9 → 2.7.1
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.
|
@@ -13,8 +13,8 @@ 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
|
|
17
|
-
const DataTable = ({ multipleActions = [],page, setPage = () => {
|
|
16
|
+
import { URL_APPLICATION, URL_APPLICATION_API } from "@/constants";
|
|
17
|
+
const DataTable = ({ multipleActions = [], page, setPage = () => {}, disableEdit, disableDelete }) => {
|
|
18
18
|
const {
|
|
19
19
|
tableName,
|
|
20
20
|
selectedField,
|
|
@@ -46,7 +46,7 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
|
|
|
46
46
|
}),
|
|
47
47
|
// keepPreviousData: true,
|
|
48
48
|
onSuccess: ({ PermissionModel, status }) => {
|
|
49
|
-
if(dataSearch?.TrangThaiXuLy !== undefined){
|
|
49
|
+
if (dataSearch?.TrangThaiXuLy !== undefined) {
|
|
50
50
|
PermissionModel.TrangThaiXuLy = dataSearch?.TrangThaiXuLy;
|
|
51
51
|
}
|
|
52
52
|
if (status) {
|
|
@@ -59,21 +59,31 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
|
|
|
59
59
|
onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }) => {
|
|
60
60
|
if (URL_APPLICATION_API) {
|
|
61
61
|
toast.success(message);
|
|
62
|
-
}else{
|
|
62
|
+
} else {
|
|
63
63
|
toast.success("Thay đổi trạng thái thành công !");
|
|
64
64
|
}
|
|
65
65
|
queryClient.invalidateQueries({ queryKey: [tableName] });
|
|
66
66
|
},
|
|
67
|
-
onError: () => {
|
|
68
|
-
|
|
67
|
+
onError: (error) => {
|
|
68
|
+
if (error.response && error.response.data && error.response.data.errors) {
|
|
69
|
+
const errors = error.response.data.errors;
|
|
70
|
+
// Chuyển đổi đối tượng lỗi thành chuỗi để hiển thị
|
|
71
|
+
const errorMessages = Object.entries(errors)
|
|
72
|
+
.map(([field, messages]) => `${field}: ${messages.join(", ")}`)
|
|
73
|
+
.join("\n");
|
|
74
|
+
toast.error(errorMessages);
|
|
75
|
+
} else {
|
|
76
|
+
// Nếu lỗi không theo định dạng mong đợi, hiển thị thông tin lỗi chung
|
|
77
|
+
toast.error("Đã xảy ra lỗi không mong muốn.");
|
|
78
|
+
}
|
|
69
79
|
}
|
|
70
80
|
});
|
|
71
81
|
const deleteMutation = useMutation(deleteDataFromTable, {
|
|
72
82
|
onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }) => {
|
|
73
|
-
if (status) {
|
|
83
|
+
if (status) {
|
|
74
84
|
if (URL_APPLICATION_API) {
|
|
75
85
|
toast.success(message);
|
|
76
|
-
}else{
|
|
86
|
+
} else {
|
|
77
87
|
toast.success("Xóa thành công !");
|
|
78
88
|
}
|
|
79
89
|
} else {
|
|
@@ -82,27 +92,52 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
|
|
|
82
92
|
|
|
83
93
|
queryClient.invalidateQueries({ queryKey: [tableName] });
|
|
84
94
|
},
|
|
85
|
-
onError: () => {
|
|
86
|
-
|
|
95
|
+
onError: (error) => {
|
|
96
|
+
if (error.response && error.response.data && error.response.data.errors) {
|
|
97
|
+
const errors = error.response.data.errors;
|
|
98
|
+
// Chuyển đổi đối tượng lỗi thành chuỗi để hiển thị
|
|
99
|
+
const errorMessages = Object.entries(errors)
|
|
100
|
+
.map(([field, messages]) => `${field}: ${messages.join(", ")}`)
|
|
101
|
+
.join("\n");
|
|
102
|
+
toast.error(errorMessages);
|
|
103
|
+
} else {
|
|
104
|
+
// Nếu lỗi không theo định dạng mong đợi, hiển thị thông tin lỗi chung
|
|
105
|
+
toast.error("Đã xảy ra lỗi không mong muốn.");
|
|
106
|
+
}
|
|
87
107
|
}
|
|
88
108
|
});
|
|
89
109
|
const deleteMultipleMutation = useMutation(deleteMultipleDataFromTable, {
|
|
90
110
|
onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }) => {
|
|
91
111
|
if (URL_APPLICATION_API) {
|
|
92
112
|
toast.success(message);
|
|
93
|
-
}else{
|
|
113
|
+
} else {
|
|
94
114
|
toast.success("Xóa thành công !");
|
|
95
115
|
}
|
|
96
116
|
setSelectedItems([]);
|
|
97
117
|
queryClient.invalidateQueries({ queryKey: [tableName] });
|
|
98
118
|
},
|
|
99
|
-
onError: () => {
|
|
100
|
-
|
|
119
|
+
onError: (error) => {
|
|
120
|
+
if (error.response && error.response.data && error.response.data.errors) {
|
|
121
|
+
const errors = error.response.data.errors;
|
|
122
|
+
// Chuyển đổi đối tượng lỗi thành chuỗi để hiển thị
|
|
123
|
+
const errorMessages = Object.entries(errors)
|
|
124
|
+
.map(([field, messages]) => `${field}: ${messages.join(", ")}`)
|
|
125
|
+
.join("\n");
|
|
126
|
+
toast.error(errorMessages);
|
|
127
|
+
} else {
|
|
128
|
+
// Nếu lỗi không theo định dạng mong đợi, hiển thị thông tin lỗi chung
|
|
129
|
+
toast.error("Đã xảy ra lỗi không mong muốn.");
|
|
130
|
+
}
|
|
101
131
|
}
|
|
102
132
|
});
|
|
103
133
|
|
|
104
134
|
const handleDelete = (id) => {
|
|
105
|
-
confirm({
|
|
135
|
+
confirm({
|
|
136
|
+
description: "Bạn có chắc chắn muốn xóa bản ghi này không?",
|
|
137
|
+
title: "Xác nhận",
|
|
138
|
+
cancellationText: "Hủy",
|
|
139
|
+
confirmationText: "Xóa"
|
|
140
|
+
})
|
|
106
141
|
.then(() => {
|
|
107
142
|
deleteMutation.mutate({
|
|
108
143
|
id,
|
|
@@ -176,11 +211,19 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
|
|
|
176
211
|
};
|
|
177
212
|
|
|
178
213
|
const handleChangeRowsPerPage = (event) => {
|
|
179
|
-
|
|
214
|
+
const newRowsPerPage = parseInt(event.target.value, 10); // Chuyển đổi giá trị thành số nguyên
|
|
215
|
+
// Lưu giá trị mới vào localStorage với khóa tùy chỉnh theo tableName
|
|
216
|
+
localStorage.setItem(`${tableName}rowsPerPage`, newRowsPerPage);
|
|
217
|
+
setRowsPerPage(newRowsPerPage);
|
|
180
218
|
setPage(0);
|
|
181
219
|
};
|
|
182
220
|
const handleDeleteMultiple = () => {
|
|
183
|
-
confirm({
|
|
221
|
+
confirm({
|
|
222
|
+
description: `Bạn có chắc chắn muốn xóa ${selectedItems?.length} bản ghi này không?`,
|
|
223
|
+
title: "Xác nhận",
|
|
224
|
+
cancellationText: "Hủy",
|
|
225
|
+
confirmationText: "Đồng ý"
|
|
226
|
+
})
|
|
184
227
|
.then(() => {
|
|
185
228
|
deleteMultipleMutation.mutate({
|
|
186
229
|
tableName,
|
|
@@ -106,8 +106,18 @@ function EditorForm({ fields, submitRef }) {
|
|
|
106
106
|
toast.error(message);
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
|
-
onError: () => {
|
|
110
|
-
|
|
109
|
+
onError: (error) => {
|
|
110
|
+
if (error.response && error.response.data && error.response.data.errors) {
|
|
111
|
+
const errors = error.response.data.errors;
|
|
112
|
+
// Chuyển đổi đối tượng lỗi thành chuỗi để hiển thị
|
|
113
|
+
const errorMessages = Object.entries(errors)
|
|
114
|
+
.map(([field, messages]) => `${field}: ${messages.join(", ")}`)
|
|
115
|
+
.join("\n");
|
|
116
|
+
toast.error(errorMessages);
|
|
117
|
+
} else {
|
|
118
|
+
// Nếu lỗi không theo định dạng mong đợi, hiển thị thông tin lỗi chung
|
|
119
|
+
toast.error("Đã xảy ra lỗi không mong muốn.");
|
|
120
|
+
}
|
|
111
121
|
}
|
|
112
122
|
});
|
|
113
123
|
const onSubmit = (data) => {
|