ui-soxo-bootstrap-core 2.4.25-dev.14 → 2.4.25-dev.15

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.
@@ -160,6 +160,17 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
160
160
  }
161
161
  }
162
162
  }, []);
163
+
164
+ useEffect(() => {
165
+ if (!loading && formContent?.role_id && roles.length > 0) {
166
+ const roleId = Number(formContent.role_id);
167
+
168
+ if (!Number.isNaN(roleId)) {
169
+ form.setFieldsValue({ role_id: roleId });
170
+ }
171
+ }
172
+ }, [loading, formContent, roles]);
173
+
163
174
  /**
164
175
  *Define the options dynamically
165
176
  */
@@ -203,7 +214,6 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
203
214
  }
204
215
  })
205
216
  .catch((error) => {
206
- console.error('Error fetching designations:', error);
207
217
  setDesignations([]);
208
218
  })
209
219
  .finally(() => setLoading(false));
@@ -215,16 +225,10 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
215
225
  function getRoles() {
216
226
  RolesAPI.getRole()
217
227
  .then((res) => {
218
- // if API returns { statusCode: 200, result: [...] }
219
- if (Array.isArray(res.result)) {
220
- setRoles(res.result.filter((r) => r.active === 'Y')); // optional: only active roles
221
- } else {
222
- setRoles([]);
223
- }
228
+ const activeRoles = Array.isArray(res.result) ? res.result.filter((r) => r.active === 'Y') : [];
229
+ setRoles(activeRoles);
224
230
  })
225
- .catch((err) => {
226
- setRoles([]);
227
- });
231
+ .catch(() => setRoles([]));
228
232
  }
229
233
 
230
234
  /** Get Department List */
@@ -243,7 +247,6 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
243
247
  }
244
248
  })
245
249
  .catch((error) => {
246
- console.error('Error fetching departments:', error);
247
250
  setDepartments([]);
248
251
  })
249
252
  .finally(() => setLoading(false));
@@ -320,25 +323,24 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
320
323
  form.setFieldsValue({ staff_code: formContent.staff_code });
321
324
  }
322
325
  }
323
- if (formContent?.id && formContent?.organization_details) {
324
- try {
325
- const org = JSON.parse(formContent.organization_details);
326
- const branchIds = org.branch_ids?.map((b) => b.id) || [];
327
- const defaultBranchObj = org.branch_ids?.find((b) => b.DefaultBranch === 'true');
328
- const defaultBr = defaultBranchObj?.id || null;
329
-
330
- setSelectedBranches(branchIds);
331
- setDefaultBranch(defaultBr);
332
-
333
- form.setFieldsValue({
334
- selectedBranches: branchIds,
335
- defaultBranch: defaultBr,
336
- });
337
- } catch (err) {
338
- console.error('Invalid organization_details JSON', err);
339
- }
340
- }
341
- }, [formContent]);
326
+ if (!formContent) return;
327
+
328
+ // normalize branch ids to NUMBER
329
+ const org =
330
+ typeof formContent.organization_details === 'string' ? JSON.parse(formContent.organization_details) : formContent.organization_details;
331
+
332
+ const branchIds = (org?.branch_ids || []).map(Number);
333
+ const defaultBr = formContent.defaultBranch ? Number(formContent.defaultBranch) : null;
334
+
335
+ // state (for filtering)
336
+ setSelectedBranches(branchIds);
337
+
338
+ // form (source of truth)
339
+ form.setFieldsValue({
340
+ selectedBranches: branchIds,
341
+ defaultBranch: defaultBr,
342
+ });
343
+ }, [formContent, form]);
342
344
  // Generate branch options for Select component
343
345
  const branchOptions = branches.map((branch) => ({
344
346
  label: branch.br_desc,
@@ -349,6 +351,8 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
349
351
  * Submit values
350
352
  */
351
353
  const onSubmit = (values) => {
354
+ values.defaultBranch = String(values.defaultBranch);
355
+
352
356
  /**If PanelOpen is open and edit mode then password will be existing password else new password*/
353
357
  if (!isPasswordVisible && mode === 'Edit') {
354
358
  values.password = body.password;
@@ -377,6 +381,7 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
377
381
  if (props?.ldap && selectedOption && selectedOption.value) {
378
382
  values = {
379
383
  ...values,
384
+
380
385
  addAllBranches: props.ldap.addAllBranches,
381
386
  auth_user: selectedOption.value,
382
387
  auth_type: 'LDAP',
@@ -387,6 +392,7 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
387
392
  if (values.attributes && typeof values === 'object') {
388
393
  values = {
389
394
  ...values,
395
+
390
396
  auth_type: 'LDAP',
391
397
 
392
398
  attributes: JSON.stringify(values.attributes),
@@ -624,22 +630,19 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
624
630
  <Select
625
631
  mode="multiple"
626
632
  placeholder="Select Branches"
627
- value={selectedBranches}
633
+ options={branchOptions}
634
+ allowClear
635
+ showSearch
636
+ optionFilterProp="label"
628
637
  onChange={(value) => {
629
- setSelectedBranches(value);
638
+ const normalized = value.map(Number);
639
+ setSelectedBranches(normalized);
630
640
 
631
- // ⬅NEW: remove defaultBranch if it’s not in selectedBranches
632
- if (!value.includes(defaultBranch)) {
633
- setDefaultBranch(undefined);
641
+ const currentDefault = form.getFieldValue('defaultBranch');
642
+ if (currentDefault && !normalized.includes(currentDefault)) {
634
643
  form.setFieldsValue({ defaultBranch: undefined });
635
644
  }
636
645
  }}
637
- options={branchOptions}
638
- allowClear
639
- showSearch
640
- optionFilterProp="label"
641
- maxTagCount={5} // Show only 5 tags
642
- maxTagPlaceholder={(omittedValues) => `+${omittedValues.length}`} // Show "+n"
643
646
  />
644
647
  </Form.Item>
645
648
  </Col>
@@ -648,9 +651,9 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
648
651
  <Form.Item label="Default Branch" name="defaultBranch" rules={[{ required: true, message: 'Please select default branch' }]}>
649
652
  <Select placeholder="Select Default Branch" onChange={setDefaultBranch}>
650
653
  {branchOptions
651
- .filter((opt) => selectedBranches.includes(opt.value))
654
+ .filter((opt) => selectedBranches.includes(Number(opt.value)))
652
655
  .map((opt) => (
653
- <Option key={opt.value} value={opt.value}>
656
+ <Option key={opt.value} value={Number(opt.value)}>
654
657
  {opt.label}
655
658
  </Option>
656
659
  ))}
@@ -726,8 +729,8 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
726
729
  </Form.Item>
727
730
  </Col>
728
731
  <Col span={8}>
729
- <Form.Item name="role_id" label="Role" rules={[{ required: true, message: 'Please Input Role' }]}>
730
- <Select placeholder="Select Role" style={{ width: '100%' }}>
732
+ <Form.Item name="role_id" label="Role" rules={[{ required: true, message: 'Please select a Role' }]}>
733
+ <Select placeholder="Select Role">
731
734
  {roles.map((role) => (
732
735
  <Option key={role.id} value={role.id}>
733
736
  {role.name}
@@ -11,7 +11,6 @@ export default function UserEdit(record) {
11
11
  // Handle edit button click
12
12
  const handleEditClick = () => {
13
13
  if (!record.id) {
14
- console.warn('Invalid record: Missing ID');
15
14
  return;
16
15
  }
17
16
 
@@ -29,9 +28,7 @@ export default function UserEdit(record) {
29
28
  // Try parsing other_details, handle error if invalid JSON
30
29
  try {
31
30
  otherDetails = JSON.parse(apiData.other_details);
32
- } catch (err) {
33
- console.warn('Failed to parse other_details:', apiData.other_details);
34
- }
31
+ } catch (err) {}
35
32
  }
36
33
  let orgDetails = {};
37
34
  try {
@@ -50,8 +47,10 @@ export default function UserEdit(record) {
50
47
  designation: apiData.designation_code,
51
48
  department: apiData.department_id,
52
49
  // Handle selected branches and default branch
50
+ organization_details: orgDetails,
53
51
  selectedBranches: orgDetails.branch_ids || [],
54
- defaultBranch: apiData.firm_id || null,
52
+ defaultBranch: apiData.branch_id || null,
53
+ role_id: apiData.role_id,
55
54
  password: apiData.password,
56
55
  user_group: apiData.user_group,
57
56
  // Handle doctor codes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-soxo-bootstrap-core",
3
- "version": "2.4.25-dev.14",
3
+ "version": "2.4.25-dev.15",
4
4
  "description": "All the Core Components for you to start",
5
5
  "keywords": [
6
6
  "all in one"