datastake-daf 0.6.816 → 0.6.817
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/dist/components/index.js +1196 -1285
- package/dist/pages/index.js +1315 -579
- package/dist/services/index.js +202 -0
- package/dist/utils/index.js +28 -0
- package/package.json +1 -1
- package/src/@daf/core/components/Charts/RadarChart/index.jsx +3 -12
- package/src/@daf/core/components/Charts/style.js +1 -2
- package/src/@daf/core/components/Dashboard/Map/ChainIcon/index.js +123 -104
- package/src/@daf/core/components/Dashboard/Widget/VegetationWidget/index.jsx +4 -0
- package/src/@daf/core/components/Table/index.jsx +11 -6
- package/src/@daf/pages/Events/Activities/columns.js +15 -11
- package/src/@daf/pages/Events/Incidents/columns.js +15 -11
- package/src/@daf/pages/Events/Testimonials/columns.js +173 -0
- package/src/@daf/pages/Events/Testimonials/config.js +175 -0
- package/src/@daf/pages/Events/columns.js +7 -3
- package/src/@daf/pages/Locations/ConflictAreas/columns.js +140 -0
- package/src/@daf/pages/Locations/ConflictAreas/config.js +41 -0
- package/src/@daf/pages/Locations/MineSite/columns.js +21 -12
- package/src/@daf/pages/Locations/MineSite/config.js +2 -1
- package/src/@daf/pages/Locations/columns.js +7 -3
- package/src/@daf/pages/Stakeholders/ArmedGroups/columns.js +110 -0
- package/src/@daf/pages/Stakeholders/ArmedGroups/config.js +41 -0
- package/src/@daf/pages/Stakeholders/Operators/columns.js +30 -14
- package/src/@daf/pages/Stakeholders/Workers/columns.js +23 -13
- package/src/@daf/pages/Stakeholders/columns.js +8 -4
- package/src/@daf/pages/Summary/Activities/MonitoringCampaign/components/BiodiversityHabitat/ObservedFauna.jsx +11 -6
- package/src/@daf/pages/Summary/Activities/MonitoringCampaign/components/MangroveGrowth/PlantedSpecies.jsx +10 -25
- package/src/@daf/pages/Summary/Activities/MonitoringCampaign/components/MangroveGrowth/SeedlingsHeight.jsx +13 -10
- package/src/@daf/pages/Summary/Activities/MonitoringCampaign/components/MangroveGrowth/VegetationHealth.jsx +4 -19
- package/src/@daf/pages/Summary/Activities/MonitoringCampaign/components/SoilWaterProfile/SoilType.jsx +10 -22
- package/src/@daf/pages/Summary/Activities/MonitoringCampaign/components/SoilWaterProfile/WaterQuality.jsx +10 -26
- package/src/@daf/pages/Summary/Activities/MonitoringCampaign/components/chartHelpers.js +0 -74
- package/src/@daf/pages/TablePage/config.js +1 -1
- package/src/@daf/pages/TablePage/helper.js +45 -0
- package/src/@daf/services/EventsService.js +115 -0
- package/src/@daf/services/LinkedSubjects.js +1 -0
- package/src/@daf/services/WorkersService.js +80 -0
- package/src/helpers/errorHandling.js +142 -74
- package/src/services.js +3 -1
- package/src/utils.js +1 -1
- package/dist/style/datastake/mapbox-gl.css +0 -330
|
@@ -59,80 +59,6 @@ export const calculateNiceAxisConfig = (data, valueField = 'value', multiplier =
|
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
/**
|
|
63
|
-
* Calculate y-axis configuration with natural numbers (integers) only
|
|
64
|
-
* Always starts from 0 and extends slightly above max for better visualization
|
|
65
|
-
* @param {number} maxValue - Maximum value from the data
|
|
66
|
-
* @param {Object} options - Optional configuration
|
|
67
|
-
* @param {number} options.minTicks - Minimum number of ticks to show (default: 4)
|
|
68
|
-
* @param {number} options.maxTicks - Maximum number of ticks to show (default: 6)
|
|
69
|
-
* @returns {Object} Axis configuration with min, max, and tickMethod
|
|
70
|
-
*/
|
|
71
|
-
export const calculateNaturalAxisConfig = (maxValue, options = {}) => {
|
|
72
|
-
const { minTicks = 4, maxTicks = 6 } = options;
|
|
73
|
-
|
|
74
|
-
if (maxValue <= 0) {
|
|
75
|
-
return {
|
|
76
|
-
min: 0,
|
|
77
|
-
max: 4,
|
|
78
|
-
tickMethod: () => [0, 1, 2, 3, 4]
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// For very small values (max <= 1), always show 0, 1, 2, 3, 4
|
|
83
|
-
if (maxValue <= 1) {
|
|
84
|
-
return {
|
|
85
|
-
min: 0,
|
|
86
|
-
max: 4,
|
|
87
|
-
tickMethod: () => [0, 1, 2, 3, 4]
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Calculate appropriate step size based on max value
|
|
92
|
-
let step = 1;
|
|
93
|
-
let displayMax = maxValue;
|
|
94
|
-
|
|
95
|
-
if (maxValue <= 5) {
|
|
96
|
-
// For small values, use step of 1 and extend a bit above
|
|
97
|
-
step = 1;
|
|
98
|
-
displayMax = Math.max(5, Math.ceil(maxValue * 1.5));
|
|
99
|
-
} else if (maxValue <= 10) {
|
|
100
|
-
// For medium-small values, use step of 2
|
|
101
|
-
step = 2;
|
|
102
|
-
displayMax = Math.ceil((maxValue * 1.2) / step) * step;
|
|
103
|
-
} else if (maxValue <= 20) {
|
|
104
|
-
// For medium values, use step of 5
|
|
105
|
-
step = 5;
|
|
106
|
-
displayMax = Math.ceil((maxValue * 1.2) / step) * step;
|
|
107
|
-
} else if (maxValue <= 50) {
|
|
108
|
-
// For larger values, use step of 10
|
|
109
|
-
step = 10;
|
|
110
|
-
displayMax = Math.ceil((maxValue * 1.2) / step) * step;
|
|
111
|
-
} else {
|
|
112
|
-
// For very large values, calculate step to get 4-6 ticks
|
|
113
|
-
const targetTicks = Math.min(maxTicks, Math.max(minTicks, Math.ceil(maxValue / 20)));
|
|
114
|
-
step = Math.ceil(maxValue / targetTicks / 10) * 10; // Round to nearest 10
|
|
115
|
-
displayMax = Math.ceil((maxValue * 1.2) / step) * step;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Generate ticks from 0 to displayMax
|
|
119
|
-
const ticks = [];
|
|
120
|
-
for (let i = 0; i <= displayMax; i += step) {
|
|
121
|
-
ticks.push(i);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Ensure max value is included if it's close
|
|
125
|
-
if (ticks[ticks.length - 1] < maxValue && maxValue - ticks[ticks.length - 1] <= step / 2) {
|
|
126
|
-
ticks.push(maxValue);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
min: 0,
|
|
131
|
-
max: displayMax,
|
|
132
|
-
tickMethod: () => ticks
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
|
|
136
62
|
/**
|
|
137
63
|
* Merge default categories with backend data
|
|
138
64
|
* Ensures all categories are displayed even if they have no data
|
|
@@ -16,7 +16,7 @@ export const getSelectFiltersConfig = ({ subject }) => {
|
|
|
16
16
|
|
|
17
17
|
export const getFiltersConfig = ({ t, subject }) => {
|
|
18
18
|
const registry = FILTER_REGISTRY[subject] || FILTER_REGISTRY[DEFAULT_SUBJECT];
|
|
19
|
-
return registry?.config({ t });
|
|
19
|
+
return registry?.config({ t , screen: subject});
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export const getFilterOptions = ({ t, subject, options }) => {
|
|
@@ -22,6 +22,14 @@ import {
|
|
|
22
22
|
} from '../Stakeholders/Workers/config.js';
|
|
23
23
|
import { getColumns as getColumnsWorkers } from "../Stakeholders/Workers/columns.js";
|
|
24
24
|
|
|
25
|
+
import {
|
|
26
|
+
getFiltersConfig as getFiltersConfigArmedGroups,
|
|
27
|
+
getFilterOptions as getFilterOptionsArmedGroups,
|
|
28
|
+
formConfig as formConfigArmedGroups,
|
|
29
|
+
viewConfig as viewConfigArmedGroups
|
|
30
|
+
} from '../Stakeholders/ArmedGroups/config.js';
|
|
31
|
+
import { getColumns as getColumnsArmedGroups } from "../Stakeholders/ArmedGroups/columns.js";
|
|
32
|
+
|
|
25
33
|
import {
|
|
26
34
|
getFiltersConfig as getFiltersConfigEvents,
|
|
27
35
|
getFilterOptions as getFilterOptionsEvents,
|
|
@@ -45,6 +53,14 @@ import {
|
|
|
45
53
|
viewConfig as viewConfigIncidents
|
|
46
54
|
} from '../Events/Incidents/config.js';
|
|
47
55
|
import { getColumns as getColumnsIncidents } from "../Events/Incidents/columns.js";
|
|
56
|
+
|
|
57
|
+
import {
|
|
58
|
+
getFiltersConfig as getFiltersConfigTestimonials,
|
|
59
|
+
getFilterOptions as getFilterOptionsTestimonials,
|
|
60
|
+
formConfig as formConfigTestimonials,
|
|
61
|
+
viewConfig as viewConfigTestimonials
|
|
62
|
+
} from '../Events/Testimonials/config.js';
|
|
63
|
+
import { getColumns as getColumnsTestimonials } from "../Events/Testimonials/columns.js";
|
|
48
64
|
|
|
49
65
|
import {
|
|
50
66
|
getFiltersConfig as getFiltersConfigLocations,
|
|
@@ -63,6 +79,14 @@ import {
|
|
|
63
79
|
sclViewConfig as sclViewConfigProductionSites
|
|
64
80
|
} from '../Locations/MineSite/config.js';
|
|
65
81
|
import { getColumns as getColumnsProductionSites } from "../Locations/MineSite/columns.js";
|
|
82
|
+
|
|
83
|
+
import {
|
|
84
|
+
getFiltersConfig as getFiltersConfigConflictAreas,
|
|
85
|
+
getFilterOptions as getFilterOptionsConflictAreas,
|
|
86
|
+
formConfig as formConfigConflictAreas,
|
|
87
|
+
viewConfig as viewConfigConflictAreas
|
|
88
|
+
} from '../Locations/ConflictAreas/config.js';
|
|
89
|
+
import { getColumns as getColumnsConflictAreas } from "../Locations/ConflictAreas/columns.js";
|
|
66
90
|
|
|
67
91
|
import {
|
|
68
92
|
getFiltersConfig as getFilterConfigDocuments,
|
|
@@ -95,6 +119,13 @@ export const FILTER_REGISTRY = {
|
|
|
95
119
|
viewConfig: viewConfigOperators,
|
|
96
120
|
columns: getColumnsOperators,
|
|
97
121
|
},
|
|
122
|
+
"armed-groups": {
|
|
123
|
+
config: getFiltersConfigArmedGroups,
|
|
124
|
+
options: getFilterOptionsArmedGroups,
|
|
125
|
+
formConfig: formConfigArmedGroups,
|
|
126
|
+
viewConfig: viewConfigArmedGroups,
|
|
127
|
+
columns: getColumnsArmedGroups,
|
|
128
|
+
},
|
|
98
129
|
events: {
|
|
99
130
|
config: getFiltersConfigEvents,
|
|
100
131
|
options: getFilterOptionsEvents,
|
|
@@ -123,6 +154,13 @@ export const FILTER_REGISTRY = {
|
|
|
123
154
|
viewConfig: viewConfigIncidents,
|
|
124
155
|
columns: getColumnsIncidents,
|
|
125
156
|
},
|
|
157
|
+
testimonials: {
|
|
158
|
+
config: getFiltersConfigTestimonials,
|
|
159
|
+
options: getFilterOptionsTestimonials,
|
|
160
|
+
formConfig: formConfigTestimonials,
|
|
161
|
+
viewConfig: viewConfigTestimonials,
|
|
162
|
+
columns: getColumnsTestimonials,
|
|
163
|
+
},
|
|
126
164
|
locations: {
|
|
127
165
|
config: getFiltersConfigLocations,
|
|
128
166
|
options: getFilterOptionsLocations,
|
|
@@ -137,6 +175,13 @@ export const FILTER_REGISTRY = {
|
|
|
137
175
|
viewConfig: viewConfigProductionSites,
|
|
138
176
|
columns: getColumnsProductionSites,
|
|
139
177
|
},
|
|
178
|
+
"conflict-areas": {
|
|
179
|
+
config: getFiltersConfigConflictAreas,
|
|
180
|
+
options: getFilterOptionsConflictAreas,
|
|
181
|
+
formConfig: formConfigConflictAreas,
|
|
182
|
+
viewConfig: viewConfigConflictAreas,
|
|
183
|
+
columns: getColumnsConflictAreas,
|
|
184
|
+
},
|
|
140
185
|
scl: {
|
|
141
186
|
config: getFiltersConfigProductionSites,
|
|
142
187
|
options: getFilterOptionsProductionSites,
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService.js";
|
|
2
|
+
import { createLazyService } from "./helpers/LazyService.js";
|
|
3
|
+
import { filterCreateData } from "../../helpers/Forms.js";
|
|
4
|
+
|
|
5
|
+
class EventsService extends BaseService {
|
|
6
|
+
getForm({ scope }, language = "en") {
|
|
7
|
+
return this.apiGet({
|
|
8
|
+
isApp: true,
|
|
9
|
+
url: `/forms/event`,
|
|
10
|
+
params: { scope, language },
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getWithModule({ query, signal, module }) {
|
|
15
|
+
return this.apiGet({
|
|
16
|
+
isApp: true,
|
|
17
|
+
url: `/${module}/event`,
|
|
18
|
+
params: query,
|
|
19
|
+
signal,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getOne({ id, module, signal }) {
|
|
24
|
+
return this.apiGet({
|
|
25
|
+
url: `/${module}/event/${id}`,
|
|
26
|
+
isApp: true,
|
|
27
|
+
signal,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get(query, signal) {
|
|
32
|
+
return this.apiGet({
|
|
33
|
+
isApp: true,
|
|
34
|
+
url: "/event",
|
|
35
|
+
params: query,
|
|
36
|
+
signal,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getData(id, sourceId, source, version) {
|
|
41
|
+
return this.apiGet({
|
|
42
|
+
isApp: true,
|
|
43
|
+
url: `/event/${id}`,
|
|
44
|
+
params: { authorId: sourceId, source, version },
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getLinking(query) {
|
|
49
|
+
return this.apiGet({
|
|
50
|
+
isApp: true,
|
|
51
|
+
url: "/event/linking",
|
|
52
|
+
params: query,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
submit(payload) {
|
|
57
|
+
if (payload.id) {
|
|
58
|
+
return this.apiPut({
|
|
59
|
+
isApp: true,
|
|
60
|
+
url: `/event/${payload.id}`,
|
|
61
|
+
data: filterCreateData(payload),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (payload?.form) {
|
|
66
|
+
delete payload.form;
|
|
67
|
+
return this.apiPut({
|
|
68
|
+
isApp: true,
|
|
69
|
+
url: "/event",
|
|
70
|
+
data: filterCreateData(payload),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return this.apiPost({
|
|
74
|
+
isApp: true,
|
|
75
|
+
url: "/event",
|
|
76
|
+
data: filterCreateData(payload),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
submitStep(data, id) {
|
|
81
|
+
return this.apiPut({
|
|
82
|
+
isApp: true,
|
|
83
|
+
url: `/event/submit/${id}`,
|
|
84
|
+
data: filterCreateData(data),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
remove(id, data) {
|
|
88
|
+
return this.apiDelete({
|
|
89
|
+
isApp: true,
|
|
90
|
+
url: `/event/${id}/remove`,
|
|
91
|
+
data: data,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
submitForm(id) {
|
|
96
|
+
const app = window.globalServicesConfig.application;
|
|
97
|
+
|
|
98
|
+
return this.apiPost({
|
|
99
|
+
isApp: true,
|
|
100
|
+
url: `/${app}/versioning/submit/Event/${id}`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getOptions() {
|
|
105
|
+
return this.apiGet({
|
|
106
|
+
isApp: true,
|
|
107
|
+
url: `/forms/options`,
|
|
108
|
+
params: {
|
|
109
|
+
id: "categoryOptions,eventsType,testimonialsType,eventCategory,countries,eventCategoryOptions",
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export default createLazyService(EventsService);
|
|
@@ -27,6 +27,7 @@ export const getNamespace = (namespace) => {
|
|
|
27
27
|
|
|
28
28
|
class LinkedSubjectsService extends BaseService {
|
|
29
29
|
getForm({ namespace }, language = "en", scope) {
|
|
30
|
+
console.log({namespace, language, scope})
|
|
30
31
|
return this.apiGet({
|
|
31
32
|
url: `forms/${namespace === "documents" ? namespace : getNamespace(namespace)}`,
|
|
32
33
|
isApp: true,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService.js";
|
|
2
|
+
import { createLazyService } from "./helpers/LazyService.js";
|
|
3
|
+
import { filterCreateData } from "../../helpers/Forms.js";
|
|
4
|
+
|
|
5
|
+
class WorkersService extends BaseService {
|
|
6
|
+
get(params) {
|
|
7
|
+
return this.apiGet({
|
|
8
|
+
isApp: true,
|
|
9
|
+
url: "/stakeholder",
|
|
10
|
+
params,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getForm(scope = "modalNashirikiWorker", language = "en") {
|
|
15
|
+
return this.apiGet({
|
|
16
|
+
isApp: true,
|
|
17
|
+
url: `/forms/stakeholder`,
|
|
18
|
+
params: { scope, language },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
getData(id, sourceId, version, source) {
|
|
22
|
+
return this.apiGet({
|
|
23
|
+
isApp: true,
|
|
24
|
+
url: `/stakeholder/${id}`,
|
|
25
|
+
params: { authorId: sourceId, version, source },
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
submit(payload) {
|
|
30
|
+
if (payload.id) {
|
|
31
|
+
// const { id, ...data } = payload;
|
|
32
|
+
return this.apiPut({
|
|
33
|
+
isApp: true,
|
|
34
|
+
url: `/stakeholder/${payload.id}`,
|
|
35
|
+
data: filterCreateData(payload),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (payload?.form) {
|
|
39
|
+
delete payload.form;
|
|
40
|
+
return this.apiPost({
|
|
41
|
+
isApp: true,
|
|
42
|
+
url: "/stakeholder",
|
|
43
|
+
data: filterCreateData(payload),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return this.apiPost({
|
|
47
|
+
isApp: true,
|
|
48
|
+
url: "/stakeholder",
|
|
49
|
+
data: filterCreateData(payload),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
submitStep(data, id) {
|
|
54
|
+
return this.apiPut({
|
|
55
|
+
isApp: true,
|
|
56
|
+
url: `/stakeholder/submit/${id}`,
|
|
57
|
+
data: filterCreateData(data),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
remove(id, data) {
|
|
62
|
+
return this.apiDelete({
|
|
63
|
+
isApp: true,
|
|
64
|
+
url: `/stakeholder/${id}/remove`,
|
|
65
|
+
data: data,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getOptions() {
|
|
70
|
+
return this.apiGet({
|
|
71
|
+
isApp: true,
|
|
72
|
+
url: `/forms/options`,
|
|
73
|
+
params: {
|
|
74
|
+
id: "activityAtSiteOptions,category,countries,optionPositionSupplyChain,subCategory",
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default createLazyService(WorkersService);
|
|
@@ -1,67 +1,135 @@
|
|
|
1
1
|
import { message } from 'antd';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Check if a successful response contains embedded error data
|
|
5
|
+
*/
|
|
6
|
+
export const isErrorResponse = (data) => {
|
|
7
|
+
if (!data) return false;
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
// Check for Exception names
|
|
11
|
+
(data.name && data.name.includes('Exception')) ||
|
|
12
|
+
// Check for nested response with error status
|
|
13
|
+
(data.response?.statusCode && data.response.statusCode >= 400) ||
|
|
14
|
+
// Check for top-level error status
|
|
15
|
+
(data.statusCode && data.statusCode >= 400) ||
|
|
16
|
+
// Check for explicit error flag
|
|
17
|
+
data.error === true ||
|
|
18
|
+
// Check for nested error property
|
|
19
|
+
(data.response?.error && data.response.error !== null)
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Extract error message from various error response formats
|
|
25
|
+
*/
|
|
26
|
+
export const getErrorMessage = (data) => {
|
|
27
|
+
return (
|
|
28
|
+
data?.message ||
|
|
29
|
+
data?.response?.message ||
|
|
30
|
+
data?.response?.error ||
|
|
31
|
+
'An error occurred'
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
3
35
|
/**
|
|
4
36
|
* Generic error handler factory for axios requests
|
|
5
37
|
* Highly configurable to adapt to different project needs
|
|
6
38
|
*/
|
|
7
39
|
export const createErrorHandler = (config = {}) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
return Promise.reject(error);
|
|
40
|
+
const {
|
|
41
|
+
onUnauthorized,
|
|
42
|
+
handleError,
|
|
43
|
+
getStorageManager,
|
|
44
|
+
checkTokenValidity = true,
|
|
45
|
+
unauthorizedRedirect = '/',
|
|
46
|
+
tokenStorageKey = 'token',
|
|
47
|
+
handleNetworkError = true,
|
|
48
|
+
} = config;
|
|
49
|
+
|
|
50
|
+
return (error, customOnUnauthorized) => {
|
|
51
|
+
// Handle cases where error.response doesn't exist (network errors)
|
|
52
|
+
if (!error.response) {
|
|
53
|
+
if (handleNetworkError && handleError) {
|
|
54
|
+
handleError({
|
|
55
|
+
status: 0,
|
|
56
|
+
statusText: "Network Error",
|
|
57
|
+
data: ["Please check your internet connection."],
|
|
58
|
+
});
|
|
29
59
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
return Promise.reject(error);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { status, statusText, data: { errors, message } = {} } = error.response || { data: {} };
|
|
64
|
+
|
|
65
|
+
// Handle 401 Unauthorized
|
|
66
|
+
if (status === 401) {
|
|
67
|
+
if (checkTokenValidity && getStorageManager) {
|
|
68
|
+
const token = getStorageManager().get(tokenStorageKey);
|
|
69
|
+
if (token) {
|
|
70
|
+
if (typeof customOnUnauthorized === 'function') {
|
|
71
|
+
customOnUnauthorized();
|
|
72
|
+
} else if (typeof onUnauthorized === 'function') {
|
|
73
|
+
onUnauthorized();
|
|
74
|
+
} else {
|
|
75
|
+
getStorageManager().clearOne(tokenStorageKey);
|
|
76
|
+
if (typeof window !== 'undefined') {
|
|
77
|
+
window.location.href = unauthorizedRedirect;
|
|
47
78
|
}
|
|
48
79
|
}
|
|
49
80
|
}
|
|
50
81
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Handle 4xx and 5xx errors
|
|
85
|
+
if (status >= 400 && status <= 500) {
|
|
86
|
+
if (handleError) {
|
|
87
|
+
handleError({
|
|
88
|
+
status,
|
|
89
|
+
statusText: message || statusText,
|
|
90
|
+
data: errors || []
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return Promise.reject(error);
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Create axios response interceptor to catch embedded errors in successful responses
|
|
101
|
+
*/
|
|
102
|
+
export const createResponseInterceptor = (config = {}) => {
|
|
103
|
+
const { showNotification = true } = config;
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
onSuccess: (response) => {
|
|
107
|
+
// Check if the response data contains an error
|
|
108
|
+
if (isErrorResponse(response.data)) {
|
|
109
|
+
const errorMessage = getErrorMessage(response.data);
|
|
110
|
+
|
|
111
|
+
if (showNotification) {
|
|
112
|
+
message.error(errorMessage);
|
|
60
113
|
}
|
|
114
|
+
|
|
115
|
+
// Convert to a rejected promise so catch blocks handle it
|
|
116
|
+
const error = new Error(errorMessage);
|
|
117
|
+
error.response = {
|
|
118
|
+
data: response.data,
|
|
119
|
+
status: response.data.statusCode || response.data.response?.statusCode || 200,
|
|
120
|
+
statusText: errorMessage,
|
|
121
|
+
};
|
|
122
|
+
error.isEmbeddedError = true; // Flag to identify these special errors
|
|
123
|
+
|
|
124
|
+
return Promise.reject(error);
|
|
61
125
|
}
|
|
62
126
|
|
|
127
|
+
return response;
|
|
128
|
+
},
|
|
129
|
+
onError: (error) => {
|
|
63
130
|
return Promise.reject(error);
|
|
64
|
-
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
65
133
|
};
|
|
66
134
|
|
|
67
135
|
/**
|
|
@@ -69,29 +137,29 @@ export const createErrorHandler = (config = {}) => {
|
|
|
69
137
|
* Useful for quick error notifications
|
|
70
138
|
*/
|
|
71
139
|
export const handleError = (err) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
140
|
+
const errorMessage = err?.response?.data?.message ||
|
|
141
|
+
err?.message ||
|
|
142
|
+
'An error occurred';
|
|
143
|
+
message.error(errorMessage);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Success message handler
|
|
148
|
+
*/
|
|
149
|
+
export const handleSuccess = (msg) => {
|
|
150
|
+
message.success(msg || 'Operation successful');
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Warning message handler
|
|
155
|
+
*/
|
|
156
|
+
export const handleWarning = (msg) => {
|
|
157
|
+
message.warning(msg || 'Warning');
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Info message handler
|
|
162
|
+
*/
|
|
163
|
+
export const handleInfo = (msg) => {
|
|
164
|
+
message.info(msg);
|
|
165
|
+
};
|
package/src/services.js
CHANGED
|
@@ -18,4 +18,6 @@ export { default as SourceService } from './@daf/services/SourceService.js';
|
|
|
18
18
|
export { default as DashboardService } from './@daf/services/DashboardService.js';
|
|
19
19
|
export { default as LinkedSubjectsService } from './@daf/services/LinkedSubjects.js';
|
|
20
20
|
export { default as OperatorService } from './@daf/services/OperatorService.js';
|
|
21
|
-
export { default as PartnerService } from './@daf/services/PartnerService.js';
|
|
21
|
+
export { default as PartnerService } from './@daf/services/PartnerService.js';
|
|
22
|
+
export { default as EventsService } from './@daf/services/EventsService.js';
|
|
23
|
+
export { default as WorkersService } from './@daf/services/WorkersService.js';
|
package/src/utils.js
CHANGED
|
@@ -46,7 +46,7 @@ export { StorageManager } from './helpers/StorageManager.js';
|
|
|
46
46
|
|
|
47
47
|
export { assignParamsToUrl, buildQueryString } from './helpers/urlHelpers.js';
|
|
48
48
|
|
|
49
|
-
export { createErrorHandler, handleError, handleSuccess, handleWarning, handleInfo } from './helpers/errorHandling.js';
|
|
49
|
+
export { createErrorHandler, handleError, handleSuccess, handleWarning, handleInfo, isErrorResponse, getErrorMessage } from './helpers/errorHandling.js';
|
|
50
50
|
|
|
51
51
|
export { createTheme, createAdminTheme } from './helpers/theme.js';
|
|
52
52
|
|