trithuc-mvc-react 3.0.5 → 3.0.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.
@@ -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) => (
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.6",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"