datastake-daf 0.6.830 → 0.6.831
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 +819 -813
- package/dist/hooks/index.js +32 -1
- package/dist/layouts/index.js +2 -2
- package/dist/pages/index.js +75 -25
- package/dist/services/index.js +113 -0
- package/dist/utils/index.js +14 -1
- package/package.json +1 -1
- package/src/@daf/core/components/EditForm/storyConfig2.js +1176 -728
- package/src/@daf/hooks/useWidgetFetch.js +7 -0
- package/src/@daf/layouts/AppLayout/components/MobileDrawer/index.js +1 -1
- package/src/@daf/pages/Summary/hook.js +52 -19
- package/src/@daf/services/MineSiteService.js +104 -0
- package/src/helpers/user.js +16 -1
- package/src/services.js +2 -1
- package/src/utils.js +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useState, useEffect } from "react";
|
|
2
2
|
import DashboardService from "../services/DashboardService.js";
|
|
3
|
+
import { isErrorResponse, getErrorMessage } from "../../helpers/errorHandling.js";
|
|
4
|
+
import { message } from "antd";
|
|
3
5
|
|
|
4
6
|
// config: {
|
|
5
7
|
// stop: boolean,
|
|
@@ -25,6 +27,11 @@ export const useWidgetFetch = ({config, getData = DashboardService.getWidget, on
|
|
|
25
27
|
try {
|
|
26
28
|
const { data } = await getData(rest);
|
|
27
29
|
setData(data || defaultData);
|
|
30
|
+
if (isErrorResponse(data)) {
|
|
31
|
+
const errorMessage = getErrorMessage(data);
|
|
32
|
+
message.error(errorMessage);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
28
35
|
onFetch()
|
|
29
36
|
} catch (err) {
|
|
30
37
|
console.log(err);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useState, useMemo, useCallback, useEffect } from "react"
|
|
2
2
|
import { debounce } from "lodash";
|
|
3
3
|
import { StorageManager } from "../../../helpers/StorageManager.js";
|
|
4
|
+
import { isErrorResponse, getErrorMessage } from "../../../helpers/errorHandling.js";
|
|
5
|
+
import { message } from "antd";
|
|
4
6
|
|
|
5
7
|
export const useSummary = ({
|
|
6
8
|
getOne,
|
|
@@ -131,32 +133,63 @@ export const useSummary = ({
|
|
|
131
133
|
}, [debouncedSearch]);
|
|
132
134
|
|
|
133
135
|
useEffect(() => {
|
|
134
|
-
if (_partners !== undefined) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
136
|
+
// if (_partners !== undefined) {
|
|
137
|
+
// if ((params?.id !== null || (isPdf && id !== null)) && !hasSelect) {
|
|
138
|
+
// getOne({ datastakeId: params?.id || id, sources: _partners });
|
|
139
|
+
// }
|
|
140
|
+
// }
|
|
139
141
|
if (hasSelect && !params?.id) {
|
|
140
142
|
getMultiple(filters);
|
|
141
143
|
}
|
|
142
|
-
}, [
|
|
144
|
+
}, [hasSelect, params?.id, filters]);
|
|
143
145
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
146
|
+
const activeId = useMemo(() => {
|
|
147
|
+
return selectedItem || params?.id;
|
|
148
|
+
}, [selectedItem, params?.id]);
|
|
149
|
+
|
|
150
|
+
const memoizedPartners = useMemo(() => {
|
|
151
|
+
return _partners;
|
|
152
|
+
}, [_partners]);
|
|
153
|
+
|
|
154
|
+
const memoizedService = useMemo(() => {
|
|
155
|
+
return service;
|
|
156
|
+
}, [service]);
|
|
157
|
+
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (!activeId || memoizedPartners === undefined) return;
|
|
160
|
+
|
|
161
|
+
let cancelled = false;
|
|
162
|
+
|
|
163
|
+
const fetchSingleItem = async () => {
|
|
164
|
+
setLoading(true);
|
|
165
|
+
try {
|
|
166
|
+
const { data } = await memoizedService.getOne(activeId, { sources: memoizedPartners });
|
|
167
|
+
|
|
168
|
+
if (cancelled) return;
|
|
169
|
+
|
|
170
|
+
setSingleItemData(data);
|
|
171
|
+
if (isErrorResponse(data)) {
|
|
172
|
+
const errorMessage = getErrorMessage(data);
|
|
173
|
+
message.error(errorMessage);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (!cancelled) {
|
|
152
178
|
console.log(error);
|
|
153
|
-
}
|
|
179
|
+
}
|
|
180
|
+
} finally {
|
|
181
|
+
if (!cancelled) {
|
|
154
182
|
setLoading(false);
|
|
155
183
|
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
fetchSingleItem();
|
|
188
|
+
|
|
189
|
+
return () => {
|
|
190
|
+
cancelled = true;
|
|
191
|
+
};
|
|
192
|
+
}, [activeId, memoizedPartners, memoizedService]);
|
|
160
193
|
|
|
161
194
|
useEffect(() => {
|
|
162
195
|
_setPartners(selectedPartners?.partners);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService.js";
|
|
2
|
+
import { createLazyService } from "./helpers/LazyService.js";
|
|
3
|
+
import { filterCreateData } from "../../helpers/Forms.js";
|
|
4
|
+
|
|
5
|
+
class MineSiteService extends BaseService {
|
|
6
|
+
get(params) {
|
|
7
|
+
const { datastakeId, ...rest } = params;
|
|
8
|
+
if(datastakeId) {
|
|
9
|
+
return this.apiGet({
|
|
10
|
+
url: `/location/${datastakeId}`,
|
|
11
|
+
params: {...rest},
|
|
12
|
+
isApp: true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return this.apiGet({
|
|
16
|
+
url: "/location",
|
|
17
|
+
params: {...rest},
|
|
18
|
+
isApp: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getOne(id, params) {
|
|
23
|
+
return this.apiGet({
|
|
24
|
+
url: `/location/${id}`,
|
|
25
|
+
params,
|
|
26
|
+
isApp: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getForm(scope = "create", language = "en") {
|
|
31
|
+
return this.apiGet({
|
|
32
|
+
url: `/forms/location`,
|
|
33
|
+
params: { scope, language },
|
|
34
|
+
isApp: true,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getAll(params, signal) {
|
|
39
|
+
return this.apiGet({
|
|
40
|
+
url: "/location",
|
|
41
|
+
params,
|
|
42
|
+
signal,
|
|
43
|
+
isApp: true,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getData(id, sourceId, source, version) {
|
|
48
|
+
return this.apiGet({
|
|
49
|
+
url: `/location/${id}`,
|
|
50
|
+
isApp: true,
|
|
51
|
+
params: { authorId: sourceId, source, version },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
submit(payload) {
|
|
56
|
+
if (payload.id) {
|
|
57
|
+
// eslint-disable-next-line no-unused-vars
|
|
58
|
+
const { namespace, ...data } = payload;
|
|
59
|
+
return this.apiPut({
|
|
60
|
+
url: `/location/${payload.id}`,
|
|
61
|
+
data: filterCreateData(data),
|
|
62
|
+
isApp: true,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (payload?.form) {
|
|
66
|
+
delete payload.form;
|
|
67
|
+
return this.apiPost({
|
|
68
|
+
url: "/location",
|
|
69
|
+
data: filterCreateData(payload),
|
|
70
|
+
isApp: true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return this.apiPost({
|
|
74
|
+
url: "/location",
|
|
75
|
+
data: filterCreateData(payload),
|
|
76
|
+
isApp: true,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
submitStep(data, id) {
|
|
81
|
+
return this.apiPut({
|
|
82
|
+
isApp: true,
|
|
83
|
+
url: `/location/submit/${id}`,
|
|
84
|
+
data: filterCreateData(data),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
remove(id, data) {
|
|
89
|
+
return this.apiDelete({
|
|
90
|
+
url: `/location/${id}/remove`,
|
|
91
|
+
data: data,
|
|
92
|
+
isApp: true,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getOptions(id = "countries,minerals") {
|
|
97
|
+
return this.apiGet({
|
|
98
|
+
isApp: true,
|
|
99
|
+
url: `/forms/options`,
|
|
100
|
+
params: { id },
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export default createLazyService(MineSiteService);
|
package/src/helpers/user.js
CHANGED
|
@@ -146,7 +146,7 @@ export const userHasInterface = (user, app, intf) => {
|
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
export const userIsAdmin = (user) => {
|
|
149
|
-
return user?.role?.id === 'APP_ADMIN';
|
|
149
|
+
return user?.role?.id === 'APP_ADMIN' || user?.role?.id === 'SUPER_ADMIN';
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
export const createModule = (selectedModule, role = "user") => {
|
|
@@ -193,3 +193,18 @@ export function getRedirectPath(user, fallback = '', app, isDatastake) {
|
|
|
193
193
|
|
|
194
194
|
return isDatastake ? `/${app}/app` : '/app';
|
|
195
195
|
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
export function mapUser(user) {
|
|
199
|
+
return {
|
|
200
|
+
...user,
|
|
201
|
+
company: user.company,
|
|
202
|
+
verified: user.emailVerified,
|
|
203
|
+
companyId: user?.company?.id,
|
|
204
|
+
modules: Array.isArray(user.company?.modules) ?
|
|
205
|
+
user.company?.modules.reduce((all, item) => {
|
|
206
|
+
all[item.id] = item;
|
|
207
|
+
return all;
|
|
208
|
+
}, {}) : user.company?.modules || {},
|
|
209
|
+
};
|
|
210
|
+
}
|
package/src/services.js
CHANGED
|
@@ -20,4 +20,5 @@ export { default as LinkedSubjectsService } from './@daf/services/LinkedSubjects
|
|
|
20
20
|
export { default as OperatorService } from './@daf/services/OperatorService.js';
|
|
21
21
|
export { default as PartnerService } from './@daf/services/PartnerService.js';
|
|
22
22
|
export { default as EventsService } from './@daf/services/EventsService.js';
|
|
23
|
-
export { default as WorkersService } from './@daf/services/WorkersService.js';
|
|
23
|
+
export { default as WorkersService } from './@daf/services/WorkersService.js';
|
|
24
|
+
export { default as MineSiteService } from './@daf/services/MineSiteService.js';
|
package/src/utils.js
CHANGED
|
@@ -21,7 +21,7 @@ export { getOptionConfig, getOptionLabel } from './@daf/core/components/DynamicV
|
|
|
21
21
|
|
|
22
22
|
export { defaultMapConfig } from './@daf/hooks/useMapHelper.js';
|
|
23
23
|
|
|
24
|
-
export { getInterface, modules, isSuperAdmin, isModuleApproved, userHasInterface, userIsAdmin, createModule, mapModulesFromApps, getRedirectPath } from './helpers/user.js'
|
|
24
|
+
export { getInterface, modules, isSuperAdmin, isModuleApproved, userHasInterface, userIsAdmin, createModule, mapModulesFromApps, getRedirectPath, mapUser } from './helpers/user.js'
|
|
25
25
|
|
|
26
26
|
export { default as locales } from './constants/locales/index.js';
|
|
27
27
|
|