trithuc-mvc-react 2.7.1 → 2.7.3

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/api/index.js CHANGED
@@ -139,19 +139,41 @@ export const saveDataToTable = async ({ tableName, data }) => {
139
139
  }
140
140
  }
141
141
  };
142
- export const changeStatusDataToTable = async ({ tableName, id }) => {
142
+ export const changeStatusDataToTable = async ({ tableName, id, fieldName }) => {
143
143
  if (!apiUrl) {
144
144
  const res = await api.post(`${getBaseUrl()}/Admin/${tableName}/ChangeStatus`, {
145
145
  id
146
146
  });
147
147
  return res.data;
148
148
  } else {
149
- const res = await api.post(`${getBaseUrl()}/${apiUrl}/${tableName}/ChangeStatus`, id, {
150
- headers: {
151
- "Content-Type": "application/json-patch+json" // Đảm bảo Content-Type là đúng
149
+ try {
150
+ if (fieldName) {
151
+ const res = await api.post(
152
+ `${getBaseUrl()}/${apiUrl ? `${apiUrl}/` : "Admin/"}${tableName}/ChangeStatus`,
153
+ {
154
+ id,
155
+ fieldName
156
+ },
157
+ {
158
+ headers: {
159
+ "Content-Type": "application/json-patch+json" // Đảm bảo Content-Type là đúng
160
+ }
161
+ }
162
+ );
163
+ return res.data;
164
+ } else {
165
+ const res = await api.post(`${getBaseUrl()}/${apiUrl ? `${apiUrl}/` : "Admin/"}${tableName}/ChangeStatus`, id, {
166
+ headers: {
167
+ "Content-Type": "application/json-patch+json" // Đảm bảo Content-Type là đúng
168
+ }
169
+ });
170
+ return res.data;
152
171
  }
153
- });
154
- return res.data;
172
+ } catch (error) {
173
+ console.error("Error changing status:", error);
174
+ // Xử lý lỗi tùy thuộc vào nhu cầu của bạn, có thể ném ra hoặc trả về giá trị mặc định
175
+ throw error; // Hoặc return { success: false, message: error.message };
176
+ }
155
177
  }
156
178
  };
157
179
 
@@ -198,3 +220,24 @@ export const uploadFile = async (formData) => {
198
220
  return res.data;
199
221
  }
200
222
  };
223
+
224
+ export const huongDan = async ({ data }) => {
225
+ if (!apiUrl) {
226
+ return [];
227
+ } else {
228
+ const res = await api.get(
229
+ `${getBaseUrl()}/${apiUrl}/HuongDanSuDung/Dropdownlist`,
230
+ {
231
+ params: {
232
+ ...data
233
+ }
234
+ },
235
+ {
236
+ headers: {
237
+ "Content-Type": "application/json-patch+json" // Đảm bảo Content-Type là đúng
238
+ }
239
+ }
240
+ );
241
+ return res.data;
242
+ }
243
+ };
@@ -0,0 +1,42 @@
1
+ import { useEffect, useState } from "react";
2
+ import { Tooltip, IconButton } from "@mui/material";
3
+ import { LightbulbOutlined } from "@mui/icons-material";
4
+ import { huongDan } from "../../api";
5
+
6
+ const HuongDanButton = ({ tableName, size = "small" }) => {
7
+ const [dataAvailable, setDataAvailable] = useState(false);
8
+
9
+ useEffect(() => {
10
+ const fetchData = async () => {
11
+ try {
12
+ const data = { TableName: tableName };
13
+ const response = await huongDan({ data });
14
+ if (response?.data[0]) {
15
+ setDataAvailable(true);
16
+ }
17
+ } catch (error) {
18
+ console.error("Error fetching guide data", error);
19
+ }
20
+ };
21
+
22
+ fetchData();
23
+ }, [tableName]);
24
+
25
+ const handleHuongDan = () => {
26
+ window.open(`/huong-dan-su-dung/::${tableName}`, "_blank").focus();
27
+ };
28
+
29
+ if (!dataAvailable) {
30
+ return null; // Không hiển thị nút nếu không có dữ liệu
31
+ }
32
+
33
+ return (
34
+ <Tooltip title="Hướng dẫn">
35
+ <IconButton variant="outlined" color="primary" size={size} onClick={handleHuongDan}>
36
+ <LightbulbOutlined fontSize="inherit" />
37
+ </IconButton>
38
+ </Tooltip>
39
+ );
40
+ };
41
+
42
+ export default HuongDanButton;
@@ -5,7 +5,7 @@ import { useEffect, useMemo, useState } from "react";
5
5
  import { DataTableContext } from "./context";
6
6
  import PropTypes from "prop-types";
7
7
  import DataTable from "./DataTable";
8
- import { Add, Refresh } from "@mui/icons-material";
8
+ import { Add, Lightbulb, LightbulbCircle, LightbulbCircleOutlined, LightbulbOutlined, Refresh } from "@mui/icons-material";
9
9
 
10
10
  import { FormProvider, useForm } from "react-hook-form";
11
11
  import EditorDialog from "./EditorDialog";
@@ -14,6 +14,7 @@ import ViewDetailDialog from "./ViewDetailDialog";
14
14
  import ExportExcelButton from "./ExportExcelButton";
15
15
  import { FilterGod } from "./FilterGod";
16
16
  import { usePermission } from "../../hooks";
17
+ import HuongDanButton from "./HuongDanButton";
17
18
 
18
19
  DataManagement.propTypes = {
19
20
  columns: PropTypes.array,
@@ -177,6 +178,7 @@ function DataManagement({
177
178
  <Stack direction="row" justifyContent={"space-between"} sx={{ mb: upXL ? 2 : 1, ...slotProps?.header?.sx }}>
178
179
  <Typography variant="h4">{title}</Typography>
179
180
  <Stack direction="row" spacing={1}>
181
+ <HuongDanButton tableName={tableName} size={elementSize} />
180
182
  <Tooltip title="Làm mới">
181
183
  <IconButton
182
184
  variant="outlined"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "2.7.1",
3
+ "version": "2.7.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"