trithuc-mvc-react 3.0.5 → 3.0.7

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.
@@ -15,7 +15,6 @@ import { TableRowRender } from "./TableRowRender";
15
15
  import TableToolbar from "./TableToolbar";
16
16
  import { useDataTable } from "./hooks";
17
17
  const defaultQueryOptions = {
18
- keepPreviousData: true, // Giữ dữ liệu cũ trong khi tải dữ liệu mới
19
18
  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
19
  cacheTime: 1000 * 60 * 30, // Thời gian dữ liệu được lưu trong cache trước khi bị xóa
21
20
  refetchOnWindowFocus: true, // Tự động lấy lại dữ liệu khi người dùng quay lại tab
@@ -13,6 +13,7 @@ import { ClearIcon, DatePicker } from "@mui/x-date-pickers";
13
13
  import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
14
14
  import "dayjs/locale/vi";
15
15
  import { toast } from "react-toastify";
16
+ import { debounce } from "lodash";
16
17
  export const FilterGod = ({ tableName, filters, elementSize = "small", setPage = () => {} }) => {
17
18
  const { handleSubmit } = useFormContext();
18
19
  const onSubmit = (data) => console.log(data);
@@ -59,16 +60,17 @@ export const FilterGod = ({ tableName, filters, elementSize = "small", setPage =
59
60
  setPage(0); // Reset trang khi clear
60
61
  };
61
62
 
62
- const handleDateChange = (newValue, fieldKey, compareKey, compareType) => {
63
+ const handleDateChange = debounce((newValue, fieldKey, compareKey, compareType) => {
63
64
  let formattedDate = null;
64
65
 
65
- // Kiểm tra nếu newValue ngày hợp lệ
66
- if (!moment(newValue, "DD/MM/YYYY", true).isValid()) {
67
- return; // Dừng nếu người dùng nhập chưa xong hoặc giá trị không hợp lệ
68
- }
66
+ // Chỉ kiểm tra nếu chuỗi độ dài tối thiểu phù hợp với định dạng "DD/MM/YYYY"
67
+ const isValidDate = moment(newValue, "DD/MM/YYYY", true).isValid();
68
+
69
+ const year = moment(newValue, "DD/MM/YYYY").year();
69
70
 
70
- if (newValue) {
71
- // Xác định thời gian dựa trên fieldKey
71
+ if (isValidDate && year >= 1000) {
72
+ // Kiểm tra năm lớn hơn hoặc bằng 1000
73
+ // Định dạng ngày khi hợp lệ
72
74
  if (fieldKey.toLowerCase().includes("from")) {
73
75
  formattedDate = moment(newValue, "DD/MM/YYYY").startOf("day").format("YYYY-MM-DD HH:mm");
74
76
  } else if (fieldKey.toLowerCase().includes("to")) {
@@ -78,6 +80,7 @@ export const FilterGod = ({ tableName, filters, elementSize = "small", setPage =
78
80
 
79
81
  const compareDate = dataSearch?.[compareKey] ? moment(dataSearch?.[compareKey]) : null;
80
82
 
83
+ // Kiểm tra ngày so sánh
81
84
  if (formattedDate && compareDate) {
82
85
  const isInvalid =
83
86
  (compareType === "min" && moment(formattedDate).isBefore(compareDate)) ||
@@ -95,11 +98,17 @@ export const FilterGod = ({ tableName, filters, elementSize = "small", setPage =
95
98
  }
96
99
  }
97
100
 
101
+ // Lưu ngày hợp lệ
98
102
  setDataSearch((prev) => ({
99
103
  ...prev,
100
104
  [fieldKey]: formattedDate
101
105
  }));
102
106
  setPage(0); // Reset page
107
+ }, 500); // Debounce 1000ms
108
+
109
+ // Gọi handleDateChange
110
+ const onInputDateChange = (e) => {
111
+ handleDateChange(e.target.value, "from", "to", "min");
103
112
  };
104
113
 
105
114
  const renderDatePicker = (fieldKey, label, compareKey, compareType) => (
@@ -172,8 +181,8 @@ export const FilterGod = ({ tableName, filters, elementSize = "small", setPage =
172
181
  );
173
182
  }
174
183
  return (
175
- <Grid key={field} md={size?.md} xs={size?.xs} sm={size?.sm}>
176
- <FilterElement name={field} {...rest} setPage={setPage} />
184
+ <Grid key={field.toString()} md={size?.md} xs={size?.xs} sm={size?.sm}>
185
+ <FilterElement name={field.toString()} {...rest} setPage={setPage} />
177
186
  </Grid>
178
187
  );
179
188
  })}
@@ -27,7 +27,7 @@ DataManagement.propTypes = {
27
27
  filters: PropTypes.arrayOf(
28
28
  PropTypes.shape({
29
29
  field: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]).isRequired,
30
- label: PropTypes.string,
30
+ label: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]), // Hỗ trợ cả chuỗi và mảng chuỗi
31
31
  placeHolder: PropTypes.string,
32
32
  type: PropTypes.oneOf([
33
33
  "text",
@@ -46,6 +46,7 @@ DataManagement.propTypes = {
46
46
  onChangeAfter: PropTypes.func
47
47
  })
48
48
  ).isRequired,
49
+
49
50
  editorFields: PropTypes.array,
50
51
  validationSchema: PropTypes.object,
51
52
  disableStatus: PropTypes.bool,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -13,12 +13,12 @@
13
13
  },
14
14
  "description": "",
15
15
  "dependencies": {
16
- "@emotion/react": "^11.13.3",
17
- "@emotion/styled": "^11.13.0",
16
+ "@emotion/react": "^11.13.5",
17
+ "@emotion/styled": "^11.13.5",
18
18
  "@hookform/resolvers": "^3.9.1",
19
19
  "@iconify/react": "^5.0.2",
20
20
  "axios": "^1.7.7",
21
- "date-fns": "^2.17.0",
21
+ "date-fns": "^3.6.0",
22
22
  "lodash": "^4.17.21",
23
23
  "moment": "^2.30.1",
24
24
  "prop-types": "^15.8.1",
@@ -27,7 +27,7 @@
27
27
  "devDependencies": {
28
28
  "@types/react": "^18.3.12",
29
29
  "@types/react-dom": "^18.3.1",
30
- "eslint": "^9.14.0",
30
+ "eslint": "^9.15.0",
31
31
  "eslint-plugin-react": "^7.37.2",
32
32
  "eslint-plugin-react-hooks": "^5.0.0",
33
33
  "eslint-plugin-react-refresh": "^0.4.14",
@@ -35,15 +35,16 @@
35
35
  "react-dom": "^18.3.1"
36
36
  },
37
37
  "peerDependencies": {
38
- "@mui/icons-material": "^5.15.12",
39
38
  "@mui/lab": "^5.0.0-alpha.142",
40
39
  "@mui/material": "^5.15.12",
41
- "@mui/x-date-pickers": "^6.10.2",
40
+ "@mui/system": "^5.15.12",
41
+ "@mui/icons-material": "^5.15.12",
42
42
  "@mui/x-tree-view": "^7.22.1",
43
- "material-ui-confirm": "^3.0.9",
43
+ "@mui/x-date-pickers": "^6.19.6",
44
+ "material-ui-confirm": "^3.0.16",
44
45
  "react": ">=16",
45
46
  "react-dom": ">=16",
46
- "react-hook-form": "^7.45.2",
47
+ "react-hook-form": "^7.53.2",
47
48
  "react-query": "^3.39.3",
48
49
  "react-toastify": "^10.0.6",
49
50
  "dayjs": "^1.11.13"