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
|
-
|
|
219
|
-
|
|
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((
|
|
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
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
633
|
+
options={branchOptions}
|
|
634
|
+
allowClear
|
|
635
|
+
showSearch
|
|
636
|
+
optionFilterProp="label"
|
|
628
637
|
onChange={(value) => {
|
|
629
|
-
|
|
638
|
+
const normalized = value.map(Number);
|
|
639
|
+
setSelectedBranches(normalized);
|
|
630
640
|
|
|
631
|
-
|
|
632
|
-
if (!
|
|
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
|
|
730
|
-
<Select placeholder="Select Role"
|
|
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.
|
|
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
|