datastake-daf 0.6.797 → 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.
Files changed (85) hide show
  1. package/dist/components/index.js +3164 -972
  2. package/dist/context/index.js +6 -6
  3. package/dist/pages/index.js +10674 -1442
  4. package/dist/services/index.js +112 -9
  5. package/dist/utils/index.js +71 -19
  6. package/package.json +1 -1
  7. package/src/@daf/core/components/EditForm/sections.jsx +18 -8
  8. package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/TopContributors/hook.js +0 -1
  9. package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/TopContributors/index.jsx +1 -1
  10. package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/UserGrowth/hook.js +1 -1
  11. package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/UserGrowth/index.jsx +1 -1
  12. package/src/@daf/core/components/Screens/Admin/AdminModals/AddUser/index.jsx +0 -1
  13. package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/columns.js +79 -0
  14. package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/helper.js +2 -2
  15. package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/index.jsx +18 -8
  16. package/src/@daf/core/components/Screens/Admin/AdminModals/CombineSubjects/index.jsx +6 -6
  17. package/src/@daf/core/components/Screens/Admin/AdminModals/NewAccount/index.jsx +1 -1
  18. package/src/@daf/core/components/Screens/Admin/AdminModals/NewUser/index.jsx +61 -38
  19. package/src/@daf/core/components/Screens/Admin/AdminScreens/Accounts.jsx +1 -4
  20. package/src/@daf/core/components/Screens/Admin/AdminScreens/AccountsView.jsx +2 -0
  21. package/src/@daf/core/components/Screens/Admin/AdminScreens/Dashboard.jsx +2 -2
  22. package/src/@daf/core/components/Screens/Admin/AdminScreens/Location.jsx +6 -7
  23. package/src/@daf/core/components/Screens/Admin/AdminScreens/Subjects.jsx +2 -3
  24. package/src/@daf/core/components/Screens/Admin/AdminScreens/SubjectsView.jsx +395 -0
  25. package/src/@daf/core/components/Screens/Admin/AdminScreens/index.js +1 -0
  26. package/src/@daf/core/components/Screens/Admin/AdminTables/AccountTable/index.jsx +1 -0
  27. package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/column.js +223 -0
  28. package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/helper.js +65 -0
  29. package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/index.jsx +73 -45
  30. package/src/@daf/core/components/Screens/Admin/AdminTables/SubjectsTable/columns.js +37 -37
  31. package/src/@daf/core/components/Screens/Admin/AdminTables/SubjectsTable/index.jsx +48 -22
  32. package/src/@daf/core/components/Screens/Admin/AdminTables/UserTable/index.jsx +1 -0
  33. package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/configTransformer.js +137 -0
  34. package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/index.js +9 -0
  35. package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/index.jsx +196 -0
  36. package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/configTransformer.js +216 -0
  37. package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/index.js +7 -0
  38. package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/index.jsx +184 -0
  39. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/config.js +64 -0
  40. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/helpers.js +13 -0
  41. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/index.jsx +77 -0
  42. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/config.js +51 -0
  43. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/helpers.js +0 -0
  44. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/index.jsx +75 -0
  45. package/src/@daf/core/components/Screens/Admin/AdminViews/components/Edit/index.jsx +7 -1
  46. package/src/@daf/core/components/Screens/Admin/AdminViews/components/SidebarMenu/index.jsx +5 -3
  47. package/src/@daf/core/components/Screens/Admin/AdminViews/components/Users/helper.js +13 -8
  48. package/src/@daf/core/components/Screens/Admin/AdminViews/components/Users/index.jsx +16 -10
  49. package/src/@daf/core/components/Screens/Admin/AdminViews/components/View/index.jsx +2 -1
  50. package/src/@daf/core/components/Screens/Admin/AdminViews/index.jsx +66 -26
  51. package/src/@daf/core/components/Screens/Admin/AppInvitation/index.jsx +193 -0
  52. package/src/@daf/core/components/Screens/Admin/adminRoutes.js +81 -2
  53. package/src/@daf/layouts/AppLayout/index.jsx +0 -1
  54. package/src/@daf/pages/Edit/hooks/usePrepareForm.js +178 -0
  55. package/src/@daf/pages/Edit/index.jsx +356 -0
  56. package/src/@daf/pages/SelfAssesment/components/AssociatedInformationTable/columns.js +180 -0
  57. package/src/@daf/pages/SelfAssesment/components/AssociatedInformationTable/config.js +0 -0
  58. package/src/@daf/pages/SelfAssesment/components/AssociatedInformationTable/index.jsx +27 -0
  59. package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/columns.js +157 -0
  60. package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/config.js +31 -0
  61. package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/index.js +77 -0
  62. package/src/@daf/pages/SelfAssesment/components/ProductionSiteTable/columns.js +117 -0
  63. package/src/@daf/pages/SelfAssesment/components/ProductionSiteTable/index.jsx +54 -0
  64. package/src/@daf/pages/SelfAssesment/index.jsx +0 -0
  65. package/src/@daf/pages/View/hooks/usePrepareForm.js +11 -1
  66. package/src/@daf/pages/View/hooks/useViewUrlParams.js +23 -1
  67. package/src/@daf/pages/View/index.jsx +14 -2
  68. package/src/@daf/services/AdminService.js +111 -7
  69. package/src/@daf/services/AuthenticationService.js +1 -0
  70. package/src/@daf/services/DashboardService.js +2 -1
  71. package/src/@daf/utils/arrays.js +1 -0
  72. package/src/@daf/utils/filters.js +15 -13
  73. package/src/constants/locales/en/translation.js +7 -0
  74. package/src/constants/locales/fr/translation.js +1 -1
  75. package/src/constants/locales/sp/translation.js +1 -1
  76. package/src/helpers/Forms.js +60 -0
  77. package/src/index.js +1 -0
  78. package/src/pages.js +4 -1
  79. package/src/utils.js +4 -2
  80. package/build/favicon.ico +0 -0
  81. package/build/logo192.png +0 -0
  82. package/build/logo512.png +0 -0
  83. package/build/manifest.json +0 -25
  84. package/build/robots.txt +0 -3
  85. package/dist/style/datastake/mapbox-gl.css +0 -330
@@ -5,6 +5,7 @@ import AdminAccountsScreen from "./AdminScreens/Accounts.jsx";
5
5
  import AdminAccountsViewScreen from "./AdminScreens/AccountsView.jsx";
6
6
  import AdminSubjectsScreen from "./AdminScreens/Subjects.jsx";
7
7
  import AdminLocationScreen from "./AdminScreens/Location.jsx";
8
+ import AdminSubjectsViewScreen from "./AdminScreens/SubjectsView.jsx";
8
9
 
9
10
  export function getAdminRoutes(config) {
10
11
  const {
@@ -15,6 +16,8 @@ export function getAdminRoutes(config) {
15
16
  useAdminAccountsViewConfig,
16
17
  useAdminSubjectsConfig,
17
18
  useAdminLocationConfig,
19
+ useAdminSubjectsViewConfig,
20
+ useAdminLocationViewConfig,
18
21
  userIsAdmin,
19
22
  } = config;
20
23
 
@@ -56,6 +59,38 @@ export function getAdminRoutes(config) {
56
59
  return <AdminLocationScreen config={locationConfig} />;
57
60
  }
58
61
 
62
+ function LocationViewWrapper() {
63
+ const locationViewConfig =
64
+ typeof useAdminLocationViewConfig === "function"
65
+ ? useAdminLocationViewConfig()
66
+ : undefined;
67
+ return <AdminSubjectsViewScreen config={{ ...locationViewConfig, subject: "location" }} />;
68
+ }
69
+
70
+ function StakeholderViewWrapper() {
71
+ const stakeholderViewConfig =
72
+ typeof useAdminSubjectsViewConfig === "function"
73
+ ? useAdminSubjectsViewConfig()
74
+ : undefined;
75
+ return <AdminSubjectsViewScreen config={{ ...stakeholderViewConfig, subject: "stakeholder" }} />;
76
+ }
77
+
78
+ function LocationEditWrapper() {
79
+ const locationViewConfig =
80
+ typeof useAdminLocationViewConfig === "function"
81
+ ? useAdminLocationViewConfig()
82
+ : undefined;
83
+ return <AdminSubjectsViewScreen config={{ ...locationViewConfig, subject: "location", mode: "edit" }} />;
84
+ }
85
+
86
+ function StakeholderEditWrapper() {
87
+ const stakeholderViewConfig =
88
+ typeof useAdminSubjectsViewConfig === "function"
89
+ ? useAdminSubjectsViewConfig()
90
+ : undefined;
91
+ return <AdminSubjectsViewScreen config={{ ...stakeholderViewConfig, subject: "stakeholder", mode: "edit" }} />;
92
+ }
93
+
59
94
  const subjectsIndexComponent =
60
95
  typeof useAdminLocationConfig === "function"
61
96
  ? <LocationWrapper />
@@ -104,7 +139,7 @@ export function getAdminRoutes(config) {
104
139
  ...(typeof useAdminLocationConfig === "function"
105
140
  ? [
106
141
  {
107
- path: "subjects/location",
142
+ path: "management/subjects/location",
108
143
  key: `${APP_PREFIX}_ADMIN_SUBJECTS_LOCATIONS`,
109
144
  exact: true,
110
145
  visible: (user) => userIsAdmin(user),
@@ -115,7 +150,7 @@ export function getAdminRoutes(config) {
115
150
  ...(typeof useAdminSubjectsConfig === "function"
116
151
  ? [
117
152
  {
118
- path: "subjects/stakeholder",
153
+ path: "management/subjects/stakeholder",
119
154
  key: `${APP_PREFIX}_ADMIN_SUBJECTS_STAKEHOLDERS`,
120
155
  exact: true,
121
156
  visible: (user) => userIsAdmin(user),
@@ -123,6 +158,50 @@ export function getAdminRoutes(config) {
123
158
  },
124
159
  ]
125
160
  : []),
161
+ ...(typeof useAdminLocationViewConfig === "function"
162
+ ? [
163
+ // {
164
+ // path: "view/management-location/:id",
165
+ // key: `${APP_PREFIX}_ADMIN_LOCATION_VIEW`,
166
+ // exact: true,
167
+ // visible: (user) => userIsAdmin(user),
168
+ // component: <LocationViewWrapper />,
169
+ // },
170
+ ]
171
+ : []),
172
+ ...(typeof useAdminSubjectsViewConfig === "function"
173
+ ? [
174
+ {
175
+ path: "view/management-stakeholder/:id",
176
+ key: `${APP_PREFIX}_ADMIN_STAKEHOLDER_VIEW`,
177
+ exact: true,
178
+ visible: (user) => userIsAdmin(user),
179
+ component: <StakeholderViewWrapper />,
180
+ },
181
+ ]
182
+ : []),
183
+ ...(typeof useAdminLocationViewConfig === "function"
184
+ ? [
185
+ {
186
+ path: "edit/management-location/:id",
187
+ key: `${APP_PREFIX}_ADMIN_LOCATION_EDIT`,
188
+ exact: true,
189
+ visible: (user) => userIsAdmin(user),
190
+ component: <LocationEditWrapper />,
191
+ },
192
+ ]
193
+ : []),
194
+ ...(typeof useAdminSubjectsViewConfig === "function"
195
+ ? [
196
+ {
197
+ path: "edit/management-stakeholder/:id",
198
+ key: `${APP_PREFIX}_ADMIN_STAKEHOLDER_EDIT`,
199
+ exact: true,
200
+ visible: (user) => userIsAdmin(user),
201
+ component: <StakeholderEditWrapper />,
202
+ },
203
+ ]
204
+ : []),
126
205
  ];
127
206
 
128
207
  return routes;
@@ -360,7 +360,6 @@ function AppLayout({
360
360
  >
361
361
  <div className="notification-icon">
362
362
  <BellOutlined />
363
- {/* Add notification count badge if needed */}
364
363
  </div>
365
364
  </Dropdown>
366
365
  </NotificationsHistoryProvider>
@@ -0,0 +1,178 @@
1
+ import { useState, useEffect } from "react";
2
+ import { hasKeyInObject } from "../../../utils/object.js"
3
+ import { mapFormGroup } from "../../../core/components/EditForm/helper.js"
4
+ import { changeInputMeta as changeInputMetaDaf, hasNotChanged} from "../../../../helpers/Forms.js"
5
+
6
+ export const usePrepareForm = ({
7
+ isSupported,
8
+ namespaceConfig,
9
+ APP,
10
+ allData,
11
+ id,
12
+ MainForm,
13
+ namespace,
14
+ setIsChanged,
15
+ changedPath,
16
+ setChangedPath,
17
+ }) => {
18
+ const [form, setForm] = useState({});
19
+ const [data, setData] = useState({});
20
+ const [groups, setGroups] = useState({});
21
+ const [linkingForms, setLinkingForms] = useState({});
22
+ const [loading, setLoading] = useState(true);
23
+ const [notFound, setNotFound] = useState(false);
24
+ const [editValues, setEditValues] = useState({});
25
+ const [inputsMeta, setInputsMeta] = useState({});
26
+ const [originalData, setOriginalData] = useState({});
27
+
28
+ const prepareForm = (setExtra = true) => {
29
+ if (isSupported) {
30
+ const dKey = namespaceConfig?.dataKey;
31
+ const nKey = `${APP}-${namespaceConfig?.view}`;
32
+ if (hasKeyInObject(allData, dKey) && hasKeyInObject(allData[dKey], nKey)) {
33
+ const d = JSON.parse(JSON.stringify(allData[dKey][nKey].data || {}));
34
+ Object.keys(d).forEach((k) => {
35
+ if (d[k] === null) {
36
+ d[k] = undefined;
37
+ }
38
+ });
39
+ if (d.datastakeId === id || d.applicationId === id || id === "user") {
40
+ const formG = mapFormGroup(allData[dKey][nKey].form || {}, d);
41
+ setForm(formG);
42
+
43
+ if (setExtra) {
44
+ if (
45
+ (d || {}).risk &&
46
+ Array.isArray(formG) &&
47
+ formG.find((r) => r.id === "risk")
48
+ ) {
49
+ const form = formG.find((r) => r.id === "risk");
50
+ if (form && form.options && form.template === "risk") {
51
+ const newData = Object.keys(d.risk).reduce((all, key) => {
52
+ const forms = form.options[key].forms;
53
+ const formsKeys = Object.keys(forms);
54
+ const formData = formsKeys.map((k) => {
55
+ const foundValue = d.risk[key].find(
56
+ (v) => v.subCategory === k,
57
+ );
58
+ return (
59
+ foundValue || {
60
+ id: k,
61
+ components: {},
62
+ config: [],
63
+ connectedEvents: {},
64
+ category: key,
65
+ score: 0,
66
+ subCategory: k,
67
+ }
68
+ );
69
+ });
70
+ all[key] = formData;
71
+ return all;
72
+ }, {});
73
+ setData({ ...d, risk: newData });
74
+ MainForm.resetFields();
75
+ setEditValues({ ...d });
76
+ setInputsMeta(d?.meta?.inputs || {});
77
+ setOriginalData({ ...d });
78
+ setLinkingForms(allData[dKey][nKey].linkingForms);
79
+ setLoading(false);
80
+ return;
81
+ }
82
+ }
83
+ setData({ ...d });
84
+ MainForm.resetFields();
85
+ setEditValues({ ...d });
86
+ setInputsMeta(d?.meta?.inputs || {});
87
+ setOriginalData({ ...d });
88
+ setLinkingForms(allData[dKey][nKey].linkingForms);
89
+ setLoading(false);
90
+ }
91
+ }
92
+ }
93
+ }
94
+ };
95
+ const getCertainData = allData?.[namespaceConfig?.dataKey];
96
+
97
+ useEffect(() => {
98
+ if(namespace && namespaceConfig) {
99
+ prepareForm(namespaceConfig?.view);
100
+ }
101
+ }, [getCertainData, namespaceConfig]);
102
+
103
+ const changeLinking = ({ key, linkingKey, value }) => {
104
+ const _val = {
105
+ linking: {
106
+ ...(data?.linking || {}),
107
+ [key]: {
108
+ ...((data?.linking || {})[key] || {}),
109
+ [linkingKey]: value,
110
+ },
111
+ },
112
+ };
113
+
114
+ const _all = { ...data, ..._val };
115
+
116
+ setData(_all);
117
+ };
118
+
119
+ const onValuesChange = (val, all) => {
120
+ setEditValues(all);
121
+ const keys = val && typeof val === "object" ? Object.keys(val) : [];
122
+ if (keys.length === 1) {
123
+ const changedKey = keys[0];
124
+ const ogData = originalData[changedKey];
125
+ const newData = all[changedKey];
126
+ let changePath = JSON.parse(JSON.stringify(changedPath));
127
+ if (!hasNotChanged({ [changedKey]: ogData }, { [changedKey]: newData })) {
128
+ if (!changePath.includes(changedKey)) {
129
+ changePath.push(changedKey);
130
+ }
131
+ } else {
132
+ changePath = changePath.filter((k) => k !== changedKey);
133
+ }
134
+ setChangedPath([...changePath]);
135
+ setIsChanged(changePath.length > 0 || newData ? true : false);
136
+ } else {
137
+ setIsChanged(true);
138
+ }
139
+ prepareForm(false);
140
+ };
141
+
142
+ const changeInputMeta = ({ key, type, value, otherValues = {} }) => {
143
+ return changeInputMetaDaf({
144
+ key,
145
+ type,
146
+ value,
147
+ otherValues,
148
+ setInputsMeta,
149
+ editValues,
150
+ MainForm,
151
+ setData,
152
+ onValuesChange,
153
+ });
154
+ };
155
+
156
+ return {
157
+ form,
158
+ data,
159
+ groups,
160
+ linkingForms,
161
+ loading,
162
+ notFound,
163
+ editValues,
164
+ inputsMeta,
165
+ originalData,
166
+ setGroups,
167
+ setNotFound,
168
+ setLinkingForms,
169
+ prepareForm,
170
+ setInputsMeta,
171
+ setData,
172
+ setLoading,
173
+ setEditValues,
174
+ changeLinking,
175
+ changeInputMeta,
176
+ onValuesChange,
177
+ }
178
+ }
@@ -0,0 +1,356 @@
1
+ import React, { useMemo, useState, useCallback, useEffect } from 'react'
2
+ import { Form, message } from 'antd';
3
+ import { useViewUrlParams } from '../View/hooks/useViewUrlParams';
4
+ import { usePrepareForm } from './hooks/usePrepareForm';
5
+ import { useViewPermissions } from '../View/hooks/useViewPermissions';
6
+ import { useCallToGetData } from '../View/hooks/useCallToGetData';
7
+ import { MessageTypes } from '../../../helpers/messages.js';
8
+ import { editErrorHandler } from "../../core/components/EditForm/helper.js"
9
+ import { transformPayload } from "../../../helpers/Forms.js"
10
+ import Loading from "../../../@daf/core/components/Loading/index.jsx"
11
+ import NotFound from "../../core/components/Screens/NotFound/index.jsx"
12
+ import Header from "../../core/components/Header/index.jsx"
13
+ import MissingTagButton from "../../core/components/UI/MissingTagButton/index.jsx"
14
+ import { Sections as EditFormSections} from "../../core/components/EditForm/sections.jsx"
15
+ import { EditForm } from "../../core/components/EditForm/form.jsx"
16
+
17
+
18
+ const Edit = ({
19
+ goTo = () => {},
20
+ allData = {},
21
+ query,
22
+ push,
23
+ searchParams,
24
+ setSearchParams,
25
+ setNotificationMode,
26
+ changeNotificationState,
27
+ addCheck,
28
+ removeCheck,
29
+ ajaxForms,
30
+ changeAjaxForms,
31
+ ajaxOptions,
32
+ changeAjaxOptions,
33
+ params,
34
+ clear,
35
+ getRedirectLink,
36
+ pathname,
37
+ search,
38
+ viewConfig,
39
+ APP,
40
+ namespaceConfiguration,
41
+ user,
42
+ t,
43
+ actionMap,
44
+ submitCall,
45
+ notificationMode,
46
+ breadcrumbs,
47
+ generatePath,
48
+ getAppHeader,
49
+ getApiBaseUrl,
50
+ namespaceOverrides,
51
+ getSubjectsDetails,
52
+
53
+ excludedKeys = [],
54
+ disabledInputs = [],
55
+ checkDuplicates = true,
56
+
57
+ }) => {
58
+ const [MainForm] = Form.useForm();
59
+ const [isChanged, setIsChanged] = useState(false);
60
+ const [highlightMandatory, setHighlightMandatory] = useState(false);
61
+ const [hasMissing, setHasMissing] = useState(false);
62
+ const [selectedForm, setSelectedForm] = useState({});
63
+ const [errors, setErrors] = useState({});
64
+ const changeErrors = useCallback((key, val) => {
65
+ setErrors((p) => ({ ...p, [key]: val }));
66
+ }, []);
67
+ const {
68
+ namespace,
69
+ id,
70
+ group,
71
+ subsection,
72
+ match,
73
+ subgroup,
74
+ formId,
75
+ getViewLink,
76
+ changedPath,
77
+ setChangedPath,
78
+ } = useViewUrlParams({
79
+ params,
80
+ push,
81
+ pathname,
82
+ search,
83
+ searchParams,
84
+ setSearchParams,
85
+ getRedirectLink,
86
+ })
87
+
88
+ const isSupported = viewConfig?.supportedNamespaces?.[APP] && viewConfig?.supportedNamespaces?.[APP]?.includes(namespace);
89
+ const getNamespaceConfig = (namespace) => namespaceConfiguration?.[namespace] || {};
90
+ const namespaceConfig = useMemo(() => getNamespaceConfig(namespace), [namespace]);
91
+
92
+ const {
93
+ form,
94
+ data,
95
+ linkingForms,
96
+ loading,
97
+ editValues,
98
+ inputsMeta,
99
+ setLoading,
100
+ changeLinking,
101
+ changeInputMeta,
102
+ onValuesChange,
103
+ } = usePrepareForm({
104
+ isSupported,
105
+ namespaceConfig,
106
+ APP,
107
+ allData,
108
+ id,
109
+ MainForm,
110
+ namespace,
111
+ setIsChanged,
112
+ changedPath,
113
+ setChangedPath,
114
+ })
115
+
116
+ useEffect(() => {
117
+ if(namespace && id && namespaceConfig && typeof getSubjectsDetails === 'function') {
118
+ getSubjectsDetails({
119
+ namespace,
120
+ id,
121
+ namespaceConfig,
122
+ })
123
+ }
124
+ }, [namespace, id, namespaceConfig])
125
+
126
+
127
+ const { canEdit } = useViewPermissions({
128
+ data,
129
+ id,
130
+ namespace,
131
+ user,
132
+ push,
133
+ getRedirectLink,
134
+ namespaceConfig: namespaceConfiguration,
135
+ APP,
136
+ viewConfig: viewConfig,
137
+ namespaceOverrides,
138
+ });
139
+
140
+ const action = useMemo(() => actionMap?.[namespaceConfig?.action], [namespaceConfig?.action, actionMap]);
141
+
142
+ const namespaceGet = {
143
+ [namespace]: () => {
144
+ return action?.({
145
+ namespace: namespaceConfig?.namespace,
146
+ module: APP,
147
+ view: namespaceConfig?.view,
148
+ ...(namespaceConfig?.scope && { scope: namespaceConfig.scope }),
149
+ datastakeId: id ? id : 'user',
150
+ })
151
+ }
152
+ }
153
+
154
+ useCallToGetData({
155
+ namespaceConfig,
156
+ namespace,
157
+ allData,
158
+ id,
159
+ isSupported,
160
+ namespaceGet,
161
+ source: null,
162
+ version: null,
163
+ user,
164
+ setLoading,
165
+ APP,
166
+ })
167
+
168
+ const callback = (type, m) => {
169
+ localStorage.removeItem(`${id}-loading`);
170
+ localStorage.setItem(`${id}-updated`, true);
171
+ if (type === MessageTypes.SUCCESS) {
172
+ message.success(m);
173
+ setIsChanged(false);
174
+ } else {
175
+ message.error(m);
176
+ }
177
+ localStorage.removeItem(`${id}-updated`);
178
+ setLoading(false);
179
+ };
180
+
181
+ const onSubmitData = () => {
182
+ clear();
183
+
184
+ // Validate custom errors
185
+ const _errors = Object.keys(errors)
186
+ .filter((k) => !!errors[k])
187
+ .map((k) => ({ name: [k] }));
188
+
189
+ if (_errors.length) {
190
+ editErrorHandler({ errorFields: _errors, t });
191
+ return;
192
+ }
193
+
194
+ // Validate and submit form
195
+ MainForm.validateFields()
196
+ .then(() => {
197
+ // Build base payload
198
+ const { _id, ..._payloadData } = {
199
+ ...editValues,
200
+ form: subsection || group,
201
+ module: APP,
202
+ view: namespaceConfig?.view,
203
+ namespace,
204
+ };
205
+
206
+ // Transform payload (process files, clean arrays)
207
+ const finalPayload = transformPayload(_payloadData);
208
+
209
+ // Setup UI state
210
+ setIsChanged(false);
211
+ setNotificationMode(notificationMode.EMPTY);
212
+ setLoading(true);
213
+ localStorage.setItem(`${id}-loading`, true);
214
+
215
+ // Submit
216
+ submitCall[namespace](
217
+ !editValues?.id
218
+ ? finalPayload
219
+ : Object.assign(finalPayload, { id: data.id }),
220
+ callback,
221
+ );
222
+ })
223
+ .catch((e) => {
224
+ console.log(e);
225
+ editErrorHandler({ errorFields: e.errorFields, t });
226
+ });
227
+ };
228
+
229
+ useEffect(
230
+ () => () => {
231
+ clear();
232
+ },
233
+ [],
234
+ );
235
+
236
+ const pageActions = [
237
+ {
238
+ tooltip: t("Save"),
239
+ onClick: () => onSubmitData(true),
240
+ disabled: !isChanged,
241
+ type: "primary",
242
+ icon: "Save",
243
+ },
244
+ {
245
+ icon: "Close",
246
+ tooltip: t("Back"),
247
+ onClick: () => {
248
+ changeNotificationState({ onYes: () => goTo(getViewLink()) });
249
+ },
250
+ },
251
+ ];
252
+
253
+ useEffect(() => {
254
+ if (isChanged) {
255
+ addCheck(() => {
256
+ goTo(`/app/view/${namespace}/${id}/${group}`);
257
+ });
258
+ } else {
259
+ removeCheck();
260
+ }
261
+ }, [isChanged, addCheck, removeCheck]);
262
+
263
+ if (!data.id && namespace !== 'kyc') {
264
+ return <Loading />;
265
+ }
266
+
267
+ if(!isSupported && !canEdit) {
268
+ return <NotFound t={t} />
269
+ }
270
+
271
+ return (
272
+ <div className="daf-edit-form">
273
+ <React.Fragment>
274
+ <Header
275
+ breadcrumbs={breadcrumbs}
276
+ title={(namespace === 'kyc' ? "KYC" : data?.name) || ""}
277
+ actionButtons={pageActions}
278
+ renderExtraComponents={
279
+ () => {
280
+ return <MissingTagButton hasMissing={hasMissing} highlightMandatory={highlightMandatory} setHighlightMandatory={setHighlightMandatory} t={t} />
281
+ }
282
+ }
283
+ />
284
+ <div className="view-content">
285
+ <EditFormSections
286
+ t={t}
287
+ data={editValues}
288
+ MainForm={MainForm}
289
+ getRedirectLink={getRedirectLink}
290
+ highlightMandatory={highlightMandatory}
291
+ search={search}
292
+ setHasMissing={setHasMissing}
293
+ mod={APP}
294
+ formConf={form}
295
+ values={data}
296
+ errors={errors}
297
+ onChangeForm={(sForm) => {
298
+ setSelectedForm(sForm);
299
+ }}
300
+ match={match}
301
+ group={group}
302
+ subsection={subsection}
303
+ subgroup={subgroup}
304
+ formid={formId}
305
+ user={user}
306
+ {...{
307
+ goTo,
308
+ pathname,
309
+ generatePath,
310
+ }}
311
+ />
312
+ <div className="form-edit">
313
+ {loading ? (
314
+ <div style={{ minHeight: 10000 }}>
315
+ <Loading background="white" />
316
+ </div>
317
+ ) : (
318
+ <EditForm
319
+ errors={errors}
320
+ changeErrors={changeErrors}
321
+ highlightMandatory={highlightMandatory}
322
+ MainForm={MainForm}
323
+ onValuesChange={onValuesChange}
324
+ disabledInputs={disabledInputs}
325
+ checkDuplicates={checkDuplicates}
326
+ inputsMeta={inputsMeta}
327
+ changeInputMeta={changeInputMeta}
328
+ changeLinking={changeLinking}
329
+ excludedKeys={excludedKeys}
330
+ hasSections={[]}
331
+ linkingForms={linkingForms}
332
+ form={selectedForm}
333
+ data={data}
334
+ {...{
335
+ t,
336
+ user,
337
+ ajaxForms,
338
+ ajaxOptions,
339
+ getAppHeader,
340
+ getApiBaseUrl,
341
+ changeAjaxOptions,
342
+ app: APP,
343
+ query,
344
+ goTo,
345
+ changeAjaxForms,
346
+ }}
347
+ />
348
+ )}
349
+ </div>
350
+ </div>
351
+ </React.Fragment>
352
+ </div>
353
+ )
354
+ }
355
+
356
+ export default Edit