@esvndev/es-react-config-setting 1.0.45 → 1.0.47

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.js CHANGED
@@ -11495,6 +11495,43 @@ const GetSettingGroup = (callback) => {
11495
11495
  callback({ status: false, data: error });
11496
11496
  });
11497
11497
  };
11498
+ const GetSettingConfig = (callback) => {
11499
+ const _url = `${BASE_URL}/api/config/get-setting-config`;
11500
+ const options = {
11501
+ method: 'GET',
11502
+ headers: {
11503
+ 'Content-Type': 'application/json',
11504
+ Authorization: `Bearer ${getToken()}`,
11505
+ },
11506
+ };
11507
+ fetch(_url, options)
11508
+ .then(response => {
11509
+ if (!response.ok) {
11510
+ console.log(`HTTP error! Status: ${response.status}`);
11511
+ return null;
11512
+ }
11513
+ return response.text(); // hoặc .json() nếu muốn object
11514
+ })
11515
+ .then(text => {
11516
+ if (text) {
11517
+ try {
11518
+ JSON.parse(text); // Kiểm tra nếu là JSON hợp lệ
11519
+ console.log('Response JSON string:', text);
11520
+ }
11521
+ catch (err) {
11522
+ console.log('Invalid JSON:', err);
11523
+ }
11524
+ callback({ status: true, data: JSON.parse(text) });
11525
+ }
11526
+ else {
11527
+ callback({ status: false, data: text });
11528
+ }
11529
+ })
11530
+ .catch(error => {
11531
+ console.log('Fetch error:', error);
11532
+ callback({ status: false, data: error });
11533
+ });
11534
+ };
11498
11535
  const GetSettingConfigByGroup = (obj, callback) => {
11499
11536
  const _url = `${BASE_URL}/api/config/get-setting-config-by-group`;
11500
11537
  const options = {
@@ -11557,6 +11594,12 @@ const SettingApp = (props) => {
11557
11594
  //Sự kiện sau khi đã đóng cài đặt
11558
11595
  const handleFormClosed = () => {
11559
11596
  };
11597
+ //Sự kiện giá trị thay đổi
11598
+ const _eventChange = (data) => {
11599
+ console.log("new data", data);
11600
+ if (eventChange)
11601
+ eventChange([{ key: "x", value: "x", state: "update" }]);
11602
+ };
11560
11603
  const DynamicIcon = ({ name, className }) => {
11561
11604
  const LucideIcon = Icon[name];
11562
11605
  return LucideIcon ? jsxRuntime.jsx(LucideIcon, { className: className }) : null;
@@ -11606,31 +11649,31 @@ const SettingApp = (props) => {
11606
11649
  switch (data.type) {
11607
11650
  case "switch":
11608
11651
  case "checkbox":
11609
- return (jsxRuntime.jsx("div", { className: "checkbox", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "checkbox", className: "" }) }, data.id));
11652
+ return (jsxRuntime.jsx("div", { className: "checkbox", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "checkbox", className: "", onChange: _eventChange }) }, data.id));
11610
11653
  case "radio":
11611
- return (jsxRuntime.jsx("div", { className: "radio-group", title: data.description, children: data.option?.map((opt, index) => (jsxRuntime.jsxs("label", { children: [jsxRuntime.jsx(Input$1, { type: "radio", name: data.name, value: opt.value }), opt.name] }, index))) }, data.id));
11654
+ return (jsxRuntime.jsx("div", { className: "radio-group", title: data.description, children: data.option?.map((opt, index) => (jsxRuntime.jsxs("label", { children: [jsxRuntime.jsx(Input$1, { type: "radio", name: data.name, value: opt.value, onChange: _eventChange }), opt.name] }, index))) }, data.id));
11612
11655
  case "combobox":
11613
- return (jsxRuntime.jsx("div", { className: "combobox", title: data.description, children: jsxRuntime.jsxs(Input$1, { type: "select", className: "input-custom", name: data.name, id: data.name, children: [jsxRuntime.jsx("option", { value: "", children: "Ch\u1ECDn m\u1ED9t gi\u00E1 tr\u1ECB" }), data.option?.map((opt, index) => (jsxRuntime.jsx("option", { value: opt.value, children: opt.name }, index)))] }) }, data.id));
11656
+ return (jsxRuntime.jsx("div", { className: "combobox", title: data.description, children: jsxRuntime.jsxs(Input$1, { type: "select", className: "input-custom", name: data.name, id: data.name, onChange: _eventChange, children: [jsxRuntime.jsx("option", { value: "", children: "Ch\u1ECDn m\u1ED9t gi\u00E1 tr\u1ECB" }), data.option?.map((opt, index) => (jsxRuntime.jsx("option", { value: opt.value, children: opt.name }, index)))] }) }, data.id));
11614
11657
  case "slider":
11615
11658
  case "text":
11616
- return (jsxRuntime.jsx("div", { className: "text-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "text", className: "input-custom", placeholder: data.name }) }, data.id));
11659
+ return (jsxRuntime.jsx("div", { className: "text-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "text", className: "input-custom", placeholder: data.name, onChange: _eventChange }) }, data.id));
11617
11660
  case "password":
11618
- return (jsxRuntime.jsx("div", { className: "text-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "password", className: "input-custom", placeholder: data.name }) }, data.id));
11661
+ return (jsxRuntime.jsx("div", { className: "text-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "password", className: "input-custom", placeholder: data.name, onChange: _eventChange }) }, data.id));
11619
11662
  case "number":
11620
- return (jsxRuntime.jsx("div", { className: "number-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "number", className: "t-right input-custom", placeholder: data.name }) }, data.id));
11663
+ return (jsxRuntime.jsx("div", { className: "number-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "number", className: "t-right input-custom", placeholder: data.name, onChange: _eventChange }) }, data.id));
11621
11664
  case "date":
11622
- return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "date", className: "t-right input-custom" }) }, data.id));
11665
+ return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "date", className: "t-right input-custom", onChange: _eventChange }) }, data.id));
11623
11666
  case "time":
11624
- return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "time", className: "t-right input-custom" }) }, data.id));
11667
+ return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "time", className: "t-right input-custom", onChange: _eventChange }) }, data.id));
11625
11668
  case "datetime":
11626
- return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "datetime", className: "t-right input-custom" }) }, data.id));
11669
+ return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "datetime", className: "t-right input-custom", onChange: _eventChange }) }, data.id));
11627
11670
  case "image":
11628
11671
  case "file":
11629
- return (jsxRuntime.jsx("div", { className: "file-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "file", className: "input-custom" }) }, data.id));
11672
+ return (jsxRuntime.jsx("div", { className: "file-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "file", className: "input-custom", onChange: _eventChange }) }, data.id));
11630
11673
  case "color":
11631
- return (jsxRuntime.jsx("div", { className: "color-picker t-right", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "color", className: "form-color input-custom" }) }, data.id));
11674
+ return (jsxRuntime.jsx("div", { className: "color-picker t-right", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "color", className: "form-color input-custom", onChange: _eventChange }) }, data.id));
11632
11675
  default:
11633
- return (jsxRuntime.jsx("div", { className: (data.type ?? 'normal') + '-input', title: data.description, children: jsxRuntime.jsx(Input$1, { type: data.type ?? '' }) }, data.id));
11676
+ return (jsxRuntime.jsx("div", { className: (data.type ?? 'normal') + '-input', title: data.description, children: jsxRuntime.jsx(Input$1, { type: data.type ?? '', onChange: _eventChange }) }, data.id));
11634
11677
  }
11635
11678
  };
11636
11679
  //hàm tạo các thông số cấu hình và cài đặt
@@ -11654,6 +11697,17 @@ const SettingApp = (props) => {
11654
11697
  };
11655
11698
 
11656
11699
  const INIT_CONFIG_SETTING = () => {
11700
+ _LOAD_();
11701
+ GetSettingConfig((data) => {
11702
+ if (data.status) {
11703
+ localStorage.setItem("INIT_CONFIG_SETTING", JSON.parse(data.data));
11704
+ }
11705
+ _LOAD_();
11706
+ });
11707
+ };
11708
+ //Nạp dữ liệu biến vào
11709
+ const _LOAD_ = () => {
11710
+ localStorage.getItem("INIT_CONFIG_SETTING");
11657
11711
  };
11658
11712
 
11659
11713
  exports.INIT_CONFIG_SETTING = INIT_CONFIG_SETTING;