ui-soxo-bootstrap-core 2.6.1-dev.4 → 2.6.1-dev.6
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.
- package/core/models/base/base.js +7 -3
- package/core/models/menus/menus.js +6 -1
- package/core/models/users/components/assign-role/assign-role.js +25 -11
- package/core/models/users/components/assign-role/assign-role.scss +7 -1
- package/core/models/users/components/user-add/user-add.js +11 -8
- package/core/models/users/components/user-add/user-edit.js +8 -1
- package/core/models/users/users.js +6 -1
- package/core/modules/reporting/components/reporting-dashboard/reporting-dashboard.js +5 -1
- package/package.json +1 -1
package/core/models/base/base.js
CHANGED
|
@@ -88,9 +88,13 @@ class BaseAPI {
|
|
|
88
88
|
* Get the data from the table
|
|
89
89
|
*/
|
|
90
90
|
get(config = {}) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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) {
|
|
@@ -177,16 +177,21 @@ 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
|
+
},
|
|
190
195
|
}).then((result) => result);
|
|
191
196
|
};
|
|
192
197
|
|
|
@@ -93,10 +93,10 @@ export default function AssignRole() {
|
|
|
93
93
|
const roleList = Array.isArray(roleRes?.result) ? roleRes.result : [];
|
|
94
94
|
|
|
95
95
|
// Extract VALID role IDs (ignore nulls & duplicates)
|
|
96
|
-
const roleIds = [...new Set(
|
|
96
|
+
const roleIds = [...new Set(roleList.filter((item) => item.role_id && item.active === 'Y').map((item) => Number(item.role_id)))];
|
|
97
97
|
|
|
98
98
|
setSelectedRoles(roleIds);
|
|
99
|
-
setInitialRoles(roleIds);
|
|
99
|
+
setInitialRoles(roleIds);
|
|
100
100
|
} catch (e) {
|
|
101
101
|
console.error(e);
|
|
102
102
|
message.error('Unable to load user details');
|
|
@@ -206,10 +206,10 @@ export default function AssignRole() {
|
|
|
206
206
|
* @returns {Promise<void>}
|
|
207
207
|
*/
|
|
208
208
|
const handleSaveUserRole = async () => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
if (!id) {
|
|
210
|
+
message.error('Invalid user');
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
213
|
// start button spinner
|
|
214
214
|
setSaving(true);
|
|
215
215
|
|
|
@@ -236,9 +236,8 @@ export default function AssignRole() {
|
|
|
236
236
|
// Only show success AFTER all saves
|
|
237
237
|
|
|
238
238
|
message.success('User roles updated successfully');
|
|
239
|
-
|
|
240
|
-
await loadUser();
|
|
241
239
|
|
|
240
|
+
await loadUser();
|
|
242
241
|
} catch (err) {
|
|
243
242
|
console.error(err);
|
|
244
243
|
message.error('Failed to save user roles');
|
|
@@ -248,6 +247,19 @@ export default function AssignRole() {
|
|
|
248
247
|
}
|
|
249
248
|
};
|
|
250
249
|
|
|
250
|
+
// Role Change
|
|
251
|
+
const rolesChanged = useMemo(() => {
|
|
252
|
+
// Length mismatch means roles were added or removed
|
|
253
|
+
if (initialRoles.length !== selectedRoles.length) return true;
|
|
254
|
+
|
|
255
|
+
// Sort both arrays before comparison (order should not matter)
|
|
256
|
+
const sortedInitial = [...initialRoles].sort();
|
|
257
|
+
const sortedSelected = [...selectedRoles].sort();
|
|
258
|
+
|
|
259
|
+
// Check for any value difference
|
|
260
|
+
return sortedInitial.some((value, index) => value !== sortedSelected[index]);
|
|
261
|
+
}, [initialRoles, selectedRoles]);
|
|
262
|
+
|
|
251
263
|
return (
|
|
252
264
|
<section className="assign-role">
|
|
253
265
|
{/* LEFT PANEL */}
|
|
@@ -308,9 +320,11 @@ export default function AssignRole() {
|
|
|
308
320
|
</div>
|
|
309
321
|
|
|
310
322
|
<div className="footer-actions">
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
323
|
+
{rolesChanged && (
|
|
324
|
+
<Button type="primary" onClick={handleSaveUserRole} loading={saving}>
|
|
325
|
+
Save
|
|
326
|
+
</Button>
|
|
327
|
+
)}
|
|
314
328
|
</div>
|
|
315
329
|
</Card>
|
|
316
330
|
</section>
|
|
@@ -27,12 +27,18 @@
|
|
|
27
27
|
.role-list-header {
|
|
28
28
|
display: flex;
|
|
29
29
|
justify-content: space-between;
|
|
30
|
-
|
|
30
|
+
align-items: center;
|
|
31
31
|
strong {
|
|
32
32
|
font-weight: 600;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
.view-all-btn {
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
color: #1677ff;
|
|
39
|
+
font-weight: 500;
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
.role-search {
|
|
37
43
|
margin: 12px 0;
|
|
38
44
|
}
|
|
@@ -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
|
|
|
@@ -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
|
-
|
|
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
|
|
341
|
+
// form values
|
|
339
342
|
form.setFieldsValue({
|
|
340
343
|
selectedBranches: branchIds,
|
|
341
|
-
defaultBranch:
|
|
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"
|
|
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:
|
|
59
|
+
defaultBranch: defaultBranchCode || null,
|
|
53
60
|
role_id: apiData.role_id,
|
|
54
61
|
password: apiData.password,
|
|
55
62
|
user_group: apiData.user_group,
|
|
@@ -292,7 +292,12 @@ class Users extends Base {
|
|
|
292
292
|
information from the API. */
|
|
293
293
|
|
|
294
294
|
getUser = ({ id }) => {
|
|
295
|
-
return ApiUtils.get({
|
|
295
|
+
return ApiUtils.get({
|
|
296
|
+
url: `users/${id}`,
|
|
297
|
+
headers: {
|
|
298
|
+
db_ptr: 'nuraho',
|
|
299
|
+
},
|
|
300
|
+
});
|
|
296
301
|
};
|
|
297
302
|
/* The `getUserRole` method is a function that takes an object with an `id` property as a parameter.
|
|
298
303
|
It then uses the `ApiUtils.get` function to make a GET request to the endpoint `core-user-roles`
|
|
@@ -314,8 +314,12 @@ export default function ReportingDashboard({
|
|
|
314
314
|
|
|
315
315
|
// Fetch result
|
|
316
316
|
const result = await CoreScripts.getReportingLisitng(coreScriptId, formBody, dbPtr);
|
|
317
|
+
|
|
318
|
+
const apiData = Array.isArray(result) ? result : Array.isArray(result?.result) ? result.result : [];
|
|
319
|
+
|
|
317
320
|
// Handle both result formats
|
|
318
|
-
let resultDetails =
|
|
321
|
+
let resultDetails = apiData[0] || [];
|
|
322
|
+
|
|
319
323
|
if (result?.result && result?.result[0]) {
|
|
320
324
|
resultDetails = result.result[0];
|
|
321
325
|
}
|