trithuc-mvc-react 2.6.5 → 2.6.7

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 { TableRowRender } from "./TableRowRender";
13
13
  import TableToolbar from "./TableToolbar";
14
14
  import { useDataTable } from "./hooks";
15
15
  import { usePermission } from "../../hooks";
16
+ import { URL_APPLICATION ,URL_APPLICATION_API } from "@/constants";
16
17
  const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit, disableDelete }) => {
17
18
  const {
18
19
  tableName,
@@ -46,14 +47,18 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
46
47
  // keepPreviousData: true,
47
48
  onSuccess: ({ PermissionModel, status }) => {
48
49
  if (status) {
49
- // setPermission(PermissionModel);
50
+ setPermission(PermissionModel);
50
51
  // console.log("LOAD LAI PermissionModel");
51
52
  }
52
53
  }
53
54
  });
54
55
  const changeStatusMutation = useMutation(changeStatusDataToTable, {
55
- onSuccess: () => {
56
- toast.success("Thay đổi trạng thái thành công !");
56
+ onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }) => {
57
+ if (URL_APPLICATION_API) {
58
+ toast.success(message);
59
+ }else{
60
+ toast.success("Thay đổi trạng thái thành công !");
61
+ }
57
62
  queryClient.invalidateQueries({ queryKey: [tableName] });
58
63
  },
59
64
  onError: () => {
@@ -61,9 +66,13 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
61
66
  }
62
67
  });
63
68
  const deleteMutation = useMutation(deleteDataFromTable, {
64
- onSuccess: ({ status }) => {
65
- if (status) {
66
- toast.success("Xóa thành công !");
69
+ onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }) => {
70
+ if (status) {
71
+ if (URL_APPLICATION_API) {
72
+ toast.success(message);
73
+ }else{
74
+ toast.success("Xóa thành công !");
75
+ }
67
76
  } else {
68
77
  toast.error(" Có lỗi xảy ra !");
69
78
  }
@@ -75,8 +84,12 @@ const DataTable = ({ multipleActions = [],page, setPage = () => { }, disableEdit
75
84
  }
76
85
  });
77
86
  const deleteMultipleMutation = useMutation(deleteMultipleDataFromTable, {
78
- onSuccess: () => {
79
- toast.success("Xóa thành công !");
87
+ onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }) => {
88
+ if (URL_APPLICATION_API) {
89
+ toast.success(message);
90
+ }else{
91
+ toast.success("Xóa thành công !");
92
+ }
80
93
  setSelectedItems([]);
81
94
  queryClient.invalidateQueries({ queryKey: [tableName] });
82
95
  },
@@ -11,6 +11,7 @@ import { saveDataToTable } from "../../api";
11
11
  import { toast } from "react-toastify";
12
12
  import { useDataTable } from "./hooks";
13
13
  import FormField from "./FormField";
14
+ import { URL_APPLICATION ,URL_APPLICATION_API } from "@/constants";
14
15
  import { yupResolver } from "@hookform/resolvers/yup";
15
16
  EditorForm.propTypes = {
16
17
  fields: PropTypes.array
@@ -61,7 +62,14 @@ function EditorForm({ fields, submitRef }) {
61
62
  } catch (e) {
62
63
  fileValue = [];
63
64
  }
64
- setValue(field, fileValue);
65
+ setValue(field, URL_APPLICATION + fileValue);
66
+ } else if (type === "imageavatar") {
67
+ try {
68
+ let fileValue = selectedEditItem[field];
69
+ setValue(field, URL_APPLICATION + fileValue);
70
+ } catch (error) {
71
+ console.log(error);
72
+ }
65
73
  } else {
66
74
  setValue(field, selectedEditItem[field]);
67
75
  }
@@ -84,13 +92,18 @@ function EditorForm({ fields, submitRef }) {
84
92
  }, [selectedEditItem]);
85
93
 
86
94
  const saveMutation = useMutation(saveDataToTable, {
87
- onSuccess: ({ status = false }, { data: { Id } }) => {
95
+ onSuccess: ({ status = false, message = " Có lỗi xảy ra !" }, { data: { Id } }) => {
88
96
  if (status) {
89
- toast.success(Id == 0 ? "Thêm thành công!" : "Cập nhật thành công!");
97
+ if (URL_APPLICATION_API) {
98
+ toast.success(message);
99
+ }else{
100
+ toast.success(Id == 0 ? "Thêm thành công!" : "Cập nhật thành công!");
101
+ }
90
102
  queryClient.invalidateQueries(tableName);
91
103
  setOpenEditorDialog(false);
92
104
  } else {
93
- toast.error(" Có lỗi xảy ra !");
105
+ console.log(status, Id);
106
+ toast.error(message);
94
107
  }
95
108
  },
96
109
  onError: () => {
@@ -115,10 +128,16 @@ function EditorForm({ fields, submitRef }) {
115
128
  if (data[field]) {
116
129
  data[field] = JSON.stringify(data[field]);
117
130
  }
118
- } else if (type == "avatar") {
131
+ } else if (type === "avatar") {
119
132
  if (data[field]?.urlFile) {
120
133
  data[field] = data[field].urlFile;
121
134
  }
135
+ } else if (type === "imageavatar") {
136
+ if (data[field]?.urlFile) {
137
+ data[field] = data[field]?.urlFile?.replaceAll(URL_APPLICATION, "");
138
+ } else if (data[field]) {
139
+ data[field] = data[field]?.replaceAll(URL_APPLICATION, "");
140
+ }
122
141
  }
123
142
  return data;
124
143
  }, data);
@@ -2,12 +2,17 @@ import { toast } from "react-toastify";
2
2
  import { exportExcel } from "../../api";
3
3
  import { Button } from "@mui/material";
4
4
  import { Download } from "@mui/icons-material";
5
+ import { URL_APPLICATION ,URL_APPLICATION_API } from "@/constants";
5
6
 
6
7
  const ExportExcelButton = ({ tableName, data, size = "small" }) => {
7
8
  const handleExportExcel = async (tableName, data) => {
8
9
  const _data = await exportExcel({ tableName, data });
9
10
  if (_data.status) {
10
- window.open(_data.url, "_blank").focus();
11
+ if(URL_APPLICATION_API){
12
+ window.open(URL_APPLICATION + _data.url, "_blank").focus();
13
+ }else{
14
+ window.open(_data.url, "_blank").focus();
15
+ }
11
16
  } else {
12
17
  toast.error("Xuất file thất bại!");
13
18
  }
@@ -372,6 +372,21 @@ function FormField({
372
372
  }}
373
373
  />
374
374
  );
375
+ case "imageavatar":
376
+ return (
377
+ <Controller
378
+ name={name}
379
+ control={control}
380
+ disabled={disabled}
381
+ render={({ field, fieldState: { error } }) => {
382
+ return (
383
+ <>
384
+ <RhfUploadAvatar name={name} disabled={disabled} />
385
+ </>
386
+ );
387
+ }}
388
+ />
389
+ );
375
390
  }
376
391
  }
377
392
 
@@ -1,6 +1,7 @@
1
1
  import { useCallback } from "react";
2
2
  import { uploadFile } from "@/apis/index";
3
- import UploadAvatar from './UploadAvatar'
3
+ import { URL_APPLICATION } from "@/constants";
4
+ import UploadAvatar from "./UploadAvatar";
4
5
  import { FormHelperText, Typography } from "@mui/material/index";
5
6
  import bytesToSize from "@/utils/bytesToSize";
6
7
  import { Controller, useFormContext } from "react-hook-form";
@@ -14,7 +15,6 @@ const RhfUploadAvatar = ({ name, disabled }) => {
14
15
  const formData = new FormData();
15
16
  formData.append("file", file);
16
17
  const data = await uploadFile(formData);
17
-
18
18
  if (file) {
19
19
  setValue(name, {
20
20
  ...file,
@@ -35,7 +35,7 @@ const RhfUploadAvatar = ({ name, disabled }) => {
35
35
  accept="image/*"
36
36
  file={value}
37
37
  maxSize={31457280}
38
- onDrop={!disabled ? handleDrop : () => { }}
38
+ onDrop={!disabled ? handleDrop : () => {}}
39
39
  error={Boolean(error)}
40
40
  helperText={error?.message}
41
41
  caption={
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "2.6.5",
3
+ "version": "2.6.7",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"