datastake-daf 0.6.794 → 0.6.795

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 (86) hide show
  1. package/build/favicon.ico +0 -0
  2. package/build/logo192.png +0 -0
  3. package/build/logo512.png +0 -0
  4. package/build/manifest.json +25 -0
  5. package/build/robots.txt +3 -0
  6. package/dist/components/index.js +3159 -4303
  7. package/dist/pages/index.js +2045 -3246
  8. package/dist/services/index.js +3 -69
  9. package/dist/utils/index.js +20 -14
  10. package/package.json +1 -1
  11. package/src/@daf/core/components/Dashboard/Map/hook.js +25 -1
  12. package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/TopContributors/hook.js +1 -0
  13. package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/TopContributors/index.jsx +1 -1
  14. package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/UserGrowth/hook.js +1 -1
  15. package/src/@daf/core/components/Screens/Admin/AdminDashboard/components/UserStatistics/UserGrowth/index.jsx +1 -1
  16. package/src/@daf/core/components/Screens/Admin/AdminModals/AddUser/index.jsx +1 -0
  17. package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/helper.js +2 -2
  18. package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/index.jsx +8 -18
  19. package/src/@daf/core/components/Screens/Admin/AdminModals/CombineSubjects/index.jsx +6 -6
  20. package/src/@daf/core/components/Screens/Admin/AdminModals/NewAccount/index.jsx +1 -1
  21. package/src/@daf/core/components/Screens/Admin/AdminScreens/Dashboard.jsx +2 -2
  22. package/src/@daf/core/components/Screens/Admin/AdminScreens/Location.jsx +7 -6
  23. package/src/@daf/core/components/Screens/Admin/AdminScreens/Subjects.jsx +2 -2
  24. package/src/@daf/core/components/Screens/Admin/AdminScreens/index.js +0 -1
  25. package/src/@daf/core/components/Screens/Admin/AdminTables/AccountTable/index.jsx +0 -1
  26. package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/index.jsx +45 -73
  27. package/src/@daf/core/components/Screens/Admin/AdminTables/SubjectsTable/columns.js +37 -37
  28. package/src/@daf/core/components/Screens/Admin/AdminTables/SubjectsTable/index.jsx +22 -48
  29. package/src/@daf/core/components/Screens/Admin/AdminTables/UserTable/index.jsx +0 -1
  30. package/src/@daf/core/components/Screens/Admin/AdminViews/components/Edit/index.jsx +1 -3
  31. package/src/@daf/core/components/Screens/Admin/AdminViews/components/SidebarMenu/index.jsx +3 -5
  32. package/src/@daf/core/components/Screens/Admin/AdminViews/components/Users/helper.js +8 -13
  33. package/src/@daf/core/components/Screens/Admin/AdminViews/components/Users/index.jsx +2 -2
  34. package/src/@daf/core/components/Screens/Admin/AdminViews/index.jsx +4 -3
  35. package/src/@daf/core/components/Screens/Admin/adminRoutes.js +2 -81
  36. package/src/@daf/pages/Dashboards/SelfAssesment/components/AssociatedInformation/index.jsx +1 -1
  37. package/src/@daf/pages/Dashboards/SelfAssesment/components/OrganisationInformation/columns.js +0 -1
  38. package/src/@daf/pages/Dashboards/SelfAssesment/components/ProductionSites/columns.js +3 -2
  39. package/src/@daf/pages/Dashboards/SelfAssesment/components/ProductionSites/index.jsx +13 -4
  40. package/src/@daf/pages/Dashboards/SelfAssesment/index.jsx +22 -20
  41. package/src/@daf/pages/Events/Activities/columns.js +1 -1
  42. package/src/@daf/pages/Events/Activities/config.js +23 -30
  43. package/src/@daf/pages/Events/Incidents/columns.js +1 -1
  44. package/src/@daf/pages/Events/Incidents/config.js +23 -30
  45. package/src/@daf/pages/Events/config.js +7 -7
  46. package/src/@daf/pages/Locations/MineSite/columns.js +3 -3
  47. package/src/@daf/pages/Locations/MineSite/config.js +20 -14
  48. package/src/@daf/pages/Locations/config.js +3 -3
  49. package/src/@daf/pages/Stakeholders/Operators/columns.js +2 -2
  50. package/src/@daf/pages/Stakeholders/Operators/config.js +9 -16
  51. package/src/@daf/pages/Stakeholders/Workers/columns.js +1 -1
  52. package/src/@daf/pages/Stakeholders/Workers/config.js +23 -29
  53. package/src/@daf/pages/Stakeholders/config.js +3 -3
  54. package/src/@daf/pages/Summary/Operator/components/TradeRelationships/helper.js +1 -1
  55. package/src/@daf/pages/TablePage/helper.js +17 -1
  56. package/src/@daf/pages/TablePage/hook.js +3 -1
  57. package/src/@daf/pages/TablePage/index.jsx +8 -6
  58. package/src/@daf/pages/View/index.jsx +4 -2
  59. package/src/@daf/services/AdminService.js +7 -79
  60. package/src/@daf/services/DashboardService.js +1 -2
  61. package/src/@daf/utils/filters.js +26 -15
  62. package/src/constants/locales/en/translation.js +1 -7
  63. package/src/constants/locales/fr/translation.js +2 -1
  64. package/src/constants/locales/sp/translation.js +2 -1
  65. package/src/pages.js +1 -10
  66. package/src/@daf/core/components/Screens/Admin/AdminModals/CombineLocation/columns.js +0 -79
  67. package/src/@daf/core/components/Screens/Admin/AdminScreens/SubjectsView.jsx +0 -272
  68. package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/column.js +0 -223
  69. package/src/@daf/core/components/Screens/Admin/AdminTables/LocationTable/helper.js +0 -65
  70. package/src/@daf/core/components/Screens/Admin/AdminViews/EditLocation/index.jsx +0 -81
  71. package/src/@daf/core/components/Screens/Admin/AdminViews/EditStakeholder/index.jsx +0 -76
  72. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/config.js +0 -38
  73. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/helpers.js +0 -13
  74. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewLocation/index.jsx +0 -77
  75. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/config.js +0 -38
  76. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/helpers.js +0 -0
  77. package/src/@daf/core/components/Screens/Admin/AdminViews/ViewStakeholder/index.jsx +0 -75
  78. package/src/@daf/pages/SelfAssesment/components/AssociatedInformationTable/columns.js +0 -180
  79. package/src/@daf/pages/SelfAssesment/components/AssociatedInformationTable/config.js +0 -0
  80. package/src/@daf/pages/SelfAssesment/components/AssociatedInformationTable/index.jsx +0 -27
  81. package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/columns.js +0 -157
  82. package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/config.js +0 -31
  83. package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/index.js +0 -77
  84. package/src/@daf/pages/SelfAssesment/components/ProductionSiteTable/columns.js +0 -117
  85. package/src/@daf/pages/SelfAssesment/components/ProductionSiteTable/index.jsx +0 -54
  86. package/src/@daf/pages/SelfAssesment/index.jsx +0 -0
@@ -56,6 +56,7 @@ export const useTablePage = ({
56
56
  data,
57
57
  applications,
58
58
  subjectClear,
59
+ APP,
59
60
  }) => {
60
61
  const [selectOptions, setSelectOptions] = useState();
61
62
  const [activeTab, setActiveTab] = useState("own");
@@ -80,8 +81,9 @@ export const useTablePage = ({
80
81
  subject,
81
82
  data,
82
83
  applications,
84
+ APP,
83
85
  }),
84
- [t, goTo, user, options, activeTab, getRedirectLink, theme, data, applications, subject, getColumns]
86
+ [t, goTo, user, options, activeTab, getRedirectLink, theme, data, applications, subject, getColumns, APP]
85
87
  );
86
88
 
87
89
  const selectFiltersConfig = useMemo(() =>
@@ -29,6 +29,7 @@ const TablePage = ({
29
29
  formValue: {},
30
30
  form: {},
31
31
  },
32
+ headerInfo = {},
32
33
  defaultValues = {},
33
34
  extendingFilters = {},
34
35
  getData = () => {},
@@ -71,12 +72,13 @@ const TablePage = ({
71
72
  data,
72
73
  applications,
73
74
  subjectClear,
75
+ APP,
74
76
  });
75
77
 
76
78
  return (
77
79
  <TablePageWithTabs
78
80
  t={t}
79
- title={t(viewConfig?.title || "")}
81
+ title={t(headerInfo?.title || viewConfig?.title || "")}
80
82
  breadCrumbs={breadcrumbs}
81
83
  location={location}
82
84
  loading={loading}
@@ -95,7 +97,7 @@ const TablePage = ({
95
97
  view={subject}
96
98
  getActiveTab={handleActiveTabChange}
97
99
  onDownload={onDownload && typeof onDownload === 'function' ? onDownload : undefined}
98
- drawerTitle={t(viewConfig?.createTitle || "")}
100
+ drawerTitle={t(headerInfo?.createTitle || viewConfig?.createTitle || "")}
99
101
  >
100
102
  {({onDrawerClose}) => (
101
103
  <Create
@@ -126,10 +128,10 @@ const TablePage = ({
126
128
  formData={formConfig.formData}
127
129
  formValue={formConfig.formValue}
128
130
  form={formConfig.form}
129
- namespace={formInfo.namespace}
130
- view={formInfo.view}
131
- scope={formInfo.scope}
132
- formType={formInfo.formType}
131
+ namespace={formConfig?.namespace || formInfo?.namespace}
132
+ view={formConfig?.view || formInfo.view}
133
+ scope={formConfig?.scope || formInfo.scope}
134
+ formType={formConfig?.formType || formInfo.formType}
133
135
  defaultData={defaultValues}
134
136
  />
135
137
  )}
@@ -49,6 +49,7 @@ const View = ({
49
49
  addData,
50
50
  options,
51
51
  getSubjectsDetails,
52
+ namespaceOverrides,
52
53
  // ADD CALLBACK TO GET THE CURRENT NAMESPACE CONFIG
53
54
  }) => {
54
55
  const getNamespaceConfig = (namespace) => namespaceConfiguration?.[namespace] || {};
@@ -110,6 +111,7 @@ const View = ({
110
111
  namespaceConfig: namespaceConfiguration,
111
112
  APP,
112
113
  viewConfig,
114
+ namespaceOverrides: namespaceOverrides,
113
115
  });
114
116
 
115
117
  const groupForm = useMemo(() => {
@@ -167,7 +169,7 @@ const View = ({
167
169
  module: APP,
168
170
  view: namespaceConfig?.view,
169
171
  ...(namespaceConfig?.scope && { scope: namespaceConfig.scope }),
170
- datastakeId: id,
172
+ datastakeId: id ? id : 'user',
171
173
  version,
172
174
  source,
173
175
  })
@@ -220,7 +222,7 @@ const View = ({
220
222
  <>
221
223
  <div className={"daf-view-form"}>
222
224
  <Header
223
- title={data?.name || ""}
225
+ title={(namespace === 'kyc' ? "KYC" : data?.name) || ""}
224
226
  breadcrumbs={breadcrumbs}
225
227
  goBackTo={goBack}
226
228
  actionButtons={actionButtons}
@@ -69,90 +69,18 @@ class AdminService extends BaseService {
69
69
  }
70
70
 
71
71
  getSubjects({ subject, params }) {
72
- return this.apiGet({
73
- url: `/management/subjects/${subject}`,
72
+ return this.apiGet({
73
+ url: `${subject}`,
74
74
  params,
75
- });
76
- }
77
-
78
- mergeLocations({ ids, data }) {
79
- const [id1, id2, ...remainingIds] = ids || [];
80
-
81
- if (!id1 || !id2) {
82
- throw new Error('At least two IDs are required for merging');
83
- }
84
-
85
- const url = `/management/merge/location/${id1}/${id2}`;
86
-
87
- const payload = {
88
- ...data,
89
- };
90
-
91
- if (remainingIds.length > 0) {
92
- payload.additionalIds = remainingIds;
93
- }
94
-
95
- return this.apiPost({
96
- url,
97
- data: payload,
98
- });
75
+ })
99
76
  }
100
77
 
101
-
102
-
103
- mergeSubjects({ subject, ids, data }) {
104
- const [id1, id2, ...remainingIds] = ids || [];
105
-
106
- if (!id1 || !id2) {
107
- throw new Error('At least two IDs are required for merging');
108
- }
109
-
110
- const url = `/management/merge/${subject}/${id1}/${id2}`;
111
-
112
- const payload = {
113
- ...data,
114
-
115
- };
116
-
117
- if (remainingIds.length > 0) {
118
- payload.additionalIds = remainingIds;
119
- }
120
-
78
+ mergeSubjects({ subject, ...data }) {
121
79
  return this.apiPost({
122
- url,
123
- data: payload,
124
- });
125
- }
126
-
127
- viewLocation({ id }) {
128
- return this.apiGet({
129
- url: `/management/subject/location/${id}`,
130
- });
131
- }
132
-
133
- viewStakeholder({ id }) {
134
- return this.apiGet({
135
- url: `/management/subject/stakeholder/${id}`,
136
- });
137
- }
138
-
139
- updateSubject({ subject, id, data }) {
140
- const type = subject === 'location' ? 'location' : 'stakeholder';
141
- return this.apiPut({
142
- url: `/management/subject/${type}/${id}`,
143
- data,
144
- });
145
- }
146
-
147
- getUserGrowth(activeFilter) {
148
- return this.apiGet({
149
- url: `/accounts/dashboard/user-growth`,
150
- isUserManager: true,
151
- params: { activeFilter },
152
- });
80
+ url: `/merge/${subject}`,
81
+ data,
82
+ })
153
83
  }
154
-
155
-
156
84
  }
157
85
 
158
86
  export default createLazyService(AdminService);
@@ -26,5 +26,4 @@ class DashboardService extends BaseService {
26
26
  }
27
27
  }
28
28
 
29
- export default createLazyService(DashboardService);
30
-
29
+ export default createLazyService(DashboardService);
@@ -63,29 +63,19 @@ export const getDefaultActiveFilters = (
63
63
  };
64
64
 
65
65
  const NEW_PAGINATION_APPS = ["nashiriki"];
66
-
67
66
  export const filterParams = (value, module) => {
68
67
  const { activeFilters, ...rest } = value;
69
68
 
70
- const {
71
- page = 1,
72
- pageSize = 20,
73
- sortDir,
74
- sortBy,
75
- search,
76
- searchParams,
77
- ...filters
78
- } = activeFilters || {};
69
+ const { page, pageSize, sortDir, sortBy, search, searchParams, ...filters } =
70
+ activeFilters || {};
79
71
 
80
72
  const params = {};
81
-
73
+
82
74
  params.pagination = JSON.stringify({
83
- page,
84
- pageSize,
75
+ [NEW_PAGINATION_APPS.includes(module) ? "skip" : "page"]: page,
76
+ [NEW_PAGINATION_APPS.includes(module) ? "take" : "pageSize"]: pageSize,
85
77
  });
86
78
 
87
- params.filters = JSON.stringify(filters);
88
-
89
79
  if (search && searchParams) {
90
80
  params.search = JSON.stringify({
91
81
  qs: search,
@@ -100,5 +90,26 @@ export const filterParams = (value, module) => {
100
90
  });
101
91
  }
102
92
 
93
+ if (Object.keys(filters).length) {
94
+ if (value.sourceId && value.sourceId === "overview") {
95
+ params.filters = JSON.stringify(filters);
96
+ } else {
97
+ params.filters = JSON.stringify({ ...filters, authorId: undefined });
98
+ }
99
+ }
100
+
103
101
  return { ...rest, ...params };
104
102
  };
103
+
104
+ export const getStatusOptions = (t) => {
105
+ return [
106
+ {
107
+ value: "submitted",
108
+ label: t("Submitted"),
109
+ },
110
+ {
111
+ value: "private",
112
+ label: t("Private"),
113
+ },
114
+ ]
115
+ }
@@ -1,11 +1,5 @@
1
1
  const en = {
2
- "sbg-admin::remove-user-title":"Remove User Title",
3
- "sbg-admin::remove-user-body":"Remove User Body",
4
- "Administrative-level-1": "Administrative Level 1",
5
- "Administrative-level-2": "Administrative Level 2",
6
- "merge-output": "Merge Output",
7
- "admin::current_subjects": "Current Subjects",
8
- "add-account":"Add Account",
2
+ "All Data": "All Data",
9
3
  "Site": "Site",
10
4
  "Production Sites": "Production Sites",
11
5
  "Type of account": "Type of account",
@@ -1,4 +1,5 @@
1
1
  const fr = {
2
+ "All Data": "Toutes les données",
2
3
  "Site": "Site",
3
4
  "Production Sites": "Sites de production",
4
5
  "Type of account": "Type de compte",
@@ -420,7 +421,7 @@ const fr = {
420
421
  Documentation: "Documents",
421
422
  "Edit project": "Modifier le projet",
422
423
  Name: "Nom",
423
- Type: "Type",
424
+ Type: "Tapez",
424
425
  type: "Type",
425
426
  Province: "Province",
426
427
  Territory: "Territoire",
@@ -1,4 +1,5 @@
1
1
  const sp = {
2
+ "All Data": "Todos los datos",
2
3
  "Site": "Sitio",
3
4
  "Production Sites": "Centros de producción",
4
5
  "Type of account": "Tipo de cuenta",
@@ -233,7 +234,7 @@ const sp = {
233
234
  "Documentation": "Documentos",
234
235
  "Edit project": "Modificar proyecto",
235
236
  "Name": "Nombre",
236
- "Type": "Tipo",
237
+ "Type": "Escribe",
237
238
  "type": "Tipo",
238
239
  "Province": "Provincia",
239
240
  "Territory": "Territorio",
package/src/pages.js CHANGED
@@ -2,17 +2,8 @@
2
2
  export { default as SupplyChainDashboard } from './@daf/pages/Dashboards/SupplyChain/index.jsx';
3
3
  export { default as UserDashboard } from './@daf/pages/Dashboards/UserDashboard/index.jsx';
4
4
  export { default as SelfAssesment } from './@daf/pages/Dashboards/SelfAssesment/index.jsx';
5
- export { default as OperatorsTable } from './@daf/pages/Stakeholders/Operators/index.jsx';
6
- export { default as LocationsTable } from './@daf/pages/Locations/index.jsx';
7
- export { default as StakeholdersTable } from './@daf/pages/Stakeholders/index.jsx';
8
- export { default as EventsTable } from './@daf/pages/Events/index.jsx';
9
- export { default as DocumentsTable } from './@daf/pages/Documents/index.jsx';
10
- export { default as WorkersTable } from './@daf/pages/Stakeholders/Workers/index.jsx';
11
- export { default as ActivitiesTable } from './@daf/pages/Events/Activities/index.jsx';
12
5
 
13
- export { default as IncidentsTable } from './@daf/pages/Events/Incidents/index.jsx';
14
- export { default as ProductionSitesTable } from './@daf/pages/Locations/MineSite/index.jsx';
15
- export { default as UsersTable } from './@daf/core/components/Screens/Users/index.jsx';
6
+ // Tables
16
7
  export { default as PartnersTable } from './@daf/pages/Partners/index.jsx';
17
8
  export { default as TablePage } from './@daf/pages/TablePage/index.jsx';
18
9
 
@@ -1,79 +0,0 @@
1
- import { findOptions } from "../../../../../../../helpers/StringHelper.js";
2
- import { Tooltip } from "antd";
3
- import { getNameByLevel } from "../../AdminTables/SubjectsTable/helper.js";
4
-
5
- export const getColumns = ({ t, selectOptions, module, entity }) => {
6
- return [
7
- {
8
- title: t("admin::organisation_id"),
9
- dataIndex: "datastakeId",
10
- key: "datastakeId",
11
- show: true,
12
- render: (value, all) => {
13
- return <Tooltip title={value}>{value}</Tooltip>;
14
- },
15
- },
16
- {
17
- title: t("Name"),
18
- dataIndex: "name",
19
- key: "name",
20
- show: true,
21
- render: (value, all) => {
22
- return <Tooltip title={value}>{value}</Tooltip>;
23
- },
24
- },
25
- {
26
- title: t("Category"),
27
- dataIndex: "category",
28
- key: "category",
29
- show: true,
30
- render: (value, all) => {
31
- const label = findOptions(value, selectOptions?.category);
32
- return <Tooltip title={label}>{label}</Tooltip>;
33
- },
34
- },
35
- {
36
- title: t("Country"),
37
- dataIndex: "country",
38
- key: "country",
39
- show: true,
40
- render: (value, all) => {
41
- const label = findOptions(value, selectOptions?.country);
42
- return <Tooltip title={label}>{label}</Tooltip>;
43
- },
44
- },
45
- {
46
- title: t("Province"),
47
- dataIndex: "administrativeLevel1",
48
- key: "administrativeLevel1",
49
- ellipsis: true,
50
- show: entity.includes("locations"),
51
- render: (value, all) => {
52
- let label;
53
- if(all?.administrativeLevel1 && value === all?.administrativeLevel1) {
54
- label = all?.linking?.SCL?.[value]?.name
55
- } else {
56
- label = getNameByLevel(all?.linking?.SCL, "level_1")?.name
57
- }
58
-
59
- return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
60
- },
61
- },
62
- {
63
- title: t("Territory"),
64
- dataIndex: "administrativeLevel2",
65
- key: "administrativeLevel2",
66
- show: entity.includes("locations"),
67
- render: (value, all) => {
68
- let label;
69
- if(all?.administrativeLevel2 && value === all?.administrativeLevel2) {
70
- label = all?.linking?.SCL?.[value]?.name
71
- } else {
72
- label = getNameByLevel(all?.linking?.SCL, "level_2")?.name
73
- }
74
-
75
- return <Tooltip title={label || '-'}>{label || '-'}</Tooltip>;
76
- },
77
- },
78
- ].filter((c) => c?.show);
79
- };
@@ -1,272 +0,0 @@
1
- import React, { useState, useEffect, useCallback, useMemo } from "react";
2
- import Header from "../../../Header/index.jsx";
3
- import Loading from "../../../Loading/index.jsx";
4
- import SideBarMenu from "../AdminViews/components/SidebarMenu/index.jsx";
5
- import ViewLocation from "../AdminViews/ViewLocation/index.jsx";
6
- import ViewStakeholder from "../AdminViews/ViewStakeholder/index.jsx";
7
- import EditLocation from "../AdminViews/EditLocation/index.jsx";
8
- import EditStakeholder from "../AdminViews/EditStakeholder/index.jsx";
9
- import { config as locationConfig } from "../AdminViews/ViewLocation/config.js";
10
- import { config as stakeholderConfig } from "../AdminViews/ViewStakeholder/config.js";
11
- import NotFound from "../../NotFound/index.jsx";
12
- import { Form, message } from "antd";
13
- import { NOTIFICATION_MODE, useForms, FormsProvider } from "../../../../context/Forms/index.js";
14
-
15
- function withFormsProvider(Component) {
16
- return function WrappedWithFormsProvider(props) {
17
- return (
18
- <FormsProvider>
19
- <Component {...props} />
20
- </FormsProvider>
21
- );
22
- };
23
- }
24
-
25
- /**
26
- * Admin Subjects View Screen
27
- * This component handles viewing and editing individual subjects (locations or stakeholders)
28
- *
29
- * @param {Object} config - Application configuration
30
- * @param {string} config.subject - Subject type: "location" or "stakeholder"
31
- * @param {string} config.id - Subject ID from route params
32
- * @param {string} config.mode - Mode: "view" or "edit"
33
- * @param {string} config.module - Module identifier
34
- * @param {Function} config.goTo - Navigation function
35
- * @param {Function} config.t - Translation function
36
- * @param {Object} config.location - Router location object
37
- * @param {Function} config.getRedirectLink - Function to get redirect links
38
- * @param {Function} config.renderBreadCrumbs - Function to render breadcrumbs
39
- * @param {Object} config.options - Options object with countries, categories, etc.
40
- * @param {Function} config.AdminService - Admin service for API calls
41
- * @param {Function} config.handleError - Error handling function
42
- */
43
- function AdminSubjectsViewScreen({ config }) {
44
- const {
45
- subject,
46
- id,
47
- mode = "view",
48
- module,
49
- goTo,
50
- t,
51
- location,
52
- getRedirectLink,
53
- renderBreadCrumbs,
54
- options,
55
- AdminService,
56
- handleError,
57
- userRoles = [],
58
- accountStatuses = [],
59
- } = config;
60
-
61
- const [loading, setLoading] = useState(false);
62
- const [data, setData] = useState({});
63
- const [editData, setEditData] = useState({});
64
- const [isChanged, setIsChanged] = useState(false);
65
- const [selectedGroup, setSelectedGroup] = useState("");
66
- const [MainForm] = Form.useForm();
67
- const { setNotificationMode, changeNotificationState } = useForms();
68
-
69
- const configs = useMemo(() => {
70
- return subject === "location" ? locationConfig : stakeholderConfig;
71
- }, [subject]);
72
-
73
- const conf = useMemo(() => {
74
- if (!Array.isArray(configs) || configs.length === 0) {
75
- console.warn("configs is not a valid array:", configs);
76
- return null;
77
- }
78
-
79
- if (!selectedGroup) {
80
- setSelectedGroup(configs[0].key);
81
- return configs[0];
82
- }
83
-
84
- const foundConfig = configs.find((c) => c.key === selectedGroup);
85
- return foundConfig || configs[0];
86
- }, [selectedGroup, configs]);
87
-
88
- useEffect(() => {
89
- MainForm.setFieldsValue(data);
90
- setEditData(data);
91
- }, [data, MainForm]);
92
-
93
- const goToView = useCallback(() => {
94
- changeNotificationState({
95
- onYes: () => {
96
- setEditData(data);
97
- setIsChanged(false);
98
- goTo(`/app/management/subject/${subject}/${id}`);
99
- },
100
- });
101
- }, [goTo, changeNotificationState, data, subject, id]);
102
-
103
- const fetchData = useCallback(async () => {
104
- try {
105
- setLoading(true);
106
-
107
- let response;
108
- if (subject === "location") {
109
- response = await AdminService.viewLocation({ id });
110
- } else if (subject === "stakeholder") {
111
- response = await AdminService.viewStakeholder({ id });
112
- }
113
-
114
- if (response?.data) {
115
- console.log('📦 Backend response data:', {
116
- id: response.data.id,
117
- datastakeId: response.data.datastakeId,
118
- name: response.data.name,
119
- fullData: response.data
120
- });
121
- setData(response.data);
122
- }
123
-
124
- setLoading(false);
125
- } catch (err) {
126
- if (handleError) {
127
- handleError(err);
128
- }
129
- setLoading(false);
130
- }
131
- }, [id, subject, AdminService, handleError]);
132
-
133
- useEffect(() => {
134
- fetchData();
135
- }, [fetchData]);
136
-
137
- const breadCrumbs = useMemo(() => {
138
- if (renderBreadCrumbs) {
139
- return renderBreadCrumbs({
140
- view: subject === "location" ? "location" : "stakeholder",
141
- t,
142
- goTo,
143
- id,
144
- isView: mode === "view",
145
- isEdit: mode === "edit",
146
- });
147
- }
148
- return [];
149
- }, [renderBreadCrumbs, subject, t, goTo, id, mode]);
150
-
151
- const formOptions = useMemo(() => {
152
- return {
153
- countries: options?.countries || [],
154
- category: options?.category || [],
155
- };
156
- }, [options]);
157
-
158
- const actionButtons = useMemo(() => {
159
- if (mode === "view") {
160
- return [
161
- {
162
- type: "primary",
163
- tooltip: t("Edit"),
164
- icon: "Edit",
165
- onClick: () => goTo(`/app/management/subject/${subject}/edit/${id}`),
166
- },
167
- ];
168
- }
169
-
170
- return [
171
- {
172
- type: "primary",
173
- tooltip: t("Save"),
174
- icon: "Save",
175
- disabled: !isChanged,
176
- onClick: () => {
177
- MainForm.validateFields()
178
- .then(async (formData) => {
179
- setLoading(true);
180
-
181
- try {
182
- const allowedKeys = conf?.items?.map(item => item.key) || [];
183
- const filteredData = {};
184
- allowedKeys.forEach(key => {
185
- if (formData[key] !== undefined) {
186
- filteredData[key] = formData[key];
187
- }
188
- });
189
-
190
- const internalId = data.id;
191
- if (!internalId) {
192
- throw new Error('Internal ID not found');
193
- }
194
-
195
- await AdminService.updateSubject({
196
- subject,
197
- id: internalId,
198
- data: filteredData
199
- });
200
- await fetchData();
201
- message.success(t("Information saved successfully"));
202
- setNotificationMode(NOTIFICATION_MODE.EMPTY);
203
- setIsChanged(false);
204
- goTo(`/app/management/subject/${subject}/${id}`);
205
- } catch (err) {
206
- handleError(err);
207
- }
208
-
209
- setLoading(false);
210
- })
211
- .catch(() => {});
212
- },
213
- },
214
- {
215
- tooltip: t("Cancel"),
216
- icon: "Close",
217
- onClick: goToView,
218
- },
219
- ];
220
- }, [t, mode, MainForm, goToView, isChanged, editData, fetchData, subject, id, goTo, handleError, AdminService, setNotificationMode]);
221
-
222
- const ViewComponent = subject === "location" ? ViewLocation : ViewStakeholder;
223
- const EditComponent = subject === "location" ? EditLocation : EditStakeholder;
224
-
225
- return (
226
- <div className={mode === "view" ? "daf-view-form" : "daf-edit-form"}>
227
- {loading && <Loading background="white" />}
228
- <Header
229
- title={data.name || t("Loading...")}
230
- breadcrumbs={breadCrumbs}
231
- actionButtons={actionButtons}
232
- />
233
- <div className="view-content">
234
- <SideBarMenu
235
- selectedGroup={selectedGroup}
236
- onChange={(v) => setSelectedGroup(v)}
237
- t={t}
238
- config={configs}
239
- />
240
- {mode === "edit" ? (
241
- <EditComponent
242
- t={t}
243
- conf={conf}
244
- data={editData}
245
- formOptions={formOptions}
246
- MainForm={MainForm}
247
- setData={setEditData}
248
- isChanged={isChanged}
249
- setIsChanged={setIsChanged}
250
- goToView={goToView}
251
- />
252
- ) : (
253
- <ViewComponent
254
- userRoles={userRoles}
255
- formOptions={formOptions}
256
- conf={conf}
257
- data={data}
258
- t={t}
259
- goTo={goTo}
260
- location={location}
261
- getRedirectLink={getRedirectLink}
262
- accountStatuses={accountStatuses}
263
- module={module}
264
- />
265
- )}
266
- </div>
267
- </div>
268
- );
269
- }
270
-
271
- export default withFormsProvider(AdminSubjectsViewScreen);
272
-