@esvndev/es-react-config-setting 1.0.68 → 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.
package/dist/index.mjs CHANGED
@@ -18698,14 +18698,20 @@ const GetSettingGroup = (callback) => {
18698
18698
  callback({ status: false, data: error });
18699
18699
  });
18700
18700
  };
18701
- const GetSettingConfig = (callback) => {
18702
- const _url = `${BASE_URL}/api/config/get-setting-config`;
18701
+ const GetSettingConfigClient = (callback) => {
18702
+ const _url = `${BASE_URL}/api/config/get-setting-config-client`;
18703
+ const _obj = {
18704
+ ModuleId: REACT_APP_PRODUCT_CODE,
18705
+ StateId: '',
18706
+ Option: JSON.stringify({ version: localStorage.getItem("app_config_setting_version") })
18707
+ };
18703
18708
  const options = {
18704
- method: 'GET',
18709
+ method: 'POST',
18705
18710
  headers: {
18706
18711
  'Content-Type': 'application/json',
18707
18712
  Authorization: `Bearer ${getToken()}`,
18708
18713
  },
18714
+ body: JSON.stringify(_obj)
18709
18715
  };
18710
18716
  fetch(_url, options)
18711
18717
  .then(response => {
@@ -18717,17 +18723,17 @@ const GetSettingConfig = (callback) => {
18717
18723
  })
18718
18724
  .then(text => {
18719
18725
  if (text) {
18726
+ let _ = "";
18720
18727
  try {
18721
- JSON.parse(text); // Kiểm tra nếu là JSON hợp lệ
18722
- console.log('Response JSON string:', text);
18728
+ _ = JSON.parse(text);
18729
+ callback(_);
18723
18730
  }
18724
18731
  catch (err) {
18725
18732
  console.log('Invalid JSON:', err);
18726
18733
  }
18727
- callback({ status: true, data: JSON.parse(text) });
18728
18734
  }
18729
18735
  else {
18730
- callback({ status: false, data: text });
18736
+ callback({ status: false });
18731
18737
  }
18732
18738
  })
18733
18739
  .catch(error => {
@@ -18988,18 +18994,50 @@ const SettingApp = (props) => {
18988
18994
  : null }));
18989
18995
  };
18990
18996
 
18997
+ const GLOBAL_WINDOW_VARIABLE = {};
18998
+ let intervalId = null;
18999
+ //Load interval data default
18991
19000
  const INIT_CONFIG_SETTING = () => {
18992
- _LOAD_();
18993
- GetSettingConfig((data) => {
18994
- if (data.status) {
18995
- localStorage.setItem("INIT_CONFIG_SETTING", JSON.parse(data.data));
19001
+ _LOAD_(null);
19002
+ if (intervalId) {
19003
+ clearInterval(intervalId);
19004
+ intervalId = null;
19005
+ }
19006
+ intervalId = setInterval(() => {
19007
+ _FETCH_AND_UPDATE();
19008
+ }, 5000);
19009
+ };
19010
+ const _FETCH_AND_UPDATE = () => {
19011
+ GetSettingConfigClient((data) => {
19012
+ try {
19013
+ if (data?.status && data?.isupdate && data?.data) {
19014
+ localStorage.setItem("init_config_setting", JSON.stringify(data.data));
19015
+ localStorage.setItem("app_config_setting_version", data.version);
19016
+ _LOAD_(data.data);
19017
+ }
19018
+ }
19019
+ catch (e) {
19020
+ console.log("Failed to save config to localStorage:", e);
18996
19021
  }
18997
- _LOAD_();
18998
19022
  });
18999
19023
  };
19000
- //Nạp dữ liệu biến vào
19001
- const _LOAD_ = () => {
19002
- localStorage.getItem("INIT_CONFIG_SETTING");
19024
+ //Add variable to localstorage
19025
+ const _LOAD_ = (data) => {
19026
+ let _ = {};
19027
+ if (!data) {
19028
+ const _json = localStorage.getItem("init_config_setting");
19029
+ try {
19030
+ _ = JSON.parse(_json ?? '{}');
19031
+ }
19032
+ catch (ex) { }
19033
+ }
19034
+ Object.keys(GLOBAL_WINDOW_VARIABLE).forEach(key => delete GLOBAL_WINDOW_VARIABLE[key]);
19035
+ try {
19036
+ for (var _p in _) {
19037
+ GLOBAL_WINDOW_VARIABLE[_p] = _[_p];
19038
+ }
19039
+ }
19040
+ catch (ex) { }
19003
19041
  };
19004
19042
 
19005
19043
  registerLicense('ORg4AjUWIQA/Gnt2VVhiQlFadVlJXmJWf1FpTGpQdk5yd19DaVZUTX1dQl9hSXlTckVmXHtfcHNVRGM=');