ui-soxo-bootstrap-core 2.6.3 → 2.6.4

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.
@@ -99,9 +99,9 @@ export default class MenuTemplateAPI extends Component {
99
99
  }
100
100
 
101
101
 
102
- if (menu && menu.model_id) {
102
+ if (menu && menu?.model_id) {
103
103
 
104
- if (menu.model_id && allModels[menu.model.name]) {
104
+ if (menu?.model_id && allModels[menu?.model?.name]) {
105
105
 
106
106
  this.loadedModel = allModels[menu.model.name]
107
107
 
@@ -39,18 +39,18 @@ function CollapsedIconMenu({ menu, collapsed, icon, caption }) {
39
39
  // Import t and i18n from useTranslation
40
40
  const { t, i18n } = useTranslation();
41
41
  const { state } = useContext(GlobalContext);
42
- const [isMobile, setIsMobile] = useState(false);
42
+ const [isMobile, setIsMobile] = useState(false);
43
43
 
44
- useEffect(() => {
45
- const handleResize = () => {
46
- setIsMobile(window.innerWidth < 768); // Common breakpoint for mobile
47
- };
44
+ useEffect(() => {
45
+ const handleResize = () => {
46
+ setIsMobile(window.innerWidth < 768); // Common breakpoint for mobile
47
+ };
48
48
 
49
- handleResize(); // Set initial value
50
- window.addEventListener('resize', handleResize);
49
+ handleResize(); // Set initial value
50
+ window.addEventListener('resize', handleResize);
51
51
 
52
- return () => window.removeEventListener('resize', handleResize);
53
- }, []);
52
+ return () => window.removeEventListener('resize', handleResize);
53
+ }, []);
54
54
 
55
55
  const menuText = t(caption);
56
56
  const menuContent = (
@@ -85,8 +85,14 @@ function CollapsedIconMenu({ menu, collapsed, icon, caption }) {
85
85
  </>
86
86
  );
87
87
 
88
- // On mobile, or when the menu is collapsed (based on original logic), don't show the popover tooltip.
89
- return isMobile || collapsed ? menuContent : <Popover content={menuText} placement="right">{menuContent}</Popover>;
88
+ // On mobile, or when the menu is collapsed (based on original logic), don't show the popover tooltip.
89
+ return isMobile || collapsed ? (
90
+ menuContent
91
+ ) : (
92
+ <Popover content={menuText} placement="right">
93
+ {menuContent}
94
+ </Popover>
95
+ );
90
96
  }
91
97
 
92
98
  export default function SideMenu({ loading, modules = [], callback, appSettings, collapsed }) {
@@ -123,7 +129,7 @@ export default function SideMenu({ loading, modules = [], callback, appSettings,
123
129
  * Logout Function
124
130
  */
125
131
  async function handleLogout() {
126
- let dbPtrValue = appSettings.headers.db_ptr;
132
+ // let dbPtrValue = appSettings.headers.db_ptr;
127
133
  const isEnvThemeTrue = process.env.REACT_APP_THEME === 'true';
128
134
 
129
135
  // Only clear localStorage if theme is not 'true'
@@ -137,7 +143,7 @@ export default function SideMenu({ loading, modules = [], callback, appSettings,
137
143
  // const result = Users.logout()
138
144
  localStorage.clear();
139
145
 
140
- localStorage.setItem('db_ptr', dbPtrValue);
146
+ // localStorage.setItem('db_ptr', dbPtrValue);
141
147
 
142
148
  let userInfo = {
143
149
  dms: {},
@@ -30,7 +30,7 @@ import { getAccessToken, getRefreshToken } from '../../utils/http/auth.helper';
30
30
 
31
31
  import { Location } from '../../utils';
32
32
 
33
- import { checkLicenseStatus, formatMobile, checkExpiryStatus } from '../../utils/common/common.utils';
33
+ import { checkLicenseStatus, formatMobile, checkExpiryStatus, safeJSON } from '../../utils/common/common.utils';
34
34
 
35
35
  import { MailOutlined, MessageOutlined, WhatsAppOutlined } from '@ant-design/icons';
36
36
 
@@ -53,13 +53,17 @@ const LICENSE_EXPIRY = '2026-12-12';
53
53
  //password valdity expire
54
54
  const PASSWORD_VALIDITY_DAYS = 90;
55
55
 
56
+ const headers = {
57
+ db_ptr: 'nuraho',
58
+ };
59
+
56
60
  /**
57
61
  *
58
62
  * @param {*} param0
59
63
  * @returns
60
64
  */
61
65
  function LoginPhone({ history, appSettings }) {
62
- const { brandLogo, heroImage, footerLogo, headers } = appSettings;
66
+ const { brandLogo, heroImage, footerLogo } = appSettings;
63
67
 
64
68
  // Hook for OTP Timer
65
69
  const { expired: otpExpired, formatted, startFromExpiry } = useOtpTimer();
@@ -213,7 +217,7 @@ function LoginPhone({ history, appSettings }) {
213
217
  setUser(data);
214
218
  // Set default communication mode automatically
215
219
  if (result.data.mode) {
216
- setCommunicationMode(result.data.mode); // <--- fix
220
+ setCommunicationMode(result.data.mode);
217
221
  }
218
222
  } else {
219
223
  let d = user;
@@ -232,6 +236,17 @@ function LoginPhone({ history, appSettings }) {
232
236
  localStorage.setItem('userInfo', JSON.stringify(userInfo));
233
237
  if (refresh_token) localStorage.setItem('refresh_token', refresh_token);
234
238
 
239
+ // Setting DBPTR
240
+ if (user?.organization_details) {
241
+ const data = safeJSON(user?.organization_details);
242
+
243
+ const defaultBranch = data.branch.find((b) => b.defaultBranch === true);
244
+
245
+ const defaultDbptr = defaultBranch?.dbPtr;
246
+
247
+ localStorage.setItem('db_ptr', defaultDbptr);
248
+ }
249
+
235
250
  history.push('/');
236
251
  }
237
252
  } else {
@@ -392,6 +407,16 @@ function LoginPhone({ history, appSettings }) {
392
407
  // Setting refresh_token
393
408
  if (result.refresh_token) localStorage.setItem('refresh_token', result.refresh_token);
394
409
 
410
+ // Setting DBPTR
411
+ if (result?.user?.organization_details) {
412
+ const data = safeJSON(result?.user?.organization_details);
413
+
414
+ const defaultBranch = data.branch.find((b) => b.defaultBranch === 'true');
415
+ const defaultDbptr = defaultBranch?.dbPtr;
416
+
417
+ localStorage.setItem('db_ptr', defaultDbptr);
418
+ }
419
+
395
420
  dispatch({ type: 'user', payload: userInfo });
396
421
  // set user info into local storage
397
422
  localStorage.setItem('userInfo', JSON.stringify(userInfo));
@@ -768,7 +793,7 @@ function LoginPhone({ history, appSettings }) {
768
793
  <h4></h4>
769
794
  </div>
770
795
 
771
- {!process.env.REACT_APP_SHOW_BRANCH_SWITCHER && <div className="branch-switcher">{globalCustomerHeader()}</div>}
796
+ {/* {!process.env.REACT_APP_SHOW_BRANCH_SWITCHER && <div className="branch-switcher">{globalCustomerHeader()}</div>} */}
772
797
 
773
798
  {process.env.REACT_APP_ENABLE_LDAP === 'true' && (
774
799
  <Button loading={ldaploading} type="secondary" className="SubmitBtn" onClick={loginWithLdap}>
@@ -1,10 +1,4 @@
1
- import {
2
- PostData,
3
- GetData,
4
- PutData,
5
- PatchData,
6
- DeleteData,
7
- } from "./../http/http.utils";
1
+ import { PostData, GetData, PutData, PatchData, DeleteData } from './../http/http.utils';
8
2
 
9
3
  let headers = {};
10
4
 
@@ -29,75 +23,103 @@ export default class ApiUtils {
29
23
  return this.user;
30
24
  };
31
25
 
32
- static get = ({ url, config = { queries: [], order: {} }, ...props }) => {
33
- const { headers } = settings;
34
-
35
- return GetData({
36
- url: createUrlParams(url, config),
37
- settings,
38
- headers,
39
- ...props,
40
- }).catch((result) => {
41
- console.log(result);
42
- });
26
+ static get = async ({ url, config = { queries: [], order: {} }, headers: customHeaders = {}, ...props }) => {
27
+ const dbPtr = localStorage.getItem('db_ptr');
28
+
29
+ try {
30
+ return await GetData({
31
+ url: createUrlParams(url, config),
32
+ settings,
33
+ headers: {
34
+ ...(settings.headers || {}),
35
+ ...(dbPtr ? { db_ptr: dbPtr } : {}),
36
+ ...customHeaders,
37
+ },
38
+ ...props,
39
+ });
40
+ } catch (result_1) {
41
+ console.log(result_1);
42
+ }
43
43
  };
44
44
 
45
- static getRecordDetail = ({ url, config = { queries: [] }, ...props }) => {
46
- const { headers } = settings;
47
-
48
- return GetData({
49
- url: createUrlParams(url, config),
50
- settings,
51
- headers,
52
- ...props,
53
- }).catch((result) => {
54
- console.log(result);
55
- });
45
+ static getRecordDetail = async ({ url, config = { queries: [] }, headers: customHeaders = {}, ...props }) => {
46
+ const dbPtr = localStorage.getItem('db_ptr');
47
+
48
+ try {
49
+ return await GetData({
50
+ url: createUrlParams(url, config),
51
+ settings,
52
+ headers: {
53
+ ...(settings.headers || {}),
54
+ ...(dbPtr ? { db_ptr: dbPtr } : {}),
55
+ ...customHeaders,
56
+ },
57
+ ...props,
58
+ });
59
+ } catch (result_1) {
60
+ console.log(result_1);
61
+ }
56
62
  };
57
63
 
58
- static post = ({ url, formBody, ...props }) => {
59
- const { headers } = settings;
64
+ static post = ({ url, formBody, headers: customHeaders = {}, ...props }) => {
65
+ const dbPtr = localStorage.getItem('db_ptr');
60
66
 
61
67
  return PostData({
62
68
  url,
63
69
  formBody,
64
70
  settings,
65
- headers,
71
+ headers: {
72
+ ...(settings.headers || {}),
73
+ ...(dbPtr ? { db_ptr: dbPtr } : {}),
74
+ ...customHeaders,
75
+ },
66
76
  ...props,
67
77
  });
68
78
  };
69
79
 
70
- static put = ({ url, formBody, ...props }) => {
71
- const { headers } = settings;
80
+ static put = ({ url, formBody, headers: customHeaders = {}, ...props }) => {
81
+ const dbPtr = localStorage.getItem('db_ptr');
72
82
 
73
83
  return PutData({
74
84
  url,
75
85
  settings,
76
86
  formBody,
77
- headers,
87
+ headers: {
88
+ ...(settings.headers || {}),
89
+ ...(dbPtr ? { db_ptr: dbPtr } : {}),
90
+ ...customHeaders,
91
+ },
78
92
  ...props,
79
93
  });
80
94
  };
81
95
 
82
- static patch = ({ url, formBody, ...props }) => {
83
- const { headers } = settings;
96
+ static patch = ({ url, formBody, headers: customHeaders = {}, ...props }) => {
97
+ const dbPtr = localStorage.getItem('db_ptr');
84
98
 
85
99
  return PatchData({
86
100
  url,
87
101
  settings,
88
102
  formBody,
89
- headers,
103
+ headers: {
104
+ ...(settings.headers || {}),
105
+ ...(dbPtr ? { db_ptr: dbPtr } : {}),
106
+ ...customHeaders,
107
+ },
90
108
  ...props,
91
109
  });
92
110
  };
93
111
 
94
- static delete = ({ url, formBody, ...props }) => {
95
- const { headers } = settings;
112
+ static delete = ({ url, formBody, headers: customHeaders = {}, ...props }) => {
113
+ const dbPtr = localStorage.getItem('db_ptr');
96
114
 
97
115
  return DeleteData({
98
116
  url,
99
117
  settings,
100
- headers,
118
+ headers: {
119
+ ...(settings.headers || {}),
120
+ ...(dbPtr ? { db_ptr: dbPtr } : {}),
121
+ ...customHeaders,
122
+ },
101
123
  ...props,
102
124
  });
103
125
  };
@@ -105,11 +127,11 @@ export default class ApiUtils {
105
127
  static upload = ({ url, data }) => {
106
128
  return fetch(process.env.REACT_APP_endpoint + url, {
107
129
  // Your POST endpoint
108
- method: "POST",
130
+ method: 'POST',
109
131
  headers: {
110
132
  // 'App-Type': 313,
111
133
  // 'App-Version': '1.0.1',
112
- Authorization: "Bearer " + localStorage.access_token,
134
+ Authorization: 'Bearer ' + localStorage.access_token,
113
135
  // type:'multipart/formData'
114
136
  },
115
137
  // credentials: 'include',
@@ -136,16 +158,17 @@ export default class ApiUtils {
136
158
  * @returns
137
159
  */
138
160
  static getAuthStatus = ({ settings: config, token }) => {
139
- headers = headers;
161
+ // headers = headers;
140
162
 
141
163
  settings = config;
142
164
 
143
165
  return GetData({
144
166
  url: `auth/profile`,
145
167
  settings,
146
-
147
- headers,
148
- token
168
+ headers: {
169
+ db_ptr: 'nuraho',
170
+ },
171
+ token,
149
172
  });
150
173
  };
151
174
  }
@@ -159,7 +182,7 @@ function createUrlParams(url, config) {
159
182
  let { queries = [], limit, order } = config;
160
183
 
161
184
  if (queries.length > 0 || limit > 0) {
162
- base_url += "?";
185
+ base_url += '?';
163
186
  }
164
187
 
165
188
  queries.forEach((ele) => {
@@ -197,3 +197,27 @@ export const formatMobile = (mobile, visibleDigits = 4) => {
197
197
  // Combine masked and visible parts without spacing the visible digits
198
198
  return `${maskedWithSpaces} ${visible}`;
199
199
  };
200
+
201
+ /**
202
+ * Safely parse a JSON value.
203
+ *
204
+ * - Accepts JSON strings or plain objects
205
+ * - Returns null on any invalid or missing data
206
+ */
207
+ export function safeJSON(value) {
208
+ if (value == null) return null;
209
+
210
+ if (typeof value === 'object' && !Array.isArray(value)) {
211
+ return value;
212
+ }
213
+
214
+ if (typeof value !== 'string' || value.trim() === '') {
215
+ return null;
216
+ }
217
+
218
+ try {
219
+ return JSON.parse(value);
220
+ } catch {
221
+ return null;
222
+ }
223
+ }
@@ -1,10 +1,8 @@
1
-
2
-
3
- import { Location } from './location/location.utils'
1
+ import { Location } from './location/location.utils';
4
2
 
5
3
  import Notification from './notification.utils';
6
4
 
7
- import DateUtils from './date/date.utils'
5
+ import DateUtils from './date/date.utils';
8
6
 
9
7
  import ApiUtils from './api/api.utils';
10
8
 
@@ -16,31 +14,27 @@ import { GetData, PostData, PutData, DeleteData } from './http/http.utils';
16
14
 
17
15
  import { getExportData } from './generic/generic.utils';
18
16
 
19
- import { ConvertBytesToArray } from './common/common.utils';
17
+ import { ConvertBytesToArray, safeJSON } from './common/common.utils';
20
18
 
21
19
  import SettingsUtil from './setting.utils';
22
20
 
23
-
24
21
  export {
25
- // FirebaseUtils,
26
-
27
- Notification,
28
-
29
- Location,
30
- DateUtils,
31
- ApiUtils,
32
- UploadUtils,
33
- GetData,
34
- PostData,
35
- PutData,
36
- DeleteData,
37
-
38
- getExportData,
39
-
40
-
41
- // Common Functions
42
- ConvertBytesToArray,
43
-
44
- SettingsUtil,
45
- FormUtils
46
- }
22
+ // FirebaseUtils,
23
+
24
+ Notification,
25
+ Location,
26
+ DateUtils,
27
+ ApiUtils,
28
+ UploadUtils,
29
+ GetData,
30
+ PostData,
31
+ PutData,
32
+ DeleteData,
33
+ getExportData,
34
+
35
+ // Common Functions
36
+ ConvertBytesToArray,
37
+ SettingsUtil,
38
+ FormUtils,
39
+ safeJSON,
40
+ };
@@ -88,9 +88,13 @@ class BaseAPI {
88
88
  * Get the data from the table
89
89
  */
90
90
  get(config = {}) {
91
- // Get the records from firebase
92
-
93
- return ApiUtils.get({ url: config.url || this.endpoint, config });
91
+ const { url, headers, ...rest } = config;
92
+ return ApiUtils.get({
93
+ url: url || this.endpoint,
94
+ headers,
95
+ config: rest,
96
+ ...rest,
97
+ });
94
98
  }
95
99
 
96
100
  getRelations(id) {
@@ -474,7 +474,7 @@ function panelActions(item, model, setSelectedRecord, setDrawerTitle, setDrawerV
474
474
  </Button>
475
475
  )}
476
476
 
477
- {/* <Button
477
+ <Button
478
478
  size="small"
479
479
  type="default"
480
480
  onClick={() => {
@@ -484,7 +484,7 @@ function panelActions(item, model, setSelectedRecord, setDrawerTitle, setDrawerV
484
484
  }}
485
485
  >
486
486
  <CopyOutlined />
487
- </Button> */}
487
+ </Button>
488
488
 
489
489
  <Popconfirm title="Are you sure?" onConfirm={() => deleteRecord(item)}>
490
490
  <Button danger size="small" type="default">
@@ -177,28 +177,47 @@ class MenusAPI extends Base {
177
177
  * @param {*} menu
178
178
  * @returns
179
179
  */
180
- getMenus = (config) => {
180
+ getMenus = (config, dbPtr = null) => {
181
181
  // Use 'core-menus' endpoint if REACT_APP_USE_CORE_MENUS is true (used for Matria)
182
182
  const url =
183
183
  process.env.REACT_APP_USE_CORE_MENUS === 'true'
184
184
  ? 'core-menus/get-menus' // Matria
185
185
  : 'menus/get-menus'; // NURA
186
186
 
187
+ if (!dbPtr) dbPtr = localStorage.db_ptr;
188
+
187
189
  return this.get({
188
190
  url,
189
191
  config,
192
+ headers: {
193
+ db_ptr: dbPtr,
194
+ },
195
+ }).then((result) => result);
196
+ };
197
+
198
+ getMenubyUser = (user_id) => {
199
+ const url = `menus/get-menus?userId=${user_id}`;
200
+ return this.get({
201
+ url,
190
202
  }).then((result) => result);
191
203
  };
192
204
 
193
205
  // get core-menu list with submenu
194
206
  getCoreMenuLists = () => {
195
207
  const url = 'core-menus/core-menus?step=1&header_id=null';
196
-
197
208
  return this.get({
198
209
  url,
199
210
  }).then((result) => result);
200
211
  };
201
212
 
213
+ getCoreMenuByRoleId = async (role_id) => {
214
+ const url = `menus/get-menus-by-role/${role_id}`;
215
+ const result = await this.get({
216
+ url,
217
+ });
218
+ return result;
219
+ };
220
+
202
221
  getCoreMenus = () => {
203
222
  return [
204
223
  // {