trithuc-mvc-react 3.4.1 → 3.4.2

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.
@@ -16,6 +16,7 @@ import TableToolbar from "./TableToolbar";
16
16
  import { useDataTable } from "./hooks";
17
17
  import DeleteConfirmationDialog from "./DeleteConfirmationDialog";
18
18
  import DeleteMultipleConfirmationDialog from "./DeleteMultipleConfirmationDialog";
19
+ import { storeGetUser } from "../../utils/storage";
19
20
  const defaultQueryOptions = {
20
21
  staleTime: 1000 * 60 * 1, // Thời gian dữ liệu có thể sử dụng lại trước khi gọi lại API
21
22
  cacheTime: 1000 * 60 * 30, // Thời gian dữ liệu được lưu trong cache trước khi bị xóa
@@ -36,7 +37,8 @@ const DataTable = ({ multipleActions = [], page, setPage = () => {}, disableEdit
36
37
  hasTabpanel,
37
38
  defaultRowsPerPage = 5
38
39
  } = useDataTable();
39
-
40
+ const user = storeGetUser();
41
+ const userId = user?.UserId;
40
42
  const { set: setPermission } = usePermission(tableName);
41
43
  const queryClient = useQueryClient();
42
44
  const confirm = useConfirm();
@@ -81,11 +83,19 @@ const DataTable = ({ multipleActions = [], page, setPage = () => {}, disableEdit
81
83
  }),
82
84
  defaultQueryOptions,
83
85
  // keepPreviousData: true,
84
- onSuccess: ({ PermissionModel, status }) => {
86
+ onSuccess: ({ PermissionModel, CountTrangThai, status }) => {
85
87
  if (dataSearch?.TrangThaiXuLy !== undefined) {
86
88
  PermissionModel.TrangThaiXuLy = dataSearch?.TrangThaiXuLy;
87
89
  }
88
90
  setPermission(PermissionModel);
91
+
92
+ if (CountTrangThai) {
93
+ const keyCounter = `${tableName}_${userId}_TrangThaiXuLyCounter`;
94
+ localStorage.setItem(keyCounter, JSON.stringify(CountTrangThai));
95
+ // 👉 Invalidate query để Tab reload ngay
96
+ queryClient.invalidateQueries({ queryKey: [tableName, "CountAllTrangThaiXuly"] });
97
+ }
98
+
89
99
  if (status) {
90
100
  // console.log("LOAD LAI PermissionModel");
91
101
  // Cuộn lên đầu trang khi tải dữ liệu thành công
@@ -15,6 +15,7 @@ import TableToolbar from "./TableToolbar";
15
15
  import { useDataTable } from "./hooks";
16
16
  import DeleteConfirmationDialog from "./DeleteConfirmationDialog";
17
17
  import DeleteMultipleConfirmationDialog from "./DeleteMultipleConfirmationDialog";
18
+ import { storeGetUser } from "../../utils/storage";
18
19
  const defaultQueryOptions = {
19
20
  staleTime: 1000 * 60 * 1, // Thời gian dữ liệu có thể sử dụng lại trước khi gọi lại API
20
21
  cacheTime: 1000 * 60 * 30, // Thời gian dữ liệu được lưu trong cache trước khi bị xóa
@@ -35,7 +36,8 @@ const DataTableSM = ({ multipleActions = [], page, setPage = () => {}, disableEd
35
36
  hasTabpanel,
36
37
  defaultRowsPerPage = 5
37
38
  } = useDataTable();
38
-
39
+ const user = storeGetUser();
40
+ const userId = user?.UserId;
39
41
  const { set: setPermission } = usePermission(tableName);
40
42
  const queryClient = useQueryClient();
41
43
  const confirm = useConfirm();
@@ -80,11 +82,19 @@ const DataTableSM = ({ multipleActions = [], page, setPage = () => {}, disableEd
80
82
  }),
81
83
  defaultQueryOptions,
82
84
  // keepPreviousData: true,
83
- onSuccess: ({ PermissionModel, status }) => {
85
+ onSuccess: ({ PermissionModel, CountTrangThai, status }) => {
84
86
  if (dataSearch?.TrangThaiXuLy !== undefined) {
85
87
  PermissionModel.TrangThaiXuLy = dataSearch?.TrangThaiXuLy;
86
88
  }
87
89
  setPermission(PermissionModel);
90
+
91
+ if (CountTrangThai) {
92
+ const keyCounter = `${tableName}_${userId}_TrangThaiXuLyCounter`;
93
+ localStorage.setItem(keyCounter, JSON.stringify(CountTrangThai));
94
+ // 👉 Invalidate query để Tab reload ngay
95
+ queryClient.invalidateQueries({ queryKey: [tableName, "CountAllTrangThaiXuly"] });
96
+ }
97
+
88
98
  if (status) {
89
99
  // console.log("LOAD LAI PermissionModel");
90
100
  // Cuộn lên đầu trang khi tải dữ liệu thành công
@@ -120,7 +120,7 @@ function DataManagement({
120
120
  const [selectedEditItem, setSelectedEditItem] = useState(null);
121
121
  const [openViewDialog, setOpenViewDialog] = useState(false);
122
122
 
123
- const { permission, canCreate, canThongKe, canBieuDo } = usePermission(apiUrl || tableName);
123
+ const { permission, canCreate, canExportData, canThongKe, canBieuDo } = usePermission(apiUrl || tableName);
124
124
 
125
125
  // console.log(">>> permission from hook:", permission);
126
126
  // console.log(">>> canCreate:", canCreate);
@@ -389,7 +389,7 @@ function DataManagement({
389
389
  <div key={index}>{button}</div>
390
390
  ))}
391
391
 
392
- <ExportExcelButton tableName={tableName} data={dataSearch} size={elementSize} />
392
+ {canExportData && <ExportExcelButton tableName={tableName} data={dataSearch} size={elementSize} />}
393
393
 
394
394
  {canCreate && !disableAdd && (
395
395
  <Button
@@ -51,6 +51,7 @@ const usePermission = (tableName) => {
51
51
  canAction: false,
52
52
  canView: false,
53
53
  canImport: false,
54
+ canExportData: false,
54
55
  canExportWord: false,
55
56
  canPayment: false,
56
57
  canThongKe: false,
@@ -86,6 +87,7 @@ const usePermission = (tableName) => {
86
87
  canAction: source.Action ?? false,
87
88
  canView: source.View ?? false,
88
89
  canImport: source.ImportFile ?? false,
90
+ canExportData: source.ExportData ?? false,
89
91
  canExportWord: source.ExportWord ?? false,
90
92
  canPayment: source.Payment ?? false,
91
93
  canThongKe: source.ThongKe ?? false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "3.4.1",
3
+ "version": "3.4.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/storage.js CHANGED
@@ -289,3 +289,26 @@ export const storeGetlanguageSystemKey = (TypeKey, SystemKey, TypeLanguage) => {
289
289
  ?.Description || ""
290
290
  );
291
291
  };
292
+ // ---------------- Storage helpers ----------------
293
+ export const storeSetKey = (Key, data) => {
294
+ if (!data) return;
295
+ const encryptedData = encryptData(data);
296
+ localStorage.setItem(Key, encryptedData);
297
+ };
298
+
299
+ export const storeGetKey = (key) => {
300
+ const encryptedData = localStorage.getItem(key);
301
+ if (!encryptedData) return null;
302
+ return decryptData(encryptedData);
303
+ };
304
+
305
+ // ---------------- Utility so sánh dữ liệu ----------------
306
+ export const isDataChanged = (oldData, newData) => {
307
+ if (!oldData) return true;
308
+ try {
309
+ return JSON.stringify(oldData) !== JSON.stringify(newData);
310
+ } catch (error) {
311
+ console.error("Error comparing data:", error);
312
+ return true; // nếu có lỗi thì coi như thay đổi
313
+ }
314
+ };