trithuc-mvc-react 1.0.12 → 1.1.0
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.
- package/components/DataManagement/FormField.jsx +1 -1
- package/components/DataManagement/TableHead.jsx +3 -2
- package/components/DataManagement/TableRowRender.jsx +10 -3
- package/components/DataManagement/index.jsx +23 -4
- package/components/MoreMenu.jsx +50 -0
- package/components/date/StaticDateRangePicker.jsx +9 -8
- package/package.json +1 -1
|
@@ -198,7 +198,7 @@ function FormField({
|
|
|
198
198
|
<Controller
|
|
199
199
|
name={name}
|
|
200
200
|
control={control}
|
|
201
|
-
|
|
201
|
+
defaultValue={true}
|
|
202
202
|
render={({ field }) => <FormControlLabel control={<Switch {...field} checked={field.value} />} label={label} />}
|
|
203
203
|
/>
|
|
204
204
|
);
|
|
@@ -2,6 +2,7 @@ import { Checkbox, TableRow, TableCell, TableHead as MuiTableHead } from "@mui/m
|
|
|
2
2
|
import { useDataTable, usePermission } from "./hooks";
|
|
3
3
|
export function TableHead({ numSelected, rowCount, onSelectAllClick, headLabel }) {
|
|
4
4
|
const { canEdit } = usePermission();
|
|
5
|
+
const { disableStatus } = useDataTable();
|
|
5
6
|
return (
|
|
6
7
|
<MuiTableHead sx={{ height: 56, visibility: numSelected > 0 ? "hidden" : "visible" }}>
|
|
7
8
|
<TableRow>
|
|
@@ -18,8 +19,8 @@ export function TableHead({ numSelected, rowCount, onSelectAllClick, headLabel }
|
|
|
18
19
|
{headCell.label}
|
|
19
20
|
</TableCell>
|
|
20
21
|
))}
|
|
21
|
-
{canEdit && <TableCell>Kích hoạt</TableCell>}
|
|
22
|
-
<TableCell>Thao tác</TableCell>
|
|
22
|
+
{!disableStatus && canEdit && <TableCell>Kích hoạt</TableCell>}
|
|
23
|
+
<TableCell sx={{minWidth: '136px'}}>Thao tác</TableCell>
|
|
23
24
|
</TableRow>
|
|
24
25
|
</MuiTableHead>
|
|
25
26
|
);
|
|
@@ -6,10 +6,15 @@ import { useDataTable, usePermission } from "./hooks";
|
|
|
6
6
|
|
|
7
7
|
// material
|
|
8
8
|
import { styled } from "@mui/material/styles";
|
|
9
|
+
import MoreMenu from "../MoreMenu";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
9
13
|
|
|
10
14
|
export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus, onDelete, onEdit }) => {
|
|
11
|
-
const { selectedField, columns } = useDataTable();
|
|
15
|
+
const { selectedField, columns, statusKey, disableStatus, tableActions } = useDataTable();
|
|
12
16
|
const { canEdit, canDelete } = usePermission();
|
|
17
|
+
console.log("tableActions", tableActions);
|
|
13
18
|
return (
|
|
14
19
|
<TableRow hover key={row[selectedField]} selected={selected}>
|
|
15
20
|
<TableCell padding="checkbox">
|
|
@@ -32,10 +37,10 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
|
|
|
32
37
|
);
|
|
33
38
|
}
|
|
34
39
|
)}
|
|
35
|
-
{canEdit && (
|
|
40
|
+
{!disableStatus && canEdit && (
|
|
36
41
|
<TableCell>
|
|
37
42
|
<Switch
|
|
38
|
-
checked={row
|
|
43
|
+
checked={row[statusKey]}
|
|
39
44
|
onChange={() => {
|
|
40
45
|
onChangeStatus(row[selectedField]);
|
|
41
46
|
}}
|
|
@@ -64,6 +69,8 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
|
|
|
64
69
|
</IconButton>
|
|
65
70
|
</Tooltip>
|
|
66
71
|
)}
|
|
72
|
+
|
|
73
|
+
{<MoreMenu actions={tableActions} data={row}/>}
|
|
67
74
|
</TableCell>
|
|
68
75
|
</TableRow>
|
|
69
76
|
);
|
|
@@ -27,10 +27,26 @@ DataManagement.propTypes = {
|
|
|
27
27
|
onChangeAfter: PropTypes.func,
|
|
28
28
|
filters: PropTypes.array
|
|
29
29
|
})
|
|
30
|
-
)
|
|
30
|
+
),
|
|
31
|
+
editorFields: PropTypes.array,
|
|
32
|
+
validationSchema: PropTypes.object,
|
|
33
|
+
disableStatus: PropTypes.bool,
|
|
34
|
+
statusKey: PropTypes.string,
|
|
35
|
+
tableActions: PropTypes.array
|
|
31
36
|
};
|
|
32
37
|
|
|
33
|
-
function DataManagement({
|
|
38
|
+
function DataManagement({
|
|
39
|
+
columns = [],
|
|
40
|
+
title,
|
|
41
|
+
tableName,
|
|
42
|
+
selectedField = "Id",
|
|
43
|
+
filters,
|
|
44
|
+
editorFields,
|
|
45
|
+
validationSchema = {},
|
|
46
|
+
statusKey = "Status",
|
|
47
|
+
disableStatus = false,
|
|
48
|
+
tableActions = []
|
|
49
|
+
}) {
|
|
34
50
|
const [openEditorDialog, setOpenEditorDialog] = useState(false);
|
|
35
51
|
const [selectedEditItem, setSelectedEditItem] = useState(null);
|
|
36
52
|
const [dataSearch, setDataSearch] = useState({});
|
|
@@ -46,9 +62,12 @@ function DataManagement({ columns = [], title, tableName, selectedField = "Id",
|
|
|
46
62
|
setOpenEditorDialog,
|
|
47
63
|
dataSearch,
|
|
48
64
|
setDataSearch,
|
|
49
|
-
validationSchema
|
|
65
|
+
validationSchema,
|
|
66
|
+
statusKey,
|
|
67
|
+
disableStatus,
|
|
68
|
+
tableActions
|
|
50
69
|
};
|
|
51
|
-
}, [tableName, selectedField, columns, selectedEditItem, dataSearch, setDataSearch, validationSchema]);
|
|
70
|
+
}, [tableName, selectedField, columns, selectedEditItem, dataSearch, setDataSearch, validationSchema, tableActions]);
|
|
52
71
|
const permissionValues = useMemo(() => {
|
|
53
72
|
return {
|
|
54
73
|
Permission,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
|
|
4
|
+
// material
|
|
5
|
+
import { Menu, MenuItem, IconButton, ListItemIcon, ListItemText } from "@mui/material";
|
|
6
|
+
import MoreVertIcon from "@mui/icons-material/MoreVert";
|
|
7
|
+
// ----------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
MoreMenu.propTypes = {
|
|
10
|
+
onDelete: PropTypes.func,
|
|
11
|
+
userName: PropTypes.string,
|
|
12
|
+
actions: PropTypes.array,
|
|
13
|
+
data: PropTypes.any
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default function MoreMenu({ data, actions }) {
|
|
17
|
+
const ref = useRef(null);
|
|
18
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
19
|
+
|
|
20
|
+
if (actions?.length == 0) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<IconButton ref={ref} onClick={() => setIsOpen(true)}>
|
|
26
|
+
<MoreVertIcon />
|
|
27
|
+
</IconButton>
|
|
28
|
+
|
|
29
|
+
<Menu
|
|
30
|
+
open={isOpen}
|
|
31
|
+
anchorEl={ref.current}
|
|
32
|
+
onClose={() => setIsOpen(false)}
|
|
33
|
+
slotProps={{
|
|
34
|
+
paper: {
|
|
35
|
+
sx: { width: 200, maxWidth: "100%" }
|
|
36
|
+
}
|
|
37
|
+
}}
|
|
38
|
+
anchorOrigin={{ vertical: "top", horizontal: "right" }}
|
|
39
|
+
transformOrigin={{ vertical: "top", horizontal: "right" }}
|
|
40
|
+
>
|
|
41
|
+
{[...actions].map(({ title, onClick, element }) => (
|
|
42
|
+
<MenuItem key={title} onClick={() => onClick(data)} sx={{ color: "text.secondary" }}>
|
|
43
|
+
<ListItemIcon>{element}</ListItemIcon>
|
|
44
|
+
<ListItemText primary={title} primaryTypographyProps={{ variant: "body2" }} />
|
|
45
|
+
</MenuItem>
|
|
46
|
+
))}
|
|
47
|
+
</Menu>
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import * as dateFns from "date-fns";
|
|
5
5
|
import { Box, Paper, Stack } from "@mui/material";
|
|
6
|
+
import viLocale from "date-fns/locale/vi";
|
|
6
7
|
// import "tailwindcss/tailwind.css";
|
|
7
8
|
|
|
8
9
|
const isBetween = (date, from, to, inclusivity) => {
|
|
@@ -18,7 +19,8 @@ const isBetween = (date, from, to, inclusivity) => {
|
|
|
18
19
|
(isAfterEqual ? dateFns.isEqual(to, date) || dateFns.isAfter(to, date) : dateFns.isAfter(to, date))
|
|
19
20
|
);
|
|
20
21
|
};
|
|
21
|
-
const days = ["
|
|
22
|
+
const days = ["CN", "T2", "T3", "T4", "T5", "T6", "T7"];
|
|
23
|
+
console.log(viLocale.localize.day);
|
|
22
24
|
|
|
23
25
|
const StaticDateRangePicker = ({ value, onUpdate }) => {
|
|
24
26
|
const [currCalendar, setCurrCalendar] = useState([]);
|
|
@@ -213,7 +215,6 @@ const StaticDateRangePicker = ({ value, onUpdate }) => {
|
|
|
213
215
|
}
|
|
214
216
|
};
|
|
215
217
|
|
|
216
|
-
const currTitle = currYear && currMonth ? dateFns.format(new Date(currYear, currMonth), "MMMM") + new Date(currYear, currMonth).getFullYear() : "";
|
|
217
218
|
return (
|
|
218
219
|
<Paper>
|
|
219
220
|
<Box sx={{ display: "flex" }} className="date-range-piker-wrapper">
|
|
@@ -221,7 +222,9 @@ const StaticDateRangePicker = ({ value, onUpdate }) => {
|
|
|
221
222
|
<div className="flex justify-between items-center">
|
|
222
223
|
<h3 className="text-lg">
|
|
223
224
|
{" "}
|
|
224
|
-
{dateFns.format(new Date(currYear, currMonth), "
|
|
225
|
+
{dateFns.format(new Date(currYear, currMonth), "MMMMMM yyyy", {
|
|
226
|
+
locale: viLocale
|
|
227
|
+
})}
|
|
225
228
|
</h3>
|
|
226
229
|
|
|
227
230
|
<Stack direction="row" spacing={2} alignItems={"center"}>
|
|
@@ -325,11 +328,9 @@ const StaticDateRangePicker = ({ value, onUpdate }) => {
|
|
|
325
328
|
<div className="drop-shadow-sm shadow-sm min-w-[10rem] p-3 rounded-lg border flex flex-col">
|
|
326
329
|
<div className="flex justify-between items-center">
|
|
327
330
|
<h3 className="text-lg">
|
|
328
|
-
{dateFns.format(dateFns.add(new Date(currYear, currMonth), { months: 1 }), "MMMM"
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
// moment({ month: currMonth }).add(1, "month").year()
|
|
332
|
-
}
|
|
331
|
+
{dateFns.format(dateFns.add(new Date(currYear, currMonth), { months: 1 }), "MMMM yyyy", {
|
|
332
|
+
locale: viLocale
|
|
333
|
+
})}
|
|
333
334
|
</h3>
|
|
334
335
|
<div className="flex gap-x-2 items-center">
|
|
335
336
|
<button
|