@esvndev/es-react-config-setting 1.0.41 → 1.0.43

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/dist/index.mjs CHANGED
@@ -11468,6 +11468,44 @@ const GetSettingGroup = (callback) => {
11468
11468
  callback({ status: false, data: error });
11469
11469
  });
11470
11470
  };
11471
+ const GetSettingConfigByGroup = (obj, callback) => {
11472
+ const _url = `${BASE_URL}/api/config/get-setting-config-by-group`;
11473
+ const options = {
11474
+ method: 'POST',
11475
+ headers: {
11476
+ 'Content-Type': 'application/json',
11477
+ Authorization: `Bearer ${getToken()}`,
11478
+ },
11479
+ body: JSON.stringify(obj)
11480
+ };
11481
+ fetch(_url, options)
11482
+ .then(response => {
11483
+ if (!response.ok) {
11484
+ console.log(`HTTP error! Status: ${response.status}`);
11485
+ return null;
11486
+ }
11487
+ return response.text(); // hoặc .json() nếu muốn object
11488
+ })
11489
+ .then(text => {
11490
+ if (text) {
11491
+ try {
11492
+ JSON.parse(text); // Kiểm tra nếu là JSON hợp lệ
11493
+ console.log('Response JSON string:', text);
11494
+ }
11495
+ catch (err) {
11496
+ console.log('Invalid JSON:', err);
11497
+ }
11498
+ callback({ status: true, data: JSON.parse(text) });
11499
+ }
11500
+ else {
11501
+ callback({ status: false, data: text });
11502
+ }
11503
+ })
11504
+ .catch(error => {
11505
+ console.log('Fetch error:', error);
11506
+ callback({ status: false, data: error });
11507
+ });
11508
+ };
11471
11509
 
11472
11510
  const SettingApp = (props) => {
11473
11511
  const { isOpen, eventChange, eventClose } = { ...props };
@@ -11497,7 +11535,7 @@ const SettingApp = (props) => {
11497
11535
  return LucideIcon ? jsx(LucideIcon, { className: className }) : null;
11498
11536
  };
11499
11537
  //#endregion
11500
- const [settingData, setSettingData] = useState([]);
11538
+ const [settingData, setSettingData] = useState({});
11501
11539
  const [dataSettingGroup, setDataSettingGroup] = useState([]);
11502
11540
  //Load data of group config and setting by group
11503
11541
  useEffect(() => {
@@ -11505,6 +11543,9 @@ const SettingApp = (props) => {
11505
11543
  GetSettingGroup((data) => {
11506
11544
  if (data.status) {
11507
11545
  setDataSettingGroup(data.data);
11546
+ setTimeout(() => {
11547
+ loadSettingConfigByGroup(data.data[0]);
11548
+ }, 500);
11508
11549
  }
11509
11550
  else {
11510
11551
  setDataSettingGroup([]);
@@ -11512,13 +11553,24 @@ const SettingApp = (props) => {
11512
11553
  });
11513
11554
  }
11514
11555
  }, [isOpen]);
11556
+ //Lấy danh sách cài đặt theo nhóm đã chọn
11557
+ const loadSettingConfigByGroup = (data) => {
11558
+ GetSettingConfigByGroup({ GroupId: data.id }, (rs) => {
11559
+ if (rs.status) {
11560
+ setSettingData(rs.data);
11561
+ }
11562
+ else {
11563
+ setSettingData([]);
11564
+ }
11565
+ });
11566
+ };
11515
11567
  //Sự kiện chọn nhóm cài đặt
11516
11568
  const switchSettingTab = (data) => {
11517
11569
  const updated = dataSettingGroup.map((item) => ({
11518
11570
  ...item,
11519
11571
  active: item.id === data.id
11520
11572
  }));
11521
- setSettingData(data);
11573
+ loadSettingConfigByGroup(data);
11522
11574
  setDataSettingGroup(updated);
11523
11575
  };
11524
11576
  //Hàm sử dụng tạo theo loại giá trị
@@ -11532,6 +11584,7 @@ const SettingApp = (props) => {
11532
11584
  return (jsx("div", { className: "radio-group", title: data.description, children: data.option?.map((opt, index) => (jsxs("label", { children: [jsx(Input$1, { type: "radio", name: data.name, value: opt.value }), opt.name] }, index))) }, data.id));
11533
11585
  case "combobox":
11534
11586
  return (jsx("div", { className: "combobox", title: data.description, children: jsxs(Input$1, { type: "select", className: "input-custom", name: data.name, id: data.name, children: [jsx("option", { value: "", children: "Ch\u1ECDn m\u1ED9t gi\u00E1 tr\u1ECB" }), data.option?.map((opt, index) => (jsx("option", { value: opt.value, children: opt.name }, index)))] }) }, data.id));
11587
+ case "slider":
11535
11588
  case "text":
11536
11589
  return (jsx("div", { className: "text-input", title: data.description, children: jsx(Input$1, { type: "text", className: "input-custom", placeholder: data.name }) }, data.id));
11537
11590
  case "password":