datastake-daf 0.6.711 → 0.6.713
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 +347 -8
- package/dist/hooks/index.js +96 -4658
- package/dist/utils/index.js +120 -2
- package/package.json +1 -1
- package/src/@daf/core/components/Icon/configs/UnderDev.js +15 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Accounts.jsx +109 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/AccountsView.jsx +73 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Dashboard.jsx +77 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/Users.jsx +117 -0
- package/src/@daf/core/components/Screens/Admin/AdminScreens/index.js +11 -0
- package/src/@daf/core/components/Screens/Admin/adminRoutes.js +104 -0
- package/src/@daf/hooks/useAdminDashboard.js +84 -0
- package/src/@daf/utils/adminConfigBuilders.js +102 -0
- package/src/hooks.js +2 -1
- package/src/index.js +19 -1
- package/src/utils.js +7 -1
- 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,84 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generic hook for fetching admin dashboard data
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} config - Configuration object
|
|
7
|
+
* @param {Object} config.dashboardService - Service object with getDashboardData method
|
|
8
|
+
* @param {Function} config.onError - Error handler function
|
|
9
|
+
*
|
|
10
|
+
* @returns {Object} Dashboard data and loading states
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const { data, loading, userGrowthData, fetchUserGrowth } = useAdminDashboard({
|
|
14
|
+
* dashboardService: {
|
|
15
|
+
* getDashboardData: () => DashboardService.getAdminStats(),
|
|
16
|
+
* getUserGrowth: (params) => DashboardService.getUserGrowth(params)
|
|
17
|
+
* },
|
|
18
|
+
* onError: (err) => console.error(err)
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
export function useAdminDashboard({ dashboardService, onError }) {
|
|
22
|
+
const [data, setData] = useState({});
|
|
23
|
+
const [loading, setLoading] = useState(false);
|
|
24
|
+
const [userGrowthData, setUserGrowthData] = useState([]);
|
|
25
|
+
const [userGrowthDataLoading, setUserGrowthDataLoading] = useState(false);
|
|
26
|
+
|
|
27
|
+
const fetchDashboardData = useCallback(async () => {
|
|
28
|
+
if (!dashboardService?.getDashboardData) {
|
|
29
|
+
console.warn("dashboardService.getDashboardData not provided");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setLoading(true);
|
|
34
|
+
try {
|
|
35
|
+
const response = await dashboardService.getDashboardData();
|
|
36
|
+
setData(response || {});
|
|
37
|
+
} catch (err) {
|
|
38
|
+
if (onError) {
|
|
39
|
+
onError(err);
|
|
40
|
+
} else {
|
|
41
|
+
console.error("Error fetching dashboard data:", err);
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
setLoading(false);
|
|
45
|
+
}
|
|
46
|
+
}, [dashboardService, onError]);
|
|
47
|
+
|
|
48
|
+
const fetchUserGrowth = useCallback(
|
|
49
|
+
async (params) => {
|
|
50
|
+
if (!dashboardService?.getUserGrowth) {
|
|
51
|
+
console.warn("dashboardService.getUserGrowth not provided");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
setUserGrowthDataLoading(true);
|
|
56
|
+
try {
|
|
57
|
+
const response = await dashboardService.getUserGrowth(params);
|
|
58
|
+
setUserGrowthData(response || []);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
if (onError) {
|
|
61
|
+
onError(err);
|
|
62
|
+
} else {
|
|
63
|
+
console.error("Error fetching user growth:", err);
|
|
64
|
+
}
|
|
65
|
+
} finally {
|
|
66
|
+
setUserGrowthDataLoading(false);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
[dashboardService, onError]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
fetchDashboardData();
|
|
74
|
+
}, [fetchDashboardData]);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
data,
|
|
78
|
+
loading,
|
|
79
|
+
userGrowthData,
|
|
80
|
+
fetchUserGrowth,
|
|
81
|
+
userGrowthDataLoading,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for building admin dashboard configurations
|
|
3
|
+
* These functions transform simple data arrays into full configuration objects
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Format string to kebab-case
|
|
8
|
+
* @param {string} str - String to format
|
|
9
|
+
* @returns {string} Kebab-cased string
|
|
10
|
+
*/
|
|
11
|
+
export function formatToKebabCase(str) {
|
|
12
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Build action widgets configuration
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} params
|
|
19
|
+
* @param {Array} params.widgets - Array of widget definitions
|
|
20
|
+
* @param {Function} params.getRedirectLink - Function to transform paths
|
|
21
|
+
* @param {Function} params.t - Translation function
|
|
22
|
+
*
|
|
23
|
+
* @returns {Array} Configured action widgets
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const widgets = buildActionWidgetsConfig({
|
|
27
|
+
* widgets: [
|
|
28
|
+
* { icon: "Search", title: "review-requests", path: "/accounts?pending=true" }
|
|
29
|
+
* ],
|
|
30
|
+
* getRedirectLink: (path) => `/app${path}`,
|
|
31
|
+
* t: (key) => translations[key]
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
export function buildActionWidgetsConfig({ widgets = [], getRedirectLink, t }) {
|
|
35
|
+
return widgets.map((widget) => ({
|
|
36
|
+
icon: widget.icon,
|
|
37
|
+
title: widget.title,
|
|
38
|
+
goToPath: getRedirectLink ? getRedirectLink(widget.path) : widget.path,
|
|
39
|
+
disabled: widget.disabled || false,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Build key indicators configuration
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} params
|
|
47
|
+
* @param {Object} params.keyIndicatorsData - Object with indicator keys and values
|
|
48
|
+
* @param {Array} params.paths - Array of paths corresponding to each indicator
|
|
49
|
+
* @param {Function} params.getRedirectLink - Function to transform paths
|
|
50
|
+
*
|
|
51
|
+
* @returns {Array} Configured key indicators
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const indicators = buildKeyIndicatorsConfig({
|
|
55
|
+
* keyIndicatorsData: { totalUsers: 100, totalAccounts: 50 },
|
|
56
|
+
* paths: ["/users", "/accounts"],
|
|
57
|
+
* getRedirectLink: (path) => `/app${path}`
|
|
58
|
+
* });
|
|
59
|
+
*/
|
|
60
|
+
export function buildKeyIndicatorsConfig({ keyIndicatorsData = {}, paths = [], getRedirectLink }) {
|
|
61
|
+
const keys = Object.keys(keyIndicatorsData);
|
|
62
|
+
|
|
63
|
+
return keys.map((key, index) => ({
|
|
64
|
+
title: formatToKebabCase(key),
|
|
65
|
+
valueToShow: keyIndicatorsData[key],
|
|
66
|
+
goToPath: getRedirectLink && paths[index] ? getRedirectLink(paths[index]) : paths[index] || "#",
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Build breadcrumbs configuration
|
|
72
|
+
*
|
|
73
|
+
* @param {Object} params
|
|
74
|
+
* @param {string} params.view - View type (e.g., "accounts", "users")
|
|
75
|
+
* @param {Function} params.t - Translation function
|
|
76
|
+
* @param {Function} params.goTo - Navigation function
|
|
77
|
+
* @param {boolean} params.isView - Is in view mode
|
|
78
|
+
* @param {boolean} params.isEdit - Is in edit mode
|
|
79
|
+
* @param {string} params.id - Entity ID
|
|
80
|
+
* @param {string} params.mode - Current mode
|
|
81
|
+
* @param {string} params.group - Current group/section
|
|
82
|
+
* @param {string} params.basePath - Base path for the view
|
|
83
|
+
*
|
|
84
|
+
* @returns {Array} Breadcrumb configuration
|
|
85
|
+
*/
|
|
86
|
+
export function buildBreadcrumbs({ view, t, goTo, isView, isEdit, id, mode, group, basePath = "/app" }) {
|
|
87
|
+
return [
|
|
88
|
+
{
|
|
89
|
+
label: t("Admin"),
|
|
90
|
+
path: basePath,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
label: t(view.charAt(0).toUpperCase() + view.slice(1)),
|
|
94
|
+
path: `${basePath}/${view}`,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: isView ? t("View") : t("Edit"),
|
|
98
|
+
path: `${basePath}/${view}/${mode}/${id}/${group}`,
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
|
package/src/hooks.js
CHANGED
|
@@ -11,4 +11,5 @@ export { useMapOnExpandableWidget } from "./@daf/hooks/useMapOnExpandableWidget"
|
|
|
11
11
|
export { checkPermission, checkPermissionList, usePermissions } from "./@daf/hooks/usePermissions";
|
|
12
12
|
export { useFirebase } from "./@daf/hooks/useFirebase.js"
|
|
13
13
|
export { useIsDatastake } from "./@daf/hooks/useIsDatastake.js"
|
|
14
|
-
export { useWidgetFetch } from "./@daf/hooks/useWidgetFetch.js"
|
|
14
|
+
export { useWidgetFetch } from "./@daf/hooks/useWidgetFetch.js"
|
|
15
|
+
export { useAdminDashboard } from "./@daf/hooks/useAdminDashboard.js"
|
package/src/index.js
CHANGED
|
@@ -146,13 +146,31 @@ export { default as StakeholderMappings } from "./@daf/core/components/Graphs/St
|
|
|
146
146
|
|
|
147
147
|
//* ------------------------------ Screens ------------------------------
|
|
148
148
|
export { default as BaseScreen } from "./@daf/core/components/Screens/BaseScreen/index.jsx";
|
|
149
|
-
// Admin
|
|
149
|
+
// Admin - Base Components
|
|
150
150
|
export { default as AdminDashboard } from "./@daf/core/components/Screens/Admin/AdminDashboard/index.jsx";
|
|
151
151
|
export { default as UserTable } from "./@daf/core/components/Screens/Admin/AdminTables/UserTable/index.jsx";
|
|
152
152
|
export { default as AccountTable } from "./@daf/core/components/Screens/Admin/AdminTables/AccountTable/index.jsx";
|
|
153
153
|
export { default as LocationTable } from "./@daf/core/components/Screens/Admin/AdminTables/LocationTable/index.jsx";
|
|
154
154
|
export { default as SubjectsTable } from "./@daf/core/components/Screens/Admin/AdminTables/SubjectsTable/index.jsx";
|
|
155
155
|
export { default as AdminView } from "./@daf/core/components/Screens/Admin/AdminViews/index.jsx";
|
|
156
|
+
|
|
157
|
+
// Admin - Ready-to-use Screen Components (Route Wrappers)
|
|
158
|
+
export {
|
|
159
|
+
AdminDashboardScreen,
|
|
160
|
+
AdminUsersScreen,
|
|
161
|
+
AdminAccountsScreen,
|
|
162
|
+
AdminAccountsViewScreen,
|
|
163
|
+
} from "./@daf/core/components/Screens/Admin/AdminScreens/index.js";
|
|
164
|
+
|
|
165
|
+
// Admin - Modals
|
|
166
|
+
export {
|
|
167
|
+
AddAccountModal,
|
|
168
|
+
AddUserModal,
|
|
169
|
+
AddUserToAccountModal,
|
|
170
|
+
} from "./@daf/core/components/Screens/Admin/AdminModals/index.js";
|
|
171
|
+
|
|
172
|
+
// Admin - Routes Generator
|
|
173
|
+
export { getAdminRoutes } from "./@daf/core/components/Screens/Admin/adminRoutes.js";
|
|
156
174
|
//Error
|
|
157
175
|
export { default as NotFound } from "./@daf/core/components/Screens/NotFound/index.jsx";
|
|
158
176
|
export { default as InformationUnavailable } from "./@daf/core/components/Screens/InformationUnavailable/index.jsx";
|
package/src/utils.js
CHANGED
|
@@ -52,4 +52,10 @@ export { createTheme, createAdminTheme } from './helpers/theme.js';
|
|
|
52
52
|
|
|
53
53
|
export { getRedirectLink } from "./@daf/hooks/useIsDatastake.js"
|
|
54
54
|
|
|
55
|
-
export { getSourceString, getDivergenceOrEqual } from './helpers/stringHelper.jsx'
|
|
55
|
+
export { getSourceString, getDivergenceOrEqual } from './helpers/stringHelper.jsx'
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
buildActionWidgetsConfig,
|
|
59
|
+
buildKeyIndicatorsConfig,
|
|
60
|
+
buildBreadcrumbs
|
|
61
|
+
} from './@daf/utils/adminConfigBuilders.js'
|
package/build/favicon.ico
DELETED
|
Binary file
|
package/build/logo192.png
DELETED
|
Binary file
|
package/build/logo512.png
DELETED
|
Binary file
|
package/build/manifest.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"short_name": "React App",
|
|
3
|
-
"name": "Create React App Sample",
|
|
4
|
-
"icons": [
|
|
5
|
-
{
|
|
6
|
-
"src": "favicon.ico",
|
|
7
|
-
"sizes": "64x64 32x32 24x24 16x16",
|
|
8
|
-
"type": "image/x-icon"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"src": "logo192.png",
|
|
12
|
-
"type": "image/png",
|
|
13
|
-
"sizes": "192x192"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"src": "logo512.png",
|
|
17
|
-
"type": "image/png",
|
|
18
|
-
"sizes": "512x512"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"start_url": ".",
|
|
22
|
-
"display": "standalone",
|
|
23
|
-
"theme_color": "#000000",
|
|
24
|
-
"background_color": "#ffffff"
|
|
25
|
-
}
|
package/build/robots.txt
DELETED