@esvndev/es-react-config-setting 1.0.50 → 1.0.51

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
@@ -18798,6 +18798,31 @@ const GetSettingConfigByGroup = (obj, callback) => {
18798
18798
  callback({ status: false, data: error });
18799
18799
  });
18800
18800
  };
18801
+ //Update setting data
18802
+ const UpdateSettingConfig = (obj, file, callback) => {
18803
+ const _url = `${BASE_URL}/api/config/update-setting-config`;
18804
+ const formData = new FormData();
18805
+ // Gửi từng item theo dạng Items[0].Key, Items[0].Value...
18806
+ obj.Items.forEach((item, index) => {
18807
+ formData.append(`Items[${index}].Key`, item.Key);
18808
+ formData.append(`Items[${index}].Value`, item.Value);
18809
+ formData.append(`Items[${index}].SortOrder`, item.SortOrder ?? 1);
18810
+ });
18811
+ if (file) {
18812
+ formData.append("file", file);
18813
+ }
18814
+ const options = {
18815
+ method: 'POST',
18816
+ headers: {
18817
+ Authorization: `Bearer ${getToken()}`
18818
+ },
18819
+ body: formData
18820
+ };
18821
+ fetch(_url, options)
18822
+ .then(res => res.json())
18823
+ .then(data => callback({ status: true, data }))
18824
+ .catch(error => callback({ status: false, data: error }));
18825
+ };
18801
18826
 
18802
18827
  const SettingApp = (props) => {
18803
18828
  const { isOpen, eventChange, eventClose } = { ...props };
@@ -18823,14 +18848,23 @@ const SettingApp = (props) => {
18823
18848
  const handleFormClosed = () => {
18824
18849
  };
18825
18850
  //Sự kiện giá trị thay đổi
18826
- const _eventChange = (data) => {
18851
+ const _eventChange = (key, data) => {
18827
18852
  if (data.target) {
18853
+ var _value = "";
18828
18854
  if (data.target.type === 'checkbox') {
18829
- console.log("new data", data.target.checked);
18855
+ _value = data.target.checked ? 'true' : 'false';
18830
18856
  }
18831
18857
  else {
18832
- console.log("new data", data.target.value);
18858
+ _value = data.target.value;
18833
18859
  }
18860
+ UpdateSettingConfig({
18861
+ Items: [{
18862
+ Key: key,
18863
+ Value: _value
18864
+ }]
18865
+ }, null, (rs) => {
18866
+ console.log(rs);
18867
+ });
18834
18868
  if (eventChange)
18835
18869
  eventChange([{ key: "x", value: "x", state: "update" }]);
18836
18870
  }
@@ -18880,34 +18914,35 @@ const SettingApp = (props) => {
18880
18914
  };
18881
18915
  //Hàm sử dụng tạo theo loại giá trị
18882
18916
  const _renderInput = (root, data) => {
18917
+ console.log(data);
18883
18918
  switch (data.type) {
18884
18919
  case "switch":
18885
18920
  case "checkbox":
18886
- return (jsxRuntime.jsx("div", { className: "checkbox", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "checkbox", className: "", onChange: _eventChange }) }, data.id));
18921
+ return (jsxRuntime.jsx("div", { className: "checkbox", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "checkbox", className: "", onChange: (e) => _eventChange(data, e) }) }, data.id));
18887
18922
  case "radio":
18888
- 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));
18923
+ 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: (e) => _eventChange(data, e) }), opt.name] }, index))) }, data.id));
18889
18924
  case "combobox":
18890
- 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));
18925
+ 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: (e) => _eventChange(data, e), 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));
18891
18926
  case "slider":
18892
18927
  case "text":
18893
- 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));
18928
+ return (jsxRuntime.jsx("div", { className: "text-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "text", className: "input-custom", placeholder: data.name, onChange: (e) => _eventChange(data, e) }) }, data.id));
18894
18929
  case "password":
18895
- 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));
18930
+ return (jsxRuntime.jsx("div", { className: "text-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "password", className: "input-custom", placeholder: data.name, onChange: (e) => _eventChange(data, e) }) }, data.id));
18896
18931
  case "number":
18897
- 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));
18932
+ 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: (e) => _eventChange(data, e) }) }, data.id));
18898
18933
  case "date":
18899
- 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));
18934
+ return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "date", className: "t-right input-custom", onChange: (e) => _eventChange(data, e) }) }, data.id));
18900
18935
  case "time":
18901
- 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));
18936
+ return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "time", className: "t-right input-custom", onChange: (e) => _eventChange(data, e) }) }, data.id));
18902
18937
  case "datetime":
18903
- 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));
18938
+ return (jsxRuntime.jsx("div", { className: "date-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "datetime", className: "t-right input-custom", onChange: (e) => _eventChange(data, e) }) }, data.id));
18904
18939
  case "image":
18905
18940
  case "file":
18906
- return (jsxRuntime.jsx("div", { className: "file-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "file", className: "input-custom", onChange: _eventChange }) }, data.id));
18941
+ return (jsxRuntime.jsx("div", { className: "file-input", title: data.description, children: jsxRuntime.jsx(Input$1, { type: "file", className: "input-custom", onChange: (e) => _eventChange(data, e) }) }, data.id));
18907
18942
  case "color":
18908
- 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));
18943
+ 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: (e) => _eventChange(data, e) }) }, data.id));
18909
18944
  default:
18910
- return (jsxRuntime.jsx("div", { className: (data.type ?? 'normal') + '-input', title: data.description, children: jsxRuntime.jsx(Input$1, { type: data.type ?? '', onChange: _eventChange }) }, data.id));
18945
+ return (jsxRuntime.jsx("div", { className: (data.type ?? 'normal') + '-input', title: data.description, children: jsxRuntime.jsx(Input$1, { type: data.type ?? '', onChange: (e) => _eventChange(data, e) }) }, data.id));
18911
18946
  }
18912
18947
  };
18913
18948
  //hàm tạo các thông số cấu hình và cài đặt