trithuc-mvc-react 1.0.0 → 1.0.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.
|
@@ -4,13 +4,18 @@ import { useMemo, useState } from "react";
|
|
|
4
4
|
|
|
5
5
|
import { TableHead } from "./TableHead";
|
|
6
6
|
import { useMutation, useQuery, useQueryClient } from "react-query";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
changeStatusDataToTable,
|
|
9
|
+
deleteDataFromTable,
|
|
10
|
+
deleteMultipleDataFromTable,
|
|
11
|
+
getDatasFromTable,
|
|
12
|
+
} from "../../api";
|
|
8
13
|
import TableRowsLoader from "../table/TableRowsLoader";
|
|
9
14
|
import { toast } from "react-toastify";
|
|
10
15
|
import { useConfirm } from "material-ui-confirm";
|
|
11
16
|
|
|
12
17
|
import { TableRowRender } from "./TableRowRender";
|
|
13
|
-
import
|
|
18
|
+
import TableToolbar from "./TableToolbar";
|
|
14
19
|
import { useDataTable, usePermission } from "./hooks";
|
|
15
20
|
|
|
16
21
|
const DataTable = () => {
|
|
@@ -28,14 +33,14 @@ const DataTable = () => {
|
|
|
28
33
|
tableName: tableName,
|
|
29
34
|
page: page + 1,
|
|
30
35
|
pageSize: rowsPerPage,
|
|
31
|
-
data: dataSearch
|
|
36
|
+
data: dataSearch,
|
|
32
37
|
}),
|
|
33
38
|
keepPreviousData: true,
|
|
34
39
|
onSuccess: ({ PermissionModel, status }) => {
|
|
35
40
|
if (!Permission && status) {
|
|
36
41
|
setPermission(PermissionModel);
|
|
37
42
|
}
|
|
38
|
-
}
|
|
43
|
+
},
|
|
39
44
|
});
|
|
40
45
|
const changeStatusMutation = useMutation(changeStatusDataToTable, {
|
|
41
46
|
onSuccess: () => {
|
|
@@ -44,7 +49,7 @@ const DataTable = () => {
|
|
|
44
49
|
},
|
|
45
50
|
onError: () => {
|
|
46
51
|
toast.error(" Có lỗi xảy ra !");
|
|
47
|
-
}
|
|
52
|
+
},
|
|
48
53
|
});
|
|
49
54
|
const deleteMutation = useMutation(deleteDataFromTable, {
|
|
50
55
|
onSuccess: ({ status }) => {
|
|
@@ -58,7 +63,7 @@ const DataTable = () => {
|
|
|
58
63
|
},
|
|
59
64
|
onError: () => {
|
|
60
65
|
toast.error(" Có lỗi xảy ra !");
|
|
61
|
-
}
|
|
66
|
+
},
|
|
62
67
|
});
|
|
63
68
|
const deleteMultipleMutation = useMutation(deleteMultipleDataFromTable, {
|
|
64
69
|
onSuccess: () => {
|
|
@@ -68,7 +73,7 @@ const DataTable = () => {
|
|
|
68
73
|
},
|
|
69
74
|
onError: () => {
|
|
70
75
|
toast.error(" Có lỗi xảy ra !");
|
|
71
|
-
}
|
|
76
|
+
},
|
|
72
77
|
});
|
|
73
78
|
|
|
74
79
|
const handleDelete = (id) => {
|
|
@@ -76,7 +81,7 @@ const DataTable = () => {
|
|
|
76
81
|
.then(() => {
|
|
77
82
|
deleteMutation.mutate({
|
|
78
83
|
id,
|
|
79
|
-
tableName
|
|
84
|
+
tableName,
|
|
80
85
|
});
|
|
81
86
|
})
|
|
82
87
|
.catch(() => {});
|
|
@@ -84,7 +89,7 @@ const DataTable = () => {
|
|
|
84
89
|
const handleChangeStatus = (Id) => {
|
|
85
90
|
changeStatusMutation.mutate({
|
|
86
91
|
tableName,
|
|
87
|
-
id: Id
|
|
92
|
+
id: Id,
|
|
88
93
|
});
|
|
89
94
|
};
|
|
90
95
|
const handlEdit = (item) => {
|
|
@@ -96,7 +101,7 @@ const DataTable = () => {
|
|
|
96
101
|
let total = data?.total ?? 0;
|
|
97
102
|
return {
|
|
98
103
|
rows: rows,
|
|
99
|
-
total
|
|
104
|
+
total,
|
|
100
105
|
};
|
|
101
106
|
}, [data]);
|
|
102
107
|
|
|
@@ -137,7 +142,7 @@ const DataTable = () => {
|
|
|
137
142
|
.then(() => {
|
|
138
143
|
deleteMultipleMutation.mutate({
|
|
139
144
|
tableName,
|
|
140
|
-
ids: selected
|
|
145
|
+
ids: selected,
|
|
141
146
|
});
|
|
142
147
|
})
|
|
143
148
|
.catch(() => {});
|
|
@@ -152,7 +157,12 @@ const DataTable = () => {
|
|
|
152
157
|
onDeleteMultiple={handleDeleteMultiple}
|
|
153
158
|
/>
|
|
154
159
|
<Table className="border">
|
|
155
|
-
<TableHead
|
|
160
|
+
<TableHead
|
|
161
|
+
headLabel={columns}
|
|
162
|
+
onSelectAllClick={handleSelectAllClick}
|
|
163
|
+
numSelected={selected?.length}
|
|
164
|
+
rowCount={rows.length}
|
|
165
|
+
/>
|
|
156
166
|
{isLoading ? (
|
|
157
167
|
<TableRowsLoader rowsNum={5} colsNum={columns.length + 4} />
|
|
158
168
|
) : (
|
|
@@ -6,13 +6,7 @@ import { useTheme } from "@mui/material/styles";
|
|
|
6
6
|
import { RootStyle } from "./TableRowRender";
|
|
7
7
|
|
|
8
8
|
// ----------------------------------------------------------------------
|
|
9
|
-
TableToolbar
|
|
10
|
-
numSelected: PropTypes.number,
|
|
11
|
-
filterName: PropTypes.string,
|
|
12
|
-
onFilterName: PropTypes.func
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const TableToolbar = ({ numSelected, onSelectAllClick, rowCount, onDeleteMultiple }) => {
|
|
9
|
+
const TableToolbar = ({ numSelected, onSelectAllClick, rowCount, onDeleteMultiple }) => {
|
|
16
10
|
const theme = useTheme();
|
|
17
11
|
const isLight = theme.palette.mode === "light";
|
|
18
12
|
const { canDeleteMulti } = usePermission();
|
|
@@ -29,10 +23,9 @@ export const TableToolbar = ({ numSelected, onSelectAllClick, rowCount, onDelete
|
|
|
29
23
|
width: "100%",
|
|
30
24
|
...(numSelected > 0 && {
|
|
31
25
|
color: isLight ? "primary.main" : "text.primary",
|
|
32
|
-
bgcolor: isLight ? "primary.lighter" : "primary.dark"
|
|
33
|
-
})
|
|
34
|
-
}}
|
|
35
|
-
>
|
|
26
|
+
bgcolor: isLight ? "primary.lighter" : "primary.dark",
|
|
27
|
+
}),
|
|
28
|
+
}}>
|
|
36
29
|
<Box padding="checkbox" sx={{ display: "flex", alignItems: "center" }}>
|
|
37
30
|
<Checkbox
|
|
38
31
|
indeterminate={numSelected > 0 && numSelected < rowCount}
|
|
@@ -55,3 +48,10 @@ export const TableToolbar = ({ numSelected, onSelectAllClick, rowCount, onDelete
|
|
|
55
48
|
)
|
|
56
49
|
);
|
|
57
50
|
};
|
|
51
|
+
TableToolbar.propTypes = {
|
|
52
|
+
numSelected: PropTypes.number,
|
|
53
|
+
filterName: PropTypes.string,
|
|
54
|
+
onFilterName: PropTypes.func
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default TableToolbar;
|