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,77 @@
|
|
|
1
|
+
import { findOptions } from "../../../../../../../helpers/StringHelper.js";
|
|
2
|
+
import { getNameByLevel } from "./helpers.js";
|
|
3
|
+
import LocationTable from "../../AdminTables/LocationTable/index.jsx";
|
|
4
|
+
|
|
5
|
+
const isView = true;
|
|
6
|
+
|
|
7
|
+
export default function View({
|
|
8
|
+
userRoles = [],
|
|
9
|
+
conf,
|
|
10
|
+
data = {},
|
|
11
|
+
formOptions = {},
|
|
12
|
+
t,
|
|
13
|
+
goTo,
|
|
14
|
+
location,
|
|
15
|
+
getRedirectLink,
|
|
16
|
+
accountStatuses,
|
|
17
|
+
module,
|
|
18
|
+
}) {
|
|
19
|
+
const renderItem = (item) => {
|
|
20
|
+
if (item.type === "location") {
|
|
21
|
+
return (
|
|
22
|
+
<LocationTable
|
|
23
|
+
isView={isView}
|
|
24
|
+
entityData={data}
|
|
25
|
+
goTo={goTo}
|
|
26
|
+
getRedirectLink={getRedirectLink}
|
|
27
|
+
t={t}
|
|
28
|
+
location={location}
|
|
29
|
+
module={module}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const getValue = () => {
|
|
35
|
+
const val =
|
|
36
|
+
item.getFormApps === true
|
|
37
|
+
? data?.apps?.find((app) => app.app === module)?.[item?.propertyName]
|
|
38
|
+
: data?.[item.key];
|
|
39
|
+
|
|
40
|
+
if (item.type === "select") {
|
|
41
|
+
const option = findOptions(val, formOptions[item.optionsName] || []);
|
|
42
|
+
return option ? t(option) : "-";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (item.type === "administrative") {
|
|
46
|
+
return getNameByLevel(data?.linking?.SCL, item.level) || "-";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return val ?? "-";
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div className="input" key={item.key}>
|
|
54
|
+
<p className="label">
|
|
55
|
+
<span>{t(item.label)}</span>
|
|
56
|
+
</p>
|
|
57
|
+
<p className="value">{getValue()}</p>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div className="content">
|
|
66
|
+
<div className="wrapper" style={{ width: 700 }}>
|
|
67
|
+
<div className="group">
|
|
68
|
+
<div className="daf-title with-subtitle">
|
|
69
|
+
<h1>{t(conf.title)}</h1>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
{conf.items.map((item) => renderItem(item))}
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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-stakeholder.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 stakeholder 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: "category",
|
|
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: "Province",
|
|
39
|
+
// key: "administrativeLevel1",
|
|
40
|
+
// type: "administrative",
|
|
41
|
+
// level: "level_1"
|
|
42
|
+
// },
|
|
43
|
+
// {
|
|
44
|
+
// label: "Territory",
|
|
45
|
+
// key: "administrativeLevel2",
|
|
46
|
+
// type: "administrative",
|
|
47
|
+
// level: "level_2"
|
|
48
|
+
// },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
];
|
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { findOptions } from "../../../../../../../helpers/StringHelper.js";
|
|
2
|
+
import StakeholderTable from "../../AdminTables/SubjectsTable/index.jsx";
|
|
3
|
+
const isView = true;
|
|
4
|
+
|
|
5
|
+
export default function View({
|
|
6
|
+
userRoles = [],
|
|
7
|
+
conf,
|
|
8
|
+
data = {},
|
|
9
|
+
formOptions = {},
|
|
10
|
+
t,
|
|
11
|
+
goTo,
|
|
12
|
+
stakeholder,
|
|
13
|
+
getRedirectLink,
|
|
14
|
+
accountStatuses,
|
|
15
|
+
module,
|
|
16
|
+
}) {
|
|
17
|
+
const renderItem = (item) => {
|
|
18
|
+
if (item.type === "stakeholder") {
|
|
19
|
+
return (
|
|
20
|
+
<StakeholderTable
|
|
21
|
+
isView={isView}
|
|
22
|
+
entityData={data}
|
|
23
|
+
goTo={goTo}
|
|
24
|
+
getRedirectLink={getRedirectLink}
|
|
25
|
+
t={t}
|
|
26
|
+
stakeholder={stakeholder}
|
|
27
|
+
module={module}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const getValue = () => {
|
|
33
|
+
const val =
|
|
34
|
+
item.getFormApps === true
|
|
35
|
+
? data?.apps?.find((app) => app.app === module)?.[item?.propertyName]
|
|
36
|
+
: data?.[item.key];
|
|
37
|
+
|
|
38
|
+
if (item.type === "select") {
|
|
39
|
+
const option = findOptions(val, formOptions[item.optionsName] || []);
|
|
40
|
+
return option ? t(option) : "-";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (item.type === "administrative") {
|
|
44
|
+
return getNameByLevel(data?.linking?.SCL, item.level) || "-";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return val ?? "-";
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className="input" key={item.key}>
|
|
52
|
+
<p className="label">
|
|
53
|
+
<span>{t(item.label)}</span>
|
|
54
|
+
</p>
|
|
55
|
+
<p className="value">{getValue()}</p>
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div className="content">
|
|
64
|
+
<div className="wrapper" style={{ width: 700 }}>
|
|
65
|
+
<div className="group">
|
|
66
|
+
<div className="daf-title with-subtitle">
|
|
67
|
+
<h1>{t(conf.title)}</h1>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
{conf.items.map((item) => renderItem(item))}
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -24,6 +24,7 @@ export default function Edit({
|
|
|
24
24
|
accountStatuses = [],
|
|
25
25
|
module,
|
|
26
26
|
transferAdmin = () => {},
|
|
27
|
+
inviteCompanyAccount = () => {},
|
|
27
28
|
}) {
|
|
28
29
|
const { addCheck, removeCheck } = useForms();
|
|
29
30
|
|
|
@@ -37,7 +38,7 @@ export default function Edit({
|
|
|
37
38
|
|
|
38
39
|
const deleteUser = useCallback(
|
|
39
40
|
(id) => {
|
|
40
|
-
// TODO: add call
|
|
41
|
+
// TODO: add call
|
|
41
42
|
console.log("DELETE", id);
|
|
42
43
|
fetchData();
|
|
43
44
|
},
|
|
@@ -131,6 +132,9 @@ export default function Edit({
|
|
|
131
132
|
goTo={goTo}
|
|
132
133
|
accountStatuses={accountStatuses}
|
|
133
134
|
transferAdmin={transferAdmin}
|
|
135
|
+
inviteCompanyAccount={inviteCompanyAccount}
|
|
136
|
+
companyId={data.id}
|
|
137
|
+
handleError={handleError}
|
|
134
138
|
/>
|
|
135
139
|
);
|
|
136
140
|
}
|
|
@@ -174,6 +178,8 @@ export default function Edit({
|
|
|
174
178
|
);
|
|
175
179
|
};
|
|
176
180
|
|
|
181
|
+
console.log(conf,"data");
|
|
182
|
+
|
|
177
183
|
return (
|
|
178
184
|
<div className="form-edit flex-row">
|
|
179
185
|
<Form
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Menu } from "antd";
|
|
2
|
-
import { config } from "../../config";
|
|
2
|
+
import { config as defaultConfig } from "../../config";
|
|
3
3
|
|
|
4
|
-
export default function SideBarMenu({ selectedGroup, onChange = () => {}, t }) {
|
|
4
|
+
export default function SideBarMenu({ selectedGroup, onChange = () => {}, t, config }) {
|
|
5
|
+
const menuConfig = config || defaultConfig;
|
|
6
|
+
|
|
5
7
|
return (
|
|
6
8
|
<Menu
|
|
7
9
|
mode="inline"
|
|
@@ -12,7 +14,7 @@ export default function SideBarMenu({ selectedGroup, onChange = () => {}, t }) {
|
|
|
12
14
|
onChange(g.key);
|
|
13
15
|
}}
|
|
14
16
|
items={
|
|
15
|
-
|
|
17
|
+
menuConfig.map((conf) => {
|
|
16
18
|
return {
|
|
17
19
|
key: conf.key,
|
|
18
20
|
label: t(conf.label),
|
|
@@ -167,10 +167,7 @@ export const getColumns = ({
|
|
|
167
167
|
return cols.filter((v) => v.show);
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
export const checkboxConfig = {
|
|
171
|
-
name: "Name",
|
|
172
|
-
datastakeId: "ID",
|
|
173
|
-
};
|
|
170
|
+
export const checkboxConfig = {};
|
|
174
171
|
|
|
175
172
|
export const selectFiltersConfig = {
|
|
176
173
|
userRole: {
|
|
@@ -194,9 +191,17 @@ export const selectFiltersConfig = {
|
|
|
194
191
|
};
|
|
195
192
|
|
|
196
193
|
export const filtersConfig = {
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
search: "",
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export const defaultUrlParams = {
|
|
198
|
+
search: "",
|
|
199
|
+
userRole: null,
|
|
200
|
+
status: null,
|
|
199
201
|
};
|
|
200
202
|
|
|
201
|
-
export const
|
|
202
|
-
|
|
203
|
+
export const defaultTableFilters = {
|
|
204
|
+
search: "",
|
|
205
|
+
userRole: null,
|
|
206
|
+
status: null,
|
|
207
|
+
};
|
|
@@ -31,6 +31,9 @@ export default function Users({
|
|
|
31
31
|
updateUser = () => {},
|
|
32
32
|
addUser = () => {},
|
|
33
33
|
transferAdmin = () => {},
|
|
34
|
+
inviteCompanyAccount = () => {},
|
|
35
|
+
companyId,
|
|
36
|
+
handleError = () => {},
|
|
34
37
|
}) {
|
|
35
38
|
const [hasError, setHasError] = useState(false);
|
|
36
39
|
const [showFilters, setShowFilters] = useState(false);
|
|
@@ -60,10 +63,10 @@ export default function Users({
|
|
|
60
63
|
userRole: userRoles.filter((u) => !u.isForAppAdmin),
|
|
61
64
|
status: accountStatuses,
|
|
62
65
|
};
|
|
63
|
-
}, [userRoles]);
|
|
66
|
+
}, [userRoles, accountStatuses]);
|
|
64
67
|
|
|
65
68
|
const canClearSearch = useMemo(() => {
|
|
66
|
-
return !!activeFilters.search;
|
|
69
|
+
return !!activeFilters.search || !!activeFilters.userRole || !!activeFilters.status;
|
|
67
70
|
}, [activeFilters]);
|
|
68
71
|
|
|
69
72
|
const onDeleteUserClick = useCallback(
|
|
@@ -173,14 +176,17 @@ export default function Users({
|
|
|
173
176
|
onClose={() => setTransferModalVisible(false)}
|
|
174
177
|
/>
|
|
175
178
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
<NewUser
|
|
180
|
+
t={t}
|
|
181
|
+
isOpen={newUserModalVisible}
|
|
182
|
+
onClose={() => setNewUserModalVisible(false)}
|
|
183
|
+
userRoles={userRoles}
|
|
184
|
+
addUser={addUser}
|
|
185
|
+
module={module}
|
|
186
|
+
inviteCompanyAccount={inviteCompanyAccount}
|
|
187
|
+
companyId={companyId}
|
|
188
|
+
handleError={handleError}
|
|
189
|
+
/>
|
|
184
190
|
</div>
|
|
185
191
|
);
|
|
186
192
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { findOptions } from "../../../../../../../../helpers/StringHelper.js";
|
|
2
2
|
import Users from "../Users/index.jsx";
|
|
3
|
-
|
|
3
|
+
import AdminService from "../../../../../../../services/AdminService.js";
|
|
4
4
|
import { renderStatus } from "./helpers.js";
|
|
5
5
|
|
|
6
6
|
const isView = true;
|
|
@@ -30,6 +30,7 @@ export default function View({
|
|
|
30
30
|
location={location}
|
|
31
31
|
accountStatuses={accountStatuses}
|
|
32
32
|
module={module}
|
|
33
|
+
inviteCompanyAccount={AdminService.inviteCompanyAccount}
|
|
33
34
|
/>
|
|
34
35
|
);
|
|
35
36
|
}
|
|
@@ -40,6 +40,7 @@ function AdminView({
|
|
|
40
40
|
handleError,
|
|
41
41
|
toggleAccountStatus,
|
|
42
42
|
transferAdmin,
|
|
43
|
+
inviteCompanyAccount,
|
|
43
44
|
}) {
|
|
44
45
|
const conf = useMemo(() => config.find((c) => c.key === group), [group]);
|
|
45
46
|
const [loading, setLoading] = useState(false);
|
|
@@ -55,7 +56,6 @@ function AdminView({
|
|
|
55
56
|
}, [data]);
|
|
56
57
|
|
|
57
58
|
const goToView = useCallback(() => {
|
|
58
|
-
console.log("goToView");
|
|
59
59
|
changeNotificationState({
|
|
60
60
|
onYes: () => {
|
|
61
61
|
setEditData(data);
|
|
@@ -63,7 +63,7 @@ function AdminView({
|
|
|
63
63
|
goTo(`/app/accounts/view/${id}/${group}`);
|
|
64
64
|
},
|
|
65
65
|
});
|
|
66
|
-
}, [goTo, changeNotificationState, data]);
|
|
66
|
+
}, [goTo, changeNotificationState, data, id, group]);
|
|
67
67
|
|
|
68
68
|
const breadCrumbs = useMemo(() => {
|
|
69
69
|
return renderBreadCrumbs({
|
|
@@ -99,9 +99,9 @@ function AdminView({
|
|
|
99
99
|
setIsChanged(false);
|
|
100
100
|
setLoading(false);
|
|
101
101
|
} catch (err) {
|
|
102
|
-
|
|
102
|
+
handleError?.(err);
|
|
103
103
|
}
|
|
104
|
-
}, [id]);
|
|
104
|
+
}, [id, getAccountData, module, handleError]);
|
|
105
105
|
|
|
106
106
|
useEffect(() => {
|
|
107
107
|
fetchData();
|
|
@@ -132,30 +132,69 @@ function AdminView({
|
|
|
132
132
|
const { accountType, ...rest } = _data;
|
|
133
133
|
const _accountType = accountType || editData.accountType;
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
135
|
+
const allUsers = editData?.users || [];
|
|
136
|
+
const existingUsers = allUsers.filter(u => !u.pendingCompanyId);
|
|
137
|
+
const pendingUsers = allUsers.filter(u => u.pendingCompanyId);
|
|
138
|
+
|
|
139
|
+
console.log('Save operation:', {
|
|
140
|
+
totalUsers: allUsers.length,
|
|
141
|
+
existingUsers: existingUsers.length,
|
|
142
|
+
pendingUsers: pendingUsers.length,
|
|
143
|
+
accountId: editData.id
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const newData = {
|
|
147
|
+
...rest,
|
|
148
|
+
users: existingUsers.map((v) => ({
|
|
149
|
+
...v,
|
|
150
|
+
status: v.status === "unsaved" ? "active" : v.status,
|
|
151
|
+
})),
|
|
152
|
+
apps: editData?.apps?.map((a) => {
|
|
153
|
+
if (a.app === module) {
|
|
154
|
+
return { ...a, interface: _accountType };
|
|
155
|
+
}
|
|
156
|
+
return a;
|
|
157
|
+
}),
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
await updateAccount({ id: editData.id, data: newData });
|
|
162
|
+
|
|
163
|
+
console.log('Checking for pending users...', {
|
|
164
|
+
hasPendingUsers: pendingUsers.length > 0,
|
|
165
|
+
hasInviteFunction: !!inviteCompanyAccount,
|
|
166
|
+
pendingUsers: pendingUsers
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (pendingUsers.length > 0 && inviteCompanyAccount) {
|
|
170
|
+
console.log('Inviting pending users:', pendingUsers.length);
|
|
171
|
+
for (const user of pendingUsers) {
|
|
172
|
+
try {
|
|
173
|
+
const { pendingCompanyId, status, ...userDataToInvite } = user;
|
|
174
|
+
console.log('Sending invitation for:', user.email, userDataToInvite);
|
|
175
|
+
await inviteCompanyAccount({
|
|
176
|
+
companyId: editData.id,
|
|
177
|
+
data: {
|
|
178
|
+
...userDataToInvite,
|
|
179
|
+
pendingCompanyId,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
console.log('Invitation sent successfully for:', user.email);
|
|
183
|
+
} catch (inviteError) {
|
|
184
|
+
console.error('Failed to invite user:', user.email, inviteError);
|
|
185
|
+
handleError(inviteError);
|
|
144
186
|
}
|
|
145
|
-
|
|
146
|
-
}),
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
await updateAccount({ id: editData.id, data: newData });
|
|
151
|
-
await fetchData();
|
|
152
|
-
message.success(t("Information saved successfully"));
|
|
153
|
-
setNotificationMode(NOTIFICATION_MODE.EMPTY);
|
|
154
|
-
setIsChanged(false);
|
|
155
|
-
} catch (err) {
|
|
156
|
-
handleError(err);
|
|
187
|
+
}
|
|
157
188
|
}
|
|
158
189
|
|
|
190
|
+
await fetchData();
|
|
191
|
+
message.success(t("Information saved successfully"));
|
|
192
|
+
setNotificationMode(NOTIFICATION_MODE.EMPTY);
|
|
193
|
+
setIsChanged(false);
|
|
194
|
+
} catch (err) {
|
|
195
|
+
handleError(err);
|
|
196
|
+
}
|
|
197
|
+
|
|
159
198
|
setLoading(false);
|
|
160
199
|
})
|
|
161
200
|
.catch(() => {});
|
|
@@ -167,7 +206,7 @@ function AdminView({
|
|
|
167
206
|
onClick: goToView,
|
|
168
207
|
},
|
|
169
208
|
];
|
|
170
|
-
}, [t, mode, MainForm, goToView, isChanged, editData, fetchData]);
|
|
209
|
+
}, [t, mode, MainForm, goToView, isChanged, editData, fetchData, updateAccount, handleError, setNotificationMode, module, inviteCompanyAccount]);
|
|
171
210
|
|
|
172
211
|
if (!conf) {
|
|
173
212
|
return <NotFound />;
|
|
@@ -205,6 +244,7 @@ function AdminView({
|
|
|
205
244
|
accountStatuses={accountStatuses}
|
|
206
245
|
module={module}
|
|
207
246
|
transferAdmin={transferAdmin}
|
|
247
|
+
inviteCompanyAccount={inviteCompanyAccount}
|
|
208
248
|
/>
|
|
209
249
|
) : (
|
|
210
250
|
<View
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
|
+
import { Checkbox, Form, Input, message } from 'antd';
|
|
3
|
+
import DafButton from '../../../Button/index.jsx';
|
|
4
|
+
import Loading from "../../../Loading/index.jsx";
|
|
5
|
+
|
|
6
|
+
export default function AppInvitation({
|
|
7
|
+
// Redux State
|
|
8
|
+
errors,
|
|
9
|
+
user,
|
|
10
|
+
invitationSuccess,
|
|
11
|
+
// Actions
|
|
12
|
+
confirmInvitation,
|
|
13
|
+
getUserFromInvitation,
|
|
14
|
+
// Configuration
|
|
15
|
+
Layout,
|
|
16
|
+
redirectPath = "/",
|
|
17
|
+
loginPath = "/login",
|
|
18
|
+
appRedirectPath = "/app",
|
|
19
|
+
params: propParams = {},
|
|
20
|
+
}) {
|
|
21
|
+
const { t } = useTranslation();
|
|
22
|
+
const routeParams = useParams();
|
|
23
|
+
const { app, companyCode, userCode } = { ...routeParams, ...propParams };
|
|
24
|
+
const [passwords] = Form.useForm();
|
|
25
|
+
const [checking, setChecking] = useState(true);
|
|
26
|
+
const goTo = useNavigate();
|
|
27
|
+
const [termsAgreed, setTermsAgreed] = useState(false);
|
|
28
|
+
const [passwordReseted, setPasswordReseted] = useState(false);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (companyCode && userCode) {
|
|
32
|
+
getUserFromInvitation({ companyCode, userCode }, () => {
|
|
33
|
+
setChecking(false);
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
setChecking(false);
|
|
37
|
+
}
|
|
38
|
+
}, [companyCode, userCode, getUserFromInvitation]);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (invitationSuccess && user && user.inviteToken) {
|
|
42
|
+
confirmInvitation(
|
|
43
|
+
{},
|
|
44
|
+
(data) => {
|
|
45
|
+
if (data.token) {
|
|
46
|
+
localStorage.setItem('token', data.token);
|
|
47
|
+
}
|
|
48
|
+
message.success(t('Invitation accepted'));
|
|
49
|
+
// Fix: ensure we don't rely on a variable from useParams that might not exist
|
|
50
|
+
// Just use the configured redirectPath
|
|
51
|
+
goTo(redirectPath);
|
|
52
|
+
},
|
|
53
|
+
{ companyCode, userCode }
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}, [invitationSuccess, user, confirmInvitation, goTo, redirectPath, companyCode, userCode, t]);
|
|
57
|
+
|
|
58
|
+
const displayError = (name) => {
|
|
59
|
+
return errors && errors[name] && errors[name].length > 0 && {
|
|
60
|
+
help: errors[name][0],
|
|
61
|
+
validateStatus: 'error',
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const subTitle = !passwordReseted ? 'Set up your password and agree with out terms and conditions.' :
|
|
66
|
+
isMobile ? 'Your account has been successfully set up. To log in use a desktop device.'
|
|
67
|
+
: 'Your account has been successfully set up. Please click the button below to log in.';
|
|
68
|
+
const title = passwordReseted ? 'Thank You!' : undefined;
|
|
69
|
+
|
|
70
|
+
if (checking && !invitationSuccess) {
|
|
71
|
+
return <Loading />;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// If auto-confirming (inviteToken present), we might want to show loading or nothing until redirect
|
|
75
|
+
if (invitationSuccess && user && user.inviteToken) {
|
|
76
|
+
// The useEffect will handle the redirect/confirm.
|
|
77
|
+
// We can show loading here too or just return null.
|
|
78
|
+
// Original code: checks invitationSuccess && !user.inviteToken for form, else redirect.
|
|
79
|
+
return <Loading />;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (invitationSuccess && !user.inviteToken) {
|
|
83
|
+
const Content = (
|
|
84
|
+
<>
|
|
85
|
+
{passwordReseted ? (
|
|
86
|
+
<div>
|
|
87
|
+
{isMobile ? null : (
|
|
88
|
+
<DafButton
|
|
89
|
+
type="primary"
|
|
90
|
+
className="normal-br"
|
|
91
|
+
onClick={() => {
|
|
92
|
+
window.location.href = loginPath;
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
{t('Log In')}
|
|
96
|
+
</DafButton>
|
|
97
|
+
)}
|
|
98
|
+
</div>
|
|
99
|
+
) : (
|
|
100
|
+
<>
|
|
101
|
+
<Form name="password" layout="vertical" form={passwords} >
|
|
102
|
+
<Form.Item
|
|
103
|
+
required
|
|
104
|
+
name="password"
|
|
105
|
+
{...displayError('password')}
|
|
106
|
+
label={t("Password")}
|
|
107
|
+
rules={[{
|
|
108
|
+
required: true,
|
|
109
|
+
message: t("errors::password should not be empty")
|
|
110
|
+
}]}>
|
|
111
|
+
<Input.Password size="large" placeholder={t("Password")} />
|
|
112
|
+
</Form.Item>
|
|
113
|
+
<Form.Item
|
|
114
|
+
required
|
|
115
|
+
name="confirmPassword"
|
|
116
|
+
{...displayError('confirmPassword')}
|
|
117
|
+
label={t("Confirm Password")}
|
|
118
|
+
dependencies={['password']}
|
|
119
|
+
rules={[
|
|
120
|
+
{
|
|
121
|
+
required: true,
|
|
122
|
+
message: t("errors::password should not be empty"),
|
|
123
|
+
},
|
|
124
|
+
({ getFieldValue }) => ({
|
|
125
|
+
validator(rule, value) {
|
|
126
|
+
if (!value || getFieldValue('password') === value) {
|
|
127
|
+
return Promise.resolve();
|
|
128
|
+
}
|
|
129
|
+
return Promise.reject(t('errors::passwordNotMatch'));
|
|
130
|
+
},
|
|
131
|
+
}),
|
|
132
|
+
]}>
|
|
133
|
+
<Input.Password size="large" placeholder={t("Confirm Password")} />
|
|
134
|
+
</Form.Item>
|
|
135
|
+
<Form.Item
|
|
136
|
+
name="mailUpdates" valuePropName="checked" noStyle>
|
|
137
|
+
<Checkbox>{t("Sign up to receive updates")}</Checkbox>
|
|
138
|
+
</Form.Item>
|
|
139
|
+
<Form.Item
|
|
140
|
+
name="agreeTerms" valuePropName="checked" noStyle>
|
|
141
|
+
<Checkbox
|
|
142
|
+
checked={termsAgreed}
|
|
143
|
+
onChange={(e) => setTermsAgreed(e.target.checked)}
|
|
144
|
+
>
|
|
145
|
+
<p className="mb-0">
|
|
146
|
+
{t('Agree to the Terms of Use of this application and the Privacy Policy')}
|
|
147
|
+
</p>
|
|
148
|
+
</Checkbox>
|
|
149
|
+
</Form.Item>
|
|
150
|
+
</Form>
|
|
151
|
+
<div className="buttons">
|
|
152
|
+
<DafButton
|
|
153
|
+
className="normal-br"
|
|
154
|
+
type="primary"
|
|
155
|
+
block
|
|
156
|
+
size="large"
|
|
157
|
+
disabled={!termsAgreed}
|
|
158
|
+
onClick={() => {
|
|
159
|
+
passwords.validateFields().then(data => {
|
|
160
|
+
const { password, mailUpdates } = data;
|
|
161
|
+
confirmInvitation(
|
|
162
|
+
{ password, mailUpdates },
|
|
163
|
+
() => { },
|
|
164
|
+
{ companyCode, userCode }
|
|
165
|
+
);
|
|
166
|
+
setPasswordReseted(true);
|
|
167
|
+
});
|
|
168
|
+
}}
|
|
169
|
+
>
|
|
170
|
+
{t("Confirm")}
|
|
171
|
+
</DafButton>
|
|
172
|
+
</div>
|
|
173
|
+
</>
|
|
174
|
+
)}
|
|
175
|
+
</>
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
if (Layout) {
|
|
179
|
+
// Assuming Layout accepts these props as per Nashiriki AuthLayout
|
|
180
|
+
return <Layout app={app} step={1} subTitle={subTitle} title={title}>{Content}</Layout>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div style={{ padding: 20, maxWidth: 400, margin: '0 auto' }}>
|
|
185
|
+
<h2>{title}</h2>
|
|
186
|
+
<p>{subTitle}</p>
|
|
187
|
+
{Content}
|
|
188
|
+
</div>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return user ? <Navigate to={appRedirectPath} /> : <Navigate to={redirectPath} />;
|
|
193
|
+
}
|