@esvndev/es-react-config-setting 1.0.44 → 1.0.46

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,43 @@ const GetSettingGroup = (callback) => {
11468
11468
  callback({ status: false, data: error });
11469
11469
  });
11470
11470
  };
11471
+ const GetSettingConfig = (callback) => {
11472
+ const _url = `${BASE_URL}/api/config/get-setting-config`;
11473
+ const options = {
11474
+ method: 'GET',
11475
+ headers: {
11476
+ 'Content-Type': 'application/json',
11477
+ Authorization: `Bearer ${getToken()}`,
11478
+ },
11479
+ };
11480
+ fetch(_url, options)
11481
+ .then(response => {
11482
+ if (!response.ok) {
11483
+ console.log(`HTTP error! Status: ${response.status}`);
11484
+ return null;
11485
+ }
11486
+ return response.text(); // hoặc .json() nếu muốn object
11487
+ })
11488
+ .then(text => {
11489
+ if (text) {
11490
+ try {
11491
+ JSON.parse(text); // Kiểm tra nếu là JSON hợp lệ
11492
+ console.log('Response JSON string:', text);
11493
+ }
11494
+ catch (err) {
11495
+ console.log('Invalid JSON:', err);
11496
+ }
11497
+ callback({ status: true, data: JSON.parse(text) });
11498
+ }
11499
+ else {
11500
+ callback({ status: false, data: text });
11501
+ }
11502
+ })
11503
+ .catch(error => {
11504
+ console.log('Fetch error:', error);
11505
+ callback({ status: false, data: error });
11506
+ });
11507
+ };
11471
11508
  const GetSettingConfigByGroup = (obj, callback) => {
11472
11509
  const _url = `${BASE_URL}/api/config/get-setting-config-by-group`;
11473
11510
  const options = {
@@ -11530,6 +11567,11 @@ const SettingApp = (props) => {
11530
11567
  //Sự kiện sau khi đã đóng cài đặt
11531
11568
  const handleFormClosed = () => {
11532
11569
  };
11570
+ //Sự kiện giá trị thay đổi
11571
+ const _eventChange = () => {
11572
+ if (eventChange)
11573
+ eventChange([{ key: "x", value: "x", state: "update" }]);
11574
+ };
11533
11575
  const DynamicIcon = ({ name, className }) => {
11534
11576
  const LucideIcon = Icon[name];
11535
11577
  return LucideIcon ? jsx(LucideIcon, { className: className }) : null;
@@ -11579,36 +11621,36 @@ const SettingApp = (props) => {
11579
11621
  switch (data.type) {
11580
11622
  case "switch":
11581
11623
  case "checkbox":
11582
- return (jsx("div", { className: "checkbox", title: data.description, children: jsx(Input$1, { type: "checkbox", className: "" }) }, data.id));
11624
+ return (jsx("div", { className: "checkbox", title: data.description, children: jsx(Input$1, { type: "checkbox", className: "", onChange: _eventChange }) }, data.id));
11583
11625
  case "radio":
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));
11626
+ 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, onChange: _eventChange }), opt.name] }, index))) }, data.id));
11585
11627
  case "combobox":
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));
11628
+ return (jsx("div", { className: "combobox", title: data.description, children: jsxs(Input$1, { type: "select", className: "input-custom", name: data.name, id: data.name, onChange: _eventChange, 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
11629
  case "slider":
11588
11630
  case "text":
11589
- return (jsx("div", { className: "text-input", title: data.description, children: jsx(Input$1, { type: "text", className: "input-custom", placeholder: data.name }) }, data.id));
11631
+ return (jsx("div", { className: "text-input", title: data.description, children: jsx(Input$1, { type: "text", className: "input-custom", placeholder: data.name, onChange: _eventChange }) }, data.id));
11590
11632
  case "password":
11591
- return (jsx("div", { className: "text-input", title: data.description, children: jsx(Input$1, { type: "password", className: "input-custom", placeholder: data.name }) }, data.id));
11633
+ return (jsx("div", { className: "text-input", title: data.description, children: jsx(Input$1, { type: "password", className: "input-custom", placeholder: data.name, onChange: _eventChange }) }, data.id));
11592
11634
  case "number":
11593
- return (jsx("div", { className: "number-input", title: data.description, children: jsx(Input$1, { type: "number", className: "t-right input-custom", placeholder: data.name }) }, data.id));
11635
+ return (jsx("div", { className: "number-input", title: data.description, children: jsx(Input$1, { type: "number", className: "t-right input-custom", placeholder: data.name, onChange: _eventChange }) }, data.id));
11594
11636
  case "date":
11595
- return (jsx("div", { className: "date-input", title: data.description, children: jsx(Input$1, { type: "date", className: "t-right input-custom" }) }, data.id));
11637
+ return (jsx("div", { className: "date-input", title: data.description, children: jsx(Input$1, { type: "date", className: "t-right input-custom", onChange: _eventChange }) }, data.id));
11596
11638
  case "time":
11597
- return (jsx("div", { className: "date-input", title: data.description, children: jsx(Input$1, { type: "time", className: "t-right input-custom" }) }, data.id));
11639
+ return (jsx("div", { className: "date-input", title: data.description, children: jsx(Input$1, { type: "time", className: "t-right input-custom", onChange: _eventChange }) }, data.id));
11598
11640
  case "datetime":
11599
- return (jsx("div", { className: "date-input", title: data.description, children: jsx(Input$1, { type: "datetime", className: "t-right input-custom" }) }, data.id));
11641
+ return (jsx("div", { className: "date-input", title: data.description, children: jsx(Input$1, { type: "datetime", className: "t-right input-custom", onChange: _eventChange }) }, data.id));
11600
11642
  case "image":
11601
11643
  case "file":
11602
- return (jsx("div", { className: "file-input", title: data.description, children: jsx(Input$1, { type: "file", className: "input-custom" }) }, data.id));
11644
+ return (jsx("div", { className: "file-input", title: data.description, children: jsx(Input$1, { type: "file", className: "input-custom", onChange: _eventChange }) }, data.id));
11603
11645
  case "color":
11604
- return (jsx("div", { className: "color-picker t-right", title: data.description, children: jsx(Input$1, { type: "color", className: "form-color input-custom" }) }, data.id));
11646
+ return (jsx("div", { className: "color-picker t-right", title: data.description, children: jsx(Input$1, { type: "color", className: "form-color input-custom", onChange: _eventChange }) }, data.id));
11605
11647
  default:
11606
- return (jsx("div", { className: (data.type ?? 'normal') + '-input', title: data.description, children: jsx(Input$1, { type: data.type ?? '' }) }, data.id));
11648
+ return (jsx("div", { className: (data.type ?? 'normal') + '-input', title: data.description, children: jsx(Input$1, { type: data.type ?? '', onChange: _eventChange }) }, data.id));
11607
11649
  }
11608
11650
  };
11609
11651
  //hàm tạo các thông số cấu hình và cài đặt
11610
11652
  const _renderView = () => {
11611
- return (settingData && settingData.data && settingData.data.length > 0 ? settingData.data.map((item, index) => {
11653
+ return (settingData && settingData.length > 0 ? settingData.map((item, index) => {
11612
11654
  return (jsxs("div", { className: "setting-section", children: [jsx("div", { className: "setting-section-label", children: jsx("div", { className: "", children: jsx("span", { children: item.name }) }) }), item.description ?
11613
11655
  jsx("div", { className: "setting-section-desc", children: jsx("div", { className: "", children: jsx("span", { children: item.description }) }) })
11614
11656
  : null, item.data ?
@@ -11627,6 +11669,17 @@ const SettingApp = (props) => {
11627
11669
  };
11628
11670
 
11629
11671
  const INIT_CONFIG_SETTING = () => {
11672
+ _LOAD_();
11673
+ GetSettingConfig((data) => {
11674
+ if (data.status) {
11675
+ localStorage.setItem("INIT_CONFIG_SETTING", JSON.parse(data.data));
11676
+ }
11677
+ _LOAD_();
11678
+ });
11679
+ };
11680
+ //Nạp dữ liệu biến vào
11681
+ const _LOAD_ = () => {
11682
+ localStorage.getItem("INIT_CONFIG_SETTING");
11630
11683
  };
11631
11684
 
11632
11685
  export { INIT_CONFIG_SETTING, SettingApp };