datastake-daf 0.6.798 → 0.6.799
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 +3158 -985
- package/dist/context/index.js +6 -6
- package/dist/pages/index.js +252 -13
- package/dist/services/index.js +112 -9
- package/dist/utils/index.js +14 -17
- package/package.json +1 -1
- package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/TopContributors/hook.js +0 -1
- package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/TopContributors/index.jsx +1 -1
- package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/UserGrowth/hook.js +1 -1
- package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/UserGrowth/index.jsx +1 -1
- package/src/@daf/core/components/Screens/Admin/AdminModals/AddUser/index.jsx +0 -1
- package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/columns.js +79 -0
- package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/helper.js +2 -2
- package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/index.jsx +18 -8
- package/src/@daf/core/components/Screens/Admin/AdminModals/CombineSubjects/index.jsx +6 -6
- package/src/@daf/core/components/Screens/Admin/AdminModals/NewAccount/index.jsx +1 -1
- package/src/@daf/core/components/Screens/Admin/AdminModals/NewUser/index.jsx +61 -38
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Accounts.jsx +1 -4
- package/src/@daf/core/components/Screens/Admin/AdminScreens/AccountsView.jsx +2 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Dashboard.jsx +2 -2
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Location.jsx +6 -7
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Subjects.jsx +2 -3
- package/src/@daf/core/components/Screens/Admin/AdminScreens/SubjectsView.jsx +395 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/index.js +1 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/AccountTable/index.jsx +1 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/column.js +223 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/helper.js +65 -0
- package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/index.jsx +73 -45
- package/src/@daf/core/components/Screens/Admin/AdminTables/SubjectsTable/columns.js +37 -37
- package/src/@daf/core/components/Screens/Admin/AdminTables/SubjectsTable/index.jsx +48 -22
- package/src/@daf/core/components/Screens/Admin/AdminTables/UserTable/index.jsx +1 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/configTransformer.js +137 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/index.js +9 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/index.jsx +196 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/configTransformer.js +216 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/index.js +7 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/index.jsx +184 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/config.js +64 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/helpers.js +13 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/index.jsx +77 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/config.js +51 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/helpers.js +0 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/index.jsx +75 -0
- package/src/@daf/core/components/Screens/Admin/AdminViews/components/Edit/index.jsx +7 -1
- package/src/@daf/core/components/Screens/Admin/AdminViews/components/SidebarMenu/index.jsx +5 -3
- package/src/@daf/core/components/Screens/Admin/AdminViews/components/Users/helper.js +13 -8
- package/src/@daf/core/components/Screens/Admin/AdminViews/components/Users/index.jsx +16 -10
- package/src/@daf/core/components/Screens/Admin/AdminViews/components/View/index.jsx +2 -1
- package/src/@daf/core/components/Screens/Admin/AdminViews/index.jsx +66 -26
- package/src/@daf/core/components/Screens/Admin/AppInvitation/index.jsx +193 -0
- package/src/@daf/core/components/Screens/Admin/adminRoutes.js +81 -2
- package/src/@daf/layouts/AppLayout/index.jsx +0 -1
- package/src/@daf/pages/SelfAssesment/components/AssociatedInformationTable/columns.js +180 -0
- package/src/@daf/pages/SelfAssesment/components/AssociatedInformationTable/config.js +0 -0
- package/src/@daf/pages/SelfAssesment/components/AssociatedInformationTable/index.jsx +27 -0
- package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/columns.js +157 -0
- package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/config.js +31 -0
- package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/index.js +77 -0
- package/src/@daf/pages/SelfAssesment/components/ProductionSiteTable/columns.js +117 -0
- package/src/@daf/pages/SelfAssesment/components/ProductionSiteTable/index.jsx +54 -0
- package/src/@daf/pages/SelfAssesment/index.jsx +0 -0
- package/src/@daf/pages/View/hooks/usePrepareForm.js +11 -1
- package/src/@daf/pages/View/index.jsx +13 -2
- package/src/@daf/services/AdminService.js +111 -7
- package/src/@daf/services/AuthenticationService.js +1 -0
- package/src/@daf/services/DashboardService.js +2 -1
- package/src/@daf/utils/filters.js +15 -13
- package/src/constants/locales/en/translation.js +7 -0
- package/src/constants/locales/fr/translation.js +1 -1
- package/src/constants/locales/sp/translation.js +1 -1
- package/src/index.js +1 -0
- package/build/favicon.ico +0 -0
- package/build/logo192.png +0 -0
- package/build/logo512.png +0 -0
- package/build/manifest.json +0 -25
- package/build/robots.txt +0 -3
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useForms } from "../../../../../context/Forms";
|
|
3
|
+
import { EditForm } from "../../../../EditForm/form.jsx";
|
|
4
|
+
import { transformConfigToEditForm } from "./configTransformer.js";
|
|
5
|
+
import { getMainApiUrl, getAppHeader as getBaseAppHeader } from "../../../../../../services/BaseService.js";
|
|
6
|
+
import { convertUndefinedToNull } from "../../../../../../utils/object.js";
|
|
7
|
+
|
|
8
|
+
export default function EditLocation({
|
|
9
|
+
t,
|
|
10
|
+
conf,
|
|
11
|
+
data = {},
|
|
12
|
+
formOptions = {},
|
|
13
|
+
MainForm,
|
|
14
|
+
setData = () => {},
|
|
15
|
+
isChanged,
|
|
16
|
+
setIsChanged,
|
|
17
|
+
goToView,
|
|
18
|
+
getApiBaseUrl = getMainApiUrl,
|
|
19
|
+
getAppHeader = getBaseAppHeader,
|
|
20
|
+
user = null,
|
|
21
|
+
goTo = () => {},
|
|
22
|
+
query = null,
|
|
23
|
+
app = null,
|
|
24
|
+
}) {
|
|
25
|
+
console.log('EditLocation - Props received:', {
|
|
26
|
+
conf,
|
|
27
|
+
data,
|
|
28
|
+
formOptions,
|
|
29
|
+
isChanged,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const { addCheck, removeCheck } = useForms();
|
|
33
|
+
|
|
34
|
+
const [inputsMeta, setInputsMeta] = useState({});
|
|
35
|
+
const [linkingForms, setLinkingForms] = useState({});
|
|
36
|
+
const [errors, setErrors] = useState({});
|
|
37
|
+
const [ajaxForms, setAjaxForms] = useState({});
|
|
38
|
+
const [ajaxOptions, setAjaxOptions] = useState({});
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (isChanged) {
|
|
42
|
+
addCheck(() => goToView());
|
|
43
|
+
} else {
|
|
44
|
+
removeCheck();
|
|
45
|
+
}
|
|
46
|
+
}, [isChanged, addCheck, removeCheck, goToView]);
|
|
47
|
+
|
|
48
|
+
const editFormConfig = useMemo(() => {
|
|
49
|
+
console.log('EditLocation - Transforming config:', {
|
|
50
|
+
conf,
|
|
51
|
+
formOptions,
|
|
52
|
+
});
|
|
53
|
+
const transformed = transformConfigToEditForm(conf, formOptions, t);
|
|
54
|
+
console.log('EditLocation - Transformed editFormConfig:', transformed);
|
|
55
|
+
return transformed;
|
|
56
|
+
}, [conf, formOptions, t]);
|
|
57
|
+
|
|
58
|
+
const onValuesChange = (changedValues, allValues) => {
|
|
59
|
+
console.log('EditLocation - Values changed:', {
|
|
60
|
+
changedValues,
|
|
61
|
+
allValues,
|
|
62
|
+
});
|
|
63
|
+
expectations
|
|
64
|
+
const convertedValues = convertUndefinedToNull(allValues);
|
|
65
|
+
|
|
66
|
+
setIsChanged(true);
|
|
67
|
+
setData(convertedValues);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const changeInputMeta = ({ key, type, value, otherValues = {} }) => {
|
|
71
|
+
console.log('EditLocation - changeInputMeta:', { key, type, value, otherValues });
|
|
72
|
+
|
|
73
|
+
setInputsMeta((prev) => ({
|
|
74
|
+
...prev,
|
|
75
|
+
[key]: { ...(prev[key] || {}), ...value },
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
const otherValuesKeys = Object.keys(otherValues);
|
|
79
|
+
if (otherValuesKeys.length) {
|
|
80
|
+
otherValuesKeys.forEach((k) => {
|
|
81
|
+
MainForm.setFieldValue(k, otherValues[k]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const updatedData = {
|
|
85
|
+
...data,
|
|
86
|
+
...otherValues,
|
|
87
|
+
};
|
|
88
|
+
setData(updatedData);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const changeLinking = ({ key, linkingKey, value }) => {
|
|
93
|
+
console.log('EditLocation - changeLinking:', { key, linkingKey, value });
|
|
94
|
+
|
|
95
|
+
const updatedLinking = {
|
|
96
|
+
...linkingForms,
|
|
97
|
+
[key]: {
|
|
98
|
+
...(linkingForms[key] || {}),
|
|
99
|
+
[linkingKey]: value,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
setLinkingForms(updatedLinking);
|
|
104
|
+
|
|
105
|
+
const updatedData = {
|
|
106
|
+
...data,
|
|
107
|
+
linking: {
|
|
108
|
+
...(data?.linking || {}),
|
|
109
|
+
[key]: {
|
|
110
|
+
...((data?.linking || {})[key] || {}),
|
|
111
|
+
[linkingKey]: value,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
setData(updatedData);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const changeErrors = (newErrors) => {
|
|
120
|
+
console.log('EditLocation - changeErrors:', newErrors);
|
|
121
|
+
setErrors(newErrors);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const changeAjaxForms = (newAjaxForms) => {
|
|
125
|
+
console.log('EditLocation - changeAjaxForms:', newAjaxForms);
|
|
126
|
+
setAjaxForms(newAjaxForms);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const changeAjaxOptions = (newAjaxOptions) => {
|
|
130
|
+
console.log('EditLocation - changeAjaxOptions:', newAjaxOptions);
|
|
131
|
+
setAjaxOptions(newAjaxOptions);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
if (!editFormConfig) {
|
|
135
|
+
console.error('EditLocation - No editFormConfig generated!');
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
const definition = (
|
|
141
|
+
<>
|
|
142
|
+
<div className="group">
|
|
143
|
+
<div className="daf-title with-subtitle">
|
|
144
|
+
<h1>{t(conf.title)}</h1>
|
|
145
|
+
{conf.description && (
|
|
146
|
+
<p style={{
|
|
147
|
+
color: '#8c8c8c',
|
|
148
|
+
fontSize: '14px',
|
|
149
|
+
marginTop: '8px',
|
|
150
|
+
marginBottom: '0',
|
|
151
|
+
lineHeight: '1.5'
|
|
152
|
+
}}>
|
|
153
|
+
{t(conf.description)}
|
|
154
|
+
</p>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
</>
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<div className="form-edit flex-row">
|
|
163
|
+
<EditForm
|
|
164
|
+
form={editFormConfig}
|
|
165
|
+
data={data}
|
|
166
|
+
allData={data}
|
|
167
|
+
MainForm={MainForm}
|
|
168
|
+
onValuesChange={onValuesChange}
|
|
169
|
+
t={t}
|
|
170
|
+
definition={definition}
|
|
171
|
+
plainForms={{}}
|
|
172
|
+
linkingForms={linkingForms}
|
|
173
|
+
inputsMeta={inputsMeta}
|
|
174
|
+
changeInputMeta={changeInputMeta}
|
|
175
|
+
changeLinking={changeLinking}
|
|
176
|
+
errors={errors}
|
|
177
|
+
changeErrors={changeErrors}
|
|
178
|
+
staticWidth="614px"
|
|
179
|
+
fullWidth={false}
|
|
180
|
+
noConvert={false}
|
|
181
|
+
getApiBaseUrl={getApiBaseUrl}
|
|
182
|
+
getAppHeader={getAppHeader}
|
|
183
|
+
getMainApiUrl={getMainApiUrl}
|
|
184
|
+
user={user}
|
|
185
|
+
ajaxForms={ajaxForms}
|
|
186
|
+
ajaxOptions={ajaxOptions}
|
|
187
|
+
changeAjaxForms={changeAjaxForms}
|
|
188
|
+
changeAjaxOptions={changeAjaxOptions}
|
|
189
|
+
app={app}
|
|
190
|
+
query={query}
|
|
191
|
+
goTo={goTo}
|
|
192
|
+
/>
|
|
193
|
+
</div>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/configTransformer.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transforms simple config format to EditForm's expected format
|
|
3
|
+
*
|
|
4
|
+
* Simple config format:
|
|
5
|
+
* {
|
|
6
|
+
* title: "Core Data",
|
|
7
|
+
* key: "core-data",
|
|
8
|
+
* items: [
|
|
9
|
+
* { label: "Name", key: "name", type: "select", optionsName: "category" }
|
|
10
|
+
* ]
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* EditForm format:
|
|
14
|
+
* {
|
|
15
|
+
* id: "core-data",
|
|
16
|
+
* options: {
|
|
17
|
+
* name: {
|
|
18
|
+
* type: "select",
|
|
19
|
+
* label: "Name",
|
|
20
|
+
* options: [...],
|
|
21
|
+
* meta: {}
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Transforms a config item to EditForm option format
|
|
29
|
+
* @param {Object} item - Config item
|
|
30
|
+
* @param {Object} formOptions - Available form options (countries, categories, etc.)
|
|
31
|
+
* @param {Function} t - Translation function
|
|
32
|
+
* @returns {Object} EditForm option configuration
|
|
33
|
+
*/
|
|
34
|
+
export function transformConfigItem(item, formOptions = {}, t = (s) => s) {
|
|
35
|
+
const {
|
|
36
|
+
key,
|
|
37
|
+
label,
|
|
38
|
+
type,
|
|
39
|
+
optionsName,
|
|
40
|
+
level,
|
|
41
|
+
placeholder,
|
|
42
|
+
rules,
|
|
43
|
+
showFormIf,
|
|
44
|
+
disabled,
|
|
45
|
+
defaultValue,
|
|
46
|
+
meta: configMeta = {},
|
|
47
|
+
...rest
|
|
48
|
+
} = item;
|
|
49
|
+
|
|
50
|
+
const option = {
|
|
51
|
+
type: type || "text",
|
|
52
|
+
label: label,
|
|
53
|
+
meta: { ...configMeta },
|
|
54
|
+
...rest,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (placeholder) {
|
|
58
|
+
option.placeholder = placeholder;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (rules && Array.isArray(rules)) {
|
|
62
|
+
option.rules = rules;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (showFormIf) {
|
|
66
|
+
option.showFormIf = showFormIf;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (disabled !== undefined) {
|
|
70
|
+
option.disabled = disabled;
|
|
71
|
+
option.meta.disableEdit = disabled;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (defaultValue !== undefined) {
|
|
75
|
+
option.meta.defaultValue = defaultValue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (type === "select" || type === "multiselect") {
|
|
79
|
+
if (optionsName && formOptions[optionsName]) {
|
|
80
|
+
option.options = formOptions[optionsName].map((opt) => {
|
|
81
|
+
if (typeof opt === 'object' && opt !== null) {
|
|
82
|
+
return {
|
|
83
|
+
value: opt.value,
|
|
84
|
+
label: t(opt.label || opt.value),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
value: opt,
|
|
89
|
+
label: t(opt),
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
} else if (level && formOptions[level]) {
|
|
93
|
+
option.options = formOptions[level].map((opt) => {
|
|
94
|
+
if (typeof opt === 'object' && opt !== null) {
|
|
95
|
+
return {
|
|
96
|
+
value: opt.value,
|
|
97
|
+
label: t(opt.label || opt.value),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
value: opt,
|
|
102
|
+
label: t(opt),
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
option.options = [];
|
|
107
|
+
console.warn(`No options found for field "${key}" with optionsName="${optionsName}" or level="${level}"`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (type === "multiselect") {
|
|
111
|
+
option.mode = "multiple";
|
|
112
|
+
option.type = "select";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (type === "ajaxSelect") {
|
|
117
|
+
const { entity, method, mapper, filters } = item;
|
|
118
|
+
|
|
119
|
+
if (!entity || !method || !mapper) {
|
|
120
|
+
console.error(`ajaxSelect field "${key}" is missing required properties (entity, method, or mapper)`);
|
|
121
|
+
option.type = "text";
|
|
122
|
+
option.disabled = true;
|
|
123
|
+
} else {
|
|
124
|
+
const filtersString = filters ? JSON.stringify(filters) : "{}";
|
|
125
|
+
const mapperString = JSON.stringify(mapper);
|
|
126
|
+
option.meta.call = `${entity}::${method}(${filtersString})::${mapperString}`;
|
|
127
|
+
option.type = "ajaxSelect";
|
|
128
|
+
|
|
129
|
+
// Disable "add new" functionality if noAddNew is set
|
|
130
|
+
if (option.meta.noAddNew) {
|
|
131
|
+
option.onNewSetValue = false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (type === "administrative") {
|
|
137
|
+
option.type = "text";
|
|
138
|
+
option.disabled = true;
|
|
139
|
+
option.meta.disableEdit = false;
|
|
140
|
+
if (level) {
|
|
141
|
+
option.meta.level = level;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (type === "input") {
|
|
146
|
+
option.type = "text";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (type === "switch" || type === "checkbox") {
|
|
150
|
+
option.type = type;
|
|
151
|
+
if (defaultValue === undefined) {
|
|
152
|
+
option.meta.defaultValue = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (type === "date" || type === "datetime" || type === "year") {
|
|
157
|
+
option.type = type;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (type === "textarea") {
|
|
161
|
+
option.type = "textarea";
|
|
162
|
+
option.rows = item.rows || 4;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (type === "number") {
|
|
166
|
+
option.type = "text";
|
|
167
|
+
option.meta.inputType = "number";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (option.position === undefined) {
|
|
171
|
+
option.position = 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return option;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Transforms simple config format to EditForm format
|
|
180
|
+
* @param {Object} conf - Simple config object
|
|
181
|
+
* @param {Object} formOptions - Available form options
|
|
182
|
+
* @param {Function} t - Translation function
|
|
183
|
+
* @returns {Object} EditForm configuration
|
|
184
|
+
*/
|
|
185
|
+
export function transformConfigToEditForm(conf, formOptions = {}, t = (s) => s) {
|
|
186
|
+
if (!conf || !conf.items || !Array.isArray(conf.items)) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const options = {};
|
|
191
|
+
conf.items.forEach((item, index) => {
|
|
192
|
+
const transformedOption = transformConfigItem(item, formOptions, t);
|
|
193
|
+
transformedOption.position = item.position !== undefined ? item.position : index;
|
|
194
|
+
options[item.key] = transformedOption;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
id: conf.key || "edit-form",
|
|
199
|
+
introText: "",
|
|
200
|
+
formTitles: conf.formTitles || {},
|
|
201
|
+
options,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Extracts field keys from config for filtering form data
|
|
207
|
+
* @param {Object} conf - Simple config object
|
|
208
|
+
* @returns {Array} Array of field keys
|
|
209
|
+
*/
|
|
210
|
+
export function getConfigFieldKeys(conf) {
|
|
211
|
+
if (!conf || !conf.items || !Array.isArray(conf.items)) {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
return conf.items.map((item) => item.key);
|
|
215
|
+
}
|
|
216
|
+
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useForms } from "../../../../../context/Forms";
|
|
3
|
+
import { EditForm } from "../../../../EditForm/form.jsx";
|
|
4
|
+
import { transformConfigToEditForm } from "./configTransformer.js";
|
|
5
|
+
import { getMainApiUrl, getAppHeader as getBaseAppHeader } from "../../../../../../services/BaseService.js";
|
|
6
|
+
import { convertUndefinedToNull } from "../../../../../../utils/object.js";
|
|
7
|
+
|
|
8
|
+
export default function EditStakeholder({
|
|
9
|
+
t,
|
|
10
|
+
conf,
|
|
11
|
+
data = {},
|
|
12
|
+
formOptions = {},
|
|
13
|
+
MainForm,
|
|
14
|
+
setData = () => {},
|
|
15
|
+
isChanged,
|
|
16
|
+
setIsChanged,
|
|
17
|
+
goToView,
|
|
18
|
+
getApiBaseUrl = getMainApiUrl,
|
|
19
|
+
getAppHeader = getBaseAppHeader,
|
|
20
|
+
user = null,
|
|
21
|
+
goTo = () => {},
|
|
22
|
+
query = null,
|
|
23
|
+
app = null,
|
|
24
|
+
}) {
|
|
25
|
+
const { addCheck, removeCheck } = useForms();
|
|
26
|
+
|
|
27
|
+
const [inputsMeta, setInputsMeta] = useState({});
|
|
28
|
+
const [linkingForms, setLinkingForms] = useState({});
|
|
29
|
+
const [errors, setErrors] = useState({});
|
|
30
|
+
const [ajaxForms, setAjaxForms] = useState({});
|
|
31
|
+
const [ajaxOptions, setAjaxOptions] = useState({});
|
|
32
|
+
|
|
33
|
+
console.log('EditStakeholder - Data received:', data);
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (isChanged) {
|
|
39
|
+
addCheck(() => goToView());
|
|
40
|
+
} else {
|
|
41
|
+
removeCheck();
|
|
42
|
+
}
|
|
43
|
+
}, [isChanged, addCheck, removeCheck, goToView]);
|
|
44
|
+
|
|
45
|
+
const editFormConfig = useMemo(() => {
|
|
46
|
+
return transformConfigToEditForm(conf, formOptions, t);
|
|
47
|
+
}, [conf, formOptions, t]);
|
|
48
|
+
|
|
49
|
+
const onValuesChange = (changedValues, allValues) => {
|
|
50
|
+
console.log('EditStakeholder - Values changed:', {
|
|
51
|
+
changedValues,
|
|
52
|
+
allValues,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const convertedValues = convertUndefinedToNull(allValues);
|
|
56
|
+
|
|
57
|
+
setIsChanged(true);
|
|
58
|
+
setData(convertedValues);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const changeInputMeta = ({ key, type, value, otherValues = {} }) => {
|
|
62
|
+
console.log('EditStakeholder - changeInputMeta:', { key, type, value, otherValues });
|
|
63
|
+
|
|
64
|
+
setInputsMeta((prev) => ({
|
|
65
|
+
...prev,
|
|
66
|
+
[key]: { ...(prev[key] || {}), ...value },
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
const otherValuesKeys = Object.keys(otherValues);
|
|
70
|
+
if (otherValuesKeys.length) {
|
|
71
|
+
otherValuesKeys.forEach((k) => {
|
|
72
|
+
MainForm.setFieldValue(k, otherValues[k]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const updatedData = {
|
|
76
|
+
...data,
|
|
77
|
+
...otherValues,
|
|
78
|
+
};
|
|
79
|
+
setData(updatedData);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const changeLinking = ({ key, linkingKey, value }) => {
|
|
84
|
+
console.log('EditStakeholder - changeLinking:', { key, linkingKey, value });
|
|
85
|
+
|
|
86
|
+
const updatedLinking = {
|
|
87
|
+
...linkingForms,
|
|
88
|
+
[key]: {
|
|
89
|
+
...(linkingForms[key] || {}),
|
|
90
|
+
[linkingKey]: value,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
setLinkingForms(updatedLinking);
|
|
95
|
+
|
|
96
|
+
const updatedData = {
|
|
97
|
+
...data,
|
|
98
|
+
linking: {
|
|
99
|
+
...(data?.linking || {}),
|
|
100
|
+
[key]: {
|
|
101
|
+
...((data?.linking || {})[key] || {}),
|
|
102
|
+
[linkingKey]: value,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
setData(updatedData);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const changeErrors = (newErrors) => {
|
|
111
|
+
console.log('EditStakeholder - changeErrors:', newErrors);
|
|
112
|
+
setErrors(newErrors);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const changeAjaxForms = (newAjaxForms) => {
|
|
116
|
+
console.log('EditStakeholder - changeAjaxForms:', newAjaxForms);
|
|
117
|
+
setAjaxForms(newAjaxForms);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const changeAjaxOptions = (newAjaxOptions) => {
|
|
121
|
+
console.log('EditStakeholder - changeAjaxOptions:', newAjaxOptions);
|
|
122
|
+
setAjaxOptions(newAjaxOptions);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
if (!editFormConfig) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const definition = (
|
|
130
|
+
<>
|
|
131
|
+
<div className="group">
|
|
132
|
+
<div className="daf-title with-subtitle">
|
|
133
|
+
<h1>{t(conf.title)}</h1>
|
|
134
|
+
{conf.description && (
|
|
135
|
+
<p style={{
|
|
136
|
+
color: '#8c8c8c',
|
|
137
|
+
fontSize: '14px',
|
|
138
|
+
marginTop: '8px',
|
|
139
|
+
marginBottom: '0',
|
|
140
|
+
lineHeight: '1.5'
|
|
141
|
+
}}>
|
|
142
|
+
{t(conf.description)}
|
|
143
|
+
</p>
|
|
144
|
+
)}
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
</>
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div className="form-edit flex-row">
|
|
152
|
+
<EditForm
|
|
153
|
+
form={editFormConfig}
|
|
154
|
+
data={data}
|
|
155
|
+
allData={data}
|
|
156
|
+
MainForm={MainForm}
|
|
157
|
+
onValuesChange={onValuesChange}
|
|
158
|
+
t={t}
|
|
159
|
+
definition={definition}
|
|
160
|
+
plainForms={{}}
|
|
161
|
+
linkingForms={linkingForms}
|
|
162
|
+
inputsMeta={inputsMeta}
|
|
163
|
+
changeInputMeta={changeInputMeta}
|
|
164
|
+
changeLinking={changeLinking}
|
|
165
|
+
errors={errors}
|
|
166
|
+
changeErrors={changeErrors}
|
|
167
|
+
staticWidth="614px"
|
|
168
|
+
fullWidth={false}
|
|
169
|
+
noConvert={false}
|
|
170
|
+
getApiBaseUrl={getApiBaseUrl}
|
|
171
|
+
getAppHeader={getAppHeader}
|
|
172
|
+
getMainApiUrl={getMainApiUrl}
|
|
173
|
+
user={user}
|
|
174
|
+
ajaxForms={ajaxForms}
|
|
175
|
+
ajaxOptions={ajaxOptions}
|
|
176
|
+
changeAjaxForms={changeAjaxForms}
|
|
177
|
+
changeAjaxOptions={changeAjaxOptions}
|
|
178
|
+
app={app}
|
|
179
|
+
query={query}
|
|
180
|
+
goTo={goTo}
|
|
181
|
+
/>
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const config = [
|
|
2
|
+
{
|
|
3
|
+
label: "Core Data",
|
|
4
|
+
key: "core-data",
|
|
5
|
+
title: "Core Data",
|
|
6
|
+
description: "this-data-is-used-to-identify-the-location.Changing-it-will-affect-the-subject-itself,any-forms-where-it-appears-and-any-related-or-linked-subjects.",
|
|
7
|
+
items: [
|
|
8
|
+
{
|
|
9
|
+
label: "Name",
|
|
10
|
+
key: "name",
|
|
11
|
+
type: "text",
|
|
12
|
+
placeholder: "Enter location name",
|
|
13
|
+
rules: [
|
|
14
|
+
{ required: true, message: "errors::Name is required" }
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
label: "Category",
|
|
19
|
+
key: "category",
|
|
20
|
+
type: "select",
|
|
21
|
+
optionsName: "categories",
|
|
22
|
+
placeholder: "Select a category",
|
|
23
|
+
rules: [
|
|
24
|
+
{ required: true, message: "errors::Category is required" }
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: "Country",
|
|
29
|
+
key: "country",
|
|
30
|
+
type: "select",
|
|
31
|
+
optionsName: "countries",
|
|
32
|
+
placeholder: "Select a country",
|
|
33
|
+
rules: [
|
|
34
|
+
{ required: true, message: "errors::Country is required" }
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: "Administrative Level 1",
|
|
39
|
+
key: "administrativeLevel1",
|
|
40
|
+
type: "ajaxSelect",
|
|
41
|
+
entity: "AdministrativeLevel",
|
|
42
|
+
method: "getOptions",
|
|
43
|
+
optionsName: "level_1",
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
label: "Administrative Level 2",
|
|
53
|
+
key: "administrativeLevel2",
|
|
54
|
+
type: "ajaxSelect",
|
|
55
|
+
entity: "AdministrativeLevel",
|
|
56
|
+
method: "getOptions",
|
|
57
|
+
optionsName: "level_2",
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const getNameByLevel = (data, level) => {
|
|
2
|
+
const entry = Object.values(data || {}).find(item => item.level === level);
|
|
3
|
+
return entry?.name || "-";
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const getAdministrativeLevel1 = (location) => {
|
|
7
|
+
return getNameByLevel(location?.linking?.SCL.name, "level_1");
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const getAdministrativeLevel2 = (location) => {
|
|
11
|
+
return getNameByLevel(location?.linking?.SCL.name, "level_2");
|
|
12
|
+
};
|
|
13
|
+
|