@esvndev/es-react-config-setting 1.0.67 → 1.0.69

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.
@@ -1,2 +1,2 @@
1
+ export declare const GLOBAL_WINDOW_VARIABLE: Record<string, any>;
1
2
  export declare const INIT_CONFIG_SETTING: () => void;
2
- export declare const INIT_CONFIG_UPDATE: (data: any) => void;
package/dist/index.js CHANGED
@@ -18725,14 +18725,20 @@ const GetSettingGroup = (callback) => {
18725
18725
  callback({ status: false, data: error });
18726
18726
  });
18727
18727
  };
18728
- const GetSettingConfig = (callback) => {
18729
- const _url = `${BASE_URL}/api/config/get-setting-config`;
18728
+ const GetSettingConfigClient = (callback) => {
18729
+ const _url = `${BASE_URL}/api/config/get-setting-config-client`;
18730
+ const _obj = {
18731
+ ModuleId: REACT_APP_PRODUCT_CODE,
18732
+ StateId: '',
18733
+ Option: JSON.stringify({ version: localStorage.getItem("app_config_setting_version") })
18734
+ };
18730
18735
  const options = {
18731
- method: 'GET',
18736
+ method: 'POST',
18732
18737
  headers: {
18733
18738
  'Content-Type': 'application/json',
18734
18739
  Authorization: `Bearer ${getToken()}`,
18735
18740
  },
18741
+ body: JSON.stringify(_obj)
18736
18742
  };
18737
18743
  fetch(_url, options)
18738
18744
  .then(response => {
@@ -18744,17 +18750,17 @@ const GetSettingConfig = (callback) => {
18744
18750
  })
18745
18751
  .then(text => {
18746
18752
  if (text) {
18753
+ let _ = "";
18747
18754
  try {
18748
- JSON.parse(text); // Kiểm tra nếu là JSON hợp lệ
18749
- console.log('Response JSON string:', text);
18755
+ _ = JSON.parse(text);
18756
+ callback(_);
18750
18757
  }
18751
18758
  catch (err) {
18752
18759
  console.log('Invalid JSON:', err);
18753
18760
  }
18754
- callback({ status: true, data: JSON.parse(text) });
18755
18761
  }
18756
18762
  else {
18757
- callback({ status: false, data: text });
18763
+ callback({ status: false });
18758
18764
  }
18759
18765
  })
18760
18766
  .catch(error => {
@@ -18804,6 +18810,7 @@ const UpdateSettingConfig = (obj, file, callback) => {
18804
18810
  const _url = `${BASE_URL}/api/config/update-setting-config`;
18805
18811
  const formData = new FormData();
18806
18812
  formData.append(`GroupId`, obj.GroupId);
18813
+ formData.append(`ModuleId`, REACT_APP_PRODUCT_CODE ?? "");
18807
18814
  obj.Items.forEach((item, index) => {
18808
18815
  formData.append(`Items[${index}].Key`, item.Key);
18809
18816
  formData.append(`Items[${index}].Value`, item.Value);
@@ -19014,18 +19021,50 @@ const SettingApp = (props) => {
19014
19021
  : null }));
19015
19022
  };
19016
19023
 
19024
+ const GLOBAL_WINDOW_VARIABLE = {};
19025
+ let intervalId = null;
19026
+ //Load interval data default
19017
19027
  const INIT_CONFIG_SETTING = () => {
19018
- _LOAD_();
19019
- GetSettingConfig((data) => {
19020
- if (data.status) {
19021
- localStorage.setItem("INIT_CONFIG_SETTING", JSON.parse(data.data));
19028
+ _LOAD_(null);
19029
+ if (intervalId) {
19030
+ clearInterval(intervalId);
19031
+ intervalId = null;
19032
+ }
19033
+ intervalId = setInterval(() => {
19034
+ _FETCH_AND_UPDATE();
19035
+ }, 5000);
19036
+ };
19037
+ const _FETCH_AND_UPDATE = () => {
19038
+ GetSettingConfigClient((data) => {
19039
+ try {
19040
+ if (data?.status && data?.isupdate && data?.data) {
19041
+ localStorage.setItem("init_config_setting", JSON.stringify(data.data));
19042
+ localStorage.setItem("app_config_setting_version", data.version);
19043
+ _LOAD_(data.data);
19044
+ }
19045
+ }
19046
+ catch (e) {
19047
+ console.log("Failed to save config to localStorage:", e);
19022
19048
  }
19023
- _LOAD_();
19024
19049
  });
19025
19050
  };
19026
- //Nạp dữ liệu biến vào
19027
- const _LOAD_ = () => {
19028
- localStorage.getItem("INIT_CONFIG_SETTING");
19051
+ //Add variable to localstorage
19052
+ const _LOAD_ = (data) => {
19053
+ let _ = {};
19054
+ if (!data) {
19055
+ const _json = localStorage.getItem("init_config_setting");
19056
+ try {
19057
+ _ = JSON.parse(_json ?? '{}');
19058
+ }
19059
+ catch (ex) { }
19060
+ }
19061
+ Object.keys(GLOBAL_WINDOW_VARIABLE).forEach(key => delete GLOBAL_WINDOW_VARIABLE[key]);
19062
+ try {
19063
+ for (var _p in _) {
19064
+ GLOBAL_WINDOW_VARIABLE[_p] = _[_p];
19065
+ }
19066
+ }
19067
+ catch (ex) { }
19029
19068
  };
19030
19069
 
19031
19070
  registerLicense('ORg4AjUWIQA/Gnt2VVhiQlFadVlJXmJWf1FpTGpQdk5yd19DaVZUTX1dQl9hSXlTckVmXHtfcHNVRGM=');