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.
@@ -6,7 +6,7 @@ import { Skeleton, Typography, message, Switch, Form, Input, Select, Checkbox, R
6
6
 
7
7
  import AsyncSelect from 'react-select/async';
8
8
 
9
- import { Table, Card, Button, JSONInput, GlobalContext } from './../../../../lib/';
9
+ import { Table, Card, Button, JSONInput, GlobalContext, safeJSON } from './../../../../lib/';
10
10
 
11
11
  import { ModelsAPI, PagesAPI, RolesAPI } from '../../..';
12
12
 
@@ -30,7 +30,7 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
30
30
  const [selectedBranches, setSelectedBranches] = useState([]);
31
31
 
32
32
  // for default branch
33
- const [defaultBranch, setDefaultBranch] = useState(null);
33
+ // const [defaultBranch, setDefaultBranch] = useState(null);
34
34
  //Need to check this condition
35
35
  const [authentication, setAuthentication] = useState(false);
36
36
 
@@ -42,7 +42,7 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
42
42
  const [selectedStaff, setSelectedStaff] = useState(null);
43
43
  const [staffList, setStaffList] = useState([]);
44
44
  /**Converting to JSON */
45
- let firmDetails = JSON.parse(user.firm.f_otherdetails1);
45
+ const firmDetails = safeJSON(user?.firm?.f_otherdetails1) ?? {};
46
46
 
47
47
  /**Variable for cheaking mandatory condition of mobile*/
48
48
  let mobileRequired;
@@ -270,8 +270,6 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
270
270
  const getStaff = () => {
271
271
  UsersAPI.getAllStaff()
272
272
  .then((res) => {
273
- console.log('Staff List Response:', res);
274
-
275
273
  if (Array.isArray(res)) {
276
274
  const list = res.map((staff) => ({
277
275
  label: `${staff.shortName || 'No Name'} (${staff.id})`,
@@ -325,20 +323,25 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
325
323
  }
326
324
  if (!formContent) return;
327
325
 
328
- // normalize branch ids to NUMBER
329
326
  const org =
330
327
  typeof formContent.organization_details === 'string' ? JSON.parse(formContent.organization_details) : formContent.organization_details;
331
328
 
329
+ // normalize branch ids to NUMBER
332
330
  const branchIds = (org?.branch_ids || []).map(Number);
333
- const defaultBr = formContent.defaultBranch ? Number(formContent.defaultBranch) : null;
331
+
332
+ // find default branch pointer
333
+ const defaultBranchObj = org?.branch?.find((br) => br.defaultBranch);
334
+
335
+ // extract dbPtr (branch code)
336
+ const defaultBranchCode = defaultBranchObj?.branch_id ? Number(defaultBranchObj.branch_id) : undefined;
334
337
 
335
338
  // state (for filtering)
336
339
  setSelectedBranches(branchIds);
337
340
 
338
- // form (source of truth)
341
+ // form values
339
342
  form.setFieldsValue({
340
343
  selectedBranches: branchIds,
341
- defaultBranch: defaultBr,
344
+ defaultBranch: defaultBranchCode,
342
345
  });
343
346
  }, [formContent, form]);
344
347
  // Generate branch options for Select component
@@ -669,7 +672,7 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
669
672
  <Col span={8}>
670
673
  {/* Default Branch */}
671
674
  <Form.Item label="Default Branch" name="defaultBranch" rules={[{ required: true, message: 'Please select default branch' }]}>
672
- <Select placeholder="Select Default Branch" onChange={setDefaultBranch}>
675
+ <Select placeholder="Select Default Branch">
673
676
  {branchOptions
674
677
  .filter((opt) => selectedBranches.includes(Number(opt.value)))
675
678
  .map((opt) => (
@@ -37,6 +37,13 @@ export default function UserEdit(record) {
37
37
  } catch (e) {
38
38
  orgDetails = {};
39
39
  }
40
+
41
+ // find default branch pointer
42
+ const defaultBranchObj = orgDetails?.branch?.find((br) => br.defaultBranch);
43
+
44
+ // extract dbPtr (branch code)
45
+ const defaultBranchCode = defaultBranchObj?.branch_id ? Number(defaultBranchObj.branch_id) : undefined;
46
+
40
47
  // Construct mapped data object
41
48
  const mappedData = {
42
49
  id: apiData.id,
@@ -49,7 +56,7 @@ export default function UserEdit(record) {
49
56
  // Handle selected branches and default branch
50
57
  organization_details: orgDetails,
51
58
  selectedBranches: orgDetails.branch_ids || [],
52
- defaultBranch: apiData.branch_id || null,
59
+ defaultBranch: defaultBranchCode || null,
53
60
  role_id: apiData.role_id,
54
61
  password: apiData.password,
55
62
  user_group: apiData.user_group,
@@ -81,7 +88,17 @@ export default function UserEdit(record) {
81
88
  <Skeleton active />
82
89
  </div>
83
90
  ) : (
84
- <UserAdd mode="Edit" formContent={userData} callback={() => setVisible(false)} edit={true} />
91
+ <UserAdd
92
+ mode="Edit"
93
+ formContent={userData}
94
+ callback={() => {
95
+ setVisible(false);
96
+ if (record.callback) {
97
+ record.callback();
98
+ }
99
+ }}
100
+ edit={true}
101
+ />
85
102
  )}
86
103
  </Modal>
87
104
  </div>
@@ -149,7 +149,13 @@ class Users extends Base {
149
149
  * @returns
150
150
  */
151
151
  create = (formBody) => {
152
- return ApiUtils.post({ url: `users/create-user`, formBody });
152
+ return ApiUtils.post({
153
+ url: `users/create-user`,
154
+ formBody,
155
+ headers: {
156
+ db_ptr: 'nuraho',
157
+ },
158
+ });
153
159
  };
154
160
 
155
161
  /**
@@ -161,7 +167,7 @@ class Users extends Base {
161
167
  return ApiUtils.get({
162
168
  url: `branch-master/get-records`,
163
169
  headers: {
164
- db_ptr: process.env.REACT_APP_HO_DB_PTR,
170
+ db_ptr: 'nuraho',
165
171
  },
166
172
  });
167
173
  };
@@ -271,25 +277,35 @@ class Users extends Base {
271
277
  * @returns
272
278
  */
273
279
  updateUser = ({ id, formBody }) => {
274
- return ApiUtils.put({ url: `users/update-user/${id}`, formBody });
280
+ return ApiUtils.put({
281
+ url: `users/update-user/${id}`,
282
+ formBody,
283
+ headers: {
284
+ db_ptr: 'nuraho',
285
+ },
286
+ });
275
287
  };
276
-
288
+
277
289
  /* The `getUser` method is a function that takes an object with an `id` property as a parameter. It
278
290
  then uses the `ApiUtils.get` function to make a GET request to the endpoint `users/` to fetch
279
291
  user data based on the provided `id`. This method is used to retrieve a specific user's
280
292
  information from the API. */
281
293
 
282
294
  getUser = ({ id }) => {
283
- return ApiUtils.get({ url: `users/${id}` });
295
+ return ApiUtils.get({
296
+ url: `users/${id}`,
297
+ headers: {
298
+ db_ptr: 'nuraho',
299
+ },
300
+ });
284
301
  };
285
- /* The `getUserRole` method is a function that takes an object with an `id` property as a parameter.
302
+ /* The `getUserRole` method is a function that takes an object with an `id` property as a parameter.
286
303
  It then uses the `ApiUtils.get` function to make a GET request to the endpoint `core-user-roles`
287
304
  with the `user_id` parameter set to the provided `id`. This method is used to fetch the role or
288
305
  roles associated with a specific user from the API. */
289
-
306
+
290
307
  getUserRole = ({ id }) => {
291
308
  return ApiUtils.get({ url: `core-user-roles?user_id=${id}&active=Y` });
292
-
293
309
  };
294
310
 
295
311
  /**
@@ -292,8 +292,11 @@ export default function ReportingDashboard({
292
292
  }
293
293
  // Fetch result
294
294
  const result = await CoreScripts.getReportingLisitng(coreScriptId, formBody, dbPtr);
295
+
296
+ const apiData = Array.isArray(result) ? result : Array.isArray(result?.result) ? result.result : [];
297
+
295
298
  // Handle both result formats
296
- let resultDetails = result[0];
299
+ let resultDetails = apiData[0] || [];
297
300
  if (result?.result && result?.result[0]) {
298
301
  resultDetails = result.result[0];
299
302
  }
@@ -324,7 +327,6 @@ export default function ReportingDashboard({
324
327
  }
325
328
  } catch (error) {
326
329
  console.error('Error fetching report data:', error);
327
- message.warn('Please try again');
328
330
  } finally {
329
331
  // Always runs, success or error
330
332
  setLoading(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-soxo-bootstrap-core",
3
- "version": "2.6.3",
3
+ "version": "2.6.4",
4
4
  "description": "All the Core Components for you to start",
5
5
  "keywords": [
6
6
  "all in one"