Skip to content

Commit b102293

Browse files
committed
fix(super-admin): improve super admin panel UX and add user management
## Changes ### Login redirect - Super admin now always redirects to /super-admin after login instead of the regular dashboard, regardless of whether organizations exist. ### Organizations page (/super-admin) - Removed decorative icons from table cells and action buttons. - Renamed "Users" action button to "View users". - Set 8px gap between action buttons for consistent spacing. ### All Users page (/super-admin/users) - Added "Invite user" button with modal (includes organization picker). - Added row click to open an edit user modal (name, surname, email, role, joined date, last login). - Removed decorative icons from table cells and action buttons. - Removed inline user count text (moved to sidebar pill instead). - Set 8px gap between filter controls for consistent spacing. - Extracted EditUserModal and InviteUserModal as isolated components to reduce parent state from 16+ variables down to 3 toggles. ### Org Users page (/super-admin/organizations/:id/users) - Removed decorative icons from email column and remove button. ### Sidebar - Added user count pill badge on the "Users" menu item. - Uses a dedicated lightweight count endpoint instead of fetching all users. ### Settings page (/super-admin/settings) - Changed title from "Super Admin Settings" to "Settings". - Added explicit breadcrumbs with settings icon. - Shows "Password" breadcrumb when on the password tab. ### Backend - Added PATCH /super-admin/users/:id endpoint for editing user details. - Added GET /super-admin/users/count endpoint for sidebar badge. - Update query uses CTE with RETURNING to avoid a second SELECT. ### Code quality - Extracted ROLE_OPTIONS and ROLE_COLORS as shared constants in roles.ts, eliminating duplication across 3 files. - Replaced native <select> elements with the project Select component.
1 parent d5cee28 commit b102293

File tree

10 files changed

+470
-93
lines changed

10 files changed

+470
-93
lines changed

Clients/src/application/constants/roles.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,20 @@ export const ROLES = {
44
3 : "Editor",
55
4 : "Auditor",
66
5 : "Super Admin"
7-
}
7+
}
8+
9+
/** Assignable role options (excludes Super Admin) for dropdowns */
10+
export const ROLE_OPTIONS = [
11+
{ value: 1, label: "Admin" },
12+
{ value: 2, label: "Reviewer" },
13+
{ value: 3, label: "Editor" },
14+
{ value: 4, label: "Auditor" },
15+
] as const;
16+
17+
/** Role badge colors for table display */
18+
export const ROLE_COLORS: Record<string, { bg: string; text: string }> = {
19+
Admin: { bg: "#eff6ff", text: "#2563eb" },
20+
Reviewer: { bg: "#faf5ff", text: "#9333ea" },
21+
Editor: { bg: "#f0fdf4", text: "#16a34a" },
22+
Auditor: { bg: "#fefce8", text: "#ca8a04" },
23+
};

Clients/src/application/repository/superAdmin.repository.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export async function updateOrganization(id: number, data: { name?: string; logo
4747
return apiServices.patch(`/super-admin/organizations/${id}`, data);
4848
}
4949

50+
export async function getUserCount() {
51+
return apiServices.get<ServerResponse<{ count: number }>>("/super-admin/users/count");
52+
}
53+
5054
export async function getAllUsers() {
5155
return apiServices.get<ServerResponse<GlobalUser[]>>("/super-admin/users");
5256
}
@@ -59,6 +63,10 @@ export async function inviteUserToOrg(orgId: number, data: { email: string; name
5963
return apiServices.post(`/super-admin/organizations/${orgId}/invite`, data);
6064
}
6165

66+
export async function updateUser(userId: number, data: { name?: string; surname?: string; email?: string; roleId?: number }) {
67+
return apiServices.patch(`/super-admin/users/${userId}`, data);
68+
}
69+
6270
export async function removeUser(userId: number) {
6371
return apiServices.delete(`/super-admin/users/${userId}`);
6472
}

Clients/src/presentation/components/SuperAdminSidebar/index.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
import React from "react";
1+
import React, { useState, useEffect, useCallback } from "react";
22
import { useLocation, useNavigate } from "react-router";
33
import { Building, Users } from "lucide-react";
44
import SidebarShell, { SidebarMenuItem } from "../Sidebar/SidebarShell";
5+
import { getUserCount } from "../../../application/repository/superAdmin.repository";
56

67
const SuperAdminSidebar: React.FC = () => {
78
const navigate = useNavigate();
89
const location = useLocation();
10+
const [userCount, setUserCount] = useState<number>(0);
11+
12+
const fetchUserCount = useCallback(async () => {
13+
try {
14+
const response = await getUserCount();
15+
const serverData = response.data as any;
16+
setUserCount(serverData?.data?.count ?? 0);
17+
} catch {
18+
// Silently fail — count will show 0
19+
}
20+
}, []);
21+
22+
useEffect(() => {
23+
fetchUserCount();
24+
}, [fetchUserCount]);
925

1026
const topItems: SidebarMenuItem[] = [
1127
{
@@ -19,6 +35,7 @@ const SuperAdminSidebar: React.FC = () => {
1935
label: "Users",
2036
icon: <Users size={16} strokeWidth={1.5} />,
2137
path: "/super-admin/users",
38+
count: userCount,
2239
},
2340
];
2441

Clients/src/presentation/pages/Authentication/Login/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,18 @@ const Login: React.FC = () => {
175175
localStorage.setItem("root_version", __APP_VERSION__);
176176
logEngine({ type: "info", message: "Super-admin login successful." });
177177

178-
// Auto-select the first organization so super-admin sees the normal UI
178+
// Auto-select the first organization so super-admin can view org data
179179
try {
180180
const orgsResponse = await getOrganizations();
181181
const orgsData = (orgsResponse.data as any)?.data || [];
182182
if (orgsData.length > 0) {
183183
dispatch(setActiveOrganizationId(orgsData[0].id));
184-
setIsSubmitting(false);
185-
navigate("/");
186-
return;
187184
}
188185
} catch (err) {
189186
console.error("Failed to fetch organizations for auto-select:", err);
190187
}
191188

192-
// No orgs available — go to super-admin panel to create one
189+
// Always go to super-admin panel
193190
setIsSubmitting(false);
194191
navigate("/super-admin");
195192
return;

0 commit comments

Comments
 (0)