trithuc-mvc-react 1.8.10 → 1.9.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.
|
@@ -134,7 +134,8 @@ function EditorForm({ fields, submitRef }) {
|
|
|
134
134
|
keyValue,
|
|
135
135
|
keyValueLabel,
|
|
136
136
|
required,
|
|
137
|
-
disabled = false
|
|
137
|
+
disabled = false,
|
|
138
|
+
...rest
|
|
138
139
|
}) => {
|
|
139
140
|
return (
|
|
140
141
|
<Grid item md={size?.md} xs={size?.xs} sm={size?.sm} key={field}>
|
|
@@ -153,6 +154,7 @@ function EditorForm({ fields, submitRef }) {
|
|
|
153
154
|
size={elementSize}
|
|
154
155
|
required={required}
|
|
155
156
|
disabled={disabled}
|
|
157
|
+
{...rest}
|
|
156
158
|
/>
|
|
157
159
|
</Grid>
|
|
158
160
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Autocomplete, FormControl, InputAdornment, InputLabel, MenuItem, OutlinedInput, Select, TextField } from "@mui/material";
|
|
2
|
-
import { useCallback } from "react";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
3
|
import { SearchOutlined } from "@mui/icons-material";
|
|
4
4
|
import { useController, useFormContext } from "react-hook-form";
|
|
5
5
|
import { debounce } from "lodash";
|
|
@@ -55,31 +55,38 @@ export function FilterElement({
|
|
|
55
55
|
/>
|
|
56
56
|
);
|
|
57
57
|
|
|
58
|
-
case "autocomplete":
|
|
58
|
+
case "autocomplete": {
|
|
59
|
+
//Bùa bởi vì không hiện giá trị đầu tiên
|
|
60
|
+
let autocompleteValue = datas?.find((item) => item[keyValue] == dataSearch[name]);
|
|
61
|
+
autocompleteValue = autocompleteValue ? { ...autocompleteValue } : { [keyLabel]: "" };
|
|
59
62
|
return (
|
|
60
63
|
<Autocomplete
|
|
61
|
-
{
|
|
64
|
+
key={name}
|
|
65
|
+
name={name}
|
|
62
66
|
disablePortal
|
|
63
67
|
loading={loading}
|
|
64
68
|
noOptionsText="Không có dữ liệu"
|
|
65
69
|
fullWidth
|
|
66
70
|
options={datas ?? []}
|
|
67
|
-
onChange={(event, newValue) => {
|
|
71
|
+
onChange={(event, newValue, reason) => {
|
|
68
72
|
let updateObject = { [name]: newValue?.[keyValue] };
|
|
69
73
|
onFieldChange(newValue?.[keyValue]);
|
|
74
|
+
|
|
70
75
|
onChange(newValue);
|
|
76
|
+
|
|
71
77
|
childrenFields?.forEach((childrenField) => {
|
|
72
78
|
setValue(childrenField, null, { shouldTouch: true });
|
|
73
79
|
updateObject[childrenField] = null;
|
|
74
80
|
});
|
|
81
|
+
|
|
75
82
|
setDataSearch({ ...dataSearch, ...updateObject });
|
|
76
83
|
}}
|
|
77
|
-
value={
|
|
84
|
+
value={autocompleteValue}
|
|
78
85
|
getOptionLabel={(option) => option?.[keyLabel]}
|
|
79
86
|
renderInput={(params) => <TextField {...params} label={label} />}
|
|
80
87
|
/>
|
|
81
88
|
);
|
|
82
|
-
|
|
89
|
+
}
|
|
83
90
|
case "select":
|
|
84
91
|
return (
|
|
85
92
|
<FormControl sx={{ minWidth: 160 }} size="small" fullWidth>
|
|
@@ -16,13 +16,12 @@ import { Controller, useFormContext } from "react-hook-form";
|
|
|
16
16
|
// Grid version 2
|
|
17
17
|
import PropTypes from "prop-types";
|
|
18
18
|
import { DatePicker } from "@mui/x-date-pickers";
|
|
19
|
-
import { useCallback, useEffect
|
|
19
|
+
import { useCallback, useEffect } from "react";
|
|
20
20
|
import moment from "moment/moment";
|
|
21
21
|
import { DEFAULT_DATE_FORMAT } from "../../constants";
|
|
22
22
|
import UploadMultipleFile from "./upload/UploadMultipleFile";
|
|
23
23
|
import RhfUploadAvatar from "./upload/RhfUploadAvatar";
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
FormField.propTypes = {
|
|
27
26
|
datas: PropTypes.array,
|
|
28
27
|
loading: PropTypes.bool
|
|
@@ -38,10 +37,11 @@ function FormField({
|
|
|
38
37
|
keyLabel,
|
|
39
38
|
keyValue,
|
|
40
39
|
keyValueLabel,
|
|
41
|
-
|
|
40
|
+
|
|
42
41
|
size,
|
|
43
42
|
required = false,
|
|
44
|
-
disabled = false
|
|
43
|
+
disabled = false,
|
|
44
|
+
...rest
|
|
45
45
|
}) {
|
|
46
46
|
const { setValue, register } = useFormContext();
|
|
47
47
|
const getValueObject = useCallback(
|
|
@@ -60,7 +60,6 @@ function FormField({
|
|
|
60
60
|
}
|
|
61
61
|
}, []);
|
|
62
62
|
|
|
63
|
-
|
|
64
63
|
switch (type) {
|
|
65
64
|
case "textarea":
|
|
66
65
|
return (
|
|
@@ -134,7 +133,10 @@ function FormField({
|
|
|
134
133
|
value={getValueObject(value)}
|
|
135
134
|
fullWidth
|
|
136
135
|
getOptionLabel={(option) => option[keyLabel]}
|
|
137
|
-
renderInput={(params) =>
|
|
136
|
+
renderInput={(params) => (
|
|
137
|
+
<TextField {...params} label={label} error={Boolean(error)} helperText={error?.message} />
|
|
138
|
+
)}
|
|
139
|
+
{...rest}
|
|
138
140
|
/>
|
|
139
141
|
);
|
|
140
142
|
}}
|
|
@@ -187,7 +189,9 @@ function FormField({
|
|
|
187
189
|
<Controller
|
|
188
190
|
name={name}
|
|
189
191
|
control={control}
|
|
190
|
-
render={({ field }) =>
|
|
192
|
+
render={({ field }) => (
|
|
193
|
+
<FormControlLabel disabled={disabled} control={<Checkbox {...field} checked={field.value} />} label={label} />
|
|
194
|
+
)}
|
|
191
195
|
/>
|
|
192
196
|
|
|
193
197
|
{/* {errors.terms && (
|
|
@@ -271,9 +275,7 @@ function FormField({
|
|
|
271
275
|
/>
|
|
272
276
|
);
|
|
273
277
|
case "file":
|
|
274
|
-
return
|
|
275
|
-
<UploadMultipleFile name={name} label={label} disabled={disabled} />
|
|
276
|
-
);
|
|
278
|
+
return <UploadMultipleFile name={name} label={label} disabled={disabled} />;
|
|
277
279
|
case "avatar":
|
|
278
280
|
return (
|
|
279
281
|
<Controller
|
|
@@ -44,8 +44,8 @@ DataManagement.propTypes = {
|
|
|
44
44
|
};
|
|
45
45
|
const getDefaultValues = (filters = []) => {
|
|
46
46
|
const defaultValues = {};
|
|
47
|
-
filters.forEach((
|
|
48
|
-
defaultValues[
|
|
47
|
+
filters.forEach(({ defaultValue, field }) => {
|
|
48
|
+
defaultValues[field] = defaultValue;
|
|
49
49
|
});
|
|
50
50
|
return defaultValues;
|
|
51
51
|
};
|
|
@@ -141,7 +141,7 @@ function DataManagement({
|
|
|
141
141
|
|
|
142
142
|
const methods = useForm({ defaultValues: getDefaultValues(filters) });
|
|
143
143
|
const { reset, setValue } = methods;
|
|
144
|
-
|
|
144
|
+
|
|
145
145
|
return (
|
|
146
146
|
<>
|
|
147
147
|
<DataTableContext.Provider value={values}>
|