ui-soxo-bootstrap-core 2.4.25-dev.13 → 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.
@@ -10,7 +10,7 @@ const DoctorAdd = ({ visible, onCancel, attributes, doctorId, doctorData, onSucc
10
10
  const [form] = Form.useForm();
11
11
  const { t } = useTranslation();
12
12
 
13
- // Signature states
13
+ // Signature states..
14
14
  const [fileUrl, setFileUrl] = useState(null);
15
15
  const [editingSignature, setEditingSignature] = useState(false);
16
16
  const [previousSignature, setPreviousSignature] = useState(null);
@@ -57,6 +57,18 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
57
57
  }
58
58
  }, [visible]);
59
59
 
60
+ const phoneValidator = (_, value) => {
61
+ if (!value) {
62
+ return Promise.resolve(); // not required
63
+ }
64
+
65
+ if (!/^\d{10}$/.test(value)) {
66
+ return Promise.reject('Phone number must be 10 digits');
67
+ }
68
+
69
+ return Promise.resolve();
70
+ };
71
+
60
72
  /** -------------------------------
61
73
  * API CALL – Designations
62
74
  * ------------------------------- */
@@ -92,11 +104,31 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
92
104
  return Promise.resolve();
93
105
  }
94
106
 
107
+ // Starting space not allowed
108
+ if (value.startsWith(' ')) {
109
+ setCodeStatus({
110
+ status: 'error',
111
+ message: 'Code cannot start with a space',
112
+ });
113
+ return Promise.reject(new Error('Code cannot start with a space'));
114
+ }
115
+
116
+ // Any space not allowed
117
+ if (/\s/.test(value)) {
118
+ setCodeStatus({
119
+ status: 'error',
120
+ message: 'Spaces are not allowed in the code',
121
+ });
122
+ return Promise.reject(new Error('Spaces are not allowed in the code'));
123
+ }
124
+
95
125
  try {
96
126
  const res = await UsersAPI.getStaffCode(value);
127
+ console.log(res.message, ' inside validateDoctorCode');
97
128
 
98
129
  if (res?.status === 409 || res?.success === false) {
99
130
  setCodeStatus({ status: 'error', message: res.message || 'Code already exists' });
131
+ console.log('here');
100
132
  return Promise.reject(new Error(res.message || 'Code already exists'));
101
133
  }
102
134
 
@@ -108,8 +140,8 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
108
140
  return Promise.resolve();
109
141
  }
110
142
 
111
- setCodeStatus({ status: 'error', message: 'Unexpected response' });
112
- return Promise.reject(new Error('Unexpected response'));
143
+ setCodeStatus({ status: 'error', message: 'Please enter a valid code' });
144
+ return Promise.reject(new Error('Please enter a valid code'));
113
145
  } catch {
114
146
  setCodeStatus({ status: 'error', message: 'Validation failed' });
115
147
  return Promise.reject(new Error('Validation failed'));
@@ -163,19 +195,19 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
163
195
  id: values.id,
164
196
  shortName: values.shortName,
165
197
  description: values.description,
166
- designationPtr: values.designation,
167
- phone: values.phone1,
168
- mobile: values.phone2,
169
- alternateMobile: values.phone2,
170
- email: values.email1,
171
- alternateEmail: values.email2,
172
- remarks: values.remarks,
198
+ designationPtr: values.designation || null,
199
+ phone: values.phone1 || null,
200
+ mobile: values.phone1 || null,
201
+ alternateMobile: values.phone2 || null,
202
+ email: values.email1 || null,
203
+ alternateEmail: values.email2 || null,
204
+ remarks: values.remarks || null,
173
205
  slNo: values.slno ? Number(values.slno) : null,
174
206
  active: values.active === 'Y' ? 'Y' : 'N',
175
- address1: values.address1,
176
- address2: values.address2,
177
- place: values.place,
178
- zip: values.zip,
207
+ address1: values.address1 || null,
208
+ address2: values.address2 || null,
209
+ place: values.place || null,
210
+ zip: values.zip || null,
179
211
  };
180
212
 
181
213
  try {
@@ -217,21 +249,20 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
217
249
  name="id"
218
250
  validateTrigger="onChange"
219
251
  hasFeedback={!editMode}
220
- rules={[{ required: true }, { validator: validateDoctorCode }]}
252
+ rules={[{ required: true, message: 'Code is required' }, { validator: validateDoctorCode }]}
221
253
  >
222
- <Input placeholder="Enter Code" ref={nameInputRef} onKeyDown={handleEnterKey} disabled={editMode} />
254
+ <Input placeholder="Enter Code" autoComplete="off" maxLength={10} ref={nameInputRef} onKeyDown={handleEnterKey} disabled={editMode} />
223
255
  </Form.Item>
224
256
  </Col>
225
257
 
226
- <Col span={6}>
227
- <Form.Item label="Name" name="shortName" rules={[{ required: true }]}>
228
- <Input placeholder="Enter Name" onKeyDown={handleEnterKey} />
258
+ <Col span={12}>
259
+ <Form.Item label="Name" name="description" rules={[{ required: true }]}>
260
+ <Input placeholder="Enter Description" autoComplete="off" onKeyDown={handleEnterKey} />
229
261
  </Form.Item>
230
262
  </Col>
231
-
232
- <Col span={12}>
233
- <Form.Item label="Description" name="description" rules={[{ required: true }]}>
234
- <Input placeholder="Enter Description" onKeyDown={handleEnterKey} />
263
+ <Col span={6}>
264
+ <Form.Item label="Short Name" name="shortName" rules={[{ required: true }]}>
265
+ <Input placeholder="Enter Short Name" autoComplete="off" onKeyDown={handleEnterKey} maxLength={10} />
235
266
  </Form.Item>
236
267
  </Col>
237
268
  </Row>
@@ -240,7 +271,7 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
240
271
  {/* GENERAL TAB */}
241
272
  <Tabs.TabPane tab="GENERAL" key="1">
242
273
  <Row gutter={16}>
243
- <Col span={6}>
274
+ {/* <Col span={6}>
244
275
  <Form.Item label="Phone Number 1" name="phone1">
245
276
  <Input maxLength={10} placeholder="Enter Phone Number" onKeyDown={handleEnterKey} />
246
277
  </Form.Item>
@@ -250,17 +281,42 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
250
281
  <Form.Item label="Phone Number 2" name="phone2">
251
282
  <Input maxLength={10} placeholder="Enter Phone Number" onKeyDown={handleEnterKey} />
252
283
  </Form.Item>
284
+ </Col> */}
285
+ <Col span={6}>
286
+ <Form.Item label="Phone Number" name="phone1" rules={[{ validator: phoneValidator }]}>
287
+ <Input
288
+ maxLength={10}
289
+ autoComplete="off"
290
+ placeholder="Enter Phone Number"
291
+ inputMode="numeric"
292
+ onChange={(e) => (e.target.value = e.target.value.replace(/\D/g, ''))}
293
+ onKeyDown={handleEnterKey}
294
+ />
295
+ </Form.Item>
296
+ </Col>
297
+
298
+ <Col span={6}>
299
+ <Form.Item label="Alternate Phone Number" name="phone2" rules={[{ validator: phoneValidator }]}>
300
+ <Input
301
+ maxLength={10}
302
+ placeholder="Enter Phone Number"
303
+ autoComplete="off"
304
+ inputMode="numeric"
305
+ onChange={(e) => (e.target.value = e.target.value.replace(/\D/g, ''))}
306
+ onKeyDown={handleEnterKey}
307
+ />
308
+ </Form.Item>
253
309
  </Col>
254
310
 
255
311
  <Col span={6}>
256
- <Form.Item label="Email ID 1" name="email1">
257
- <Input placeholder="Enter Email" onKeyDown={handleEnterKey} />
312
+ <Form.Item label="Email ID" name="email1">
313
+ <Input autoComplete="off" placeholder="Enter Email" onKeyDown={handleEnterKey} />
258
314
  </Form.Item>
259
315
  </Col>
260
316
 
261
317
  <Col span={6}>
262
- <Form.Item label="Email ID 2" name="email2">
263
- <Input placeholder="Enter Email" onKeyDown={handleEnterKey} />
318
+ <Form.Item label="Alternate Email" name="email2">
319
+ <Input autoComplete="off" placeholder="Enter Email" onKeyDown={handleEnterKey} />
264
320
  </Form.Item>
265
321
  </Col>
266
322
  </Row>
@@ -273,8 +329,8 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
273
329
  </Col>
274
330
 
275
331
  <Col span={8}>
276
- <Form.Item label="Serial Number" name="slno">
277
- <Input placeholder="Enter Serial Number" onKeyDown={handleEnterKey} />
332
+ <Form.Item label="Serial Number" name="slno" rules={[{ message: 'only numbers are allowed', pattern: /^\d*$/ }]}>
333
+ <Input autoComplete="off" maxLength={5} placeholder="Enter Serial Number" onKeyDown={handleEnterKey} />
278
334
  </Form.Item>
279
335
  </Col>
280
336
 
@@ -297,7 +353,7 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
297
353
  <Row>
298
354
  <Col span={24}>
299
355
  <Form.Item label="Remarks" name="remarks">
300
- <Input placeholder="Enter Remarks" onKeyDown={handleEnterKey} />
356
+ <Input autoComplete="off" placeholder="Enter Remarks" onKeyDown={handleEnterKey} />
301
357
  </Form.Item>
302
358
  </Col>
303
359
  </Row>
@@ -308,13 +364,13 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
308
364
  <Row gutter={16}>
309
365
  <Col span={12}>
310
366
  <Form.Item label="Address Line 1" name="address1">
311
- <Input placeholder="Enter Address" onKeyDown={handleEnterKey} />
367
+ <Input autoComplete="off" placeholder="Enter Address" onKeyDown={handleEnterKey} />
312
368
  </Form.Item>
313
369
  </Col>
314
370
 
315
371
  <Col span={12}>
316
372
  <Form.Item label="Address Line 2" name="address2">
317
- <Input placeholder="Enter Address" onKeyDown={handleEnterKey} />
373
+ <Input autoComplete="off" placeholder="Enter Address" onKeyDown={handleEnterKey} />
318
374
  </Form.Item>
319
375
  </Col>
320
376
  </Row>
@@ -322,13 +378,13 @@ const StaffAdd = ({ visible, onCancel, staffId, staffData, onSuccess }) => {
322
378
  <Row gutter={16}>
323
379
  <Col span={12}>
324
380
  <Form.Item label="Place" name="place">
325
- <Input placeholder="Enter Place" onKeyDown={handleEnterKey} />
381
+ <Input autoComplete="off" placeholder="Enter Place" onKeyDown={handleEnterKey} />
326
382
  </Form.Item>
327
383
  </Col>
328
384
 
329
385
  <Col span={12}>
330
386
  <Form.Item label="Zip Code" name="zip">
331
- <Input placeholder="Enter Zip Code" maxLength={7} onKeyDown={handleEnterKey} />
387
+ <Input autoComplete="off" placeholder="Enter Zip Code" maxLength={7} onKeyDown={handleEnterKey} />
332
388
  </Form.Item>
333
389
  </Col>
334
390
  </Row>
@@ -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),
@@ -506,12 +512,20 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
506
512
  {' '}
507
513
  {/* Show extra dropdown only if user type is Doctor */}
508
514
  {userType === 'RAD' && (
509
- <Form.Item name="default_code" label="Default Code" rules={[{ required: true, message: 'Please select a default code' }]}>
515
+ <Form.Item
516
+ name="default_code"
517
+ preserve={false}
518
+ label="Default Code"
519
+ rules={[{ required: true, message: 'Please select a default code' }]}
520
+ >
510
521
  <Select
511
522
  placeholder="Select Code"
512
523
  options={doctorList}
513
524
  showSearch
514
525
  optionFilterProp="label"
526
+ onChange={(value) => {
527
+ form.setFieldsValue({ default_code: value });
528
+ }}
515
529
  dropdownRender={(menu) => (
516
530
  <>
517
531
  {menu}
@@ -541,12 +555,20 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
541
555
  </Form.Item>
542
556
  )}
543
557
  {userType === 'STAFF' && (
544
- <Form.Item name="staff_code" label="Staff Code" rules={[{ required: true, message: 'Please select a staff code' }]}>
558
+ <Form.Item
559
+ name="staff_code"
560
+ preserve={false} // THIS FIXES IT
561
+ label="Staff Code"
562
+ rules={[{ required: true, message: 'Please select a staff code' }]}
563
+ >
545
564
  <Select
546
565
  placeholder="Select Code"
547
566
  options={staffList}
548
567
  showSearch
549
568
  optionFilterProp="label"
569
+ onChange={(value) => {
570
+ form.setFieldsValue({ staff_code: value });
571
+ }}
550
572
  dropdownRender={(menu) => (
551
573
  <>
552
574
  {menu}
@@ -584,7 +606,7 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
584
606
  <Col span={8}>
585
607
  {/* Mobile */}
586
608
  <Form.Item name="mobile" label="Mobile" rules={[{ required: true, message: 'Please enter your mobile number' }]}>
587
- <Input placeholder="Enter Mobile" />
609
+ <Input placeholder="Enter Mobile" maxLength={10} />
588
610
  </Form.Item>
589
611
  </Col>
590
612
  <Col span={8}>
@@ -608,22 +630,19 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
608
630
  <Select
609
631
  mode="multiple"
610
632
  placeholder="Select Branches"
611
- value={selectedBranches}
633
+ options={branchOptions}
634
+ allowClear
635
+ showSearch
636
+ optionFilterProp="label"
612
637
  onChange={(value) => {
613
- setSelectedBranches(value);
638
+ const normalized = value.map(Number);
639
+ setSelectedBranches(normalized);
614
640
 
615
- // ⬅NEW: remove defaultBranch if it’s not in selectedBranches
616
- if (!value.includes(defaultBranch)) {
617
- setDefaultBranch(undefined);
641
+ const currentDefault = form.getFieldValue('defaultBranch');
642
+ if (currentDefault && !normalized.includes(currentDefault)) {
618
643
  form.setFieldsValue({ defaultBranch: undefined });
619
644
  }
620
645
  }}
621
- options={branchOptions}
622
- allowClear
623
- showSearch
624
- optionFilterProp="label"
625
- maxTagCount={5} // Show only 5 tags
626
- maxTagPlaceholder={(omittedValues) => `+${omittedValues.length}`} // Show "+n"
627
646
  />
628
647
  </Form.Item>
629
648
  </Col>
@@ -632,9 +651,9 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
632
651
  <Form.Item label="Default Branch" name="defaultBranch" rules={[{ required: true, message: 'Please select default branch' }]}>
633
652
  <Select placeholder="Select Default Branch" onChange={setDefaultBranch}>
634
653
  {branchOptions
635
- .filter((opt) => selectedBranches.includes(opt.value))
654
+ .filter((opt) => selectedBranches.includes(Number(opt.value)))
636
655
  .map((opt) => (
637
- <Option key={opt.value} value={opt.value}>
656
+ <Option key={opt.value} value={Number(opt.value)}>
638
657
  {opt.label}
639
658
  </Option>
640
659
  ))}
@@ -710,8 +729,8 @@ const UserAdd = ({ model, callback, edit, history, formContent, match, additiona
710
729
  </Form.Item>
711
730
  </Col>
712
731
  <Col span={8}>
713
- <Form.Item name="role_id" label="Role" rules={[{ required: true, message: 'Please Input Role' }]}>
714
- <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">
715
734
  {roles.map((role) => (
716
735
  <Option key={role.id} value={role.id}>
717
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.13",
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"